diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-27 11:40:00 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-27 11:40:00 +0700 |
commit | b27039585917e3c0651de353faef68fe6bbc68d9 (patch) | |
tree | 0cdad9b0772f6e7ae061ba24ed0514b71b8e358b /crypto/src/math/ec/multiplier/ZSignedDigitR2LMultiplier.cs | |
parent | Use custom curve if available (diff) | |
download | BouncyCastle.NET-ed25519-b27039585917e3c0651de353faef68fe6bbc68d9.tar.xz |
Port of latest EC multipliers from Java
Diffstat (limited to '')
-rw-r--r-- | crypto/src/math/ec/multiplier/ZSignedDigitR2LMultiplier.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crypto/src/math/ec/multiplier/ZSignedDigitR2LMultiplier.cs b/crypto/src/math/ec/multiplier/ZSignedDigitR2LMultiplier.cs new file mode 100644 index 000000000..91c06cbb8 --- /dev/null +++ b/crypto/src/math/ec/multiplier/ZSignedDigitR2LMultiplier.cs @@ -0,0 +1,30 @@ +namespace Org.BouncyCastle.Math.EC.Multiplier +{ + public class ZSignedDigitR2LMultiplier + : AbstractECMultiplier + { + /** + * 'Zeroless' Signed Digit Right-to-Left. + */ + protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k) + { + ECPoint R0 = p.Curve.Infinity, R1 = p; + + int n = k.BitLength; + int s = k.GetLowestSetBit(); + + R1 = R1.TimesPow2(s); + + int i = s; + while (++i < n) + { + R0 = R0.Add(k.TestBit(i) ? R1 : R1.Negate()); + R1 = R1.Twice(); + } + + R0 = R0.Add(R1); + + return R0; + } + } +} |