1package org.bouncycastle.math.ec; 2 3import java.math.BigInteger; 4 5import org.bouncycastle.math.ec.endo.GLVEndomorphism; 6 7public class GLVMultiplier extends AbstractECMultiplier 8{ 9 protected final ECCurve curve; 10 protected final GLVEndomorphism glvEndomorphism; 11 12 public GLVMultiplier(ECCurve curve, GLVEndomorphism glvEndomorphism) 13 { 14 if (curve == null || curve.getOrder() == null) 15 { 16 throw new IllegalArgumentException("Need curve with known group order"); 17 } 18 19 this.curve = curve; 20 this.glvEndomorphism = glvEndomorphism; 21 } 22 23 protected ECPoint multiplyPositive(ECPoint p, BigInteger k) 24 { 25 if (!curve.equals(p.getCurve())) 26 { 27 throw new IllegalStateException(); 28 } 29 30 BigInteger n = p.getCurve().getOrder(); 31 BigInteger[] ab = glvEndomorphism.decomposeScalar(k.mod(n)); 32 BigInteger a = ab[0], b = ab[1]; 33 34 ECPointMap pointMap = glvEndomorphism.getPointMap(); 35 if (glvEndomorphism.hasEfficientPointMap()) 36 { 37 return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap, b); 38 } 39 40 return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap.map(p), b); 41 } 42} 43