summary refs log tree commit diff
path: root/crypto/src/pqc/crypto/cmce/Utils.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-13 00:06:54 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-13 00:06:54 +0700
commitb01d0c65de49d0f0e0050d4640c6649909848320 (patch)
treed6ac4ae43ff2148b645dcabb6a69dbbb3f63ba83 /crypto/src/pqc/crypto/cmce/Utils.cs
parentCmce perf. opts. (diff)
downloadBouncyCastle.NET-ed25519-b01d0c65de49d0f0e0050d4640c6649909848320.tar.xz
Refactoring in Pqc.Crypto.Cmce
Diffstat (limited to '')
-rw-r--r--crypto/src/pqc/crypto/cmce/Utils.cs34
1 files changed, 15 insertions, 19 deletions
diff --git a/crypto/src/pqc/crypto/cmce/Utils.cs b/crypto/src/pqc/crypto/cmce/Utils.cs
index 85eadb953..0ebe168b1 100644
--- a/crypto/src/pqc/crypto/cmce/Utils.cs
+++ b/crypto/src/pqc/crypto/cmce/Utils.cs
@@ -1,20 +1,17 @@
-
 using Org.BouncyCastle.Crypto.Utilities;
 
 namespace Org.BouncyCastle.Pqc.Crypto.Cmce
 {
-
-    class Utils
+    internal class Utils
     {
         internal static void StoreGF(byte[] dest, int offset, ushort a)
         {
-            dest[offset + 0] = (byte) (a & 0xFF);
-            dest[offset + 1] = (byte) (a >> 8);
+            Pack.UInt16_To_LE(a, dest, offset);
         }
 
         internal static ushort LoadGF(byte[] src, int offset, int gfmask)
         {
-            return (ushort) (Pack.LE_To_UInt16(src, offset) & gfmask);
+            return (ushort)(Pack.LE_To_UInt16(src, offset) & gfmask);
         }
 
         internal static uint Load4(byte[] input, int offset)
@@ -24,15 +21,12 @@ namespace Org.BouncyCastle.Pqc.Crypto.Cmce
 
         internal static void Store8(byte[] output, int offset, ulong input)
         {
-            //use pack
-            output[offset + 0] = (byte) ((input >> 0x00) & 0xFF);
-            output[offset + 1] = (byte) ((input >> 0x08) & 0xFF);
-            output[offset + 2] = (byte) ((input >> 0x10) & 0xFF);
-            output[offset + 3] = (byte) ((input >> 0x18) & 0xFF);
-            output[offset + 4] = (byte) ((input >> 0x20) & 0xFF);
-            output[offset + 5] = (byte) ((input >> 0x28) & 0xFF);
-            output[offset + 6] = (byte) ((input >> 0x30) & 0xFF);
-            output[offset + 7] = (byte) ((input >> 0x38) & 0xFF);
+            Pack.UInt64_To_LE(input, output, offset);
+        }
+
+        internal static void Store8(byte[] output, int offset, ulong[] input, int inOff, int inLen)
+        {
+            Pack.UInt64_To_LE(input, inOff, inLen, output, offset);
         }
 
         internal static ulong Load8(byte[] input, int offset)
@@ -40,16 +34,18 @@ namespace Org.BouncyCastle.Pqc.Crypto.Cmce
             return Pack.LE_To_UInt64(input, offset);
         }
 
+        internal static void Load8(byte[] input, int offset, ulong[] output, int outOff, int outLen)
+        {
+            Pack.LE_To_UInt64(input, offset, output, outOff, outLen);
+        }
+
         internal static ushort Bitrev(ushort a, int GFBITS)
         {
             a = (ushort) (((a & 0x00FF) << 8) | ((a & 0xFF00) >> 8));
             a = (ushort) (((a & 0x0F0F) << 4) | ((a & 0xF0F0) >> 4));
             a = (ushort) (((a & 0x3333) << 2) | ((a & 0xCCCC) >> 2));
             a = (ushort) (((a & 0x5555) << 1) | ((a & 0xAAAA) >> 1));
-            if (GFBITS == 12)
-                return (ushort) (a >> 4);
-            return (ushort) (a >> 3);
+            return (ushort)(a >> (16 - GFBITS));
         }
-
     }
 }