summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2023-08-23 16:18:26 +1000
committerDavid Hook <dgh@cryptoworkshop.com>2023-08-23 16:18:26 +1000
commitbdf66c1d6f5922134fa959a2825d5b324243e3fc (patch)
treec94a836dba5cf4ef9595dc1d22bf68cfa91eabc4 /crypto/src
parentImprove EdDSA scalar reduction (diff)
downloadBouncyCastle.NET-ed25519-bdf66c1d6f5922134fa959a2825d5b324243e3fc.tar.xz
updated SPHINCS+ keys and OIDs
Diffstat (limited to '')
-rw-r--r--crypto/src/asn1/bc/BCObjectIdentifiers.cs13
-rw-r--r--crypto/src/pqc/crypto/sphincsplus/SPHINCSPlusPublicKeyParameters.cs2
-rw-r--r--crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs27
-rw-r--r--crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs2
-rw-r--r--crypto/src/pqc/crypto/utils/PqcUtilities.cs19
5 files changed, 58 insertions, 5 deletions
diff --git a/crypto/src/asn1/bc/BCObjectIdentifiers.cs b/crypto/src/asn1/bc/BCObjectIdentifiers.cs
index fffbb1294..ce1249d38 100644
--- a/crypto/src/asn1/bc/BCObjectIdentifiers.cs
+++ b/crypto/src/asn1/bc/BCObjectIdentifiers.cs
@@ -179,6 +179,19 @@ namespace Org.BouncyCastle.Asn1.BC
         public static readonly DerObjectIdentifier sphincsPlus_haraka_256s_r3_simple = sphincsPlus.Branch("35");
         public static readonly DerObjectIdentifier sphincsPlus_haraka_256f_r3_simple = sphincsPlus.Branch("36");
 
+        // Interop OIDs.
+        public static readonly DerObjectIdentifier sphincsPlus_sha2_128s_simple = new DerObjectIdentifier("1.3.9999.6.4.16");
+        public static readonly DerObjectIdentifier sphincsPlus_sha2_128f_simple = new DerObjectIdentifier("1.3.9999.6.4.13");
+        public static readonly DerObjectIdentifier sphincsPlus_shake_128f_simple = new DerObjectIdentifier("1.3.9999.6.7.4");
+
+        public static readonly DerObjectIdentifier sphincsPlus_sha2_192s_simple = new DerObjectIdentifier("1.3.9999.6.5.12");
+        public static readonly DerObjectIdentifier sphincsPlus_sha2_192f_simple = new DerObjectIdentifier("1.3.9999.6.5.10");
+        public static readonly DerObjectIdentifier sphincsPlus_shake_192f_simple = new DerObjectIdentifier("1.3.9999.6.8.3");
+    
+        public static readonly DerObjectIdentifier sphincsPlus_sha2_256s_simple = new DerObjectIdentifier("1.3.9999.6.6.12");
+        public static readonly DerObjectIdentifier sphincsPlus_sha2_256f_simple = new DerObjectIdentifier("1.3.9999.6.6.10");
+        public static readonly DerObjectIdentifier sphincsPlus_shake_256f_simple = new DerObjectIdentifier("1.3.9999.6.9.3");
+
         [Obsolete("Will be removed - name is erroneous")]
         public static readonly DerObjectIdentifier sphincsPlus_shake_256 = sphincsPlus.Branch("1");
         [Obsolete("Will be removed - name is erroneous")]
diff --git a/crypto/src/pqc/crypto/sphincsplus/SPHINCSPlusPublicKeyParameters.cs b/crypto/src/pqc/crypto/sphincsplus/SPHINCSPlusPublicKeyParameters.cs
index 13028ea1b..7536e1a89 100644
--- a/crypto/src/pqc/crypto/sphincsplus/SPHINCSPlusPublicKeyParameters.cs
+++ b/crypto/src/pqc/crypto/sphincsplus/SPHINCSPlusPublicKeyParameters.cs
@@ -27,7 +27,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.SphincsPlus
 
         public byte[] GetEncoded()
         {
-            return Arrays.ConcatenateAll(Parameters.GetEncoded(), m_pk.seed, m_pk.root);
+            return Arrays.ConcatenateAll(m_pk.seed, m_pk.root);
         }
 
         public byte[] GetRoot()
diff --git a/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs b/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs
index 5dcd7ab0c..73a553d0e 100644
--- a/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs
+++ b/crypto/src/pqc/crypto/utils/PqcPublicKeyFactory.cs
@@ -142,6 +142,16 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities
             Converters[BCObjectIdentifiers.sphincsPlus_shake_256f_r3] = new SphincsPlusConverter();
             Converters[BCObjectIdentifiers.sphincsPlus_haraka_256s_r3] = new SphincsPlusConverter();
             Converters[BCObjectIdentifiers.sphincsPlus_haraka_256f_r3] = new SphincsPlusConverter();
+
+            Converters[BCObjectIdentifiers.sphincsPlus_sha2_128s_simple] = new SphincsPlusConverter();
+            Converters[BCObjectIdentifiers.sphincsPlus_sha2_128f_simple] = new SphincsPlusConverter();
+            Converters[BCObjectIdentifiers.sphincsPlus_shake_128f_simple] = new SphincsPlusConverter();
+            Converters[BCObjectIdentifiers.sphincsPlus_sha2_192s_simple] = new SphincsPlusConverter();
+            Converters[BCObjectIdentifiers.sphincsPlus_sha2_192f_simple] = new SphincsPlusConverter();
+            Converters[BCObjectIdentifiers.sphincsPlus_shake_192f_simple] = new SphincsPlusConverter();
+            Converters[BCObjectIdentifiers.sphincsPlus_sha2_256s_simple] = new SphincsPlusConverter();
+            Converters[BCObjectIdentifiers.sphincsPlus_sha2_256f_simple] = new SphincsPlusConverter();
+            Converters[BCObjectIdentifiers.sphincsPlus_shake_256f_simple] = new SphincsPlusConverter();
         }
 
         /// <summary> Create a public key from a SubjectPublicKeyInfo encoding</summary>
@@ -219,11 +229,22 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities
         {
             internal override AsymmetricKeyParameter GetPublicKeyParameters(SubjectPublicKeyInfo keyInfo, object defaultParams)
             {
-                byte[] keyEnc = Asn1OctetString.GetInstance(keyInfo.ParsePublicKey()).GetOctets();
+                try
+                {
+                    byte[] keyEnc = Asn1OctetString.GetInstance(keyInfo.ParsePublicKey()).GetOctets();
 
-                SphincsPlusParameters spParams = PqcUtilities.SphincsPlusParamsLookup(keyInfo.Algorithm.Algorithm);
+                    SphincsPlusParameters spParams = PqcUtilities.SphincsPlusParamsLookup(keyInfo.Algorithm.Algorithm);
 
-                return new SphincsPlusPublicKeyParameters(spParams, Arrays.CopyOfRange(keyEnc, 4, keyEnc.Length));
+                    return new SphincsPlusPublicKeyParameters(spParams, Arrays.CopyOfRange(keyEnc, 4, keyEnc.Length));
+                }
+                catch (Exception e)
+                {
+                    byte[] keyEnc = keyInfo.PublicKey.GetOctets();
+
+                    SphincsPlusParameters spParams = PqcUtilities.SphincsPlusParamsLookup(keyInfo.Algorithm.Algorithm);
+
+                    return new SPHINCSPlusPublicKeyParameters(spParams, keyEnc);
+                }
             }
         }
         
diff --git a/crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs b/crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs
index 7b1142607..d99b5966b 100644
--- a/crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs
+++ b/crypto/src/pqc/crypto/utils/PqcSubjectPublicKeyInfoFactory.cs
@@ -60,7 +60,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities
 
                 AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(
                     PqcUtilities.SphincsPlusOidLookup(sphincsPlusPublicKeyParameters.Parameters));
-                return new SubjectPublicKeyInfo(algorithmIdentifier, new DerOctetString(encoding));
+                return new SubjectPublicKeyInfo(algorithmIdentifier, encoding);
             }
             if (publicKey is CmcePublicKeyParameters cmcePublicKeyParameters)
             {
diff --git a/crypto/src/pqc/crypto/utils/PqcUtilities.cs b/crypto/src/pqc/crypto/utils/PqcUtilities.cs
index 5172733fd..c0093c33c 100644
--- a/crypto/src/pqc/crypto/utils/PqcUtilities.cs
+++ b/crypto/src/pqc/crypto/utils/PqcUtilities.cs
@@ -234,6 +234,16 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities
             sphincsPlusOids[SphincsPlusParameters.haraka_256s] = BCObjectIdentifiers.sphincsPlus_haraka_256s_r3;
             sphincsPlusOids[SphincsPlusParameters.haraka_256f] = BCObjectIdentifiers.sphincsPlus_haraka_256f_r3;
 
+            sphincsPlusOids[SphincsPlusParameters.sha2_128s_simple] = BCObjectIdentifiers.sphincsPlus_sha2_128s_simple;
+            sphincsPlusOids[SphincsPlusParameters.sha2_128f_simple] = BCObjectIdentifiers.sphincsPlus_sha2_128f_simple;
+            sphincsPlusOids[SphincsPlusParameters.shake_128f_simple] = BCObjectIdentifiers.sphincsPlus_shake_128f_simple;
+            sphincsPlusOids[SphincsPlusParameters.sha2_192s_simple] = BCObjectIdentifiers.sphincsPlus_sha2_192s_simple;
+            sphincsPlusOids[SphincsPlusParameters.sha2_192f_simple] = BCObjectIdentifiers.sphincsPlus_sha2_192f_simple;
+            sphincsPlusOids[SphincsPlusParameters.shake_192f_simple] = BCObjectIdentifiers.sphincsPlus_shake_192f_simple;
+            sphincsPlusOids[SphincsPlusParameters.sha2_256s_simple] = BCObjectIdentifiers.sphincsPlus_sha2_256s_simple;
+            sphincsPlusOids[SphincsPlusParameters.sha2_256f_simple] = BCObjectIdentifiers.sphincsPlus_sha2_256f_simple;
+            sphincsPlusOids[SphincsPlusParameters.shake_256f_simple] = BCObjectIdentifiers.sphincsPlus_shake_256f_simple;
+
             sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_sha2_128s_r3] = SphincsPlusParameters.sha2_128s;
             sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_sha2_128f_r3] = SphincsPlusParameters.sha2_128f;
             sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_shake_128s_r3] = SphincsPlusParameters.shake_128s;
@@ -252,6 +262,15 @@ namespace Org.BouncyCastle.Pqc.Crypto.Utilities
             sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_shake_256f_r3] = SphincsPlusParameters.shake_256f;
             sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_haraka_256s_r3] = SphincsPlusParameters.haraka_256s;
             sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_haraka_256f_r3] = SphincsPlusParameters.haraka_256f;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_sha2_128s_simple = SphincsPlusParameters.sha2_128s_simple;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_sha2_128f_simple = SphincsPlusParameters.sha2_128f_simple;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_shake_128f_simple = SphincsPlusParameters.shake_128f_simple;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_sha2_192s_simple = SphincsPlusParameters.sha2_192s_simple;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_sha2_192f_simple = SphincsPlusParameters.sha2_192f_simple;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_shake_192f_simple = SphincsPlusParameters.shake_192f_simple;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_sha2_256s_simple = SphincsPlusParameters.sha2_256s_simple;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_sha2_256f_simple = SphincsPlusParameters.sha2_256f_simple;
+            sphincsPlusParams[BCObjectIdentifiers.sphincsPlus_shake_256f_simple] = SphincsPlusParameters.shake_256f_simple;
         }
 
         internal static DerObjectIdentifier McElieceOidLookup(CmceParameters parameters)