From 6836706a1da6ed16e7d08dbddbb0220fd6722391 Mon Sep 17 00:00:00 2001 From: mw Date: Wed, 14 Sep 2022 08:38:18 +1000 Subject: Cleanup. --- .../src/pqc/crypto/test/CrystalsDilithiumTest.cs | 46 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'crypto/test/src') 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 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"); } -- cgit 1.5.1