Skip to content
Permalink
Browse files

8236070: Backout fix for JDK-8234465

Reviewed-by: mullan
  • Loading branch information
wangweij committed Dec 17, 2019
1 parent bd6ab22 commit 010ac54044e649ca2766b1c491134953b74d1e64
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -201,7 +201,6 @@ private PrivateKey implTranslatePrivateKey(PrivateKey key)
ECPrivateKey ecKey = (ECPrivateKey)key;
return new ECPrivateKeyImpl(
ecKey.getS(),
null,
ecKey.getParams()
);
} else if ("PKCS#8".equals(key.getFormat())) {
@@ -238,7 +237,7 @@ private PrivateKey implGeneratePrivate(KeySpec keySpec)
return new ECPrivateKeyImpl(pkcsSpec.getEncoded());
} else if (keySpec instanceof ECPrivateKeySpec) {
ECPrivateKeySpec ecSpec = (ECPrivateKeySpec)keySpec;
return new ECPrivateKeyImpl(ecSpec.getS(), null, ecSpec.getParams());
return new ECPrivateKeyImpl(ecSpec.getS(), ecSpec.getParams());
} else {
throw new InvalidKeySpecException("Only ECPrivateKeySpec "
+ "and PKCS8EncodedKeySpec supported for EC private keys");
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -199,10 +199,11 @@ public KeyPair generateKeyPair() {
AffinePoint affGen = new AffinePoint(x, y);
Point pub = ops.multiply(affGen, privArr);
AffinePoint affPub = pub.asAffine();

PrivateKey privateKey = new ECPrivateKeyImpl(privArr, ecParams);

ECPoint w = new ECPoint(affPub.getX().asBigInteger(),
affPub.getY().asBigInteger());

PrivateKey privateKey = new ECPrivateKeyImpl(privArr, w, ecParams);
PublicKey publicKey = new ECPublicKeyImpl(w, ecParams);

return Optional.of(new KeyPair(publicKey, privateKey));
@@ -224,12 +225,11 @@ private KeyPair generateKeyPairNative(SecureRandom random)
// keyBytes[0] is the encoding of the native private key
BigInteger s = new BigInteger(1, (byte[]) keyBytes[0]);

PrivateKey privateKey = new ECPrivateKeyImpl(s, ecParams);

// keyBytes[1] is the encoding of the native public key
byte[] pubKey = (byte[]) keyBytes[1];
ECPoint w = ECUtil.decodePoint(pubKey, ecParams.getCurve());

PrivateKey privateKey = new ECPrivateKeyImpl(s, w, ecParams);

PublicKey publicKey = new ECPublicKeyImpl(w, ecParams);

return new KeyPair(publicKey, privateKey);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -52,8 +52,8 @@
* }
* </pre>
*
* We currently ignore the optional parameters. We require that the
* parameters are encoded as part of the AlgorithmIdentifier,
* We currently ignore the optional parameters and publicKey fields. We
* require that the parameters are encoded as part of the AlgorithmIdentifier,
* not in the private key structure.
*
* @since 1.6
@@ -66,7 +66,6 @@
private BigInteger s; // private value
private byte[] arrayS; // private value as a little-endian array
private ECParameterSpec params;
private ECPoint pub; // the optional public key

/**
* Construct a key from its encoding. Called by the ECKeyFactory.
@@ -79,20 +78,18 @@
* Construct a key from its components. Used by the
* KeyFactory.
*/
ECPrivateKeyImpl(BigInteger s, ECPoint pub, ECParameterSpec params)
ECPrivateKeyImpl(BigInteger s, ECParameterSpec params)
throws InvalidKeyException {
this.s = s;
this.params = params;
this.pub = pub;
makeEncoding(s);

}

ECPrivateKeyImpl(byte[] s, ECPoint pub, ECParameterSpec params)
ECPrivateKeyImpl(byte[] s, ECParameterSpec params)
throws InvalidKeyException {
this.arrayS = s.clone();
this.params = params;
this.pub = pub;
makeEncoding(s);
}

@@ -105,12 +102,6 @@ private void makeEncoding(byte[] s) throws InvalidKeyException {
byte[] privBytes = s.clone();
ArrayUtil.reverse(privBytes);
out.putOctetString(privBytes);
if (pub != null) {
DerOutputStream pubDer = new DerOutputStream();
pubDer.putBitString(ECUtil.encodePoint(pub, params.getCurve()));
out.write(DerValue.createTag(DerValue.TAG_CONTEXT,
true, (byte) 0x01), pubDer);
}
DerValue val =
new DerValue(DerValue.tag_Sequence, out.toByteArray());
key = val.toByteArray();
@@ -195,25 +186,22 @@ protected void parseKeyBits() throws InvalidKeyException {
byte[] privData = data.getOctetString();
ArrayUtil.reverse(privData);
arrayS = privData;
AlgorithmParameters algParams = this.algid.getParameters();
if (algParams == null) {
throw new InvalidKeyException("EC domain parameters must be "
+ "encoded in the algorithm identifier");
}
params = algParams.getParameterSpec(ECParameterSpec.class);
while (data.available() != 0) {
DerValue value = data.getDerValue();
if (value.isContextSpecific((byte) 0)) {
// ignore for now. Usually not encoded because
// pkcs8 already has the params
// ignore for now
} else if (value.isContextSpecific((byte) 1)) {
pub = ECUtil.decodePoint(
value.data.getUnalignedBitString().toByteArray(),
params.getCurve());
// ignore for now
} else {
throw new InvalidKeyException("Unexpected value: " + value);
}
}
AlgorithmParameters algParams = this.algid.getParameters();
if (algParams == null) {
throw new InvalidKeyException("EC domain parameters must be "
+ "encoded in the algorithm identifier");
}
params = algParams.getParameterSpec(ECParameterSpec.class);
} catch (IOException e) {
throw new InvalidKeyException("Invalid EC private key", e);
} catch (InvalidParameterSpecException e) {

This file was deleted.

0 comments on commit 010ac54

Please sign in to comment.
You can’t perform that action at this time.