summary refs log tree commit diff
path: root/crypto/src/math/raw
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-12 22:41:39 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-12 22:41:39 +0700
commit6b5d68e8a8d1991e15873ff1e0615d87f3eb7eec (patch)
treee899b3327fa90d1a70d24d53c8870d182585e73a /crypto/src/math/raw
parentPicnic perf. opts. (diff)
downloadBouncyCastle.NET-ed25519-6b5d68e8a8d1991e15873ff1e0615d87f3eb7eec.tar.xz
Refactoring in Pqc.Crypto.Cmce
Diffstat (limited to 'crypto/src/math/raw')
-rw-r--r--crypto/src/math/raw/Interleave.cs40
1 files changed, 27 insertions, 13 deletions
diff --git a/crypto/src/math/raw/Interleave.cs b/crypto/src/math/raw/Interleave.cs

index 02aa79551..3e994a43c 100644 --- a/crypto/src/math/raw/Interleave.cs +++ b/crypto/src/math/raw/Interleave.cs
@@ -12,23 +12,37 @@ namespace Org.BouncyCastle.Math.Raw private const ulong M64 = 0x5555555555555555UL; private const ulong M64R = 0xAAAAAAAAAAAAAAAAUL; - internal static uint Expand8to16(uint x) + internal static uint Expand8to16(byte x) { - x &= 0xFFU; - x = (x | (x << 4)) & 0x0F0FU; - x = (x | (x << 2)) & 0x3333U; - x = (x | (x << 1)) & 0x5555U; - return x; + uint t = x; + +#if NETCOREAPP3_0_OR_GREATER + if (Bmi2.IsSupported) + { + return Bmi2.ParallelBitDeposit(t, 0x55555555U); + } +#endif + t = (t | (t << 4)) & 0x0F0FU; + t = (t | (t << 2)) & 0x3333U; + t = (t | (t << 1)) & 0x5555U; + return t; } - internal static uint Expand16to32(uint x) + internal static uint Expand16to32(ushort x) { - x &= 0xFFFFU; - x = (x | (x << 8)) & 0x00FF00FFU; - x = (x | (x << 4)) & 0x0F0F0F0FU; - x = (x | (x << 2)) & 0x33333333U; - x = (x | (x << 1)) & 0x55555555U; - return x; + uint t = x; + +#if NETCOREAPP3_0_OR_GREATER + if (Bmi2.IsSupported) + { + return Bmi2.ParallelBitDeposit(t, 0x55555555U); + } +#endif + t = (t | (t << 8)) & 0x00FF00FFU; + t = (t | (t << 4)) & 0x0F0F0F0FU; + t = (t | (t << 2)) & 0x33333333U; + t = (t | (t << 1)) & 0x55555555U; + return t; } internal static ulong Expand32to64(uint x)