Refine search
public X962Parameters( X9ECParameters ecParameters) { this.params = ecParameters.toASN1Primitive(); }
X9ECParameters x9 = NISTNamedCurves.getByName("P-224"); // or whatever curve you want to use ECPoint g = x9.getG(); BigInteger n = x9.getN(); int nBitLength = n.bitLength(); BigInteger x; do { x = new BigInteger(nBitLength, random); } while (x.equals(ZERO) || (x.compareTo(n) >= 0)); ECPoint randomPoint = g.multiply(x);
protected X9ECParameters createParameters() { ECCurve curve = new ECCurve.Fp( new BigInteger("E95E4A5F737059DC60DFC7AD95B3D8139515620F", 16), // q new BigInteger("340E7BE2A280EB74E2BE61BADA745D97E8F7C300", 16), // a new BigInteger("1E589A8595423412134FAA2DBDEC95C8D8675E58", 16)); // b return new X9ECParameters( curve, curve.decodePoint(Hex.decode("04BED5AF16EA3F6A4F62938C4631EB5AF7BDBCDBC31667CB477A1A8EC338F94741669C976316DA6321")), // G new BigInteger("E95E4A5F737059DC60DF5991D45029409E60FC09", 16), //n new BigInteger("01", 16)); // h } };
ECCurve curve = EC5Util.convertCurve(ecSpec.getCurve()); X9ECParameters ecP = new X9ECParameters( curve, EC5Util.convertPoint(curve, ecSpec.getGenerator(), withCompression), ecSpec.getOrder(), BigInteger.valueOf(ecSpec.getCofactor()), ecSpec.getCurve().getSeed());
public static ExtendedKey create(byte[] seed) throws ValidationException { try { Mac mac = Mac.getInstance("HmacSHA512", "BC"); SecretKey seedkey = new SecretKeySpec(BITCOIN_SEED, "HmacSHA512"); mac.init(seedkey); byte[] lr = mac.doFinal(seed); byte[] l = Arrays.copyOfRange(lr, 0, 32); byte[] r = Arrays.copyOfRange(lr, 32, 64); BigInteger m = new BigInteger(1, l); if (m.compareTo(curve.getN()) >= 0) { throw new ValidationException("This is rather unlikely, but it did just happen"); } ECKeyPair keyPair = new ECKeyPair(l, true); return new ExtendedKey(keyPair, r, 0, 0, 0); } catch (NoSuchAlgorithmException e) { throw new ValidationException(e); } catch (NoSuchProviderException e) { throw new ValidationException(e); } catch (InvalidKeyException e) { throw new ValidationException(e); } }
bytes = Arrays.copyOf(bytes, 32); // Chop off the additional marker byte. BigInteger privKeyB = new BigInteger(1, bytes); ECDomainParameters CURVE = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); BigInteger HALF_CURVE_ORDER = params.getN().shiftRight(1); SecureRandom secureRandom = new SecureRandom();
private static void implPrintRootZ(X9ECParameters x9) { ECFieldElement z = x9.getCurve().fromBigInteger(BigInteger.valueOf(2)); ECFieldElement rootZ = z.sqrt(); System.out.println(rootZ.toBigInteger().toString(16).toUpperCase()); if (!rootZ.square().equals(z)) { throw new IllegalStateException("Optimized-sqrt sanity check failed"); } }
X9ECParameters x9 = NISTNamedCurves.getByName("P-224"); ECCurve.Fp curve = (Fp) x9.getCurve(); BigInteger q = curve.getQ(); ECFieldElement x1 = new ECFieldElement.Fp(q, new BigInteger("8")); ECFieldElement y1 = new ECFieldElement.Fp(q, new BigInteger("9"));
protected X9ECParameters createParameters() { BigInteger p = fromHex("F1FD178C0B3AD58F10126DE8CE42435B3961ADBCABC8CA6DE8FCF353D86E9C03"); BigInteger a = fromHex("F1FD178C0B3AD58F10126DE8CE42435B3961ADBCABC8CA6DE8FCF353D86E9C00"); BigInteger b = fromHex("EE353FCA5428A9300D4ABA754A44C00FDFEC0C9AE4B1A1803075ED967B7BB73F"); byte[] S = null; BigInteger n = fromHex("F1FD178C0B3AD58F10126DE8CE42435B53DC67E140D2BF941FFDD459C6D655E1"); BigInteger h = BigInteger.valueOf(1); ECCurve curve = configureCurve(new ECCurve.Fp(p, a, b, n, h)); X9ECPoint G = new X9ECPoint(curve, Hex.decode("04" + "B6B3D4C356C139EB31183D4749D423958C27D2DCAF98B70164C97A2DD98F5CFF" + "6142E0F7C8B204911F9271F0F3ECEF8C2701C307E8E4C9E183115A1554062CFB")); return new X9ECParameters(curve, G, n, h, S); } };
public static void discoverEndomorphisms(X9ECParameters x9) { if (x9 == null) { throw new NullPointerException("x9"); } ECCurve c = x9.getCurve(); if (ECAlgorithms.isFpCurve(c)) { BigInteger characteristic = c.getField().getCharacteristic(); if (c.getA().isZero() && characteristic.mod(ECConstants.THREE).equals(ECConstants.ONE)) { System.out.println("Curve has a 'GLV Type B' endomorphism with these parameters:"); printGLVTypeBParameters(x9); } } }
public static ECParameterSpec convertToSpec( X9ECParameters domainParameters) { return new ECParameterSpec( convertCurve(domainParameters.getCurve(), null), // JDK 1.5 has trouble with this if it's not null... new ECPoint( domainParameters.getG().getAffineXCoord().toBigInteger(), domainParameters.getG().getAffineYCoord().toBigInteger()), domainParameters.getN(), domainParameters.getH().intValue()); }
/** * Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by the BitCoin reference * implementation in its wallet storage format. */ public byte[] toASN1() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(400); // ASN1_SEQUENCE(EC_PRIVATEKEY) = { // ASN1_SIMPLE(EC_PRIVATEKEY, version, LONG), // ASN1_SIMPLE(EC_PRIVATEKEY, privateKey, ASN1_OCTET_STRING), // ASN1_EXP_OPT(EC_PRIVATEKEY, parameters, ECPKPARAMETERS, 0), // ASN1_EXP_OPT(EC_PRIVATEKEY, publicKey, ASN1_BIT_STRING, 1) // } ASN1_SEQUENCE_END(EC_PRIVATEKEY) DERSequenceGenerator seq = new DERSequenceGenerator(baos); seq.addObject(new ASN1Integer(1)); // version seq.addObject(new DEROctetString(priv.toByteArray())); seq.addObject(new DERTaggedObject(0, SECNamedCurves.getByName("secp256k1").toASN1Primitive())); seq.addObject(new DERTaggedObject(1, new DERBitString(getPubKey()))); seq.close(); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); // Cannot happen, writing to memory stream. } }
private static ECPoint decode(final byte[] toAdd) { return CURVE.getCurve().decodePoint(toAdd); }
private static ECPoint gMultiply(BigInteger p) { return CURVE.getG() .multiply(p); } }
private static void printGLVTypeBParameters(X9ECParameters x9) { // x^2 + x + 1 = 0 mod n BigInteger[] lambdas = solveQuadraticEquation(x9.getN(), ECConstants.ONE, ECConstants.ONE); /* * The 'Beta' values are field elements of order 3. There are only two such values besides 1, each corresponding * to one choice for 'Lambda'. */ ECFieldElement[] betas = findBetaValues(x9.getCurve()); printGLVTypeBParameters(x9, lambdas[0], betas); System.out.println("OR"); printGLVTypeBParameters(x9, lambdas[1], betas); }
static BigInteger n() { return CURVE.getN(); }
curve = ecP.getCurve(); X9ECParameters ecP = X9ECParameters.getInstance(params.getParameters()); curve = ecP.getCurve();
public static X9ECParameters getInstance(Object obj) { if (obj instanceof X9ECParameters) { return (X9ECParameters)obj; } if (obj != null) { return new X9ECParameters(ASN1Sequence.getInstance(obj)); } return null; }
public Object parseObject(PemObject obj) throws IOException { try { Object param = ASN1Primitive.fromByteArray(obj.getContent()); if (param instanceof ASN1ObjectIdentifier) { return ASN1Primitive.fromByteArray(obj.getContent()); } else if (param instanceof ASN1Sequence) { return X9ECParameters.getInstance(param); } else { return null; // implicitly CA } } catch (IOException e) { throw e; } catch (Exception e) { throw new PEMException("exception extracting EC named curve: " + e.toString()); } } }