protected X9ECParameters createParameters() { int m = 283; int k1 = 5; int k2 = 7; int k3 = 12; BigInteger a = ECConstants.ZERO; BigInteger b = BigInteger.valueOf(1); byte[] S = null; BigInteger n = fromHex("01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61"); BigInteger h = BigInteger.valueOf(4); ECCurve curve = configureCurve(new ECCurve.F2m(m, k1, k2, k3, a, b, n, h)); //ECPoint G = curve.decodePoint(Hex.decode("02" //+ "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836")); ECPoint G = curve.decodePoint(Hex.decode("04" + "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836" + "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259")); return new X9ECParameters(curve, G, n, h, S); } };
/** * Computes the auxiliary values <code>s<sub>0</sub></code> and * <code>s<sub>1</sub></code> used for partial modular reduction. * @param curve The elliptic curve for which to compute * <code>s<sub>0</sub></code> and <code>s<sub>1</sub></code>. * @throws IllegalArgumentException if <code>curve</code> is not a * Koblitz curve (Anomalous Binary Curve, ABC). */ public static BigInteger[] getSi(ECCurve.F2m curve) { if (!curve.isKoblitz()) { throw new IllegalArgumentException("si is defined for Koblitz curves only"); } int m = curve.getM(); int a = curve.getA().toBigInteger().intValue(); byte mu = curve.getMu(); int shifts = getShiftsForCofactor(curve.getCofactor()); int index = m + 3 - a; BigInteger[] ui = getLucas(mu, index, false); if (mu == 1) { ui[0] = ui[0].negate(); ui[1] = ui[1].negate(); } BigInteger dividend0 = ECConstants.ONE.add(ui[1]).shiftRight(shifts); BigInteger dividend1 = ECConstants.ONE.add(ui[0]).shiftRight(shifts).negate(); return new BigInteger[] { dividend0, dividend1 }; }
this.a = fromBigInteger(a); this.b = fromBigInteger(b); this.coord = F2M_DEFAULT_COORDS;
this.a = fromBigInteger(a); this.b = fromBigInteger(b); this.coord = F2M_DEFAULT_COORDS;
ECCurve curve = new ECCurve.F2m(field.getM(), field.getK1(), field.getK2(), field.getK3(), binary.getA(), new BigInteger(1, b_bytes)); byte[] g_bytes = binary.getG(); if (info.getPrivateKeyAlgorithm().getAlgorithm().equals(UAObjectIdentifiers.dstu4145le))
ECCurve curve = new ECCurve.F2m(field.getM(), field.getK1(), field.getK2(), field.getK3(), binary.getA(), new BigInteger(1, b_bytes)); byte[] g_bytes = binary.getG(); if (info.getAlgorithm().getAlgorithm().equals(UAObjectIdentifiers.dstu4145le))
? new ECCurve.F2m(m, k1, k2, k3, a, b, order, cofactor) : new ECCurve.F2m(m, k1, a, b, order, cofactor);
? new ECCurve.F2m(m, k1, k2, k3, a, b, order, cofactor) : new ECCurve.F2m(m, k1, a, b, order, cofactor);
curve = new ECCurve.F2m(m, k1, k2, k3, x9A.getValue().toBigInteger(), x9B.getValue().toBigInteger());
curve = new ECCurve.F2m(m, k1, k2, k3, A, B, order, cofactor);
ECCurve curve = new ECCurve.F2m(field.getM(), field.getK1(), field.getK2(), field.getK3(), binary.getA(), new BigInteger(1, b_bytes)); byte[] g_bytes = binary.getG(); if (keyInfo.getAlgorithm().getAlgorithm().equals(UAObjectIdentifiers.dstu4145le))
ECFieldElement x = fromBigInteger(X1), y = null; if (x.isZero()) ECFieldElement z = solveQuadraticEquation(beta); if (z != null) switch (this.getCoordinateSystem()) return this.createRawPoint(x, y, true);
byte a = curve.getA().toBigInteger().byteValue(); curve.setPreCompInfo(p, PRECOMP_NAME, pre);
ECFieldElement zeroElement = fromBigInteger(ECConstants.ZERO); do ECFieldElement t = fromBigInteger(new BigInteger(m, rand)); z = zeroElement; ECFieldElement w = beta;
c = new ECCurve.F2m( ((ECFieldF2m)curve.getField()).getM(), k[2], k[1], k[0], curve.getA(), curve.getB()); c = new ECCurve.F2m( ((ECFieldF2m)curve.getField()).getM(), k[0], curve.getA(), curve.getB());
public ECPoint createPoint(BigInteger x, BigInteger y, boolean withCompression) { ECFieldElement X = fromBigInteger(x), Y = fromBigInteger(y); switch (this.getCoordinateSystem()) { case COORD_LAMBDA_AFFINE: case COORD_LAMBDA_PROJECTIVE: { if (X.isZero()) { if (!Y.square().equals(this.getB())) { throw new IllegalArgumentException(); } } else { // Y becomes Lambda (X + Y/X) here Y = Y.divide(X).add(X); } break; } default: { break; } } return createRawPoint(X, Y, withCompression); }
/** * Multiplies a {@link org.bouncycastle.math.ec.ECPoint.F2m ECPoint.F2m} * by an element <code>λ</code> of <code><b>Z</b>[τ]</code> * using the <code>τ</code>-adic NAF (TNAF) method, given the TNAF * of <code>λ</code>. * @param p The ECPoint.F2m to multiply. * @param u The the TNAF of <code>λ</code>.. * @return <code>λ * p</code> */ public static ECPoint.F2m multiplyFromTnaf(ECPoint.F2m p, byte[] u) { ECCurve.F2m curve = (ECCurve.F2m)p.getCurve(); ECPoint.F2m q = (ECPoint.F2m) curve.getInfinity(); for (int i = u.length - 1; i >= 0; i--) { q = tau(q); if (u[i] == 1) { q = (ECPoint.F2m)q.addSimple(p); } else if (u[i] == -1) { q = (ECPoint.F2m)q.subtractSimple(p); } } return q; }
/** * Multiplies a {@link org.bouncycastle.math.ec.ECPoint.F2m ECPoint.F2m} * by <code>k</code> using the reduced <code>τ</code>-adic NAF (RTNAF) * method. * @param p The ECPoint.F2m 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.F2m)) { throw new IllegalArgumentException("Only ECPoint.F2m can be " + "used in WTauNafMultiplier"); } ECPoint.F2m p = (ECPoint.F2m)point; ECCurve.F2m curve = (ECCurve.F2m)p.getCurve(); int m = curve.getM(); byte a = curve.getA().toBigInteger().byteValue(); byte mu = curve.getMu(); BigInteger[] s = curve.getSi(); ZTauElement rho = Tnaf.partModReduction(k, m, a, s, mu, (byte)10); return multiplyWTnaf(p, rho, curve.getPreCompInfo(p, PRECOMP_NAME), a, mu); }
public static ECCurve convertCurve( EllipticCurve ec) { ECField field = ec.getField(); BigInteger a = ec.getA(); BigInteger b = ec.getB(); if (field instanceof ECFieldFp) { ECCurve.Fp curve = new ECCurve.Fp(((ECFieldFp)field).getP(), a, b); if (customCurves.containsKey(curve)) { return (ECCurve)customCurves.get(curve); } return curve; } else { ECFieldF2m fieldF2m = (ECFieldF2m)field; int m = fieldF2m.getM(); int ks[] = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial()); return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b); } }
protected X9ECParameters createParameters() { int m = 571; int k1 = 2; int k2 = 5; int k3 = 10; BigInteger a = BigInteger.valueOf(1); BigInteger b = fromHex("02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A"); byte[] S = Hex.decode("2AA058F73A0E33AB486B0F610410C53A7F132310"); BigInteger n = fromHex("03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47"); BigInteger h = BigInteger.valueOf(2); ECCurve curve = configureCurve(new ECCurve.F2m(m, k1, k2, k3, a, b, n, h)); //ECPoint G = curve.decodePoint(Hex.decode("03" //+ "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19")); ECPoint G = curve.decodePoint(Hex.decode("04" + "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19" + "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B")); return new X9ECParameters(curve, G, n, h, S); } };