diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-27 11:14:16 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-27 11:14:16 +0700 |
commit | ab5eb010d9a966246bcada6b3b884af4350207ae (patch) | |
tree | e108a0cc9f303933b937938c7b73549b1fc9824b /crypto/src/math/ec/custom/sec/Nat384.cs | |
parent | Optimize final adjustments in Reduce() (diff) | |
download | BouncyCastle.NET-ed25519-ab5eb010d9a966246bcada6b3b884af4350207ae.tar.xz |
Add custom curve for secp384r1 (P-384)
Diffstat (limited to 'crypto/src/math/ec/custom/sec/Nat384.cs')
-rw-r--r-- | crypto/src/math/ec/custom/sec/Nat384.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/crypto/src/math/ec/custom/sec/Nat384.cs b/crypto/src/math/ec/custom/sec/Nat384.cs new file mode 100644 index 000000000..273ee2d65 --- /dev/null +++ b/crypto/src/math/ec/custom/sec/Nat384.cs @@ -0,0 +1,46 @@ +using System; +using System.Diagnostics; + +namespace Org.BouncyCastle.Math.EC.Custom.Sec +{ + internal abstract class Nat384 + { + public static void Mul(uint[] x, uint[] y, uint[] zz) + { + Nat192.Mul(x, y, zz); + Nat192.Mul(x, 6, y, 6, zz, 12); + + uint c18 = Nat192.AddToEachOther(zz, 6, zz, 12); + uint c12 = c18 + Nat192.AddTo(zz, 0, zz, 6, 0); + c18 += Nat192.AddTo(zz, 18, zz, 12, c12); + + uint[] dx = Nat192.Create(), dy = Nat192.Create(); + bool neg = Nat192.Diff(x, 6, x, 0, dx, 0) != Nat192.Diff(y, 6, y, 0, dy, 0); + + uint[] tt = Nat192.CreateExt(); + Nat192.Mul(dx, dy, tt); + + c18 += neg ? Nat.AddTo(12, tt, 0, zz, 6) : (uint)Nat.SubFrom(12, tt, 0, zz, 6); + Nat.AddWordExt(12, c18, zz, 18); + } + + public static void Square(uint[] x, uint[] zz) + { + Nat192.Square(x, zz); + Nat192.Square(x, 6, zz, 12); + + uint c18 = Nat192.AddToEachOther(zz, 6, zz, 12); + uint c12 = c18 + Nat192.AddTo(zz, 0, zz, 6, 0); + c18 += Nat192.AddTo(zz, 18, zz, 12, c12); + + uint[] dx = Nat192.Create(); + Nat192.Diff(x, 6, x, 0, dx, 0); + + uint[] m = Nat192.CreateExt(); + Nat192.Square(dx, m); + + c18 += (uint)Nat.SubFrom(12, m, 0, zz, 6); + Nat.AddWordExt(12, c18, zz, 18); + } + } +} |