summary refs log tree commit diff
path: root/crypto/src/pqc/crypto/crystals/dilithium/DilithiumPrivateKeyParameters.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/pqc/crypto/crystals/dilithium/DilithiumPrivateKeyParameters.cs')
-rw-r--r--crypto/src/pqc/crypto/crystals/dilithium/DilithiumPrivateKeyParameters.cs22
1 files changed, 22 insertions, 0 deletions
diff --git a/crypto/src/pqc/crypto/crystals/dilithium/DilithiumPrivateKeyParameters.cs b/crypto/src/pqc/crypto/crystals/dilithium/DilithiumPrivateKeyParameters.cs
index 66a518c93..cf18ce56e 100644
--- a/crypto/src/pqc/crypto/crystals/dilithium/DilithiumPrivateKeyParameters.cs
+++ b/crypto/src/pqc/crypto/crystals/dilithium/DilithiumPrivateKeyParameters.cs
@@ -27,6 +27,28 @@ namespace Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium
             m_t1 = Arrays.Clone(t1);
         }
 
+        public DilithiumPrivateKeyParameters(DilithiumParameters parameters, byte[] encoding, DilithiumPublicKeyParameters pubKey)
+    : base(true, parameters)
+        {
+            DilithiumEngine eng = parameters.GetEngine(null);
+
+            int index = 0;
+            m_rho = Arrays.CopyOfRange(encoding, 0, DilithiumEngine.SeedBytes); index += DilithiumEngine.SeedBytes;
+            m_k = Arrays.CopyOfRange(encoding, index, index + DilithiumEngine.SeedBytes); index += DilithiumEngine.SeedBytes;
+            m_tr = Arrays.CopyOfRange(encoding, index, index + DilithiumEngine.TrBytes); index += DilithiumEngine.TrBytes;
+            int delta = eng.L * eng.PolyEtaPackedBytes;
+            m_s1 = Arrays.CopyOfRange(encoding, index, index + delta); index += delta;
+            delta = eng.K * eng.PolyEtaPackedBytes;
+            m_s2 = Arrays.CopyOfRange(encoding, index, index + delta); index += delta;
+            delta = eng.K * DilithiumEngine.PolyT0PackedBytes;
+            m_t0 = Arrays.CopyOfRange(encoding, index, index + delta);
+
+            if (pubKey != null)
+            {
+                m_t1 = Arrays.Clone(pubKey.GetT1());
+            }
+        }
+
         public byte[] GetEncoded() => Arrays.ConcatenateAll(m_rho, m_k, m_tr, m_s1, m_s2, m_t0);
 
         public byte[] K => Arrays.Clone(m_k);