summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2022-09-20 16:14:16 +1000
committerDavid Hook <dgh@cryptoworkshop.com>2022-09-20 16:14:16 +1000
commit29713a2a41a0ef69b13466ece39ac92d2db6bcc3 (patch)
tree86c31daa9fc496d5f6e2a37d17f6b562d57de542
parentAdd MapElements methods (diff)
downloadBouncyCastle.NET-ed25519-29713a2a41a0ef69b13466ece39ac92d2db6bcc3.tar.xz
added randomized signing
-rw-r--r--crypto/src/pqc/crypto/crystals/dilithium/DilithiumEngine.cs3
-rw-r--r--crypto/src/pqc/crypto/crystals/dilithium/DilithiumSigner.cs13
-rw-r--r--crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs4
3 files changed, 9 insertions, 11 deletions
diff --git a/crypto/src/pqc/crypto/crystals/dilithium/DilithiumEngine.cs b/crypto/src/pqc/crypto/crystals/dilithium/DilithiumEngine.cs
index b5ac413e4..9b6479eaf 100644
--- a/crypto/src/pqc/crypto/crystals/dilithium/DilithiumEngine.cs
+++ b/crypto/src/pqc/crypto/crystals/dilithium/DilithiumEngine.cs
@@ -17,7 +17,6 @@ namespace Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium
         public const int RootOfUnity = 1753;
         public const int SeedBytes = 32;
         public const int CrhBytes = 64;
-        public const bool RandomizedSigning = false;
 
         public const int PolyT1PackedBytes = 320;
         public const int PolyT0PackedBytes = 416;
@@ -185,7 +184,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium
             ShakeDigest256.BlockUpdate(msg, 0, msglen);
             ShakeDigest256.DoFinal(mu, 0, CrhBytes);
 
-            if (RandomizedSigning)
+            if (_random != null)
             {
                 _random.NextBytes(rhoPrime);
             }
diff --git a/crypto/src/pqc/crypto/crystals/dilithium/DilithiumSigner.cs b/crypto/src/pqc/crypto/crystals/dilithium/DilithiumSigner.cs
index 98b19ff3e..58b9d1803 100644
--- a/crypto/src/pqc/crypto/crystals/dilithium/DilithiumSigner.cs
+++ b/crypto/src/pqc/crypto/crystals/dilithium/DilithiumSigner.cs
@@ -12,9 +12,8 @@ namespace Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium
 
         private SecureRandom random;
 
-        public DilithiumSigner(SecureRandom random)
+        public DilithiumSigner()
         {
-            this.random = random;
         }
 
         public void Init(bool forSigning, ICipherParameters param)
@@ -22,15 +21,15 @@ namespace Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium
             if (forSigning)
             {
                 if (param is ParametersWithRandom)
-            {
+                {
                     privKey = (DilithiumPrivateKeyParameters)((ParametersWithRandom)param).Parameters;
                     random = ((ParametersWithRandom)param).Random;
                 }
                 else
-                    {
-                        privKey = (DilithiumPrivateKeyParameters)param;
-                        random = new SecureRandom();
-                    }
+                {
+                    privKey = (DilithiumPrivateKeyParameters)param;
+                    random = null;
+                }
             }
             else
             {
diff --git a/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs b/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs
index fc26f3c5f..351fc9140 100644
--- a/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs
+++ b/crypto/test/src/pqc/crypto/test/CrystalsDilithiumTest.cs
@@ -60,7 +60,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests
                 AsymmetricCipherKeyPair kp = kpGen.GenerateKeyPair();
 
 
-                DilithiumSigner signer = new DilithiumSigner(random);
+                DilithiumSigner signer = new DilithiumSigner();
 
                 signer.Init(true, kp.Private);
 
@@ -112,7 +112,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests
             //
             // Signature test
             //
-            DilithiumSigner signer = new DilithiumSigner(random);
+            DilithiumSigner signer = new DilithiumSigner();
 
             signer.Init(true, privParams);
             byte[] sigGenerated = signer.GenerateSignature(msg);