diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-31 18:43:12 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-31 18:43:12 +0700 |
commit | 7118a1a3f987cd82db0243ebcd03e844e73b7ffa (patch) | |
tree | f03753da78d3531fcf845b70c79091191fb95edf /crypto/src/math/ec/custom/sec/Nat192.cs | |
parent | Add custom curves for secp192k1 and secp192r1 (P-192) (diff) | |
download | BouncyCastle.NET-ed25519-7118a1a3f987cd82db0243ebcd03e844e73b7ffa.tar.xz |
Improve reduction speed for secp192k1 and secp256k1 custom fields
Diffstat (limited to 'crypto/src/math/ec/custom/sec/Nat192.cs')
-rw-r--r-- | crypto/src/math/ec/custom/sec/Nat192.cs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/crypto/src/math/ec/custom/sec/Nat192.cs b/crypto/src/math/ec/custom/sec/Nat192.cs index 55e684cc2..b61c7a468 100644 --- a/crypto/src/math/ec/custom/sec/Nat192.cs +++ b/crypto/src/math/ec/custom/sec/Nat192.cs @@ -321,6 +321,40 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec } } + public static ulong Mul33AddExt(uint x, uint[] yy, int yyOff, uint[] zz, int zzOff) + { + Debug.Assert(x >> 31 == 0); + Debug.Assert(yyOff <= 6); + Debug.Assert(zzOff <= 6); + ulong c = 0, xVal = x; + ulong yy00 = yy[yyOff + 0]; + c += xVal * yy00 + zz[zzOff + 0]; + zz[zzOff + 0] = (uint)c; + c >>= 32; + ulong yy01 = yy[yyOff + 1]; + c += xVal * yy01 + yy00 + zz[zzOff + 1]; + zz[zzOff + 1] = (uint)c; + c >>= 32; + ulong yy02 = yy[yyOff + 2]; + c += xVal * yy02 + yy01 + zz[zzOff + 2]; + zz[zzOff + 2] = (uint)c; + c >>= 32; + ulong yy03 = yy[yyOff + 3]; + c += xVal * yy03 + yy02 + zz[zzOff + 3]; + zz[zzOff + 3] = (uint)c; + c >>= 32; + ulong yy04 = yy[yyOff + 4]; + c += xVal * yy04 + yy03 + zz[zzOff + 4]; + zz[zzOff + 4] = (uint)c; + c >>= 32; + ulong yy05 = yy[yyOff + 5]; + c += xVal * yy05 + yy04 + zz[zzOff + 5]; + zz[zzOff + 5] = (uint)c; + c >>= 32; + c += yy05; + return c; + } + public static uint MulWordAddExt(uint x, uint[] yy, int yyOff, uint[] zz, int zzOff) { Debug.Assert(yyOff <= 6); @@ -347,6 +381,28 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec return (uint)c; } + public static uint Mul33DWordAdd(uint x, ulong y, uint[] z, int zOff) + { + Debug.Assert(x >> 31 == 0); + Debug.Assert(zOff < 2); + ulong c = 0, xVal = x; + ulong y00 = y & M; + c += xVal * y00 + z[zOff + 0]; + z[zOff + 0] = (uint)c; + c >>= 32; + ulong y01 = y >> 32; + c += xVal * y01 + y00 + z[zOff + 1]; + z[zOff + 1] = (uint)c; + c >>= 32; + c += y01 + z[zOff + 2]; + z[zOff + 2] = (uint)c; + c >>= 32; + c += z[zOff + 3]; + z[zOff + 3] = (uint)c; + c >>= 32; + return c == 0 ? 0 : Inc(z, zOff + 4); + } + public static uint MulWordDwordAdd(uint x, ulong y, uint[] z, int zOff) { Debug.Assert(zOff < 4); |