summary refs log tree commit diff
diff options
context:
space:
mode:
authorroyb <roy.basmacier@primekey.com>2022-10-24 16:11:15 -0400
committerroyb <roy.basmacier@primekey.com>2022-10-24 16:11:15 -0400
commit57aa077d8dc52a7bbd6ad118cec5d7a5000840a5 (patch)
tree9c609d2bf8125e90fb8fd436884d2a79957c1fa7
parentMerge remote-tracking branch 'origin/master' (diff)
downloadBouncyCastle.NET-ed25519-57aa077d8dc52a7bbd6ad118cec5d7a5000840a5.tar.xz
namespace error
-rw-r--r--crypto/src/pqc/crypto/saber/Symmetric.cs135
1 files changed, 69 insertions, 66 deletions
diff --git a/crypto/src/pqc/crypto/saber/Symmetric.cs b/crypto/src/pqc/crypto/saber/Symmetric.cs
index dc47b87bb..bcbe8a9a3 100644
--- a/crypto/src/pqc/crypto/saber/Symmetric.cs
+++ b/crypto/src/pqc/crypto/saber/Symmetric.cs
@@ -3,94 +3,97 @@ using Org.BouncyCastle.Crypto.Digests;
 using Org.BouncyCastle.Crypto.Modes;
 using Org.BouncyCastle.Crypto.Parameters;
 
-namespace Org.BouncyCastle.Pqc.Crypto.Saber;
-
-public abstract class Symmetric
+namespace Org.BouncyCastle.Pqc.Crypto.Saber
 {
 
-    internal abstract void Hash_h(byte[] output, byte[] input, int outputOffset);
-
-    internal abstract void Hash_g(byte[] output, byte[] input);
-
-    internal abstract void Prf(byte[] output, byte[] input, int inLen, int outputLen);
-
-    protected internal class ShakeSymmetric
-        : Symmetric
+    public abstract class Symmetric
     {
 
-        private readonly Sha3Digest sha3Digest256;
-        private readonly Sha3Digest sha3Digest512;
-        private readonly IXof shakeDigest;
+        internal abstract void Hash_h(byte[] output, byte[] input, int outputOffset);
 
-        internal ShakeSymmetric()
-        {
-            shakeDigest = new ShakeDigest(128);
-            sha3Digest256 = new Sha3Digest(256);
-            sha3Digest512 = new Sha3Digest(512);
-        }
+        internal abstract void Hash_g(byte[] output, byte[] input);
 
-        internal override void Hash_h(byte[] output, byte[] input, int outputOffset)
-        {
-            sha3Digest256.BlockUpdate(input, 0, input.Length);
-            sha3Digest256.DoFinal(output, outputOffset);
-        }
+        internal abstract void Prf(byte[] output, byte[] input, int inLen, int outputLen);
 
-        internal override void Hash_g(byte[] output, byte[] input)
+        protected internal class ShakeSymmetric
+            : Symmetric
         {
-            sha3Digest512.BlockUpdate(input, 0, input.Length);
-            sha3Digest512.DoFinal(output, 0);
-        }
 
-        internal override void Prf(byte[] output, byte[] input, int inLen, int outputLen)
-        {
-            shakeDigest.Reset();
-            shakeDigest.BlockUpdate(input, 0, inLen);
-            shakeDigest.OutputFinal(output, 0, outputLen);
-        }
+            private readonly Sha3Digest sha3Digest256;
+            private readonly Sha3Digest sha3Digest512;
+            private readonly IXof shakeDigest;
 
+            internal ShakeSymmetric()
+            {
+                shakeDigest = new ShakeDigest(128);
+                sha3Digest256 = new Sha3Digest(256);
+                sha3Digest512 = new Sha3Digest(512);
+            }
 
-    }
-    internal class AesSymmetric
-        : Symmetric
-    {
+            internal override void Hash_h(byte[] output, byte[] input, int outputOffset)
+            {
+                sha3Digest256.BlockUpdate(input, 0, input.Length);
+                sha3Digest256.DoFinal(output, outputOffset);
+            }
 
-        private readonly Sha256Digest sha256Digest;
-        private readonly Sha512Digest sha512Digest;
+            internal override void Hash_g(byte[] output, byte[] input)
+            {
+                sha3Digest512.BlockUpdate(input, 0, input.Length);
+                sha3Digest512.DoFinal(output, 0);
+            }
 
-        private readonly SicBlockCipher cipher;
+            internal override void Prf(byte[] output, byte[] input, int inLen, int outputLen)
+            {
+                shakeDigest.Reset();
+                shakeDigest.BlockUpdate(input, 0, inLen);
+                shakeDigest.OutputFinal(output, 0, outputLen);
+            }
 
 
-        protected internal AesSymmetric()
-        {
-            sha256Digest = new Sha256Digest();
-            sha512Digest = new Sha512Digest();
-            cipher = new SicBlockCipher(AesUtilities.CreateEngine());
-        }
-        
-        internal override void Hash_h(byte[] output, byte[] input, int outputOffset)
-        {
-            sha256Digest.BlockUpdate(input, 0, input.Length);
-            sha256Digest.DoFinal(output, outputOffset);
         }
 
-        internal override void Hash_g(byte[] output, byte[] input)
+        internal class AesSymmetric
+            : Symmetric
         {
-            sha512Digest.BlockUpdate(input, 0, input.Length);
-            sha512Digest.DoFinal(output, 0);
-        }
 
-        internal override void Prf(byte[] output, byte[] input, int inLen, int outputLen)
-        {
-            ParametersWithIV kp = new ParametersWithIV(new KeyParameter(input, 0, inLen), new byte[16]);
-            cipher.Init(true, kp);
-            byte[] buf = new byte[outputLen];   // TODO: there might be a more efficient way of doing this...
-            for (int i = 0; i < outputLen; i+= 16)
+            private readonly Sha256Digest sha256Digest;
+            private readonly Sha512Digest sha512Digest;
+
+            private readonly SicBlockCipher cipher;
+
+
+            protected internal AesSymmetric()
             {
-                cipher.ProcessBlock(buf, i, output, i);
+                sha256Digest = new Sha256Digest();
+                sha512Digest = new Sha512Digest();
+                cipher = new SicBlockCipher(AesUtilities.CreateEngine());
             }
-        }
 
+            internal override void Hash_h(byte[] output, byte[] input, int outputOffset)
+            {
+                sha256Digest.BlockUpdate(input, 0, input.Length);
+                sha256Digest.DoFinal(output, outputOffset);
+            }
+
+            internal override void Hash_g(byte[] output, byte[] input)
+            {
+                sha512Digest.BlockUpdate(input, 0, input.Length);
+                sha512Digest.DoFinal(output, 0);
+            }
+
+            internal override void Prf(byte[] output, byte[] input, int inLen, int outputLen)
+            {
+                ParametersWithIV kp = new ParametersWithIV(new KeyParameter(input, 0, inLen), new byte[16]);
+                cipher.Init(true, kp);
+                byte[] buf = new byte[outputLen]; // TODO: there might be a more efficient way of doing this...
+                for (int i = 0; i < outputLen; i += 16)
+                {
+                    cipher.ProcessBlock(buf, i, output, i);
+                }
+            }
 
-    }
 
+        }
+
+    }
 }
\ No newline at end of file