public ECPoint threeTimes() { return twicePlus(this); }
public ECPoint threeTimes() { return twicePlus(this); }
/** * Joye's double-add algorithm. */ protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { ECPoint[] R = new ECPoint[]{ p.getCurve().getInfinity(), p }; int n = k.bitLength(); for (int i = 0; i < n; ++i) { int b = k.testBit(i) ? 1 : 0; int bp = 1 - b; R[bp] = R[bp].twicePlus(R[b]); } return R[0]; } }
/** * Joye's double-add algorithm. */ protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { ECPoint[] R = new ECPoint[]{ p.getCurve().getInfinity(), p }; int n = k.bitLength(); for (int i = 0; i < n; ++i) { int b = k.testBit(i) ? 1 : 0; int bp = 1 - b; R[bp] = R[bp].twicePlus(R[b]); } return R[0]; } }
/** * 'Zeroless' Signed Digit Left-to-Right. */ protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { ECPoint addP = p.normalize(), subP = addP.negate(); ECPoint R0 = addP; int n = k.bitLength(); int s = k.getLowestSetBit(); int i = n; while (--i > s) { R0 = R0.twicePlus(k.testBit(i) ? addP : subP); } R0 = R0.timesPow2(s); return R0; } }
/** * 'Zeroless' Signed Digit Left-to-Right. */ protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { ECPoint addP = p.normalize(), subP = addP.negate(); ECPoint R0 = addP; int n = k.bitLength(); int s = k.getLowestSetBit(); int i = n; while (--i > s) { R0 = R0.twicePlus(k.testBit(i) ? addP : subP); } R0 = R0.timesPow2(s); return R0; } }
ECPoint r = table[n >>> 1]; R = R.twicePlus(r); R = R.timesPow2(zeroes);
protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { int[] naf = WNafUtil.generateCompactNaf(k); ECPoint addP = p.normalize(), subP = addP.negate(); ECPoint R = p.getCurve().getInfinity(); int i = naf.length; while (--i >= 0) { int ni = naf[i]; int digit = ni >> 16, zeroes = ni & 0xFFFF; R = R.twicePlus(digit < 0 ? subP : addP); R = R.timesPow2(zeroes); } return R; } }
ECPoint r = table[n >>> 1]; R = R.twicePlus(r); R = R.timesPow2(zeroes);
protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { int[] naf = WNafUtil.generateCompactNaf(k); ECPoint addP = p.normalize(), subP = addP.negate(); ECPoint R = p.getCurve().getInfinity(); int i = naf.length; while (--i >= 0) { int ni = naf[i]; int digit = ni >> 16, zeroes = ni & 0xFFFF; R = R.twicePlus(digit < 0 ? subP : addP); R = R.timesPow2(zeroes); } return R; } }
R = R.twicePlus(lookupTable[index]);
static ECPoint implShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l) { ECCurve curve = P.getCurve(); ECPoint infinity = curve.getInfinity(); // TODO conjugate co-Z addition (ZADDC) can return both of these ECPoint PaddQ = P.add(Q); ECPoint PsubQ = P.subtract(Q); ECPoint[] points = new ECPoint[]{ Q, PsubQ, P, PaddQ }; curve.normalizeAll(points); ECPoint[] table = new ECPoint[] { points[3].negate(), points[2].negate(), points[1].negate(), points[0].negate(), infinity, points[0], points[1], points[2], points[3] }; byte[] jsf = WNafUtil.generateJSF(k, l); ECPoint R = infinity; int i = jsf.length; while (--i >= 0) { int jsfi = jsf[i]; // NOTE: The shifting ensures the sign is extended correctly int kDigit = ((jsfi << 24) >> 28), lDigit = ((jsfi << 28) >> 28); int index = 4 + (kDigit * 3) + lDigit; R = R.twicePlus(table[index]); } return R; }
static ECPoint implShamirsTrickJsf(ECPoint P, BigInteger k, ECPoint Q, BigInteger l) { ECCurve curve = P.getCurve(); ECPoint infinity = curve.getInfinity(); // TODO conjugate co-Z addition (ZADDC) can return both of these ECPoint PaddQ = P.add(Q); ECPoint PsubQ = P.subtract(Q); ECPoint[] points = new ECPoint[]{ Q, PsubQ, P, PaddQ }; curve.normalizeAll(points); ECPoint[] table = new ECPoint[] { points[3].negate(), points[2].negate(), points[1].negate(), points[0].negate(), infinity, points[0], points[1], points[2], points[3] }; byte[] jsf = WNafUtil.generateJSF(k, l); ECPoint R = infinity; int i = jsf.length; while (--i >= 0) { int jsfi = jsf[i]; // NOTE: The shifting ensures the sign is extended correctly int kDigit = ((jsfi << 24) >> 28), lDigit = ((jsfi << 28) >> 28); int index = 4 + (kDigit * 3) + lDigit; R = R.twicePlus(table[index]); } return R; }