Example usage for org.bouncycastle.math.ec ECPoint getAffineXCoord

List of usage examples for org.bouncycastle.math.ec ECPoint getAffineXCoord

Introduction

In this page you can find the example usage for org.bouncycastle.math.ec ECPoint getAffineXCoord.

Prototype

public ECFieldElement getAffineXCoord() 

Source Link

Document

Returns the affine x-coordinate after checking that this point is normalized.

Usage

From source file:com.github.horrorho.inflatabledonkey.crypto.ec.ECCurvePoint.java

License:Open Source License

public byte[] agreement(BigInteger d) {
    // TODO thread safety of ECPoint unclear.
    synchronized (lock) {
        ECPoint P = Q.multiply(d).normalize();
        if (P.isInfinity()) {
            throw new IllegalStateException("invalid EDCH: infinity");
        }//from  www.ja  va2 s  . c  o  m

        return P.getAffineXCoord().getEncoded();
    }
}

From source file:com.github.horrorho.inflatabledonkey.crypto.rfc6637.RFC6637KDF.java

License:Open Source License

public byte[] apply(ECPoint S, byte[] fingerprint) throws IOException {
    // RFC Sections 7, 8
    byte[] ZB = S.getAffineXCoord().getEncoded();

    Digest digest = digestFactory.get();

    digest.update((byte) 0x00); // 00
    digest.update((byte) 0x00); // 00
    digest.update((byte) 0x00); // 00 
    digest.update((byte) 0x01); // 01 
    digest.update(ZB, 0, ZB.length); // ZB

    // Params/*  w w w . ja va 2  s .c  o  m*/
    digest.update(formattedOid, 0, formattedOid.length); // curve_OID_len || curve_OID 
    digest.update(publicKeyAlgID); // public_key_alg_ID
    digest.update((byte) 0x03); // 03
    digest.update((byte) 0x01); // 01
    digest.update(kdfHashID); // KDF_hash_ID
    digest.update(symAlgID); // KEK_alg_ID for AESKeyWrap
    digest.update(ANONYMOUS_SENDER, 0, ANONYMOUS_SENDER.length); // "Anonymous Sender    "
    digest.update(fingerprint, 0, fingerprint.length); // recipient_fingerprint

    byte[] hash = new byte[digest.getDigestSize()];
    digest.doFinal(hash, 0);
    return hash;
}

From source file:org.cryptoworkshop.ximix.demo.ballot.Main.java

License:Apache License

public static void outputPoint(BufferedWriter cWrt, ECPoint point, boolean isLast) throws IOException {
    cWrt.write("        {");
    cWrt.newLine();// w  ww .  ja  va 2s.  c o m
    cWrt.write("            \"x\" : \"" + point.getAffineXCoord().toBigInteger().toString(16) + "\",");
    cWrt.newLine();
    cWrt.write("            \"y\" : \"" + point.getAffineYCoord().toBigInteger().toString(16) + "\"");
    cWrt.newLine();
    if (isLast) {
        cWrt.write("        }");
    } else {
        cWrt.write("        },");
    }
    cWrt.newLine();
}

From source file:org.cryptoworkshop.ximix.node.crypto.signature.ECDSASignerEngine.java

License:Apache License

private void generateAndSendKAndP(SignatureMessage message) throws IOException {
    ECDSAInitialiseMessage ecdsaCreate = ECDSAInitialiseMessage.getInstance(message.getPayload());
    SubjectPublicKeyInfo pubKeyInfo = nodeContext.getPublicKey(ecdsaCreate.getKeyID());
    ECDomainParameters domainParams = ((ECPublicKeyParameters) PublicKeyFactory.createKey(pubKeyInfo))
            .getParameters();//from w  w w  .j a v  a2 s  . c om
    SigID sigID = new SigID(ecdsaCreate.getSigID());

    sharedKMap.init(sigID, ecdsaCreate.getNodesToUse().length);

    paramsMap.put(ecdsaCreate.getKeyID(), domainParams);

    BigInteger n = ecdsaCreate.getN();
    int nBitLength = n.bitLength();
    BigInteger k, r;

    do // generate r
    {
        do {
            k = new BigInteger(nBitLength, new SecureRandom());
        } while (k.equals(BigInteger.ZERO) || k.compareTo(n) >= 0);

        ECPoint p = domainParams.getG().multiply(k).normalize();

        // 5.3.3
        BigInteger x = p.getAffineXCoord().toBigInteger();

        r = x.mod(n);
    } while (r.equals(BigInteger.ZERO));

    ShamirSecretSplitter sss = new ShamirSecretSplitter(getNumberOfPeers(ecdsaCreate.getNodesToUse()),
            ecdsaCreate.getThreshold(), n, new SecureRandom());

    SplitSecret split = sss.split(k);

    execute(new SendShareTask(sigID, Type.STORE_K, ecdsaCreate.getNodesToUse(), sharedKMap, split.getShares()));

    sharedPMap.init(sigID, ecdsaCreate.getNodesToUse().length);

    execute(new SendPointShareTask(sigID, ecdsaCreate.getKeyID(), ecdsaCreate.getNodesToUse(),
            split.getShares()));
}

From source file:org.cryptoworkshop.ximix.node.crypto.signature.ECDSASignerEngine.java

License:Apache License

private void initialiseR(SignatureMessage message) throws IOException, ServiceConnectionException {
    ECDSAInitialiseMessage ecdsaCreate = ECDSAInitialiseMessage.getInstance(message.getPayload());
    SigID sigID = new SigID(ecdsaCreate.getSigID());
    ECDomainParameters domainParams = paramsMap.get(ecdsaCreate.getKeyID());

    sharedPMap.waitFor(sigID); // wait till local P value set

    ECPoint p = accumulateECPoint(ecdsaCreate.getNodesToUse(), Type.FETCH_P,
            new ECDSAFetchMessage(ecdsaCreate.getSigID(), ecdsaCreate.getKeyID(), ecdsaCreate.getNodesToUse()),
            domainParams.getCurve(), domainParams.getN());
    // 5.3.3//from  w w w .ja v  a  2s.  c o  m
    BigInteger x = p.getAffineXCoord().toBigInteger();
    BigInteger r = x.mod(domainParams.getN());

    rMap.put(sigID, r);
}

From source file:org.sufficientlysecure.keychain.securitytoken.SCP11bSecureMessaging.java

License:Open Source License

private static ECPublicKey newECDHPublicKey(final ECKeyFormat kf, byte[] data) throws InvalidKeySpecException,
        NoSuchAlgorithmException, InvalidParameterSpecException, NoSuchProviderException {
    if (ecdhFactory == null) {
        ecdhFactory = KeyFactory.getInstance(SCP11B_KEY_AGREEMENT_KEY_TYPE, PROVIDER);
    }/*w w w . j av a 2s .  co  m*/

    final X9ECParameters params = NISTNamedCurves.getByOID(kf.getCurveOID());
    if (params == null) {
        throw new InvalidParameterSpecException("unsupported curve");
    }

    final ECCurve curve = params.getCurve();
    final ECPoint p = curve.decodePoint(data);
    if (!p.isValid()) {
        throw new InvalidKeySpecException("invalid EC point");
    }

    final java.security.spec.ECPublicKeySpec pk = new java.security.spec.ECPublicKeySpec(
            new java.security.spec.ECPoint(p.getAffineXCoord().toBigInteger(),
                    p.getAffineYCoord().toBigInteger()),
            getAlgorithmParameterSpec(kf));

    return (ECPublicKey) (ecdhFactory.generatePublic(pk));
}