diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-13 22:54:23 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-13 22:54:23 +0700 |
commit | 104b98cc2797c4613151b95dc87218eca7f32c98 (patch) | |
tree | f0e6d13b80c03fbcea305195071b63c85534249f /crypto/src/math/ec/multiplier/WNafUtilities.cs | |
parent | Fix bug in DoFinal introduced by last change (diff) | |
download | BouncyCastle.NET-ed25519-104b98cc2797c4613151b95dc87218eca7f32c98.tar.xz |
Port GLV implementation from Java
Diffstat (limited to '')
-rw-r--r-- | crypto/src/math/ec/multiplier/WNafUtilities.cs | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/crypto/src/math/ec/multiplier/WNafUtilities.cs b/crypto/src/math/ec/multiplier/WNafUtilities.cs index 179d6d6eb..98e4f545f 100644 --- a/crypto/src/math/ec/multiplier/WNafUtilities.cs +++ b/crypto/src/math/ec/multiplier/WNafUtilities.cs @@ -268,6 +268,11 @@ namespace Org.BouncyCastle.Math.EC.Multiplier return wnaf; } + public static WNafPreCompInfo GetWNafPreCompInfo(ECPoint p) + { + return GetWNafPreCompInfo(p.Curve.GetPreCompInfo(p, PRECOMP_NAME)); + } + public static WNafPreCompInfo GetWNafPreCompInfo(PreCompInfo preCompInfo) { if ((preCompInfo != null) && (preCompInfo is WNafPreCompInfo)) @@ -309,6 +314,45 @@ namespace Org.BouncyCastle.Math.EC.Multiplier return w + 2; } + public static ECPoint MapPointWithPrecomp(ECPoint p, int width, bool includeNegated, + ECPointMap pointMap) + { + ECCurve c = p.Curve; + WNafPreCompInfo wnafPreCompP = Precompute(p, width, includeNegated); + + ECPoint q = pointMap.Map(p); + WNafPreCompInfo wnafPreCompQ = GetWNafPreCompInfo(c.GetPreCompInfo(q, PRECOMP_NAME)); + + ECPoint twiceP = wnafPreCompP.Twice; + if (twiceP != null) + { + ECPoint twiceQ = pointMap.Map(twiceP); + wnafPreCompQ.Twice = twiceQ; + } + + ECPoint[] preCompP = wnafPreCompP.PreComp; + ECPoint[] preCompQ = new ECPoint[preCompP.Length]; + for (int i = 0; i < preCompP.Length; ++i) + { + preCompQ[i] = pointMap.Map(preCompP[i]); + } + wnafPreCompQ.PreComp = preCompQ; + + if (includeNegated) + { + ECPoint[] preCompNegQ = new ECPoint[preCompQ.Length]; + for (int i = 0; i < preCompNegQ.Length; ++i) + { + preCompNegQ[i] = preCompQ[i].Negate(); + } + wnafPreCompQ.PreCompNeg = preCompNegQ; + } + + c.SetPreCompInfo(q, PRECOMP_NAME, wnafPreCompQ); + + return q; + } + public static WNafPreCompInfo Precompute(ECPoint p, int width, bool includeNegated) { ECCurve c = p.Curve; @@ -335,7 +379,7 @@ namespace Org.BouncyCastle.Math.EC.Multiplier ECPoint twiceP = wnafPreCompInfo.Twice; if (twiceP == null) { - twiceP = preComp[0].Twice().Normalize(); + twiceP = preComp[0].Twice(); wnafPreCompInfo.Twice = twiceP; } |