diff --git a/Ed25519.Tests/Ed25519.Tests.csproj b/Ed25519.Tests/Ed25519.Tests.csproj
new file mode 100644
index 0000000..63a2738
--- /dev/null
+++ b/Ed25519.Tests/Ed25519.Tests.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net5.0
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ed25519/Tests/EdPointTests.cs b/Ed25519.Tests/EdPointTests.cs
similarity index 96%
rename from Ed25519/Tests/EdPointTests.cs
rename to Ed25519.Tests/EdPointTests.cs
index eb697e7..90363bd 100644
--- a/Ed25519/Tests/EdPointTests.cs
+++ b/Ed25519.Tests/EdPointTests.cs
@@ -1,42 +1,42 @@
-#if DEBUG
-
-using System;
-using System.Collections.Generic;
-using System.Numerics;
-using System.Text;
-using NUnit.Framework;
-
-namespace Ed25519
-{
- internal sealed class EdPointTests
- {
- [Test]
- public void TestScalMul01()
- {
- var point = new EdPoint
- {
- X = new BigInteger(1_000_000_000_000d),
- Y = new BigInteger(1_024),
- };
-
- var scalar = new BigInteger(10_000);
- var result = point.ScalarMul(scalar);
-
- Assert.That(result.X, Is.EqualTo(BigInteger.Parse("21818314728053983532520901163316227408567979942776402561242051297393768362536")));
- Assert.That(result.Y, Is.EqualTo(BigInteger.Parse("22622610217554165211892652042645278972766880794387244645923515142420844725944")));
- }
-
- [Test]
- public void TestExpMod01()
- {
- var number = new BigInteger(10_000d);
- var exponent = new BigInteger(10d);
- var modulo = new BigInteger(105d);
-
- var result = number.ExpMod(exponent, modulo);
- Assert.That(result, Is.EqualTo(new BigInteger(25d)));
- }
- }
-}
-
+#if DEBUG
+
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+using System.Text;
+using NUnit.Framework;
+
+namespace Ed25519
+{
+ internal sealed class EdPointTests
+ {
+ [Test]
+ public void TestScalMul01()
+ {
+ var point = new EdPoint
+ {
+ X = new BigInteger(1_000_000_000_000d),
+ Y = new BigInteger(1_024),
+ };
+
+ var scalar = new BigInteger(10_000);
+ var result = point.ScalarMul(scalar);
+
+ Assert.That(result.X, Is.EqualTo(BigInteger.Parse("21818314728053983532520901163316227408567979942776402561242051297393768362536")));
+ Assert.That(result.Y, Is.EqualTo(BigInteger.Parse("22622610217554165211892652042645278972766880794387244645923515142420844725944")));
+ }
+
+ [Test]
+ public void TestExpMod01()
+ {
+ var number = new BigInteger(10_000d);
+ var exponent = new BigInteger(10d);
+ var modulo = new BigInteger(105d);
+
+ var result = number.ExpMod(exponent, modulo);
+ Assert.That(result, Is.EqualTo(new BigInteger(25d)));
+ }
+ }
+}
+
#endif
\ No newline at end of file
diff --git a/Ed25519/Tests/SignerTests.cs b/Ed25519.Tests/SignerTests.cs
similarity index 98%
rename from Ed25519/Tests/SignerTests.cs
rename to Ed25519.Tests/SignerTests.cs
index ea36897..14ddb00 100644
--- a/Ed25519/Tests/SignerTests.cs
+++ b/Ed25519.Tests/SignerTests.cs
@@ -1,914 +1,914 @@
-#if DEBUG
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
-using NUnit.Framework;
-
-namespace Ed25519
-{
- internal sealed class SignerTests
- {
- [Test]
- public void TestSignatureLength()
- {
- var message = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var signature = Signer.Sign(message, privateKey, publicKey);
-
- Assert.That(signature.Length, Is.EqualTo(64));
- }
-
- [Test]
- public async Task TestSignatureLengthAsync()
- {
- var message = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
- var signature = await Signer.SignAsync(message, privateKey, publicKey);
-
- Assert.That(signature.Length, Is.EqualTo(64));
- }
-
- [Test]
- public void TestManipulatedPublicKey()
- {
- var message = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey()[2..];
-
- try
- {
- Signer.Sign(message, privateKey, publicKey);
- Assert.Fail("Should not be reached!");
- }
- catch (ArgumentException e)
- {
- Assert.That(true); // Public key is too short!
- }
- }
-
- [Test]
- public async Task TestManipulatedPublicKeyAsync()
- {
- var message = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = (await privateKey.ExtractPublicKeyAsync())[2..];
-
- try
- {
- await Signer.SignAsync(message, privateKey, publicKey);
- Assert.Fail("Should not be reached!");
- }
- catch (ArgumentException e)
- {
- Assert.That(true); // Public key is too short!
- }
- }
-
- [Test]
- public void TestSimpleMessageValidation()
- {
- var message = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var signature = Signer.Sign(message, privateKey, publicKey);
- var validationResult = Signer.Validate(signature, message, publicKey);
-
- Assert.That(validationResult, Is.True);
- }
-
- [Test]
- public async Task TestSimpleMessageValidationAsync()
- {
- var message = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
- var signature = await Signer.SignAsync(message, privateKey, publicKey);
- var validationResult = await Signer.ValidateAsync(signature, message, publicKey);
-
- Assert.That(validationResult, Is.True);
- }
-
- [Test]
- public void TestSlightlyChangedMessageValidation()
- {
- var messageOriginal = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var signature = Signer.Sign(messageOriginal, privateKey, publicKey);
-
- var messageAltered = Encoding.UTF8.GetBytes("This is a test message!");
- var validationResult = Signer.Validate(signature, messageAltered, publicKey);
-
- Assert.That(validationResult, Is.False); // Message was altered!
- }
-
- [Test]
- public async Task TestSlightlyChangedMessageValidationAsync()
- {
- var messageOriginal = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
- var signature = await Signer.SignAsync(messageOriginal, privateKey, publicKey);
-
- var messageAltered = Encoding.UTF8.GetBytes("This is a test message!");
- var validationResult = await Signer.ValidateAsync(signature, messageAltered, publicKey);
-
- Assert.That(validationResult, Is.False); // Message was altered!
- }
-
- [Test]
- public void TestSlightlyChangedMessageDifferentSignatures()
- {
- var messageOriginal = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var signatureOriginal = Signer.Sign(messageOriginal, privateKey, publicKey);
-
- var messageAltered = Encoding.UTF8.GetBytes("This is a test message!");
- var signatureAltered = Signer.Sign(messageAltered, privateKey, publicKey);
-
- // Two different messages must produce different signatures!
- Assert.That(signatureOriginal.ToArray(), Is.Not.EqualTo(signatureAltered.ToArray()));
- }
-
- [Test]
- public async Task TestSlightlyChangedMessageDifferentSignaturesAsync()
- {
- var messageOriginal = Encoding.UTF8.GetBytes("This is a test message.");
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
- var signatureOriginal = await Signer.SignAsync(messageOriginal, privateKey, publicKey);
-
- var messageAltered = Encoding.UTF8.GetBytes("This is a test message!");
- var signatureAltered = await Signer.SignAsync(messageAltered, privateKey, publicKey);
-
- // Two different messages must produce different signatures!
- Assert.That(signatureOriginal, Is.Not.EqualTo(signatureAltered));
- }
-
- [Test]
- public void TestMessageValidationWithDifferentEncodings()
- {
- var messageOriginal = Encoding.ASCII.GetBytes("This is a test message.");
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var signatureOriginal = Signer.Sign(messageOriginal, privateKey, publicKey);
-
- var messageAltered = Encoding.UTF32.GetBytes("This is a test message.");
- var signatureAltered = Signer.Sign(messageAltered, privateKey, publicKey);
-
- // Two equal messages with different encoding must produce different signatures:
- Assert.That(signatureOriginal.ToArray(), Is.Not.EqualTo(signatureAltered.ToArray()));
- }
-
- [Test]
- public async Task TestMessageValidationWithDifferentEncodingsAsync()
- {
- var messageOriginal = Encoding.ASCII.GetBytes("This is a test message.");
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
- var signatureOriginal = await Signer.SignAsync(messageOriginal, privateKey, publicKey);
-
- var messageAltered = Encoding.UTF32.GetBytes("This is a test message.");
- var signatureAltered = await Signer.SignAsync(messageAltered, privateKey, publicKey);
-
- // Two equal messages with different encoding must produce different signatures:
- Assert.That(signatureOriginal, Is.Not.EqualTo(signatureAltered));
- }
-
- [Test]
- public void TestMessageWithUmlautsAndDifferentEncodings()
- {
- var messageOriginal = Encoding.ASCII.GetBytes("This is a test message with umlauts äöü.");
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var signatureOriginal = Signer.Sign(messageOriginal, privateKey, publicKey);
-
- var messageAltered = Encoding.UTF8.GetBytes("This is a test message with umlauts äöü.");
- var signatureAltered = Signer.Sign(messageAltered, privateKey, publicKey);
-
- // Two equal messages with different encoding must produce different signatures:
- Assert.That(signatureOriginal.ToArray(), Is.Not.EqualTo(signatureAltered.ToArray()));
- }
-
- [Test]
- public void TestMessageWithUmlauts()
- {
- var messageOriginal = Encoding.UTF8.GetBytes("This is a test message with umlauts äöü.");
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var signatureOriginal = Signer.Sign(messageOriginal, privateKey, publicKey);
-
- var message2 = Encoding.UTF8.GetBytes("This is a test message with umlauts äöü.");
- var signature2 = Signer.Sign(message2, privateKey, publicKey);
- var validationResult = Signer.Validate(signatureOriginal, message2, publicKey);
-
- // Two equal messages must produce same signatures:
- Assert.That(signatureOriginal.ToArray(), Is.EqualTo(signature2.ToArray()));
- Assert.That(validationResult, Is.True);
- }
-
- [Test]
- public void TestKeyGeneratorWithoutPassword()
- {
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
-
- Assert.That(privateKey.Length, Is.EqualTo(32));
- Assert.That(publicKey.Length, Is.EqualTo(32));
- Assert.That(privateKey.ToArray(), Is.Not.EqualTo(publicKey.ToArray()));
- }
-
- [Test]
- public async Task TestKeyGeneratorWithoutPasswordAsync()
- {
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
-
- Assert.That(privateKey.Length, Is.EqualTo(32));
- Assert.That(publicKey.Length, Is.EqualTo(32));
- Assert.That(privateKey, Is.Not.EqualTo(publicKey));
- }
-
- [Test]
- public void TestKeyGeneratorWithPassword()
- {
- var password = "test password";
- var privateKeyEncrypted = Signer.GeneratePrivateKey(password);
- var privateKeyDecrypted = privateKeyEncrypted.DecryptPrivateKey(password);
- var publicKey = privateKeyDecrypted.ExtractPublicKey();
-
- Assert.That(privateKeyEncrypted.Length, Is.GreaterThan(32));
- Assert.That(privateKeyDecrypted.Length, Is.EqualTo(32));
- Assert.That(publicKey.Length, Is.EqualTo(32));
- Assert.That(privateKeyEncrypted.ToArray(), Is.Not.EqualTo(privateKeyDecrypted.ToArray()));
- Assert.That(privateKeyEncrypted.ToArray(), Is.Not.EqualTo(publicKey.ToArray()));
- Assert.That(privateKeyDecrypted.ToArray(), Is.Not.EqualTo(publicKey.ToArray()));
- }
-
- [Test]
- public async Task TestKeyGeneratorWithPasswordAsync()
- {
- var password = "test password";
- var privateKeyEncrypted = await Signer.GeneratePrivateKeyAsync(password);
- var privateKeyDecrypted = await privateKeyEncrypted.DecryptPrivateKeyAsync(password);
- var publicKey = await privateKeyDecrypted.ExtractPublicKeyAsync();
-
- Assert.That(privateKeyEncrypted.Length, Is.GreaterThan(32));
- Assert.That(privateKeyDecrypted.Length, Is.EqualTo(32));
- Assert.That(publicKey.Length, Is.EqualTo(32));
- Assert.That(privateKeyEncrypted, Is.Not.EqualTo(privateKeyDecrypted));
- Assert.That(privateKeyEncrypted, Is.Not.EqualTo(publicKey));
- Assert.That(privateKeyDecrypted, Is.Not.EqualTo(publicKey));
- }
-
- [Test]
- public void TestMultipleKeysWithoutPassword()
- {
- var privateKey1 = Signer.GeneratePrivateKey();
- var privateKey2 = Signer.GeneratePrivateKey();
- var privateKey3 = Signer.GeneratePrivateKey();
-
- Assert.That(privateKey1.ToArray(), Is.Not.EqualTo(privateKey2.ToArray()));
- Assert.That(privateKey1.ToArray(), Is.Not.EqualTo(privateKey3.ToArray()));
- Assert.That(privateKey2.ToArray(), Is.Not.EqualTo(privateKey3.ToArray()));
- }
-
- [Test]
- public async Task TestMultipleKeysWithoutPasswordAsync()
- {
- var privateKey1 = await Signer.GeneratePrivateKeyAsync();
- var privateKey2 = await Signer.GeneratePrivateKeyAsync();
- var privateKey3 = await Signer.GeneratePrivateKeyAsync();
-
- Assert.That(privateKey1, Is.Not.EqualTo(privateKey2));
- Assert.That(privateKey1, Is.Not.EqualTo(privateKey3));
- Assert.That(privateKey2, Is.Not.EqualTo(privateKey3));
- }
-
- [Test]
- public void TestMultipleKeysWithPassword()
- {
- var password = "test password";
- var privateKey1 = Signer.GeneratePrivateKey(password);
- var privateKey2 = Signer.GeneratePrivateKey(password);
- var privateKey3 = Signer.GeneratePrivateKey(password);
-
- Assert.That(privateKey1.ToArray(), Is.Not.EqualTo(privateKey2.ToArray()));
- Assert.That(privateKey1.ToArray(), Is.Not.EqualTo(privateKey3.ToArray()));
- Assert.That(privateKey2.ToArray(), Is.Not.EqualTo(privateKey3.ToArray()));
- }
-
- [Test]
- public async Task TestMultipleKeysWithPasswordAsync()
- {
- var password = "test password";
- var privateKey1 = await Signer.GeneratePrivateKeyAsync(password);
- var privateKey2 = await Signer.GeneratePrivateKeyAsync(password);
- var privateKey3 = await Signer.GeneratePrivateKeyAsync(password);
-
- Assert.That(privateKey1, Is.Not.EqualTo(privateKey2));
- Assert.That(privateKey1, Is.Not.EqualTo(privateKey3));
- Assert.That(privateKey2, Is.Not.EqualTo(privateKey3));
- }
-
- [Test]
- public void TestPublicKeyFromRandomData()
- {
- var privateKey = new byte[] {0x00, 0xac, 0x48}.AsSpan();
- var publicKey = privateKey.ExtractPublicKey();
-
- Assert.That(privateKey.Length, Is.EqualTo(3));
- Assert.That(publicKey.Length, Is.EqualTo(0));
- Assert.That(publicKey.IsEmpty, Is.True);
- }
-
- [Test]
- public async Task TestPublicKeyFromRandomDataAsync()
- {
- var privateKey = new byte[] { 0x00, 0xac, 0x48 };
- var publicKey = await privateKey.ExtractPublicKeyAsync();
-
- Assert.That(privateKey.Length, Is.EqualTo(3));
- Assert.That(publicKey, Is.Null);
- }
-
- [Test]
- public void TestWritingAndLoadingKeys()
- {
- var tempFilePrivate = Path.GetTempFileName();
- var tempFilePublic = Path.GetTempFileName();
-
- try
- {
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
-
- privateKey.WriteKey(tempFilePrivate);
- publicKey.WriteKey(tempFilePublic);
-
- var reloadPrivateKey = Signer.LoadKey(tempFilePrivate);
- var reloadPublicKey = Signer.LoadKey(tempFilePublic);
-
- Assert.That(reloadPublicKey.Length, Is.EqualTo(32));
- Assert.That(reloadPrivateKey.Length, Is.EqualTo(32));
-
- Assert.That(reloadPublicKey.ToArray(), Is.EqualTo(publicKey.ToArray()));
- Assert.That(reloadPrivateKey.ToArray(), Is.EqualTo(privateKey.ToArray()));
- }
- finally
- {
- File.Delete(tempFilePublic);
- File.Delete(tempFilePrivate);
- }
- }
-
- [Test]
- public async Task TestWritingAndLoadingKeysAsync()
- {
- var tempFilePrivate = Path.GetTempFileName();
- var tempFilePublic = Path.GetTempFileName();
-
- try
- {
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
-
- await privateKey.WriteKeyAsync(tempFilePrivate);
- await publicKey.WriteKeyAsync(tempFilePublic);
-
- var reloadPrivateKey = await Signer.LoadKeyAsync(tempFilePrivate);
- var reloadPublicKey = await Signer.LoadKeyAsync(tempFilePublic);
-
- Assert.That(reloadPublicKey.Length, Is.EqualTo(32));
- Assert.That(reloadPrivateKey.Length, Is.EqualTo(32));
-
- Assert.That(reloadPublicKey, Is.EqualTo(publicKey));
- Assert.That(reloadPrivateKey, Is.EqualTo(privateKey));
- }
- finally
- {
- File.Delete(tempFilePublic);
- File.Delete(tempFilePrivate);
- }
- }
-
- [Test]
- public void TestExtractPublicKeyFromEncryptedPrivateKey()
- {
- var privateKeyEncrypted = Signer.GeneratePrivateKey("secret password");
- var privateKeyDecrypted = privateKeyEncrypted.DecryptPrivateKey("secret password");
- var publicKeyFromDecrypted = privateKeyDecrypted.ExtractPublicKey();
- var publicKeyFromEncrypted = privateKeyEncrypted.ExtractPublicKey();
-
- Assert.That(publicKeyFromDecrypted.ToArray(), Is.Not.EqualTo(publicKeyFromEncrypted.ToArray()));
- }
-
- [Test]
- public async Task TestExtractPublicKeyFromEncryptedPrivateKeyAsync()
- {
- var privateKeyEncrypted = await Signer.GeneratePrivateKeyAsync("secret password");
- var privateKeyDecrypted = await privateKeyEncrypted.DecryptPrivateKeyAsync("secret password");
- var publicKeyFromDecrypted = await privateKeyDecrypted.ExtractPublicKeyAsync();
- var publicKeyFromEncrypted = await privateKeyEncrypted.ExtractPublicKeyAsync();
-
- Assert.That(publicKeyFromDecrypted, Is.Not.EqualTo(publicKeyFromEncrypted));
- }
-
- [Test]
- public void TestExtractPublicKeyFromTooShortPrivateKey()
- {
- var privateKey= Signer.GeneratePrivateKey()[..6]; // Six first bytes from private key!
- var publicKey = privateKey.ExtractPublicKey();
- Assert.That(publicKey == ReadOnlySpan.Empty, Is.True);
- }
-
- [Test]
- public async Task TestExtractPublicKeyFromTooShortPrivateKeyAsync()
- {
- var privateKey = (await Signer.GeneratePrivateKeyAsync())[..6]; // Six first bytes from private key!
- var publicKey = await privateKey.ExtractPublicKeyAsync();
- Assert.That(publicKey, Is.Null);
- }
-
- [Test]
- public void TestSigningBehaviourPrivateKeyWithPassword()
- {
- var privateKeyEncrypted = Signer.GeneratePrivateKey("secret password");
- var privateKeyDecrypted = privateKeyEncrypted.DecryptPrivateKey("secret password");
- var publicKey = privateKeyDecrypted.ExtractPublicKey();
- var message = Encoding.UTF8.GetBytes("This is a test message.");
- var signaturePrivateKeyDecrypted = Signer.Sign(message, privateKeyDecrypted, publicKey);
- var signaturePrivateKeyEncrypted = Signer.Sign(message, privateKeyEncrypted[..32], publicKey); // Note: The encrypted private key is 64 bytes long!
- var validationDecrypted = Signer.Validate(signaturePrivateKeyDecrypted, message, publicKey);
- var validationEncrypted = Signer.Validate(signaturePrivateKeyEncrypted, message, publicKey);
-
- Assert.That(validationDecrypted, Is.True); // This is the intended behaviour. The public key was derived from the decrypted private key.
- Assert.That(validationEncrypted, Is.False); // This should fail, because the public key does not match the *encrypted* private key!
- Assert.That(signaturePrivateKeyEncrypted.ToArray(), Is.Not.EqualTo(signaturePrivateKeyDecrypted.ToArray()));
- }
-
- [Test]
- public async Task TestSigningBehaviourPrivateKeyWithPasswordAsync()
- {
- var privateKeyEncrypted = await Signer.GeneratePrivateKeyAsync("secret password");
- var privateKeyDecrypted = await privateKeyEncrypted.DecryptPrivateKeyAsync("secret password");
- var publicKey = await privateKeyDecrypted.ExtractPublicKeyAsync();
- var message = Encoding.UTF8.GetBytes("This is a test message.");
- var signaturePrivateKeyDecrypted = await Signer.SignAsync(message, privateKeyDecrypted, publicKey);
- var signaturePrivateKeyEncrypted = await Signer.SignAsync(message, privateKeyEncrypted[..32], publicKey); // Note: The encrypted private key is 64 bytes long!
- var validationDecrypted = await Signer.ValidateAsync(signaturePrivateKeyDecrypted, message, publicKey);
- var validationEncrypted = await Signer.ValidateAsync(signaturePrivateKeyEncrypted, message, publicKey);
-
- Assert.That(validationDecrypted, Is.True); // This is the intended behaviour. The public key was derived from the decrypted private key.
- Assert.That(validationEncrypted, Is.False); // This should fail, because the public key does not match the *encrypted* private key!
- Assert.That(signaturePrivateKeyEncrypted, Is.Not.EqualTo(signaturePrivateKeyDecrypted));
- }
-
- [Test]
- public void TestPerformanceSigning()
- {
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var rng = new Random();
- var payload = new byte[1_024];
- var stopwatch = new Stopwatch();
- var desiredRuntime = TimeSpan.FromSeconds(30);
- var counter = 0;
-
- while (true)
- {
- counter++;
- rng.NextBytes(payload);
-
- stopwatch.Start();
- Signer.Sign(payload, privateKey, publicKey);
- stopwatch.Stop();
-
- if(stopwatch.Elapsed >= desiredRuntime)
- break;
- }
-
- var result = counter / stopwatch.Elapsed.TotalSeconds;
- TestContext.Write($"Benchmark for signing messages: {result:0.00} messages/second");
- Assert.That(true);
- }
-
- [Test]
- public async Task TestPerformanceSigningAsync()
- {
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
- var rng = new Random();
- var payload = new byte[1_024];
- var stopwatch = new Stopwatch();
- var desiredRuntime = TimeSpan.FromSeconds(30);
- var counter = 0;
-
- while (true)
- {
- counter++;
- rng.NextBytes(payload);
-
- stopwatch.Start();
- await Signer.SignAsync(payload, privateKey, publicKey);
- stopwatch.Stop();
-
- if (stopwatch.Elapsed >= desiredRuntime)
- break;
- }
-
- var result = counter / stopwatch.Elapsed.TotalSeconds;
- TestContext.Write($"Benchmark for signing messages: {result:0.00} messages/second");
- Assert.That(true);
- }
-
- [Test]
- public void TestPerformanceValidation()
- {
- var privateKey = Signer.GeneratePrivateKey();
- var publicKey = privateKey.ExtractPublicKey();
- var rng = new Random();
- var payload = new byte[1_024];
- var stopwatch = new Stopwatch();
- var desiredRuntime = TimeSpan.FromSeconds(30);
- var counter = 0;
-
- while (true)
- {
- counter++;
- rng.NextBytes(payload);
-
- var signature = Signer.Sign(payload, privateKey, publicKey);
-
- stopwatch.Start();
- Signer.Validate(signature, payload, publicKey);
- stopwatch.Stop();
-
- if (stopwatch.Elapsed >= desiredRuntime)
- break;
- }
-
- var result = counter / stopwatch.Elapsed.TotalSeconds;
- TestContext.Write($"Benchmark for validation of messages: {result:0.00} messages/second");
- Assert.That(true);
- }
-
- [Test]
- public async Task TestPerformanceValidationAsync()
- {
- var privateKey = await Signer.GeneratePrivateKeyAsync();
- var publicKey = await privateKey.ExtractPublicKeyAsync();
- var rng = new Random();
- var payload = new byte[1_024];
- var stopwatch = new Stopwatch();
- var desiredRuntime = TimeSpan.FromSeconds(30);
- var counter = 0;
-
- while (true)
- {
- counter++;
- rng.NextBytes(payload);
-
- var signature = await Signer.SignAsync(payload, privateKey, publicKey);
-
- stopwatch.Start();
- await Signer.ValidateAsync(signature, payload, publicKey);
- stopwatch.Stop();
-
- if (stopwatch.Elapsed >= desiredRuntime)
- break;
- }
-
- var result = counter / stopwatch.Elapsed.TotalSeconds;
- TestContext.Write($"Benchmark for validation of messages: {result:0.00} messages/second");
- Assert.That(true);
- }
-
- [Test]
- public void TestLoadingNotExistingKey()
- {
- var key = Signer.LoadKey(Guid.NewGuid().ToString());
- Assert.That(key == ReadOnlySpan.Empty, Is.True);
- }
-
- [Test]
- public async Task TestLoadingNotExistingKeyAsync()
- {
- var key = await Signer.LoadKeyAsync(Guid.NewGuid().ToString());
- Assert.That(key, Is.Null);
- }
-
- // See https://tools.ietf.org/html/rfc8032#section-7.1
- [Test]
- public void TestRFC8032Test01EmptyMessage()
- {
- var message = new ReadOnlySpan(); // Empty message!
- var publicKey = new byte[]
- {
- 0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7, 0xd5, 0x4b, 0xfe, 0xd3, 0xc9, 0x64, 0x07, 0x3a,
- 0x0e, 0xe1, 0x72, 0xf3, 0xda, 0xa6, 0x23, 0x25, 0xaf, 0x02, 0x1a, 0x68, 0xf7, 0x07, 0x51, 0x1a,
- };
-
- var privateKey = new byte[]
- {
- 0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, 0xba, 0x84, 0x4a, 0xf4, 0x92, 0xec, 0x2c, 0xc4,
- 0x44, 0x49, 0xc5, 0x69, 0x7b, 0x32, 0x69, 0x19, 0x70, 0x3b, 0xac, 0x03, 0x1c, 0xae, 0x7f, 0x60,
- };
-
- var expectedSignature = new byte[]
- {
- 0xe5, 0x56, 0x43, 0x00, 0xc3, 0x60, 0xac, 0x72, 0x90, 0x86, 0xe2, 0xcc, 0x80, 0x6e, 0x82, 0x8a,
- 0x84, 0x87, 0x7f, 0x1e, 0xb8, 0xe5, 0xd9, 0x74, 0xd8, 0x73, 0xe0, 0x65, 0x22, 0x49, 0x01, 0x55,
- 0x5f, 0xb8, 0x82, 0x15, 0x90, 0xa3, 0x3b, 0xac, 0xc6, 0x1e, 0x39, 0x70, 0x1c, 0xf9, 0xb4, 0x6b,
- 0xd2, 0x5b, 0xf5, 0xf0, 0x59, 0x5b, 0xbe, 0x24, 0x65, 0x51, 0x41, 0x43, 0x8e, 0x7a, 0x10, 0x0b,
- };
-
- var signature = Signer.Sign(message, privateKey, publicKey);
- Assert.That(signature.ToArray(), Is.EqualTo(expectedSignature));
-
- var validationResult = Signer.Validate(signature, message, publicKey);
- Assert.That(validationResult, Is.True);
- }
-
- // See https://tools.ietf.org/html/rfc8032#section-7.1
- [Test]
- public void TestRFC8032Test02OneByteMessage()
- {
- var message = new byte[]
- {
- 0x72,
- };
-
- var publicKey = new byte[]
- {
- 0x3d, 0x40, 0x17, 0xc3, 0xe8, 0x43, 0x89, 0x5a, 0x92, 0xb7, 0x0a, 0xa7, 0x4d, 0x1b, 0x7e, 0xbc,
- 0x9c, 0x98, 0x2c, 0xcf, 0x2e, 0xc4, 0x96, 0x8c, 0xc0, 0xcd, 0x55, 0xf1, 0x2a, 0xf4, 0x66, 0x0c,
- };
-
- var privateKey = new byte[]
- {
- 0x4c, 0xcd, 0x08, 0x9b, 0x28, 0xff, 0x96, 0xda, 0x9d, 0xb6, 0xc3, 0x46, 0xec, 0x11, 0x4e, 0x0f,
- 0x5b, 0x8a, 0x31, 0x9f, 0x35, 0xab, 0xa6, 0x24, 0xda, 0x8c, 0xf6, 0xed, 0x4f, 0xb8, 0xa6, 0xfb,
- };
-
- var expectedSignature = new byte[]
- {
- 0x92, 0xa0, 0x09, 0xa9, 0xf0, 0xd4, 0xca, 0xb8, 0x72, 0x0e, 0x82, 0x0b, 0x5f, 0x64, 0x25, 0x40,
- 0xa2, 0xb2, 0x7b, 0x54, 0x16, 0x50, 0x3f, 0x8f, 0xb3, 0x76, 0x22, 0x23, 0xeb, 0xdb, 0x69, 0xda,
- 0x08, 0x5a, 0xc1, 0xe4, 0x3e, 0x15, 0x99, 0x6e, 0x45, 0x8f, 0x36, 0x13, 0xd0, 0xf1, 0x1d, 0x8c,
- 0x38, 0x7b, 0x2e, 0xae, 0xb4, 0x30, 0x2a, 0xee, 0xb0, 0x0d, 0x29, 0x16, 0x12, 0xbb, 0x0c, 0x00,
- };
-
- var signature = Signer.Sign(message, privateKey, publicKey);
- Assert.That(signature.ToArray(), Is.EqualTo(expectedSignature));
-
- var validationResult = Signer.Validate(signature, message, publicKey);
- Assert.That(validationResult, Is.True);
- }
-
- // See https://tools.ietf.org/html/rfc8032#section-7.1
- [Test]
- public void TestRFC8032Test03TwoByteMessage()
- {
- var message = new byte[]
- {
- 0xaf, 0x82,
- };
-
- var publicKey = new byte[]
- {
- 0xfc, 0x51, 0xcd, 0x8e, 0x62, 0x18, 0xa1, 0xa3, 0x8d, 0xa4, 0x7e, 0xd0, 0x02, 0x30, 0xf0, 0x58,
- 0x08, 0x16, 0xed, 0x13, 0xba, 0x33, 0x03, 0xac, 0x5d, 0xeb, 0x91, 0x15, 0x48, 0x90, 0x80, 0x25,
-
- };
-
- var privateKey = new byte[]
- {
- 0xc5, 0xaa, 0x8d, 0xf4, 0x3f, 0x9f, 0x83, 0x7b, 0xed, 0xb7, 0x44, 0x2f, 0x31, 0xdc, 0xb7, 0xb1,
- 0x66, 0xd3, 0x85, 0x35, 0x07, 0x6f, 0x09, 0x4b, 0x85, 0xce, 0x3a, 0x2e, 0x0b, 0x44, 0x58, 0xf7,
- };
-
- var expectedSignature = new byte[]
- {
- 0x62, 0x91, 0xd6, 0x57, 0xde, 0xec, 0x24, 0x02, 0x48, 0x27, 0xe6, 0x9c, 0x3a, 0xbe, 0x01, 0xa3,
- 0x0c, 0xe5, 0x48, 0xa2, 0x84, 0x74, 0x3a, 0x44, 0x5e, 0x36, 0x80, 0xd7, 0xdb, 0x5a, 0xc3, 0xac,
- 0x18, 0xff, 0x9b, 0x53, 0x8d, 0x16, 0xf2, 0x90, 0xae, 0x67, 0xf7, 0x60, 0x98, 0x4d, 0xc6, 0x59,
- 0x4a, 0x7c, 0x15, 0xe9, 0x71, 0x6e, 0xd2, 0x8d, 0xc0, 0x27, 0xbe, 0xce, 0xea, 0x1e, 0xc4, 0x0a,
- };
-
- var signature = Signer.Sign(message, privateKey, publicKey);
- Assert.That(signature.ToArray(), Is.EqualTo(expectedSignature));
-
- var validationResult = Signer.Validate(signature, message, publicKey);
- Assert.That(validationResult, Is.True);
- }
-
- // See https://tools.ietf.org/html/rfc8032#section-7.1
- [Test]
- public void TestRFC8032Test04With1kMessage()
- {
- var message = new byte[]
- {
- 0x08, 0xb8, 0xb2, 0xb7, 0x33, 0x42, 0x42, 0x43, 0x76, 0x0f, 0xe4, 0x26, 0xa4, 0xb5, 0x49, 0x08,
- 0x63, 0x21, 0x10, 0xa6, 0x6c, 0x2f, 0x65, 0x91, 0xea, 0xbd, 0x33, 0x45, 0xe3, 0xe4, 0xeb, 0x98,
- 0xfa, 0x6e, 0x26, 0x4b, 0xf0, 0x9e, 0xfe, 0x12, 0xee, 0x50, 0xf8, 0xf5, 0x4e, 0x9f, 0x77, 0xb1,
- 0xe3, 0x55, 0xf6, 0xc5, 0x05, 0x44, 0xe2, 0x3f, 0xb1, 0x43, 0x3d, 0xdf, 0x73, 0xbe, 0x84, 0xd8,
- 0x79, 0xde, 0x7c, 0x00, 0x46, 0xdc, 0x49, 0x96, 0xd9, 0xe7, 0x73, 0xf4, 0xbc, 0x9e, 0xfe, 0x57,
- 0x38, 0x82, 0x9a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 0xee, 0xee, 0x47, 0x5a, 0x64, 0xdf, 0xac, 0x86, 0xab, 0xa4, 0x1c,
- 0x06, 0x18, 0x98, 0x3f, 0x87, 0x41, 0xc5, 0xef, 0x68, 0xd3, 0xa1, 0x01, 0xe8, 0xa3, 0xb8, 0xca,
- 0xc6, 0x0c, 0x90, 0x5c, 0x15, 0xfc, 0x91, 0x08, 0x40, 0xb9, 0x4c, 0x00, 0xa0, 0xb9, 0xd0,
- };
-
- var publicKey = new byte[]
- {
- 0x27, 0x81, 0x17, 0xfc, 0x14, 0x4c, 0x72, 0x34, 0x0f, 0x67, 0xd0, 0xf2, 0x31, 0x6e, 0x83, 0x86,
- 0xce, 0xff, 0xbf, 0x2b, 0x24, 0x28, 0xc9, 0xc5, 0x1f, 0xef, 0x7c, 0x59, 0x7f, 0x1d, 0x42, 0x6e,
- };
-
- var privateKey = new byte[]
- {
- 0xf5, 0xe5, 0x76, 0x7c, 0xf1, 0x53, 0x31, 0x95, 0x17, 0x63, 0x0f, 0x22, 0x68, 0x76, 0xb8, 0x6c,
- 0x81, 0x60, 0xcc, 0x58, 0x3b, 0xc0, 0x13, 0x74, 0x4c, 0x6b, 0xf2, 0x55, 0xf5, 0xcc, 0x0e, 0xe5,
- };
-
- var expectedSignature = new byte[]
- {
- 0x0a, 0xab, 0x4c, 0x90, 0x05, 0x01, 0xb3, 0xe2, 0x4d, 0x7c, 0xdf, 0x46, 0x63, 0x32, 0x6a, 0x3a,
- 0x87, 0xdf, 0x5e, 0x48, 0x43, 0xb2, 0xcb, 0xdb, 0x67, 0xcb, 0xf6, 0xe4, 0x60, 0xfe, 0xc3, 0x50,
- 0xaa, 0x53, 0x71, 0xb1, 0x50, 0x8f, 0x9f, 0x45, 0x28, 0xec, 0xea, 0x23, 0xc4, 0x36, 0xd9, 0x4b,
- 0x5e, 0x8f, 0xcd, 0x4f, 0x68, 0x1e, 0x30, 0xa6, 0xac, 0x00, 0xa9, 0x70, 0x4a, 0x18, 0x8a, 0x03,
- };
-
- var signature = Signer.Sign(message, privateKey, publicKey);
- Assert.That(signature.ToArray(), Is.EqualTo(expectedSignature));
-
- var validationResult = Signer.Validate(signature, message, publicKey);
- Assert.That(validationResult, Is.True);
- }
-
- // See https://tools.ietf.org/html/rfc8032#section-7.1
- [Test]
- public async Task TestRFC8032Test04With1kMessageAsync()
- {
- var message = new byte[]
- {
- 0x08, 0xb8, 0xb2, 0xb7, 0x33, 0x42, 0x42, 0x43, 0x76, 0x0f, 0xe4, 0x26, 0xa4, 0xb5, 0x49, 0x08,
- 0x63, 0x21, 0x10, 0xa6, 0x6c, 0x2f, 0x65, 0x91, 0xea, 0xbd, 0x33, 0x45, 0xe3, 0xe4, 0xeb, 0x98,
- 0xfa, 0x6e, 0x26, 0x4b, 0xf0, 0x9e, 0xfe, 0x12, 0xee, 0x50, 0xf8, 0xf5, 0x4e, 0x9f, 0x77, 0xb1,
- 0xe3, 0x55, 0xf6, 0xc5, 0x05, 0x44, 0xe2, 0x3f, 0xb1, 0x43, 0x3d, 0xdf, 0x73, 0xbe, 0x84, 0xd8,
- 0x79, 0xde, 0x7c, 0x00, 0x46, 0xdc, 0x49, 0x96, 0xd9, 0xe7, 0x73, 0xf4, 0xbc, 0x9e, 0xfe, 0x57,
- 0x38, 0x82, 0x9a, 0xdb, 0x26, 0xc8, 0x1b, 0x37, 0xc9, 0x3a, 0x1b, 0x27, 0x0b, 0x20, 0x32, 0x9d,
- 0x65, 0x86, 0x75, 0xfc, 0x6e, 0xa5, 0x34, 0xe0, 0x81, 0x0a, 0x44, 0x32, 0x82, 0x6b, 0xf5, 0x8c,
- 0x94, 0x1e, 0xfb, 0x65, 0xd5, 0x7a, 0x33, 0x8b, 0xbd, 0x2e, 0x26, 0x64, 0x0f, 0x89, 0xff, 0xbc,
- 0x1a, 0x85, 0x8e, 0xfc, 0xb8, 0x55, 0x0e, 0xe3, 0xa5, 0xe1, 0x99, 0x8b, 0xd1, 0x77, 0xe9, 0x3a,
- 0x73, 0x63, 0xc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 0x32, 0x46, 0xf6, 0xb1, 0x11, 0x63, 0x98, 0xa3, 0x46, 0xf1, 0xa6, 0x41, 0xf3, 0xb0, 0x41,
- 0xe9, 0x89, 0xf7, 0x91, 0x4f, 0x90, 0xcc, 0x2c, 0x7f, 0xff, 0x35, 0x78, 0x76, 0xe5, 0x06, 0xb5,
- 0x0d, 0x33, 0x4b, 0xa7, 0x7c, 0x22, 0x5b, 0xc3, 0x07, 0xba, 0x53, 0x71, 0x52, 0xf3, 0xf1, 0x61,
- 0x0e, 0x4e, 0xaf, 0xe5, 0x95, 0xf6, 0xd9, 0xd9, 0x0d, 0x11, 0xfa, 0xa9, 0x33, 0xa1, 0x5e, 0xf1,
- 0x36, 0x95, 0x46, 0x86, 0x8a, 0x7f, 0x3a, 0x45, 0xa9, 0x67, 0x68, 0xd4, 0x0f, 0xd9, 0xd0, 0x34,
- 0x12, 0xc0, 0x91, 0xc6, 0x31, 0x5c, 0xf4, 0xfd, 0xe7, 0xcb, 0x68, 0x60, 0x69, 0x37, 0x38, 0x0d,
- 0xb2, 0xea, 0xaa, 0x70, 0x7b, 0x4c, 0x41, 0x85, 0xc3, 0x2e, 0xdd, 0xcd, 0xd3, 0x06, 0x70, 0x5e,
- 0x4d, 0xc1, 0xff, 0xc8, 0x72, 0xee, 0xee, 0x47, 0x5a, 0x64, 0xdf, 0xac, 0x86, 0xab, 0xa4, 0x1c,
- 0x06, 0x18, 0x98, 0x3f, 0x87, 0x41, 0xc5, 0xef, 0x68, 0xd3, 0xa1, 0x01, 0xe8, 0xa3, 0xb8, 0xca,
- 0xc6, 0x0c, 0x90, 0x5c, 0x15, 0xfc, 0x91, 0x08, 0x40, 0xb9, 0x4c, 0x00, 0xa0, 0xb9, 0xd0,
- };
-
- var publicKey = new byte[]
- {
- 0x27, 0x81, 0x17, 0xfc, 0x14, 0x4c, 0x72, 0x34, 0x0f, 0x67, 0xd0, 0xf2, 0x31, 0x6e, 0x83, 0x86,
- 0xce, 0xff, 0xbf, 0x2b, 0x24, 0x28, 0xc9, 0xc5, 0x1f, 0xef, 0x7c, 0x59, 0x7f, 0x1d, 0x42, 0x6e,
- };
-
- var privateKey = new byte[]
- {
- 0xf5, 0xe5, 0x76, 0x7c, 0xf1, 0x53, 0x31, 0x95, 0x17, 0x63, 0x0f, 0x22, 0x68, 0x76, 0xb8, 0x6c,
- 0x81, 0x60, 0xcc, 0x58, 0x3b, 0xc0, 0x13, 0x74, 0x4c, 0x6b, 0xf2, 0x55, 0xf5, 0xcc, 0x0e, 0xe5,
- };
-
- var expectedSignature = new byte[]
- {
- 0x0a, 0xab, 0x4c, 0x90, 0x05, 0x01, 0xb3, 0xe2, 0x4d, 0x7c, 0xdf, 0x46, 0x63, 0x32, 0x6a, 0x3a,
- 0x87, 0xdf, 0x5e, 0x48, 0x43, 0xb2, 0xcb, 0xdb, 0x67, 0xcb, 0xf6, 0xe4, 0x60, 0xfe, 0xc3, 0x50,
- 0xaa, 0x53, 0x71, 0xb1, 0x50, 0x8f, 0x9f, 0x45, 0x28, 0xec, 0xea, 0x23, 0xc4, 0x36, 0xd9, 0x4b,
- 0x5e, 0x8f, 0xcd, 0x4f, 0x68, 0x1e, 0x30, 0xa6, 0xac, 0x00, 0xa9, 0x70, 0x4a, 0x18, 0x8a, 0x03,
- };
-
- var signature = await Signer.SignAsync(message, privateKey, publicKey);
- Assert.That(signature, Is.EqualTo(expectedSignature));
-
- var validationResult = await Signer.ValidateAsync(signature, message, publicKey);
- Assert.That(validationResult, Is.True);
- }
- }
-}
-
+#if DEBUG
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+using NUnit.Framework;
+
+namespace Ed25519
+{
+ internal sealed class SignerTests
+ {
+ [Test]
+ public void TestSignatureLength()
+ {
+ var message = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var signature = Signer.Sign(message, privateKey, publicKey);
+
+ Assert.That(signature.Length, Is.EqualTo(64));
+ }
+
+ [Test]
+ public async Task TestSignatureLengthAsync()
+ {
+ var message = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+ var signature = await Signer.SignAsync(message, privateKey, publicKey);
+
+ Assert.That(signature.Length, Is.EqualTo(64));
+ }
+
+ [Test]
+ public void TestManipulatedPublicKey()
+ {
+ var message = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey()[2..];
+
+ try
+ {
+ Signer.Sign(message, privateKey, publicKey);
+ Assert.Fail("Should not be reached!");
+ }
+ catch (ArgumentException e)
+ {
+ Assert.That(true); // Public key is too short!
+ }
+ }
+
+ [Test]
+ public async Task TestManipulatedPublicKeyAsync()
+ {
+ var message = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = (await privateKey.ExtractPublicKeyAsync())[2..];
+
+ try
+ {
+ await Signer.SignAsync(message, privateKey, publicKey);
+ Assert.Fail("Should not be reached!");
+ }
+ catch (ArgumentException e)
+ {
+ Assert.That(true); // Public key is too short!
+ }
+ }
+
+ [Test]
+ public void TestSimpleMessageValidation()
+ {
+ var message = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var signature = Signer.Sign(message, privateKey, publicKey);
+ var validationResult = Signer.Validate(signature, message, publicKey);
+
+ Assert.That(validationResult, Is.True);
+ }
+
+ [Test]
+ public async Task TestSimpleMessageValidationAsync()
+ {
+ var message = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+ var signature = await Signer.SignAsync(message, privateKey, publicKey);
+ var validationResult = await Signer.ValidateAsync(signature, message, publicKey);
+
+ Assert.That(validationResult, Is.True);
+ }
+
+ [Test]
+ public void TestSlightlyChangedMessageValidation()
+ {
+ var messageOriginal = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var signature = Signer.Sign(messageOriginal, privateKey, publicKey);
+
+ var messageAltered = Encoding.UTF8.GetBytes("This is a test message!");
+ var validationResult = Signer.Validate(signature, messageAltered, publicKey);
+
+ Assert.That(validationResult, Is.False); // Message was altered!
+ }
+
+ [Test]
+ public async Task TestSlightlyChangedMessageValidationAsync()
+ {
+ var messageOriginal = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+ var signature = await Signer.SignAsync(messageOriginal, privateKey, publicKey);
+
+ var messageAltered = Encoding.UTF8.GetBytes("This is a test message!");
+ var validationResult = await Signer.ValidateAsync(signature, messageAltered, publicKey);
+
+ Assert.That(validationResult, Is.False); // Message was altered!
+ }
+
+ [Test]
+ public void TestSlightlyChangedMessageDifferentSignatures()
+ {
+ var messageOriginal = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var signatureOriginal = Signer.Sign(messageOriginal, privateKey, publicKey);
+
+ var messageAltered = Encoding.UTF8.GetBytes("This is a test message!");
+ var signatureAltered = Signer.Sign(messageAltered, privateKey, publicKey);
+
+ // Two different messages must produce different signatures!
+ Assert.That(signatureOriginal.ToArray(), Is.Not.EqualTo(signatureAltered.ToArray()));
+ }
+
+ [Test]
+ public async Task TestSlightlyChangedMessageDifferentSignaturesAsync()
+ {
+ var messageOriginal = Encoding.UTF8.GetBytes("This is a test message.");
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+ var signatureOriginal = await Signer.SignAsync(messageOriginal, privateKey, publicKey);
+
+ var messageAltered = Encoding.UTF8.GetBytes("This is a test message!");
+ var signatureAltered = await Signer.SignAsync(messageAltered, privateKey, publicKey);
+
+ // Two different messages must produce different signatures!
+ Assert.That(signatureOriginal, Is.Not.EqualTo(signatureAltered));
+ }
+
+ [Test]
+ public void TestMessageValidationWithDifferentEncodings()
+ {
+ var messageOriginal = Encoding.ASCII.GetBytes("This is a test message.");
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var signatureOriginal = Signer.Sign(messageOriginal, privateKey, publicKey);
+
+ var messageAltered = Encoding.UTF32.GetBytes("This is a test message.");
+ var signatureAltered = Signer.Sign(messageAltered, privateKey, publicKey);
+
+ // Two equal messages with different encoding must produce different signatures:
+ Assert.That(signatureOriginal.ToArray(), Is.Not.EqualTo(signatureAltered.ToArray()));
+ }
+
+ [Test]
+ public async Task TestMessageValidationWithDifferentEncodingsAsync()
+ {
+ var messageOriginal = Encoding.ASCII.GetBytes("This is a test message.");
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+ var signatureOriginal = await Signer.SignAsync(messageOriginal, privateKey, publicKey);
+
+ var messageAltered = Encoding.UTF32.GetBytes("This is a test message.");
+ var signatureAltered = await Signer.SignAsync(messageAltered, privateKey, publicKey);
+
+ // Two equal messages with different encoding must produce different signatures:
+ Assert.That(signatureOriginal, Is.Not.EqualTo(signatureAltered));
+ }
+
+ [Test]
+ public void TestMessageWithUmlautsAndDifferentEncodings()
+ {
+ var messageOriginal = Encoding.ASCII.GetBytes("This is a test message with umlauts äöü.");
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var signatureOriginal = Signer.Sign(messageOriginal, privateKey, publicKey);
+
+ var messageAltered = Encoding.UTF8.GetBytes("This is a test message with umlauts äöü.");
+ var signatureAltered = Signer.Sign(messageAltered, privateKey, publicKey);
+
+ // Two equal messages with different encoding must produce different signatures:
+ Assert.That(signatureOriginal.ToArray(), Is.Not.EqualTo(signatureAltered.ToArray()));
+ }
+
+ [Test]
+ public void TestMessageWithUmlauts()
+ {
+ var messageOriginal = Encoding.UTF8.GetBytes("This is a test message with umlauts äöü.");
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var signatureOriginal = Signer.Sign(messageOriginal, privateKey, publicKey);
+
+ var message2 = Encoding.UTF8.GetBytes("This is a test message with umlauts äöü.");
+ var signature2 = Signer.Sign(message2, privateKey, publicKey);
+ var validationResult = Signer.Validate(signatureOriginal, message2, publicKey);
+
+ // Two equal messages must produce same signatures:
+ Assert.That(signatureOriginal.ToArray(), Is.EqualTo(signature2.ToArray()));
+ Assert.That(validationResult, Is.True);
+ }
+
+ [Test]
+ public void TestKeyGeneratorWithoutPassword()
+ {
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+
+ Assert.That(privateKey.Length, Is.EqualTo(32));
+ Assert.That(publicKey.Length, Is.EqualTo(32));
+ Assert.That(privateKey.ToArray(), Is.Not.EqualTo(publicKey.ToArray()));
+ }
+
+ [Test]
+ public async Task TestKeyGeneratorWithoutPasswordAsync()
+ {
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+
+ Assert.That(privateKey.Length, Is.EqualTo(32));
+ Assert.That(publicKey.Length, Is.EqualTo(32));
+ Assert.That(privateKey, Is.Not.EqualTo(publicKey));
+ }
+
+ [Test]
+ public void TestKeyGeneratorWithPassword()
+ {
+ var password = "test password";
+ var privateKeyEncrypted = Signer.GeneratePrivateKey(password);
+ var privateKeyDecrypted = privateKeyEncrypted.DecryptPrivateKey(password);
+ var publicKey = privateKeyDecrypted.ExtractPublicKey();
+
+ Assert.That(privateKeyEncrypted.Length, Is.GreaterThan(32));
+ Assert.That(privateKeyDecrypted.Length, Is.EqualTo(32));
+ Assert.That(publicKey.Length, Is.EqualTo(32));
+ Assert.That(privateKeyEncrypted.ToArray(), Is.Not.EqualTo(privateKeyDecrypted.ToArray()));
+ Assert.That(privateKeyEncrypted.ToArray(), Is.Not.EqualTo(publicKey.ToArray()));
+ Assert.That(privateKeyDecrypted.ToArray(), Is.Not.EqualTo(publicKey.ToArray()));
+ }
+
+ [Test]
+ public async Task TestKeyGeneratorWithPasswordAsync()
+ {
+ var password = "test password";
+ var privateKeyEncrypted = await Signer.GeneratePrivateKeyAsync(password);
+ var privateKeyDecrypted = await privateKeyEncrypted.DecryptPrivateKeyAsync(password);
+ var publicKey = await privateKeyDecrypted.ExtractPublicKeyAsync();
+
+ Assert.That(privateKeyEncrypted.Length, Is.GreaterThan(32));
+ Assert.That(privateKeyDecrypted.Length, Is.EqualTo(32));
+ Assert.That(publicKey.Length, Is.EqualTo(32));
+ Assert.That(privateKeyEncrypted, Is.Not.EqualTo(privateKeyDecrypted));
+ Assert.That(privateKeyEncrypted, Is.Not.EqualTo(publicKey));
+ Assert.That(privateKeyDecrypted, Is.Not.EqualTo(publicKey));
+ }
+
+ [Test]
+ public void TestMultipleKeysWithoutPassword()
+ {
+ var privateKey1 = Signer.GeneratePrivateKey();
+ var privateKey2 = Signer.GeneratePrivateKey();
+ var privateKey3 = Signer.GeneratePrivateKey();
+
+ Assert.That(privateKey1.ToArray(), Is.Not.EqualTo(privateKey2.ToArray()));
+ Assert.That(privateKey1.ToArray(), Is.Not.EqualTo(privateKey3.ToArray()));
+ Assert.That(privateKey2.ToArray(), Is.Not.EqualTo(privateKey3.ToArray()));
+ }
+
+ [Test]
+ public async Task TestMultipleKeysWithoutPasswordAsync()
+ {
+ var privateKey1 = await Signer.GeneratePrivateKeyAsync();
+ var privateKey2 = await Signer.GeneratePrivateKeyAsync();
+ var privateKey3 = await Signer.GeneratePrivateKeyAsync();
+
+ Assert.That(privateKey1, Is.Not.EqualTo(privateKey2));
+ Assert.That(privateKey1, Is.Not.EqualTo(privateKey3));
+ Assert.That(privateKey2, Is.Not.EqualTo(privateKey3));
+ }
+
+ [Test]
+ public void TestMultipleKeysWithPassword()
+ {
+ var password = "test password";
+ var privateKey1 = Signer.GeneratePrivateKey(password);
+ var privateKey2 = Signer.GeneratePrivateKey(password);
+ var privateKey3 = Signer.GeneratePrivateKey(password);
+
+ Assert.That(privateKey1.ToArray(), Is.Not.EqualTo(privateKey2.ToArray()));
+ Assert.That(privateKey1.ToArray(), Is.Not.EqualTo(privateKey3.ToArray()));
+ Assert.That(privateKey2.ToArray(), Is.Not.EqualTo(privateKey3.ToArray()));
+ }
+
+ [Test]
+ public async Task TestMultipleKeysWithPasswordAsync()
+ {
+ var password = "test password";
+ var privateKey1 = await Signer.GeneratePrivateKeyAsync(password);
+ var privateKey2 = await Signer.GeneratePrivateKeyAsync(password);
+ var privateKey3 = await Signer.GeneratePrivateKeyAsync(password);
+
+ Assert.That(privateKey1, Is.Not.EqualTo(privateKey2));
+ Assert.That(privateKey1, Is.Not.EqualTo(privateKey3));
+ Assert.That(privateKey2, Is.Not.EqualTo(privateKey3));
+ }
+
+ [Test]
+ public void TestPublicKeyFromRandomData()
+ {
+ var privateKey = new byte[] {0x00, 0xac, 0x48}.AsSpan();
+ var publicKey = privateKey.ExtractPublicKey();
+
+ Assert.That(privateKey.Length, Is.EqualTo(3));
+ Assert.That(publicKey.Length, Is.EqualTo(0));
+ Assert.That(publicKey.IsEmpty, Is.True);
+ }
+
+ [Test]
+ public async Task TestPublicKeyFromRandomDataAsync()
+ {
+ var privateKey = new byte[] { 0x00, 0xac, 0x48 };
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+
+ Assert.That(privateKey.Length, Is.EqualTo(3));
+ Assert.That(publicKey, Is.Null);
+ }
+
+ [Test]
+ public void TestWritingAndLoadingKeys()
+ {
+ var tempFilePrivate = Path.GetTempFileName();
+ var tempFilePublic = Path.GetTempFileName();
+
+ try
+ {
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+
+ privateKey.WriteKey(tempFilePrivate);
+ publicKey.WriteKey(tempFilePublic);
+
+ var reloadPrivateKey = Signer.LoadKey(tempFilePrivate);
+ var reloadPublicKey = Signer.LoadKey(tempFilePublic);
+
+ Assert.That(reloadPublicKey.Length, Is.EqualTo(32));
+ Assert.That(reloadPrivateKey.Length, Is.EqualTo(32));
+
+ Assert.That(reloadPublicKey.ToArray(), Is.EqualTo(publicKey.ToArray()));
+ Assert.That(reloadPrivateKey.ToArray(), Is.EqualTo(privateKey.ToArray()));
+ }
+ finally
+ {
+ File.Delete(tempFilePublic);
+ File.Delete(tempFilePrivate);
+ }
+ }
+
+ [Test]
+ public async Task TestWritingAndLoadingKeysAsync()
+ {
+ var tempFilePrivate = Path.GetTempFileName();
+ var tempFilePublic = Path.GetTempFileName();
+
+ try
+ {
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+
+ await privateKey.WriteKeyAsync(tempFilePrivate);
+ await publicKey.WriteKeyAsync(tempFilePublic);
+
+ var reloadPrivateKey = await Signer.LoadKeyAsync(tempFilePrivate);
+ var reloadPublicKey = await Signer.LoadKeyAsync(tempFilePublic);
+
+ Assert.That(reloadPublicKey.Length, Is.EqualTo(32));
+ Assert.That(reloadPrivateKey.Length, Is.EqualTo(32));
+
+ Assert.That(reloadPublicKey, Is.EqualTo(publicKey));
+ Assert.That(reloadPrivateKey, Is.EqualTo(privateKey));
+ }
+ finally
+ {
+ File.Delete(tempFilePublic);
+ File.Delete(tempFilePrivate);
+ }
+ }
+
+ [Test]
+ public void TestExtractPublicKeyFromEncryptedPrivateKey()
+ {
+ var privateKeyEncrypted = Signer.GeneratePrivateKey("secret password");
+ var privateKeyDecrypted = privateKeyEncrypted.DecryptPrivateKey("secret password");
+ var publicKeyFromDecrypted = privateKeyDecrypted.ExtractPublicKey();
+ var publicKeyFromEncrypted = privateKeyEncrypted.ExtractPublicKey();
+
+ Assert.That(publicKeyFromDecrypted.ToArray(), Is.Not.EqualTo(publicKeyFromEncrypted.ToArray()));
+ }
+
+ [Test]
+ public async Task TestExtractPublicKeyFromEncryptedPrivateKeyAsync()
+ {
+ var privateKeyEncrypted = await Signer.GeneratePrivateKeyAsync("secret password");
+ var privateKeyDecrypted = await privateKeyEncrypted.DecryptPrivateKeyAsync("secret password");
+ var publicKeyFromDecrypted = await privateKeyDecrypted.ExtractPublicKeyAsync();
+ var publicKeyFromEncrypted = await privateKeyEncrypted.ExtractPublicKeyAsync();
+
+ Assert.That(publicKeyFromDecrypted, Is.Not.EqualTo(publicKeyFromEncrypted));
+ }
+
+ [Test]
+ public void TestExtractPublicKeyFromTooShortPrivateKey()
+ {
+ var privateKey= Signer.GeneratePrivateKey()[..6]; // Six first bytes from private key!
+ var publicKey = privateKey.ExtractPublicKey();
+ Assert.That(publicKey == ReadOnlySpan.Empty, Is.True);
+ }
+
+ [Test]
+ public async Task TestExtractPublicKeyFromTooShortPrivateKeyAsync()
+ {
+ var privateKey = (await Signer.GeneratePrivateKeyAsync())[..6]; // Six first bytes from private key!
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+ Assert.That(publicKey, Is.Null);
+ }
+
+ [Test]
+ public void TestSigningBehaviourPrivateKeyWithPassword()
+ {
+ var privateKeyEncrypted = Signer.GeneratePrivateKey("secret password");
+ var privateKeyDecrypted = privateKeyEncrypted.DecryptPrivateKey("secret password");
+ var publicKey = privateKeyDecrypted.ExtractPublicKey();
+ var message = Encoding.UTF8.GetBytes("This is a test message.");
+ var signaturePrivateKeyDecrypted = Signer.Sign(message, privateKeyDecrypted, publicKey);
+ var signaturePrivateKeyEncrypted = Signer.Sign(message, privateKeyEncrypted[..32], publicKey); // Note: The encrypted private key is 64 bytes long!
+ var validationDecrypted = Signer.Validate(signaturePrivateKeyDecrypted, message, publicKey);
+ var validationEncrypted = Signer.Validate(signaturePrivateKeyEncrypted, message, publicKey);
+
+ Assert.That(validationDecrypted, Is.True); // This is the intended behaviour. The public key was derived from the decrypted private key.
+ Assert.That(validationEncrypted, Is.False); // This should fail, because the public key does not match the *encrypted* private key!
+ Assert.That(signaturePrivateKeyEncrypted.ToArray(), Is.Not.EqualTo(signaturePrivateKeyDecrypted.ToArray()));
+ }
+
+ [Test]
+ public async Task TestSigningBehaviourPrivateKeyWithPasswordAsync()
+ {
+ var privateKeyEncrypted = await Signer.GeneratePrivateKeyAsync("secret password");
+ var privateKeyDecrypted = await privateKeyEncrypted.DecryptPrivateKeyAsync("secret password");
+ var publicKey = await privateKeyDecrypted.ExtractPublicKeyAsync();
+ var message = Encoding.UTF8.GetBytes("This is a test message.");
+ var signaturePrivateKeyDecrypted = await Signer.SignAsync(message, privateKeyDecrypted, publicKey);
+ var signaturePrivateKeyEncrypted = await Signer.SignAsync(message, privateKeyEncrypted[..32], publicKey); // Note: The encrypted private key is 64 bytes long!
+ var validationDecrypted = await Signer.ValidateAsync(signaturePrivateKeyDecrypted, message, publicKey);
+ var validationEncrypted = await Signer.ValidateAsync(signaturePrivateKeyEncrypted, message, publicKey);
+
+ Assert.That(validationDecrypted, Is.True); // This is the intended behaviour. The public key was derived from the decrypted private key.
+ Assert.That(validationEncrypted, Is.False); // This should fail, because the public key does not match the *encrypted* private key!
+ Assert.That(signaturePrivateKeyEncrypted, Is.Not.EqualTo(signaturePrivateKeyDecrypted));
+ }
+
+ [Test]
+ public void TestPerformanceSigning()
+ {
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var rng = new Random();
+ var payload = new byte[1_024];
+ var stopwatch = new Stopwatch();
+ var desiredRuntime = TimeSpan.FromSeconds(30);
+ var counter = 0;
+
+ while (true)
+ {
+ counter++;
+ rng.NextBytes(payload);
+
+ stopwatch.Start();
+ Signer.Sign(payload, privateKey, publicKey);
+ stopwatch.Stop();
+
+ if(stopwatch.Elapsed >= desiredRuntime)
+ break;
+ }
+
+ var result = counter / stopwatch.Elapsed.TotalSeconds;
+ TestContext.Write($"Benchmark for signing messages: {result:0.00} messages/second");
+ Assert.That(true);
+ }
+
+ [Test]
+ public async Task TestPerformanceSigningAsync()
+ {
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+ var rng = new Random();
+ var payload = new byte[1_024];
+ var stopwatch = new Stopwatch();
+ var desiredRuntime = TimeSpan.FromSeconds(30);
+ var counter = 0;
+
+ while (true)
+ {
+ counter++;
+ rng.NextBytes(payload);
+
+ stopwatch.Start();
+ await Signer.SignAsync(payload, privateKey, publicKey);
+ stopwatch.Stop();
+
+ if (stopwatch.Elapsed >= desiredRuntime)
+ break;
+ }
+
+ var result = counter / stopwatch.Elapsed.TotalSeconds;
+ TestContext.Write($"Benchmark for signing messages: {result:0.00} messages/second");
+ Assert.That(true);
+ }
+
+ [Test]
+ public void TestPerformanceValidation()
+ {
+ var privateKey = Signer.GeneratePrivateKey();
+ var publicKey = privateKey.ExtractPublicKey();
+ var rng = new Random();
+ var payload = new byte[1_024];
+ var stopwatch = new Stopwatch();
+ var desiredRuntime = TimeSpan.FromSeconds(30);
+ var counter = 0;
+
+ while (true)
+ {
+ counter++;
+ rng.NextBytes(payload);
+
+ var signature = Signer.Sign(payload, privateKey, publicKey);
+
+ stopwatch.Start();
+ Signer.Validate(signature, payload, publicKey);
+ stopwatch.Stop();
+
+ if (stopwatch.Elapsed >= desiredRuntime)
+ break;
+ }
+
+ var result = counter / stopwatch.Elapsed.TotalSeconds;
+ TestContext.Write($"Benchmark for validation of messages: {result:0.00} messages/second");
+ Assert.That(true);
+ }
+
+ [Test]
+ public async Task TestPerformanceValidationAsync()
+ {
+ var privateKey = await Signer.GeneratePrivateKeyAsync();
+ var publicKey = await privateKey.ExtractPublicKeyAsync();
+ var rng = new Random();
+ var payload = new byte[1_024];
+ var stopwatch = new Stopwatch();
+ var desiredRuntime = TimeSpan.FromSeconds(30);
+ var counter = 0;
+
+ while (true)
+ {
+ counter++;
+ rng.NextBytes(payload);
+
+ var signature = await Signer.SignAsync(payload, privateKey, publicKey);
+
+ stopwatch.Start();
+ await Signer.ValidateAsync(signature, payload, publicKey);
+ stopwatch.Stop();
+
+ if (stopwatch.Elapsed >= desiredRuntime)
+ break;
+ }
+
+ var result = counter / stopwatch.Elapsed.TotalSeconds;
+ TestContext.Write($"Benchmark for validation of messages: {result:0.00} messages/second");
+ Assert.That(true);
+ }
+
+ [Test]
+ public void TestLoadingNotExistingKey()
+ {
+ var key = Signer.LoadKey(Guid.NewGuid().ToString());
+ Assert.That(key == ReadOnlySpan.Empty, Is.True);
+ }
+
+ [Test]
+ public async Task TestLoadingNotExistingKeyAsync()
+ {
+ var key = await Signer.LoadKeyAsync(Guid.NewGuid().ToString());
+ Assert.That(key, Is.Null);
+ }
+
+ // See https://tools.ietf.org/html/rfc8032#section-7.1
+ [Test]
+ public void TestRFC8032Test01EmptyMessage()
+ {
+ var message = new ReadOnlySpan(); // Empty message!
+ var publicKey = new byte[]
+ {
+ 0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7, 0xd5, 0x4b, 0xfe, 0xd3, 0xc9, 0x64, 0x07, 0x3a,
+ 0x0e, 0xe1, 0x72, 0xf3, 0xda, 0xa6, 0x23, 0x25, 0xaf, 0x02, 0x1a, 0x68, 0xf7, 0x07, 0x51, 0x1a,
+ };
+
+ var privateKey = new byte[]
+ {
+ 0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, 0xba, 0x84, 0x4a, 0xf4, 0x92, 0xec, 0x2c, 0xc4,
+ 0x44, 0x49, 0xc5, 0x69, 0x7b, 0x32, 0x69, 0x19, 0x70, 0x3b, 0xac, 0x03, 0x1c, 0xae, 0x7f, 0x60,
+ };
+
+ var expectedSignature = new byte[]
+ {
+ 0xe5, 0x56, 0x43, 0x00, 0xc3, 0x60, 0xac, 0x72, 0x90, 0x86, 0xe2, 0xcc, 0x80, 0x6e, 0x82, 0x8a,
+ 0x84, 0x87, 0x7f, 0x1e, 0xb8, 0xe5, 0xd9, 0x74, 0xd8, 0x73, 0xe0, 0x65, 0x22, 0x49, 0x01, 0x55,
+ 0x5f, 0xb8, 0x82, 0x15, 0x90, 0xa3, 0x3b, 0xac, 0xc6, 0x1e, 0x39, 0x70, 0x1c, 0xf9, 0xb4, 0x6b,
+ 0xd2, 0x5b, 0xf5, 0xf0, 0x59, 0x5b, 0xbe, 0x24, 0x65, 0x51, 0x41, 0x43, 0x8e, 0x7a, 0x10, 0x0b,
+ };
+
+ var signature = Signer.Sign(message, privateKey, publicKey);
+ Assert.That(signature.ToArray(), Is.EqualTo(expectedSignature));
+
+ var validationResult = Signer.Validate(signature, message, publicKey);
+ Assert.That(validationResult, Is.True);
+ }
+
+ // See https://tools.ietf.org/html/rfc8032#section-7.1
+ [Test]
+ public void TestRFC8032Test02OneByteMessage()
+ {
+ var message = new byte[]
+ {
+ 0x72,
+ };
+
+ var publicKey = new byte[]
+ {
+ 0x3d, 0x40, 0x17, 0xc3, 0xe8, 0x43, 0x89, 0x5a, 0x92, 0xb7, 0x0a, 0xa7, 0x4d, 0x1b, 0x7e, 0xbc,
+ 0x9c, 0x98, 0x2c, 0xcf, 0x2e, 0xc4, 0x96, 0x8c, 0xc0, 0xcd, 0x55, 0xf1, 0x2a, 0xf4, 0x66, 0x0c,
+ };
+
+ var privateKey = new byte[]
+ {
+ 0x4c, 0xcd, 0x08, 0x9b, 0x28, 0xff, 0x96, 0xda, 0x9d, 0xb6, 0xc3, 0x46, 0xec, 0x11, 0x4e, 0x0f,
+ 0x5b, 0x8a, 0x31, 0x9f, 0x35, 0xab, 0xa6, 0x24, 0xda, 0x8c, 0xf6, 0xed, 0x4f, 0xb8, 0xa6, 0xfb,
+ };
+
+ var expectedSignature = new byte[]
+ {
+ 0x92, 0xa0, 0x09, 0xa9, 0xf0, 0xd4, 0xca, 0xb8, 0x72, 0x0e, 0x82, 0x0b, 0x5f, 0x64, 0x25, 0x40,
+ 0xa2, 0xb2, 0x7b, 0x54, 0x16, 0x50, 0x3f, 0x8f, 0xb3, 0x76, 0x22, 0x23, 0xeb, 0xdb, 0x69, 0xda,
+ 0x08, 0x5a, 0xc1, 0xe4, 0x3e, 0x15, 0x99, 0x6e, 0x45, 0x8f, 0x36, 0x13, 0xd0, 0xf1, 0x1d, 0x8c,
+ 0x38, 0x7b, 0x2e, 0xae, 0xb4, 0x30, 0x2a, 0xee, 0xb0, 0x0d, 0x29, 0x16, 0x12, 0xbb, 0x0c, 0x00,
+ };
+
+ var signature = Signer.Sign(message, privateKey, publicKey);
+ Assert.That(signature.ToArray(), Is.EqualTo(expectedSignature));
+
+ var validationResult = Signer.Validate(signature, message, publicKey);
+ Assert.That(validationResult, Is.True);
+ }
+
+ // See https://tools.ietf.org/html/rfc8032#section-7.1
+ [Test]
+ public void TestRFC8032Test03TwoByteMessage()
+ {
+ var message = new byte[]
+ {
+ 0xaf, 0x82,
+ };
+
+ var publicKey = new byte[]
+ {
+ 0xfc, 0x51, 0xcd, 0x8e, 0x62, 0x18, 0xa1, 0xa3, 0x8d, 0xa4, 0x7e, 0xd0, 0x02, 0x30, 0xf0, 0x58,
+ 0x08, 0x16, 0xed, 0x13, 0xba, 0x33, 0x03, 0xac, 0x5d, 0xeb, 0x91, 0x15, 0x48, 0x90, 0x80, 0x25,
+
+ };
+
+ var privateKey = new byte[]
+ {
+ 0xc5, 0xaa, 0x8d, 0xf4, 0x3f, 0x9f, 0x83, 0x7b, 0xed, 0xb7, 0x44, 0x2f, 0x31, 0xdc, 0xb7, 0xb1,
+ 0x66, 0xd3, 0x85, 0x35, 0x07, 0x6f, 0x09, 0x4b, 0x85, 0xce, 0x3a, 0x2e, 0x0b, 0x44, 0x58, 0xf7,
+ };
+
+ var expectedSignature = new byte[]
+ {
+ 0x62, 0x91, 0xd6, 0x57, 0xde, 0xec, 0x24, 0x02, 0x48, 0x27, 0xe6, 0x9c, 0x3a, 0xbe, 0x01, 0xa3,
+ 0x0c, 0xe5, 0x48, 0xa2, 0x84, 0x74, 0x3a, 0x44, 0x5e, 0x36, 0x80, 0xd7, 0xdb, 0x5a, 0xc3, 0xac,
+ 0x18, 0xff, 0x9b, 0x53, 0x8d, 0x16, 0xf2, 0x90, 0xae, 0x67, 0xf7, 0x60, 0x98, 0x4d, 0xc6, 0x59,
+ 0x4a, 0x7c, 0x15, 0xe9, 0x71, 0x6e, 0xd2, 0x8d, 0xc0, 0x27, 0xbe, 0xce, 0xea, 0x1e, 0xc4, 0x0a,
+ };
+
+ var signature = Signer.Sign(message, privateKey, publicKey);
+ Assert.That(signature.ToArray(), Is.EqualTo(expectedSignature));
+
+ var validationResult = Signer.Validate(signature, message, publicKey);
+ Assert.That(validationResult, Is.True);
+ }
+
+ // See https://tools.ietf.org/html/rfc8032#section-7.1
+ [Test]
+ public void TestRFC8032Test04With1kMessage()
+ {
+ var message = new byte[]
+ {
+ 0x08, 0xb8, 0xb2, 0xb7, 0x33, 0x42, 0x42, 0x43, 0x76, 0x0f, 0xe4, 0x26, 0xa4, 0xb5, 0x49, 0x08,
+ 0x63, 0x21, 0x10, 0xa6, 0x6c, 0x2f, 0x65, 0x91, 0xea, 0xbd, 0x33, 0x45, 0xe3, 0xe4, 0xeb, 0x98,
+ 0xfa, 0x6e, 0x26, 0x4b, 0xf0, 0x9e, 0xfe, 0x12, 0xee, 0x50, 0xf8, 0xf5, 0x4e, 0x9f, 0x77, 0xb1,
+ 0xe3, 0x55, 0xf6, 0xc5, 0x05, 0x44, 0xe2, 0x3f, 0xb1, 0x43, 0x3d, 0xdf, 0x73, 0xbe, 0x84, 0xd8,
+ 0x79, 0xde, 0x7c, 0x00, 0x46, 0xdc, 0x49, 0x96, 0xd9, 0xe7, 0x73, 0xf4, 0xbc, 0x9e, 0xfe, 0x57,
+ 0x38, 0x82, 0x9a, 0xdb, 0x26, 0xc8, 0x1b, 0x37, 0xc9, 0x3a, 0x1b, 0x27, 0x0b, 0x20, 0x32, 0x9d,
+ 0x65, 0x86, 0x75, 0xfc, 0x6e, 0xa5, 0x34, 0xe0, 0x81, 0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 0x98, 0x3f, 0x87, 0x41, 0xc5, 0xef, 0x68, 0xd3, 0xa1, 0x01, 0xe8, 0xa3, 0xb8, 0xca,
+ 0xc6, 0x0c, 0x90, 0x5c, 0x15, 0xfc, 0x91, 0x08, 0x40, 0xb9, 0x4c, 0x00, 0xa0, 0xb9, 0xd0,
+ };
+
+ var publicKey = new byte[]
+ {
+ 0x27, 0x81, 0x17, 0xfc, 0x14, 0x4c, 0x72, 0x34, 0x0f, 0x67, 0xd0, 0xf2, 0x31, 0x6e, 0x83, 0x86,
+ 0xce, 0xff, 0xbf, 0x2b, 0x24, 0x28, 0xc9, 0xc5, 0x1f, 0xef, 0x7c, 0x59, 0x7f, 0x1d, 0x42, 0x6e,
+ };
+
+ var privateKey = new byte[]
+ {
+ 0xf5, 0xe5, 0x76, 0x7c, 0xf1, 0x53, 0x31, 0x95, 0x17, 0x63, 0x0f, 0x22, 0x68, 0x76, 0xb8, 0x6c,
+ 0x81, 0x60, 0xcc, 0x58, 0x3b, 0xc0, 0x13, 0x74, 0x4c, 0x6b, 0xf2, 0x55, 0xf5, 0xcc, 0x0e, 0xe5,
+ };
+
+ var expectedSignature = new byte[]
+ {
+ 0x0a, 0xab, 0x4c, 0x90, 0x05, 0x01, 0xb3, 0xe2, 0x4d, 0x7c, 0xdf, 0x46, 0x63, 0x32, 0x6a, 0x3a,
+ 0x87, 0xdf, 0x5e, 0x48, 0x43, 0xb2, 0xcb, 0xdb, 0x67, 0xcb, 0xf6, 0xe4, 0x60, 0xfe, 0xc3, 0x50,
+ 0xaa, 0x53, 0x71, 0xb1, 0x50, 0x8f, 0x9f, 0x45, 0x28, 0xec, 0xea, 0x23, 0xc4, 0x36, 0xd9, 0x4b,
+ 0x5e, 0x8f, 0xcd, 0x4f, 0x68, 0x1e, 0x30, 0xa6, 0xac, 0x00, 0xa9, 0x70, 0x4a, 0x18, 0x8a, 0x03,
+ };
+
+ var signature = Signer.Sign(message, privateKey, publicKey);
+ Assert.That(signature.ToArray(), Is.EqualTo(expectedSignature));
+
+ var validationResult = Signer.Validate(signature, message, publicKey);
+ Assert.That(validationResult, Is.True);
+ }
+
+ // See https://tools.ietf.org/html/rfc8032#section-7.1
+ [Test]
+ public async Task TestRFC8032Test04With1kMessageAsync()
+ {
+ var message = new byte[]
+ {
+ 0x08, 0xb8, 0xb2, 0xb7, 0x33, 0x42, 0x42, 0x43, 0x76, 0x0f, 0xe4, 0x26, 0xa4, 0xb5, 0x49, 0x08,
+ 0x63, 0x21, 0x10, 0xa6, 0x6c, 0x2f, 0x65, 0x91, 0xea, 0xbd, 0x33, 0x45, 0xe3, 0xe4, 0xeb, 0x98,
+ 0xfa, 0x6e, 0x26, 0x4b, 0xf0, 0x9e, 0xfe, 0x12, 0xee, 0x50, 0xf8, 0xf5, 0x4e, 0x9f, 0x77, 0xb1,
+ 0xe3, 0x55, 0xf6, 0xc5, 0x05, 0x44, 0xe2, 0x3f, 0xb1, 0x43, 0x3d, 0xdf, 0x73, 0xbe, 0x84, 0xd8,
+ 0x79, 0xde, 0x7c, 0x00, 0x46, 0xdc, 0x49, 0x96, 0xd9, 0xe7, 0x73, 0xf4, 0xbc, 0x9e, 0xfe, 0x57,
+ 0x38, 0x82, 0x9a, 0xdb, 0x26, 0xc8, 0x1b, 0x37, 0xc9, 0x3a, 0x1b, 0x27, 0x0b, 0x20, 0x32, 0x9d,
+ 0x65, 0x86, 0x75, 0xfc, 0x6e, 0xa5, 0x34, 0xe0, 0x81, 0x0a, 0x44, 0x32, 0x82, 0x6b, 0xf5, 0x8c,
+ 0x94, 0x1e, 0xfb, 0x65, 0xd5, 0x7a, 0x33, 0x8b, 0xbd, 0x2e, 0x26, 0x64, 0x0f, 0x89, 0xff, 0xbc,
+ 0x1a, 0x85, 0x8e, 0xfc, 0xb8, 0x55, 0x0e, 0xe3, 0xa5, 0xe1, 0x99, 0x8b, 0xd1, 0x77, 0xe9, 0x3a,
+ 0x73, 0x63, 0xc3, 0x44, 0xfe, 0x6b, 0x19, 0x9e, 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 0x86,
+ 0xce, 0xff, 0xbf, 0x2b, 0x24, 0x28, 0xc9, 0xc5, 0x1f, 0xef, 0x7c, 0x59, 0x7f, 0x1d, 0x42, 0x6e,
+ };
+
+ var privateKey = new byte[]
+ {
+ 0xf5, 0xe5, 0x76, 0x7c, 0xf1, 0x53, 0x31, 0x95, 0x17, 0x63, 0x0f, 0x22, 0x68, 0x76, 0xb8, 0x6c,
+ 0x81, 0x60, 0xcc, 0x58, 0x3b, 0xc0, 0x13, 0x74, 0x4c, 0x6b, 0xf2, 0x55, 0xf5, 0xcc, 0x0e, 0xe5,
+ };
+
+ var expectedSignature = new byte[]
+ {
+ 0x0a, 0xab, 0x4c, 0x90, 0x05, 0x01, 0xb3, 0xe2, 0x4d, 0x7c, 0xdf, 0x46, 0x63, 0x32, 0x6a, 0x3a,
+ 0x87, 0xdf, 0x5e, 0x48, 0x43, 0xb2, 0xcb, 0xdb, 0x67, 0xcb, 0xf6, 0xe4, 0x60, 0xfe, 0xc3, 0x50,
+ 0xaa, 0x53, 0x71, 0xb1, 0x50, 0x8f, 0x9f, 0x45, 0x28, 0xec, 0xea, 0x23, 0xc4, 0x36, 0xd9, 0x4b,
+ 0x5e, 0x8f, 0xcd, 0x4f, 0x68, 0x1e, 0x30, 0xa6, 0xac, 0x00, 0xa9, 0x70, 0x4a, 0x18, 0x8a, 0x03,
+ };
+
+ var signature = await Signer.SignAsync(message, privateKey, publicKey);
+ Assert.That(signature, Is.EqualTo(expectedSignature));
+
+ var validationResult = await Signer.ValidateAsync(signature, message, publicKey);
+ Assert.That(validationResult, Is.True);
+ }
+ }
+}
+
#endif
\ No newline at end of file
diff --git a/Ed25519.sln b/Ed25519.sln
index 620cf86..1c174be 100644
--- a/Ed25519.sln
+++ b/Ed25519.sln
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ed25519", "Ed25519\Ed25519.csproj", "{A36D2E95-E99A-4CB4-B735-417BAE007BC7}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ed25519.Tests", "Ed25519.Tests\Ed25519.Tests.csproj", "{D725532A-B9B2-44D8-8E36-5EC76EAFDAAC}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
{A36D2E95-E99A-4CB4-B735-417BAE007BC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A36D2E95-E99A-4CB4-B735-417BAE007BC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A36D2E95-E99A-4CB4-B735-417BAE007BC7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D725532A-B9B2-44D8-8E36-5EC76EAFDAAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D725532A-B9B2-44D8-8E36-5EC76EAFDAAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D725532A-B9B2-44D8-8E36-5EC76EAFDAAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D725532A-B9B2-44D8-8E36-5EC76EAFDAAC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Ed25519/Ed25519.csproj b/Ed25519/Ed25519.csproj
index 51aa39a..a542937 100644
--- a/Ed25519/Ed25519.csproj
+++ b/Ed25519/Ed25519.csproj
@@ -1,7 +1,7 @@
-
+
- netcoreapp3.1
+ net5.0
true
true
Thorsten Sommer
@@ -29,13 +29,7 @@
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/Ed25519/EdPoint.cs b/Ed25519/EdPoint.cs
index 55c850d..b1c0cda 100644
--- a/Ed25519/EdPoint.cs
+++ b/Ed25519/EdPoint.cs
@@ -5,7 +5,7 @@
namespace Ed25519
{
- internal struct EdPoint
+ public struct EdPoint
{
public BigInteger X { get; set; }
diff --git a/Ed25519/Extensions.cs b/Ed25519/Extensions.cs
index 5ccb6e0..e31748e 100644
--- a/Ed25519/Extensions.cs
+++ b/Ed25519/Extensions.cs
@@ -75,7 +75,7 @@ internal static BigInteger RecoverX(this BigInteger y)
return x;
}
- internal static BigInteger ExpMod(this BigInteger number, BigInteger exponent, BigInteger modulo)
+ public static BigInteger ExpMod(this BigInteger number, BigInteger exponent, BigInteger modulo)
{
var numberOperations = (int)Math.Ceiling(BigInteger.Log(exponent, 2)) + 1;
var series = new bool[numberOperations];