diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2020-09-21 19:46:52 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2020-09-21 19:46:52 +0700 |
commit | 661a878a61a8734ef71cbd81da4f53f62f513212 (patch) | |
tree | 9f58350da0f2f5104d131c14b564cda3a5f9a653 /crypto/src/math/raw/Interleave.cs | |
parent | No need for Obsolete in internal class (diff) | |
download | BouncyCastle.NET-ed25519-661a878a61a8734ef71cbd81da4f53f62f513212.tar.xz |
ECC: Binary field perf. opt.
Diffstat (limited to 'crypto/src/math/raw/Interleave.cs')
-rw-r--r-- | crypto/src/math/raw/Interleave.cs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/math/raw/Interleave.cs b/crypto/src/math/raw/Interleave.cs index 591ba3f15..49d3768d7 100644 --- a/crypto/src/math/raw/Interleave.cs +++ b/crypto/src/math/raw/Interleave.cs @@ -93,6 +93,23 @@ namespace Org.BouncyCastle.Math.Raw z[zOff + 1] = (x >> 1) & M64; } + internal static void Expand64To128(ulong[] xs, int xsOff, int xsLen, ulong[] zs, int zsOff) + { + for (int i = 0; i < xsLen; ++i) + { + // "shuffle" low half to even bits and high half to odd bits + ulong x = xs[xsOff + i], t; + t = (x ^ (x >> 16)) & 0x00000000FFFF0000UL; x ^= (t ^ (t << 16)); + t = (x ^ (x >> 8)) & 0x0000FF000000FF00UL; x ^= (t ^ (t << 8)); + t = (x ^ (x >> 4)) & 0x00F000F000F000F0UL; x ^= (t ^ (t << 4)); + t = (x ^ (x >> 2)) & 0x0C0C0C0C0C0C0C0CUL; x ^= (t ^ (t << 2)); + t = (x ^ (x >> 1)) & 0x2222222222222222UL; x ^= (t ^ (t << 1)); + + zs[zsOff++] = (x ) & M64; + zs[zsOff++] = (x >> 1) & M64; + } + } + internal static void Expand64To128Rev(ulong x, ulong[] z, int zOff) { // "shuffle" low half to even bits and high half to odd bits |