summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authormw <megan@cryptoworkshop.com>2022-09-14 08:38:18 +1000
committermw <megan@cryptoworkshop.com>2022-09-14 08:38:18 +1000
commit6836706a1da6ed16e7d08dbddbb0220fd6722391 (patch)
tree231a97d72a6754f6fbb96e3edc302adf018d93f0 /crypto/test
parentadded missing usage (diff)
downloadBouncyCastle.NET-ed25519-6836706a1da6ed16e7d08dbddbb0220fd6722391.tar.xz
Cleanup.
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs46
1 files changed, 42 insertions, 4 deletions
diff --git a/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs b/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs

index 1fddfb565..fc26f3c5f 100644 --- a/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs +++ b/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs
@@ -37,6 +37,45 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests RunTestVectorFile(testVectorFile); } + [Test] + public void TestDilithiumRandom() + { + byte[] msg = Strings.ToByteArray("Hello World!"); + + Security.SecureRandom random = new Security.SecureRandom(); + + DilithiumKeyPairGenerator kpGen = new DilithiumKeyPairGenerator(); + DilithiumKeyGenerationParameters genParams = new DilithiumKeyGenerationParameters(random, DilithiumParameters.Dilithium2); + kpGen.Init(genParams); + + + + + for (int i = 0; i < 1000; i++) { + + // + // Generate keys and test. + // + + AsymmetricCipherKeyPair kp = kpGen.GenerateKeyPair(); + + + DilithiumSigner signer = new DilithiumSigner(random); + + signer.Init(true, kp.Private); + + byte[] s = signer.GenerateSignature(msg); + + signer.Init(false, kp.Public); + + + Assert.True(signer.VerifySignature(msg,s),"Here "+i); + + } + } + + + private static void TestVectors(string name, IDictionary<string, string> buf) { string count = buf["count"]; @@ -85,13 +124,12 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests Assert.True(smlen == attachedSig.Length, name + " " + count + ": signature length"); - byte[] msg1 = new byte[msg.Length]; + signer.Init(false, pubParams); - Assert.True(signer.VerifySignature(msg1, attachedSig), (name + " " + count + ": signature verify")); - - Assert.True(Arrays.AreEqual(msg, msg1), name + " " + count + ": signature message verify"); + Assert.True(signer.VerifySignature(msg, sigGenerated), (name + " " + count + ": signature verify")); + Assert.True(Arrays.AreEqual(sigExpected, attachedSig), name + " " + count + ": signature gen match"); }