Search in sources :

Example 11 with X9IntegerConverter

use of org.bouncycastle.asn1.x9.X9IntegerConverter in project icon-sdk-java by icon-project.

the class ECDSASignature method decompressKey.

/**
 * Decompress a compressed public key (x co-ord and low-bit of y-coord).
 */
private ECPoint decompressKey(BigInteger xBN, boolean yBit) {
    X9IntegerConverter x9 = new X9IntegerConverter();
    byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(curve.getCurve()));
    compEnc[0] = (byte) (yBit ? 0x03 : 0x02);
    return curve.getCurve().decodePoint(compEnc);
}
Also used : X9IntegerConverter(org.bouncycastle.asn1.x9.X9IntegerConverter)

Example 12 with X9IntegerConverter

use of org.bouncycastle.asn1.x9.X9IntegerConverter in project drongo by sparrowwallet.

the class ECKey method decompressKey.

/**
 * Decompress a compressed public key (x co-ord and low-bit of y-coord).
 */
private static ECPoint decompressKey(BigInteger xBN, boolean yBit) {
    X9IntegerConverter x9 = new X9IntegerConverter();
    byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve()));
    compEnc[0] = (byte) (yBit ? 0x03 : 0x02);
    return CURVE.getCurve().decodePoint(compEnc);
}
Also used : X9IntegerConverter(org.bouncycastle.asn1.x9.X9IntegerConverter)

Example 13 with X9IntegerConverter

use of org.bouncycastle.asn1.x9.X9IntegerConverter in project web3sdk by FISCO-BCOS.

the class Sign method decompressKey.

/**
 * Decompress a compressed public key (x co-ord and low-bit of y-coord).
 */
private static ECPoint decompressKey(BigInteger xBN, boolean yBit) {
    X9IntegerConverter x9 = new X9IntegerConverter();
    byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve()));
    compEnc[0] = (byte) (yBit ? 0x03 : 0x02);
    return CURVE.getCurve().decodePoint(compEnc);
}
Also used : X9IntegerConverter(org.bouncycastle.asn1.x9.X9IntegerConverter)

Example 14 with X9IntegerConverter

use of org.bouncycastle.asn1.x9.X9IntegerConverter in project aion by aionnetwork.

the class ECKeySecp256k1 method decompressKey.

/**
 * Decompress a compressed public key (x co-ord and low-bit of y-coord).
 *
 * @param xBN -
 * @param yBit -
 * @return -
 */
private ECPoint decompressKey(BigInteger xBN, boolean yBit) {
    X9IntegerConverter x9 = new X9IntegerConverter();
    byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve()));
    compEnc[0] = (byte) (yBit ? 0x03 : 0x02);
    return CURVE.getCurve().decodePoint(compEnc);
}
Also used : X9IntegerConverter(org.spongycastle.asn1.x9.X9IntegerConverter)

Example 15 with X9IntegerConverter

use of org.bouncycastle.asn1.x9.X9IntegerConverter in project robovm by robovm.

the class BCECPublicKey method populateFromPubKeyInfo.

private void populateFromPubKeyInfo(SubjectPublicKeyInfo info) {
    X962Parameters params = new X962Parameters((ASN1Primitive) info.getAlgorithm().getParameters());
    ECCurve curve;
    EllipticCurve ellipticCurve;
    if (params.isNamedCurve()) {
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) params.getParameters();
        X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
        curve = ecP.getCurve();
        ellipticCurve = EC5Util.convertCurve(curve, ecP.getSeed());
        ecSpec = new ECNamedCurveSpec(ECUtil.getCurveName(oid), ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH());
    } else if (params.isImplicitlyCA()) {
        ecSpec = null;
        curve = configuration.getEcImplicitlyCa().getCurve();
    } else {
        X9ECParameters ecP = X9ECParameters.getInstance(params.getParameters());
        curve = ecP.getCurve();
        ellipticCurve = EC5Util.convertCurve(curve, ecP.getSeed());
        this.ecSpec = new ECParameterSpec(ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH().intValue());
    }
    DERBitString bits = info.getPublicKeyData();
    byte[] data = bits.getBytes();
    ASN1OctetString key = new DEROctetString(data);
    //
    if (data[0] == 0x04 && data[1] == data.length - 2 && (data[2] == 0x02 || data[2] == 0x03)) {
        int qLength = new X9IntegerConverter().getByteLength(curve);
        if (qLength >= data.length - 3) {
            try {
                key = (ASN1OctetString) ASN1Primitive.fromByteArray(data);
            } catch (IOException ex) {
                throw new IllegalArgumentException("error recovering public key");
            }
        }
    }
    X9ECPoint derQ = new X9ECPoint(curve, key);
    this.q = derQ.getPoint();
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) X9ECParameters(org.bouncycastle.asn1.x9.X9ECParameters) X9IntegerConverter(org.bouncycastle.asn1.x9.X9IntegerConverter) DERBitString(org.bouncycastle.asn1.DERBitString) IOException(java.io.IOException) X9ECPoint(org.bouncycastle.asn1.x9.X9ECPoint) ECPoint(java.security.spec.ECPoint) DEROctetString(org.bouncycastle.asn1.DEROctetString) X9ECPoint(org.bouncycastle.asn1.x9.X9ECPoint) ECPoint(java.security.spec.ECPoint) X962Parameters(org.bouncycastle.asn1.x9.X962Parameters) EllipticCurve(java.security.spec.EllipticCurve) ECParameterSpec(java.security.spec.ECParameterSpec) X9ECPoint(org.bouncycastle.asn1.x9.X9ECPoint) ECCurve(org.bouncycastle.math.ec.ECCurve) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) ECNamedCurveSpec(org.bouncycastle.jce.spec.ECNamedCurveSpec)

Aggregations

X9IntegerConverter (org.bouncycastle.asn1.x9.X9IntegerConverter)18 X9IntegerConverter (org.spongycastle.asn1.x9.X9IntegerConverter)8 IOException (java.io.IOException)5 ECPoint (java.security.spec.ECPoint)5 ECParameterSpec (java.security.spec.ECParameterSpec)4 EllipticCurve (java.security.spec.EllipticCurve)4 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)3 DERBitString (org.bouncycastle.asn1.DERBitString)3 DEROctetString (org.bouncycastle.asn1.DEROctetString)3 X962Parameters (org.bouncycastle.asn1.x9.X962Parameters)3 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)3 X9ECPoint (org.bouncycastle.asn1.x9.X9ECPoint)3 ECNamedCurveSpec (org.bouncycastle.jce.spec.ECNamedCurveSpec)3 ECCurve (org.bouncycastle.math.ec.ECCurve)3 ASN1BitString (com.github.zhenwei.core.asn1.ASN1BitString)2 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)2 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)2 X962Parameters (com.github.zhenwei.core.asn1.x9.X962Parameters)2 X9ECPoint (com.github.zhenwei.core.asn1.x9.X9ECPoint)2 X9IntegerConverter (com.github.zhenwei.core.asn1.x9.X9IntegerConverter)2