Search in sources :

Example 86 with ECPoint

use of java.security.spec.ECPoint in project jruby-openssl by jruby.

the class PKeyEC method dh_compute_key.

@JRubyMethod(name = "dh_compute_key")
public IRubyObject dh_compute_key(final ThreadContext context, final IRubyObject point) {
    try {
        // "BC"
        KeyAgreement agreement = SecurityHelper.getKeyAgreement("ECDH");
        agreement.init(getPrivateKey());
        if (point.isNil()) {
            agreement.doPhase(getPublicKey(), true);
        } else {
            final ECPoint ecPoint = ((Point) point).asECPoint();
            final String name = getCurveName();
            // "BC"
            KeyFactory keyFactory = KeyFactory.getInstance("EC");
            ECParameterSpec spec = getParamSpec(name);
            ECPublicKey ecPublicKey = (ECPublicKey) keyFactory.generatePublic(new ECPublicKeySpec(ecPoint, spec));
            agreement.doPhase(ecPublicKey, true);
        }
        final byte[] secret = agreement.generateSecret();
        return StringHelper.newString(context.runtime, secret);
    } catch (NoSuchAlgorithmException ex) {
        throw newECError(context.runtime, ex.toString());
    } catch (InvalidKeyException ex) {
        throw newECError(context.runtime, ex.toString());
    } catch (GeneralSecurityException ex) {
        throw newECError(context.runtime, ex.toString());
    }
}
Also used : ECPublicKey(java.security.interfaces.ECPublicKey) ECParameterSpec(java.security.spec.ECParameterSpec) GeneralSecurityException(java.security.GeneralSecurityException) ECPoint(java.security.spec.ECPoint) RubyString(org.jruby.RubyString) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyAgreement(javax.crypto.KeyAgreement) ECPoint(java.security.spec.ECPoint) InvalidKeyException(java.security.InvalidKeyException) KeyFactory(java.security.KeyFactory) ECPublicKeySpec(java.security.spec.ECPublicKeySpec) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 87 with ECPoint

use of java.security.spec.ECPoint in project perun by CESNET.

the class urn_perun_user_attribute_def_def_sshPublicKey method getECPoint.

/**
 * Provides means to get from a parsed Q value to the X and Y point values.
 * that can be used to create and ECPoint compatible with ECPublicKeySpec.
 *
 * @param q          According to RFC 5656:
 *                   "Q is the public key encoded from an elliptic curve point into an octet string"
 * @param identifier According to RFC 5656:
 *                   "The string [identifier] is the identifier of the elliptic curve domain parameters."
 * @return An ECPoint suitable for creating a JCE ECPublicKeySpec.
 */
private ECPoint getECPoint(BigInteger q, String identifier) {
    String name = identifier.replace("nist", "sec") + "r1";
    ECNamedCurveParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec(name);
    org.bouncycastle.math.ec.ECPoint point = ecSpec.getCurve().decodePoint(q.toByteArray());
    BigInteger x = point.getAffineXCoord().toBigInteger();
    BigInteger y = point.getAffineYCoord().toBigInteger();
    return new ECPoint(x, y);
}
Also used : ECNamedCurveParameterSpec(org.bouncycastle.jce.spec.ECNamedCurveParameterSpec) BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint) ECPublicKeySpec(java.security.spec.ECPublicKeySpec) ECGenParameterSpec(java.security.spec.ECGenParameterSpec) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) ECNamedCurveParameterSpec(org.bouncycastle.jce.spec.ECNamedCurveParameterSpec) ECParameterSpec(java.security.spec.ECParameterSpec) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec)

Example 88 with ECPoint

use of java.security.spec.ECPoint in project wycheproof by google.

the class EcdhTest method testTimingSecp256r1.

@SlowTest(providers = { ProviderType.BOUNCY_CASTLE, ProviderType.SPONGY_CASTLE, ProviderType.OPENJDK })
@Test
public void testTimingSecp256r1() throws Exception {
    // edge case for projective coordinates
    BigInteger x1 = new BigInteger("81bfb55b010b1bdf08b8d9d8590087aa278e28febff3b05632eeff09011c5579", 16);
    BigInteger y1 = new BigInteger("732d0e65267ea28b7af8cfcb148936c2af8664cbb4f04e188148a1457400c2a7", 16);
    ECPoint p1 = new ECPoint(x1, y1);
    // random point
    BigInteger x2 = new BigInteger("8608e36a91f1fba12e4074972af446176b5608c9c58dc318bd0742754c3dcee7", 16);
    BigInteger y2 = new BigInteger("bc2c9ecd44af916ca58d9e3ef1257f698d350ef486eb86137fe69a7375bcc191", 16);
    ECPoint p2 = new ECPoint(x2, y2);
    testTiming(EcUtil.getNistP256Params(), p1, p2, new BigInteger("2"), 256, "secp256r1");
}
Also used : BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint) SlowTest(com.google.security.wycheproof.WycheproofRunner.SlowTest) SlowTest(com.google.security.wycheproof.WycheproofRunner.SlowTest) Test(org.junit.Test) NoPresubmitTest(com.google.security.wycheproof.WycheproofRunner.NoPresubmitTest)

Example 89 with ECPoint

use of java.security.spec.ECPoint in project wycheproof by google.

the class EcdhTest method testTimingSecp384r1.

@SlowTest(providers = { ProviderType.BOUNCY_CASTLE, ProviderType.SPONGY_CASTLE, ProviderType.OPENJDK })
@Test
public void testTimingSecp384r1() throws Exception {
    // edge case for projective coordinates
    BigInteger x1 = new BigInteger("7a6fadfee03eb09554f2a04fe08300aca88bb3a46e8f6347bace672cfe427698" + "8541cef8dc10536a84580215f5f90a3b", 16);
    BigInteger y1 = new BigInteger("6d243d5d9de1cdddd04cbeabdc7a0f6c244391f7cb2d5738fe13c334add4b458" + "5fef61ffd446db33b39402278713ae78", 16);
    ECPoint p1 = new ECPoint(x1, y1);
    // random point
    BigInteger x2 = new BigInteger("71f3c57d6a879889e582af2c7c5444b0eb6ba95d88365b21ca9549475273ecdd" + "3930aa0bebbd1cf084e4049667278602", 16);
    BigInteger y2 = new BigInteger("9dcbc4d843af8944eb4ba018d369b351a9ea0f7b9e3561df2ee218d54e198f7c" + "837a3abaa41dffd2d2cb771a7599ed9e", 16);
    ECPoint p2 = new ECPoint(x2, y2);
    testTiming(EcUtil.getNistP384Params(), p1, p2, new BigInteger("2"), 384, "secp384r1");
}
Also used : BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint) SlowTest(com.google.security.wycheproof.WycheproofRunner.SlowTest) SlowTest(com.google.security.wycheproof.WycheproofRunner.SlowTest) Test(org.junit.Test) NoPresubmitTest(com.google.security.wycheproof.WycheproofRunner.NoPresubmitTest)

Example 90 with ECPoint

use of java.security.spec.ECPoint in project wycheproof by google.

the class EcdhTest method testTimingBrainpoolP256r1.

@SlowTest(providers = { ProviderType.BOUNCY_CASTLE, ProviderType.SPONGY_CASTLE, ProviderType.OPENJDK })
@Test
public void testTimingBrainpoolP256r1() throws Exception {
    // edge case for Jacobian and projective coordinates
    BigInteger x1 = new BigInteger("79838c22d2b8dc9af2e6cf56f8826dc3dfe10fcb17b6aaaf551ee52bef12f826", 16);
    BigInteger y1 = new BigInteger("1e2ed3d453088c8552c6feecf898667bc1e15905002edec6b269feb7bea09d5b", 16);
    ECPoint p1 = new ECPoint(x1, y1);
    // random point
    BigInteger x2 = new BigInteger("2720b2e821b2ac8209b573bca755a68821e1e09deb580666702570dd527dd4c1", 16);
    BigInteger y2 = new BigInteger("25cdd610243c7e693fad7bd69b43ae3e63e94317c4c6b717d9c8bc3be8c996fb", 16);
    ECPoint p2 = new ECPoint(x2, y2);
    testTiming(EcUtil.getBrainpoolP256r1Params(), p1, p2, new BigInteger("2"), 255, "brainpoolP256r1");
}
Also used : BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint) SlowTest(com.google.security.wycheproof.WycheproofRunner.SlowTest) SlowTest(com.google.security.wycheproof.WycheproofRunner.SlowTest) Test(org.junit.Test) NoPresubmitTest(com.google.security.wycheproof.WycheproofRunner.NoPresubmitTest)

Aggregations

ECPoint (java.security.spec.ECPoint)111 ECParameterSpec (java.security.spec.ECParameterSpec)56 BigInteger (java.math.BigInteger)54 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)36 ECPublicKey (java.security.interfaces.ECPublicKey)31 EllipticCurve (java.security.spec.EllipticCurve)31 KeyPair (java.security.KeyPair)20 ECPrivateKey (java.security.interfaces.ECPrivateKey)20 PublicKey (java.security.PublicKey)17 ECFieldFp (java.security.spec.ECFieldFp)17 ECGenParameterSpec (java.security.spec.ECGenParameterSpec)16 Test (org.junit.Test)16 KeyFactory (java.security.KeyFactory)15 KeyPairGenerator (java.security.KeyPairGenerator)14 AlgorithmParameters (java.security.AlgorithmParameters)13 GeneralSecurityException (java.security.GeneralSecurityException)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 KeySpec (java.security.spec.KeySpec)11 IOException (java.io.IOException)10 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)9