/** * Multiplies a {@link org.bouncycastle.math.ec.ECPoint.AbstractF2m ECPoint.AbstractF2m} * by a <code>BigInteger</code> using the reduced <code>τ</code>-adic * NAF (RTNAF) method. * @param p The ECPoint.AbstractF2m to multiply. * @param k The <code>BigInteger</code> by which to multiply <code>p</code>. * @return <code>k * p</code> */ public static ECPoint.AbstractF2m multiplyRTnaf(ECPoint.AbstractF2m p, BigInteger k) { ECCurve.AbstractF2m curve = (ECCurve.AbstractF2m) p.getCurve(); int m = curve.getFieldSize(); int a = curve.getA().toBigInteger().intValue(); byte mu = getMu(a); BigInteger[] s = curve.getSi(); ZTauElement rho = partModReduction(k, m, (byte)a, s, mu, (byte)10); return multiplyTnaf(p, rho); }
/** * Multiplies a {@link org.bouncycastle.math.ec.ECPoint.AbstractF2m ECPoint.AbstractF2m} * by <code>k</code> using the reduced <code>τ</code>-adic NAF (RTNAF) * method. * @param point The ECPoint.AbstractF2m to multiply. * @param k The integer by which to multiply <code>k</code>. * @return <code>p</code> multiplied by <code>k</code>. */ protected ECPoint multiplyPositive(ECPoint point, BigInteger k) { if (!(point instanceof ECPoint.AbstractF2m)) { throw new IllegalArgumentException("Only ECPoint.AbstractF2m can be " + "used in WTauNafMultiplier"); } ECPoint.AbstractF2m p = (ECPoint.AbstractF2m)point; ECCurve.AbstractF2m curve = (ECCurve.AbstractF2m)p.getCurve(); int m = curve.getFieldSize(); byte a = curve.getA().toBigInteger().byteValue(); byte mu = Tnaf.getMu(a); BigInteger[] s = curve.getSi(); ZTauElement rho = Tnaf.partModReduction(k, m, a, s, mu, (byte)10); return multiplyWTnaf(p, rho, a, mu); }
ECCurve curve = this.getCurve(); int coord = curve.getCoordinateSystem();
protected boolean satisfiesCurveEquation() ECCurve curve = this.getCurve(); ECFieldElement X = this.x, A = curve.getA(), B = curve.getB();
protected boolean satisfiesCurveEquation() ECCurve curve = this.getCurve(); ECFieldElement X = this.x, A = curve.getA(), B = curve.getB();
ECFieldElement L2 = L.add(X).divide(scale).add(X2); return this.getCurve().createRawPoint(X, L2, this.getRawZCoords(), this.withCompression); // earlier JDK ECFieldElement Z2 = Z.multiply(scale); return this.getCurve().createRawPoint(X2, L2, new ECFieldElement[]{ Z2 }, this.withCompression); // earlier JDK
public ECPoint.AbstractF2m tau() { if (this.isInfinity()) { return this; } ECCurve curve = this.getCurve(); int coord = curve.getCoordinateSystem(); ECFieldElement X1 = this.x; switch (coord) { case ECCurve.COORD_AFFINE: case ECCurve.COORD_LAMBDA_AFFINE: { ECFieldElement Y1 = this.y; return (ECPoint.AbstractF2m)curve.createRawPoint(X1.square(), Y1.square(), this.withCompression); } case ECCurve.COORD_HOMOGENEOUS: case ECCurve.COORD_LAMBDA_PROJECTIVE: { ECFieldElement Y1 = this.y, Z1 = this.zs[0]; return (ECPoint.AbstractF2m)curve.createRawPoint(X1.square(), Y1.square(), new ECFieldElement[]{ Z1.square() }, this.withCompression); } default: { throw new IllegalStateException("unsupported coordinate system"); } } }
ECCurve curve = p.getCurve(); ECPoint.AbstractF2m q = (ECPoint.AbstractF2m)curve.getInfinity(); ECPoint.AbstractF2m pNeg = (ECPoint.AbstractF2m)p.negate();
/** * Does the precomputation for WTNAF multiplication. * @param p The <code>ECPoint</code> for which to do the precomputation. * @param a The parameter <code>a</code> of the elliptic curve. * @return The precomputation array for <code>p</code>. */ public static ECPoint.AbstractF2m[] getPreComp(ECPoint.AbstractF2m p, byte a) { byte[][] alphaTnaf = (a == 0) ? Tnaf.alpha0Tnaf : Tnaf.alpha1Tnaf; ECPoint.AbstractF2m[] pu = new ECPoint.AbstractF2m[(alphaTnaf.length + 1) >>> 1]; pu[0] = p; int precompLen = alphaTnaf.length; for (int i = 3; i < precompLen; i += 2) { pu[i >>> 1] = Tnaf.multiplyFromTnaf(p, alphaTnaf[i]); } p.getCurve().normalizeAll(pu); return pu; } }
public ECPoint scaleY(ECFieldElement scale) { if (this.isInfinity()) { return this; } int coord = this.getCurveCoordinateSystem(); switch (coord) { case ECCurve.COORD_LAMBDA_AFFINE: case ECCurve.COORD_LAMBDA_PROJECTIVE: { ECFieldElement X = this.getRawXCoord(), L = this.getRawYCoord(); // earlier JDK // Y is actually Lambda (X + Y/X) here ECFieldElement L2 = L.add(X).multiply(scale).add(X); return this.getCurve().createRawPoint(X, L2, this.getRawZCoords(), this.withCompression); // earlier JDK } default: { return super.scaleY(scale); } } }
/** * Multiplies a {@link org.bouncycastle.math.ec.ECPoint.AbstractF2m ECPoint.AbstractF2m} * by an element <code>λ</code> of <code><b>Z</b>[τ]</code> * using the <code>τ</code>-adic NAF (TNAF) method. * @param p The ECPoint.AbstractF2m to multiply. * @param lambda The element <code>λ</code> of * <code><b>Z</b>[τ]</code>. * @return <code>λ * p</code> */ public static ECPoint.AbstractF2m multiplyTnaf(ECPoint.AbstractF2m p, ZTauElement lambda) { ECCurve.AbstractF2m curve = (ECCurve.AbstractF2m)p.getCurve(); byte mu = getMu(curve.getA()); byte[] u = tauAdicNaf(mu, lambda); ECPoint.AbstractF2m q = multiplyFromTnaf(p, u); return q; }