Skip to content

Commit 5efddfc

Browse files
committed
switch to .net standard library, add missing fe_tobytes call
1 parent a1d500d commit 5efddfc

28 files changed

+92
-711
lines changed

curve25519Tests/AndroidJavaCompatibilityTests.cs renamed to curve25519-dotnet-tests/AndroidJavaCompatibilityTests.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
using System.Diagnostics;
2020
using System.Runtime.InteropServices.WindowsRuntime;
2121
using System.Text;
22-
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
2322
using org.whispersystems.curve25519;
2423
using org.whispersystems.curve25519.csharp;
25-
using Windows.Security.Cryptography;
26-
using Windows.Storage.Streams;
2724
using curve25519_dotnet.csharp;
25+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2826

2927
namespace curve25519Tests
3028
{
@@ -34,10 +32,12 @@ public class AndroidJavaCompatibilityTests
3432
#region Test helper code
3533
private Curve25519 curve25519;
3634
private const int EXPECTED_LEN = 32;
37-
private static byte[] GetRandomBuffer(int expectedLen)
35+
private static void Memset(byte[] buf, byte val)
3836
{
39-
IBuffer randomIBuffer = CryptographicBuffer.GenerateRandom((uint)expectedLen);
40-
return WindowsRuntimeBufferExtensions.ToArray(randomIBuffer, 0, expectedLen);
37+
for(int i=0;i<buf.Length;i++)
38+
{
39+
buf[i] = val;
40+
}
4141
}
4242
#endregion
4343

@@ -88,7 +88,7 @@ public void sha512_fast_test()
8888
}
8989

9090
[TestMethod]
91-
public void strict_fast_test(int silent)
91+
public void strict_fast_test()
9292
{
9393
byte[] unreduced1 = new byte[] {
9494
0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
@@ -299,7 +299,7 @@ public void xeddsa_fast_test()
299299
Assert.AreEqual(0, xeddsa.xed25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), "XEdDSA verify #1");
300300
signature[0] ^= 1;
301301
Assert.AreNotEqual(0, xeddsa.xed25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), "XEdDSA verify #2");
302-
pubkey[32] = 0xff;
302+
Memset(pubkey, 0xff);
303303
Assert.AreNotEqual(0, xeddsa.xed25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), "XEdDSA verify #3");
304304
}
305305

@@ -345,7 +345,7 @@ public void vxeddsa_fast_test()
345345
signature[0] ^= 1;
346346
Assert.AreNotEqual(0, vxeddsa.vxed25519_verify(sha512provider, vrf_out, signature, pubkey, msg, MSG_LEN), "VXEdDSA verify #2");
347347

348-
pubkey[32] = 0xff;
348+
Memset(pubkey, 0xff);
349349
Assert.AreNotEqual(0, vxeddsa.vxed25519_verify(sha512provider, vrf_out, signature, pubkey, msg, MSG_LEN), "VXEdDSA verify #3");
350350
Keygen.curve25519_keygen(pubkey, privkey);
351351

curve25519Tests/BasicTests.cs renamed to curve25519-dotnet-tests/BasicTests.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*/
1717

1818
using curve25519;
19-
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
19+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2020
using org.whispersystems.curve25519;
2121
using System;
2222
using System.Runtime.InteropServices.WindowsRuntime;
23+
using System.Security.Cryptography;
2324
using System.Text;
24-
using Windows.Security.Cryptography;
25-
using Windows.Storage.Streams;
2625

2726
namespace Curve25519WinRT.WindowsPhone_Tests
2827
{
@@ -34,8 +33,9 @@ public class BasicTests
3433
private const int EXPECTED_LEN = 32;
3534
private static byte[] GetRandomBuffer(int expectedLen)
3635
{
37-
IBuffer randomIBuffer = CryptographicBuffer.GenerateRandom((uint)expectedLen);
38-
return WindowsRuntimeBufferExtensions.ToArray(randomIBuffer, 0, expectedLen);
36+
byte[] buffer = new byte[expectedLen];
37+
RandomNumberGenerator.Create().GetBytes(buffer);
38+
return buffer;
3939
}
4040
#endregion
4141

curve25519Tests/ConversionRelatedTests.cs renamed to curve25519-dotnet-tests/ConversionRelatedTests.cs

+6-14
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
*/
1717

1818
using System;
19-
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
20-
using Windows.Security.Cryptography.Core;
21-
using Windows.Storage.Streams;
2219
using System.Runtime.InteropServices.WindowsRuntime;
20+
using System.Security.Cryptography;
2321
using curve25519.donna;
22+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2423

2524
namespace curve25519Tests
2625
{
@@ -104,19 +103,12 @@ public void TestSha512ProviderConsistency()
104103
byte[] digestActual = new byte[digestExpectedLength];
105104
provider.calculateDigest(digestActual, message, message.Length);
106105

107-
//The WinRT way
108-
HashAlgorithmProvider sha512Provider = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha512);
109-
IBuffer bMessage = WindowsRuntimeBufferExtensions.AsBuffer(message);
110-
IBuffer bDigest = sha512Provider.HashData(bMessage);
111-
byte[] digestWinRT = WindowsRuntimeBufferExtensions.ToArray(bDigest);
112-
113-
//The PCLCrypto way
114-
PCLCrypto.IHashAlgorithmProvider sha512PCLProvider = PCLCrypto.WinRTCrypto.HashAlgorithmProvider.OpenAlgorithm(PCLCrypto.HashAlgorithm.Sha512);
115-
byte[] digestPCL = sha512PCLProvider.HashData(message);
106+
//the dotnet standard way
107+
var sha = SHA512.Create();
108+
var shaHash = sha.ComputeHash(message);
116109

117110
//Did we get the same value for all ways?
118-
CollectionAssert.AreEqual(digestWinRT, digestActual);
119-
CollectionAssert.AreEqual(digestPCL, digestWinRT);
111+
CollectionAssert.AreEqual(shaHash, digestActual);
120112
}
121113

122114
[TestMethod]

curve25519Tests/JavaCompatibilityTests.cs renamed to curve25519-dotnet-tests/JavaCompatibilityTests.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
*/
1717

1818
using System;
19-
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
20-
using Windows.Storage.Streams;
21-
using Windows.Security.Cryptography;
2219
using System.Runtime.InteropServices.WindowsRuntime;
2320
using System.Collections.Generic;
2421
using org.whispersystems.curve25519;
2522
using org.whispersystems.curve25519.csharp;
2623
using System.Text;
2724
using curve25519;
25+
using Microsoft.VisualStudio.TestTools.UnitTesting;
26+
using System.Security.Cryptography;
2827

2928
namespace Curve25519WinRT.WindowsPhone_Tests
3029
{
@@ -45,11 +44,6 @@ public class JavaCompatibilityTests
4544
#region Test helper code
4645
private Curve25519 curve25519;
4746
private const int EXPECTED_LEN = 32;
48-
private static byte[] GetRandomBuffer(int expectedLen)
49-
{
50-
IBuffer randomIBuffer = CryptographicBuffer.GenerateRandom((uint)expectedLen);
51-
return WindowsRuntimeBufferExtensions.ToArray(randomIBuffer, 0, expectedLen);
52-
}
5347
#endregion
5448

5549
[TestInitialize]

curve25519Tests/PerformanceTests.cs renamed to curve25519-dotnet-tests/PerformanceTests.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
*/
1717

1818
using curve25519;
19-
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
19+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2020
using org.whispersystems.curve25519;
2121
using System;
2222
using System.Runtime.InteropServices.WindowsRuntime;
2323
using System.Text;
24-
using Windows.Security.Cryptography;
25-
using Windows.Storage.Streams;
2624

2725
namespace curve25519Tests
2826
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
12+
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\curve25519-dotnet\curve25519-dotnet.csproj" />
17+
</ItemGroup>
18+
19+
</Project>

curve25519-dotnet.sln

+42-40
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27428.2043
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "curve25519-dotnet", "curve25519-dotnet\curve25519-dotnet.csproj", "{C45AFFFF-2C87-436B-BCA0-E7F223965478}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "curve25519-dotnet", "curve25519-dotnet\curve25519-dotnet.csproj", "{93E57A57-76B7-4B72-915F-DEB83B3F6793}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "curve25519Tests", "curve25519Tests\curve25519Tests.csproj", "{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "curve25519-dotnet-tests", "curve25519-dotnet-tests\curve25519-dotnet-tests.csproj", "{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}"
9+
ProjectSection(ProjectDependencies) = postProject
10+
{93E57A57-76B7-4B72-915F-DEB83B3F6793} = {93E57A57-76B7-4B72-915F-DEB83B3F6793}
11+
EndProjectSection
912
EndProject
1013
Global
1114
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,44 +22,43 @@ Global
1922
Release|x86 = Release|x86
2023
EndGlobalSection
2124
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Debug|Any CPU.Build.0 = Debug|Any CPU
24-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Debug|ARM.ActiveCfg = Debug|Any CPU
25-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Debug|ARM.Build.0 = Debug|Any CPU
26-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Debug|x64.ActiveCfg = Debug|Any CPU
27-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Debug|x64.Build.0 = Debug|Any CPU
28-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Debug|x86.ActiveCfg = Debug|Any CPU
29-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Debug|x86.Build.0 = Debug|Any CPU
30-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Release|Any CPU.Build.0 = Release|Any CPU
32-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Release|ARM.ActiveCfg = Release|Any CPU
33-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Release|ARM.Build.0 = Release|Any CPU
34-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Release|x64.ActiveCfg = Release|Any CPU
35-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Release|x64.Build.0 = Release|Any CPU
36-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Release|x86.ActiveCfg = Release|Any CPU
37-
{C45AFFFF-2C87-436B-BCA0-E7F223965478}.Release|x86.Build.0 = Release|Any CPU
38-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|Any CPU.ActiveCfg = Debug|x86
39-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|ARM.ActiveCfg = Debug|ARM
40-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|ARM.Build.0 = Debug|ARM
41-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|ARM.Deploy.0 = Debug|ARM
42-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|x64.ActiveCfg = Debug|x64
43-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|x64.Build.0 = Debug|x64
44-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|x64.Deploy.0 = Debug|x64
45-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|x86.ActiveCfg = Debug|x86
46-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|x86.Build.0 = Debug|x86
47-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Debug|x86.Deploy.0 = Debug|x86
48-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|Any CPU.ActiveCfg = Release|x86
49-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|ARM.ActiveCfg = Release|ARM
50-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|ARM.Build.0 = Release|ARM
51-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|ARM.Deploy.0 = Release|ARM
52-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|x64.ActiveCfg = Release|x64
53-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|x64.Build.0 = Release|x64
54-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|x64.Deploy.0 = Release|x64
55-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|x86.ActiveCfg = Release|x86
56-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|x86.Build.0 = Release|x86
57-
{12D04A31-1196-4EA4-AA1A-CBDB78EE088A}.Release|x86.Deploy.0 = Release|x86
25+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Debug|ARM.ActiveCfg = Debug|Any CPU
28+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Debug|ARM.Build.0 = Debug|Any CPU
29+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Debug|x64.ActiveCfg = Debug|Any CPU
30+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Debug|x64.Build.0 = Debug|Any CPU
31+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Debug|x86.ActiveCfg = Debug|Any CPU
32+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Debug|x86.Build.0 = Debug|Any CPU
33+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Release|ARM.ActiveCfg = Release|Any CPU
36+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Release|ARM.Build.0 = Release|Any CPU
37+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Release|x64.ActiveCfg = Release|Any CPU
38+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Release|x64.Build.0 = Release|Any CPU
39+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Release|x86.ActiveCfg = Release|Any CPU
40+
{93E57A57-76B7-4B72-915F-DEB83B3F6793}.Release|x86.Build.0 = Release|Any CPU
41+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Debug|ARM.ActiveCfg = Debug|Any CPU
44+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Debug|ARM.Build.0 = Debug|Any CPU
45+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Debug|x64.ActiveCfg = Debug|Any CPU
46+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Debug|x64.Build.0 = Debug|Any CPU
47+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Debug|x86.ActiveCfg = Debug|Any CPU
48+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Debug|x86.Build.0 = Debug|Any CPU
49+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
50+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Release|Any CPU.Build.0 = Release|Any CPU
51+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Release|ARM.ActiveCfg = Release|Any CPU
52+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Release|ARM.Build.0 = Release|Any CPU
53+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Release|x64.ActiveCfg = Release|Any CPU
54+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Release|x64.Build.0 = Release|Any CPU
55+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Release|x86.ActiveCfg = Release|Any CPU
56+
{E2BD5B37-DF04-46FD-A919-B60F08BBF0B3}.Release|x86.Build.0 = Release|Any CPU
5857
EndGlobalSection
5958
GlobalSection(SolutionProperties) = preSolution
6059
HideSolutionNode = FALSE
6160
EndGlobalSection
61+
GlobalSection(ExtensibilityGlobals) = postSolution
62+
SolutionGuid = {D7A99D94-DCDC-42DB-846E-8C7C206CDFE7}
63+
EndGlobalSection
6264
EndGlobal

curve25519-dotnet/Properties/AssemblyInfo.cs

-30
This file was deleted.

curve25519-dotnet/README.md

-7
This file was deleted.

curve25519-dotnet/csharp/fe_isreduced.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static bool fe_isreduced(byte[] curve25519_pubkey)
1515
byte[] strict = new byte[32];
1616

1717
Fe_frombytes.fe_frombytes(fe, curve25519_pubkey);
18+
Fe_tobytes.fe_tobytes(strict, fe);
1819
if (Crypto_verify_32.crypto_verify_32(strict, curve25519_pubkey) != 0)
1920
return false;
2021
return true;

0 commit comments

Comments
 (0)