public ECPoint subtract(ECPoint b) { if (b.isInfinity()) { return this; } // Add -b return this.add(b.negate()); }
public ECPoint subtract(ECPoint b) { if (b.isInfinity()) { return this; } // Add -b return this.add(b.negate()); } }
public ECPoint subtract(ECPoint b) { if (b.isInfinity()) { return this; } // Add -b return this.add(b.negate()); } }
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; }
@Override public byte[] getPublicKeyAtOffset(byte[] publicKey, byte[] offset) { BigInteger offsetInt = new BigInteger(publicKey); boolean invert = false; if (offsetInt.compareTo(BigInteger.ZERO) < 0) { invert = true; offsetInt = offsetInt.abs(); } ECPoint oG = curve.getG().multiply(offsetInt); if (invert) { oG = oG.negate(); } return oG.add(curve.getCurve().decodePoint(publicKey)).getEncoded(true); }
public ECPoint multiply(ECPoint p, BigInteger k) { int sign = k.signum(); if (sign == 0 || p.isInfinity()) { return p.getCurve().getInfinity(); } ECPoint positive = multiplyPositive(p, k.abs()); ECPoint result = sign > 0 ? positive : positive.negate(); /* * Although the various multipliers ought not to produce invalid output under normal * circumstances, a final check here is advised to guard against fault attacks. */ return checkResult(result); }
public ECPoint multiply(ECPoint p, BigInteger k) { int sign = k.signum(); if (sign == 0 || p.isInfinity()) { return p.getCurve().getInfinity(); } ECPoint positive = multiplyPositive(p, k.abs()); ECPoint result = sign > 0 ? positive : positive.negate(); /* * Although the various multipliers ought not to produce invalid output under normal * circumstances, a final check here is advised to guard against fault attacks. */ return ECAlgorithms.validatePoint(result); }
/** * '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; } }
protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { int[] naf = WNafUtil.generateCompactNaf(k); ECPoint R0 = p.getCurve().getInfinity(), R1 = p; int zeroes = 0; for (int i = 0; i < naf.length; ++i) { int ni = naf[i]; int digit = ni >> 16; zeroes += ni & 0xFFFF; R1 = R1.timesPow2(zeroes); R0 = R0.add(digit < 0 ? R1.negate() : R1); zeroes = 1; } return R0; } }
protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { int[] naf = WNafUtil.generateCompactNaf(k); ECPoint R0 = p.getCurve().getInfinity(), R1 = p; int zeroes = 0; for (int i = 0; i < naf.length; ++i) { int ni = naf[i]; int digit = ni >> 16; zeroes += ni & 0xFFFF; R1 = R1.timesPow2(zeroes); R0 = R0.add(digit < 0 ? R1.negate() : R1); zeroes = 1; } return R0; } }
public AsymmetricCipherKeyPair generateKeyPair() { AsymmetricCipherKeyPair pair = super.generateKeyPair(); ECPublicKeyParameters pub = (ECPublicKeyParameters)pair.getPublic(); ECPrivateKeyParameters priv = (ECPrivateKeyParameters)pair.getPrivate(); pub = new ECPublicKeyParameters(pub.getQ().negate(), pub.getParameters()); return new AsymmetricCipherKeyPair(pub, priv); } }
/** * 'Zeroless' Signed Digit Right-to-Left. */ protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { ECPoint R0 = p.getCurve().getInfinity(), 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; } }
/** * 'Zeroless' Signed Digit Right-to-Left. */ protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { ECPoint R0 = p.getCurve().getInfinity(), 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; } }
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; } }
public AsymmetricCipherKeyPair generateKeyPair() { AsymmetricCipherKeyPair pair = super.generateKeyPair(); ECPublicKeyParameters pub = (ECPublicKeyParameters)pair.getPublic(); ECPrivateKeyParameters priv = (ECPrivateKeyParameters)pair.getPrivate(); pub = new ECPublicKeyParameters(pub.getQ().negate(), pub.getParameters()); return new AsymmetricCipherKeyPair(pub, priv); } }
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; } }
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; } });
protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { ECCurve curveOrig = p.getCurve(); ECCurve curveAdd = configureCurve(curveOrig, additionCoord); ECCurve curveDouble = configureCurve(curveOrig, doublingCoord); int[] naf = WNafUtil.generateCompactNaf(k); ECPoint Ra = curveAdd.getInfinity(); ECPoint Td = curveDouble.importPoint(p); int zeroes = 0; for (int i = 0; i < naf.length; ++i) { int ni = naf[i]; int digit = ni >> 16; zeroes += ni & 0xFFFF; Td = Td.timesPow2(zeroes); ECPoint Tj = curveAdd.importPoint(Td); if (digit < 0) { Tj = Tj.negate(); } Ra = Ra.add(Tj); zeroes = 1; } return curveOrig.importPoint(Ra); }
protected ECPoint multiplyPositive(ECPoint p, BigInteger k) { ECCurve curveOrig = p.getCurve(); ECCurve curveAdd = configureCurve(curveOrig, additionCoord); ECCurve curveDouble = configureCurve(curveOrig, doublingCoord); int[] naf = WNafUtil.generateCompactNaf(k); ECPoint Ra = curveAdd.getInfinity(); ECPoint Td = curveDouble.importPoint(p); int zeroes = 0; for (int i = 0; i < naf.length; ++i) { int ni = naf[i]; int digit = ni >> 16; zeroes += ni & 0xFFFF; Td = Td.timesPow2(zeroes); ECPoint Tj = curveAdd.importPoint(Td); if (digit < 0) { Tj = Tj.negate(); } Ra = Ra.add(Tj); zeroes = 1; } return curveOrig.importPoint(Ra); }