diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-01-03 12:42:34 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-01-03 12:42:34 +0700 |
commit | 3fff58abf4e3357335fc44f48e03cca0f32983ac (patch) | |
tree | efeca569692beaf322ac83c8498c268937e881c4 /crypto | |
parent | JPAKE: Improved calculation of s (diff) | |
download | BouncyCastle.NET-ed25519-3fff58abf4e3357335fc44f48e03cca0f32983ac.tar.xz |
Pqc cleanup
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/pqc/crypto/bike/BikeEngine.cs | 3 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/bike/BikeUtilities.cs | 39 | ||||
-rw-r--r-- | crypto/src/pqc/crypto/hqc/HqcEngine.cs | 6 |
3 files changed, 29 insertions, 19 deletions
diff --git a/crypto/src/pqc/crypto/bike/BikeEngine.cs b/crypto/src/pqc/crypto/bike/BikeEngine.cs index 896503c6d..a6371b726 100644 --- a/crypto/src/pqc/crypto/bike/BikeEngine.cs +++ b/crypto/src/pqc/crypto/bike/BikeEngine.cs @@ -252,8 +252,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Bike // 3. Compute K byte[] wlist = FunctionH(mPrime); - if (Arrays.AreEqual(ePrimeBytes, 0, ePrimeBytes.Length, - wlist, 0, ePrimeBytes.Length)) + if (Arrays.AreEqual(ePrimeBytes, 0, ePrimeBytes.Length, wlist, 0, ePrimeBytes.Length)) { FunctionK(mPrime, c0, c1, k); } diff --git a/crypto/src/pqc/crypto/bike/BikeUtilities.cs b/crypto/src/pqc/crypto/bike/BikeUtilities.cs index 0e60bc7b0..40bd6d148 100644 --- a/crypto/src/pqc/crypto/bike/BikeUtilities.cs +++ b/crypto/src/pqc/crypto/bike/BikeUtilities.cs @@ -1,4 +1,6 @@ -using Org.BouncyCastle.Crypto.Utilities; +using System; + +using Org.BouncyCastle.Crypto.Utilities; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Utilities; @@ -70,36 +72,45 @@ namespace Org.BouncyCastle.Pqc.Crypto.Bike internal static void GenerateRandomByteArray(byte[] res, uint size, uint weight, IXof digest) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + Span<byte> buf = stackalloc byte[4]; +#else byte[] buf = new byte[4]; - uint rand_pos; +#endif for (int i = (int)weight - 1; i >= 0; i--) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + digest.Output(buf); + ulong temp = Pack.LE_To_UInt32(buf); +#else digest.Output(buf, 0, 4); - ulong temp = (Pack.LE_To_UInt32(buf, 0)) & 0xFFFFFFFFUL; - temp = temp * (size - (uint)i) >> 32; - rand_pos = (uint) temp; + ulong temp = Pack.LE_To_UInt32(buf, 0); +#endif - rand_pos += (uint)i; + temp = temp * (size - (uint)i) >> 32; + uint rand_pos = (uint)i + (uint)temp; - if(CHECK_BIT(res, rand_pos) != 0) + if (CheckBit(res, rand_pos) != 0) { rand_pos = (uint)i; } - SET_BIT(res, rand_pos); + SetBit(res, rand_pos); } } - protected static uint CHECK_BIT(byte[] tmp, uint position) + + private static uint CheckBit(byte[] tmp, uint position) { uint index = position / 8; uint pos = position % 8; - return (((uint)tmp[index] >> (int)(pos)) & 0x01); + return ((uint)tmp[index] >> (int)pos) & 1U; } - protected static void SET_BIT(byte[] tmp, uint position) + + private static void SetBit(byte[] tmp, uint position) { - uint index = position/8; - uint pos = position%8; - tmp[index] |= (byte)(1UL << (int)pos); + uint index = position / 8; + uint pos = position % 8; + tmp[index] |= (byte)(1 << (int)pos); } } } diff --git a/crypto/src/pqc/crypto/hqc/HqcEngine.cs b/crypto/src/pqc/crypto/hqc/HqcEngine.cs index ee628e843..4e163fc6e 100644 --- a/crypto/src/pqc/crypto/hqc/HqcEngine.cs +++ b/crypto/src/pqc/crypto/hqc/HqcEngine.cs @@ -34,10 +34,10 @@ namespace Org.BouncyCastle.Pqc.Crypto.Hqc private int N1N2_BYTE; private int N1_BYTE; - private int GF_POLY_WT = 5; - private int GF_POLY_M2 = 4; + //private int GF_POLY_WT = 5; + //private int GF_POLY_M2 = 4; private int SALT_SIZE_BYTES = 16; - private int SALT_SIZE_64 = 2; + //private int SALT_SIZE_64 = 2; private int[] generatorPoly; private int SHA512_BYTES = 512 / 8; |