| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | using Renci.SshNet.Security.Org.BouncyCastle.Math.EC.Endo; |
| | | 4 | | |
| | | 5 | | namespace Renci.SshNet.Security.Org.BouncyCastle.Math.EC.Multiplier |
| | | 6 | | { |
| | | 7 | | internal class GlvMultiplier |
| | | 8 | | : AbstractECMultiplier |
| | | 9 | | { |
| | | 10 | | protected readonly ECCurve curve; |
| | | 11 | | protected readonly GlvEndomorphism glvEndomorphism; |
| | | 12 | | |
| | 0 | 13 | | public GlvMultiplier(ECCurve curve, GlvEndomorphism glvEndomorphism) |
| | 0 | 14 | | { |
| | 0 | 15 | | if (curve == null || curve.Order == null) |
| | 0 | 16 | | throw new ArgumentException("Need curve with known group order", "curve"); |
| | | 17 | | |
| | 0 | 18 | | this.curve = curve; |
| | 0 | 19 | | this.glvEndomorphism = glvEndomorphism; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k) |
| | 0 | 23 | | { |
| | 0 | 24 | | if (!curve.Equals(p.Curve)) |
| | 0 | 25 | | throw new InvalidOperationException(); |
| | | 26 | | |
| | 0 | 27 | | BigInteger n = p.Curve.Order; |
| | 0 | 28 | | BigInteger[] ab = glvEndomorphism.DecomposeScalar(k.Mod(n)); |
| | 0 | 29 | | BigInteger a = ab[0], b = ab[1]; |
| | | 30 | | |
| | 0 | 31 | | ECPointMap pointMap = glvEndomorphism.PointMap; |
| | 0 | 32 | | if (glvEndomorphism.HasEfficientPointMap) |
| | 0 | 33 | | { |
| | 0 | 34 | | return ECAlgorithms.ImplShamirsTrickWNaf(p, a, pointMap, b); |
| | | 35 | | } |
| | | 36 | | |
| | 0 | 37 | | return ECAlgorithms.ImplShamirsTrickWNaf(p, a, pointMap.Map(p), b); |
| | 0 | 38 | | } |
| | | 39 | | } |
| | | 40 | | } |