public PreCompInfo precompute(PreCompInfo existing) { WNafPreCompInfo result = new WNafPreCompInfo(); ECPoint twiceP = wnafPreCompP.getTwice(); if (twiceP != null) { ECPoint twiceQ = pointMap.map(twiceP); result.setTwice(twiceQ); } ECPoint[] preCompP = wnafPreCompP.getPreComp(); ECPoint[] preCompQ = new ECPoint[preCompP.length]; for (int i = 0; i < preCompP.length; ++i) { preCompQ[i] = pointMap.map(preCompP[i]); } result.setPreComp(preCompQ); if (includeNegated) { ECPoint[] preCompNegQ = new ECPoint[preCompQ.length]; for (int i = 0; i < preCompNegQ.length; ++i) { preCompNegQ[i] = preCompQ[i].negate(); } result.setPreCompNeg(preCompNegQ); } return result; } });
final WNafPreCompInfo wnafPreCompP = precompute(p, width, includeNegated); ECPoint q = pointMap.map(p); c.precompute(q, PRECOMP_NAME, new PreCompCallback()
protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { if (!curve.equals(p.getCurve())) { throw new IllegalStateException(); } BigInteger n = p.getCurve().getOrder(); BigInteger[] ab = glvEndomorphism.decomposeScalar(k.mod(n)); BigInteger a = ab[0], b = ab[1]; ECPointMap pointMap = glvEndomorphism.getPointMap(); if (glvEndomorphism.hasEfficientPointMap()) { return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap, b); } return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap.map(p), b); } }
WNafPreCompInfo wnafPreCompP = precompute(p, width, includeNegated); ECPoint q = pointMap.map(p); WNafPreCompInfo wnafPreCompQ = getWNafPreCompInfo(c.getPreCompInfo(q, PRECOMP_NAME)); if (twiceP != null) ECPoint twiceQ = pointMap.map(twiceP); wnafPreCompQ.setTwice(twiceQ); for (int i = 0; i < preCompP.length; ++i) preCompQ[i] = pointMap.map(preCompP[i]);
protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { if (!curve.equals(p.getCurve())) { throw new IllegalStateException(); } BigInteger n = p.getCurve().getOrder(); BigInteger[] ab = glvEndomorphism.decomposeScalar(k.mod(n)); BigInteger a = ab[0], b = ab[1]; ECPointMap pointMap = glvEndomorphism.getPointMap(); if (glvEndomorphism.hasEfficientPointMap()) { return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap, b); } return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap.map(p), b); } }
static ECPoint implSumOfMultipliesGLV(ECPoint[] ps, BigInteger[] ks, GLVEndomorphism glvEndomorphism) { BigInteger n = ps[0].getCurve().getOrder(); int len = ps.length; BigInteger[] abs = new BigInteger[len << 1]; for (int i = 0, j = 0; i < len; ++i) { BigInteger[] ab = glvEndomorphism.decomposeScalar(ks[i].mod(n)); abs[j++] = ab[0]; abs[j++] = ab[1]; } ECPointMap pointMap = glvEndomorphism.getPointMap(); if (glvEndomorphism.hasEfficientPointMap()) { return ECAlgorithms.implSumOfMultiplies(ps, pointMap, abs); } ECPoint[] pqs = new ECPoint[len << 1]; for (int i = 0, j = 0; i < len; ++i) { ECPoint p = ps[i], q = pointMap.map(p); pqs[j++] = p; pqs[j++] = q; } return ECAlgorithms.implSumOfMultiplies(pqs, abs); }
static ECPoint implSumOfMultipliesGLV(ECPoint[] ps, BigInteger[] ks, GLVEndomorphism glvEndomorphism) { BigInteger n = ps[0].getCurve().getOrder(); int len = ps.length; BigInteger[] abs = new BigInteger[len << 1]; for (int i = 0, j = 0; i < len; ++i) { BigInteger[] ab = glvEndomorphism.decomposeScalar(ks[i].mod(n)); abs[j++] = ab[0]; abs[j++] = ab[1]; } ECPointMap pointMap = glvEndomorphism.getPointMap(); if (glvEndomorphism.hasEfficientPointMap()) { return ECAlgorithms.implSumOfMultiplies(ps, pointMap, abs); } ECPoint[] pqs = new ECPoint[len << 1]; for (int i = 0, j = 0; i < len; ++i) { ECPoint p = ps[i], q = pointMap.map(p); pqs[j++] = p; pqs[j++] = q; } return ECAlgorithms.implSumOfMultiplies(pqs, abs); }