summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-05 18:16:51 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-05 18:16:51 +0700
commit2b958f0933d5abc865ccea785b774df8910510b2 (patch)
tree6b55bcd035e8460c54df7f13f9511a8a71417eb2
parentPort OpenPGP support for XDH, EdDSA from bc-java (diff)
downloadBouncyCastle.NET-ed25519-2b958f0933d5abc865ccea785b774df8910510b2.tar.xz
Resolve some FIXMEs
-rw-r--r--crypto/src/pqc/crypto/lms/HSS.cs2
-rw-r--r--crypto/src/pqc/crypto/lms/HSSSignature.cs70
-rw-r--r--crypto/src/security/JksStore.cs5
3 files changed, 29 insertions, 48 deletions
diff --git a/crypto/src/pqc/crypto/lms/HSS.cs b/crypto/src/pqc/crypto/lms/HSS.cs
index 317ee89f5..4634088c7 100644
--- a/crypto/src/pqc/crypto/lms/HSS.cs
+++ b/crypto/src/pqc/crypto/lms/HSS.cs
@@ -163,7 +163,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms
 
         public static bool VerifySignature(HssPublicKeyParameters publicKey, HssSignature signature, byte[] message)
         {
-            int Nspk = signature.GetlMinus1();
+            int Nspk = signature.GetLMinus1();
             if (Nspk + 1 != publicKey.L)
                 return false;
 
diff --git a/crypto/src/pqc/crypto/lms/HSSSignature.cs b/crypto/src/pqc/crypto/lms/HSSSignature.cs
index 7c4599835..21f0397c8 100644
--- a/crypto/src/pqc/crypto/lms/HSSSignature.cs
+++ b/crypto/src/pqc/crypto/lms/HSSSignature.cs
@@ -9,15 +9,15 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms
     public sealed class HssSignature
         : IEncodable
     {
-        private int lMinus1;
-        private LmsSignedPubKey[] signedPubKey;
-        private LmsSignature signature;
+        private readonly int m_lMinus1;
+        private readonly LmsSignedPubKey[] m_signedPubKey;
+        private readonly LmsSignature m_signature;
 
         public HssSignature(int lMinus1, LmsSignedPubKey[] signedPubKey, LmsSignature signature)
         {
-            this.lMinus1 = lMinus1;
-            this.signedPubKey = signedPubKey;
-            this.signature = signature;
+            m_lMinus1 = lMinus1;
+            m_signedPubKey = signedPubKey;
+            m_signature = signature;
         }
 
         /**
@@ -73,81 +73,63 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms
             throw new ArgumentException($"cannot parse {src}");
         }
 
-        // FIXME
-        public int GetlMinus1()
+        public int GetLMinus1()
         {
-            return lMinus1;
+            return m_lMinus1;
         }
 
+        // FIXME
         public LmsSignedPubKey[] GetSignedPubKeys()
         {
-            return signedPubKey;
+            return m_signedPubKey;
         }
 
-        public LmsSignature Signature => signature;
+        public LmsSignature Signature => m_signature;
 
-        public override bool Equals(Object o)
+        public override bool Equals(object other)
         {
-            if (this == o)
-            {
+            if (this == other)
                 return true;
-            }
-
-            if (o == null || GetType() != o.GetType())
-            {
+            if (!(other is HssSignature that))
                 return false;
-            }
 
-            HssSignature signature1 = (HssSignature) o;
-
-            if (lMinus1 != signature1.lMinus1)
-            {
+            if (this.m_lMinus1 != that.m_lMinus1)
                 return false;
-            }
-
-            // FIXME
-            // Probably incorrect - comparing Object[] arrays with Arrays.equals
 
-            if (signedPubKey.Length != signature1.signedPubKey.Length)
-            {
+            if (this.m_signedPubKey.Length != that.m_signedPubKey.Length)
                 return false;
-            }
 
-            for (int t = 0; t < signedPubKey.Length; t++)
+            for (int t = 0; t < m_signedPubKey.Length; t++)
             {
-                if (!signedPubKey[t].Equals(signature1.signedPubKey[t]))
-                {
+                if (!this.m_signedPubKey[t].Equals(that.m_signedPubKey[t]))
                     return false;
-                }
             }
 
-            return signature != null ? signature.Equals(signature1.signature) : signature1.signature == null;
+            return Equals(this.m_signature, that.m_signature);
         }
 
         public override int GetHashCode()
         {
-            int result = lMinus1;
-            result = 31 * result + signedPubKey.GetHashCode();
-            result = 31 * result + (signature != null ? signature.GetHashCode() : 0);
+            int result = m_lMinus1;
+            result = 31 * result + m_signedPubKey.GetHashCode();
+            result = 31 * result + (m_signature != null ? m_signature.GetHashCode() : 0);
             return result;
         }
 
         public byte[] GetEncoded()
         {
             Composer composer = Composer.Compose();
-            composer.U32Str(lMinus1);
-            if (signedPubKey != null)
+            composer.U32Str(m_lMinus1);
+            if (m_signedPubKey != null)
             {
-                foreach (LmsSignedPubKey sigPub in signedPubKey)
+                foreach (LmsSignedPubKey sigPub in m_signedPubKey)
                 {
                     composer.Bytes(sigPub);
                 }
             }
 
-            composer.Bytes(signature);
+            composer.Bytes(m_signature);
             return composer.Build();
-
         }
-
     }
 }
diff --git a/crypto/src/security/JksStore.cs b/crypto/src/security/JksStore.cs
index 30b21fad2..9f4aced96 100644
--- a/crypto/src/security/JksStore.cs
+++ b/crypto/src/security/JksStore.cs
@@ -10,6 +10,7 @@ using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.IO;
 using Org.BouncyCastle.Pkcs;
 using Org.BouncyCastle.Utilities;
+using Org.BouncyCastle.Utilities.Collections;
 using Org.BouncyCastle.Utilities.Date;
 using Org.BouncyCastle.Utilities.IO;
 using Org.BouncyCastle.X509;
@@ -216,9 +217,7 @@ namespace Org.BouncyCastle.Security
             {
                 var aliases = new HashSet<string>(m_certificateEntries.Keys);
                 aliases.UnionWith(m_keyEntries.Keys);
-                // FIXME
-                //return CollectionUtilities.Proxy(aliases);
-                return aliases;
+                return CollectionUtilities.Proxy(aliases);
             }
         }