diff options
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/jce/provider/JCEECPublicKey.java')
-rw-r--r-- | bcprov/src/main/java/org/bouncycastle/jce/provider/JCEECPublicKey.java | 215 |
1 files changed, 107 insertions, 108 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/jce/provider/JCEECPublicKey.java b/bcprov/src/main/java/org/bouncycastle/jce/provider/JCEECPublicKey.java index 94fb7289..654b5e1d 100644 --- a/bcprov/src/main/java/org/bouncycastle/jce/provider/JCEECPublicKey.java +++ b/bcprov/src/main/java/org/bouncycastle/jce/provider/JCEECPublicKey.java @@ -18,11 +18,10 @@ import org.bouncycastle.asn1.ASN1Sequence; import org.bouncycastle.asn1.DERBitString; import org.bouncycastle.asn1.DERNull; import org.bouncycastle.asn1.DEROctetString; -// BEGIN android-removed +// Android-removed: Unsupported algorithms // import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers; // import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves; // import org.bouncycastle.asn1.cryptopro.GOST3410PublicKeyAlgParameters; -// END android-removed import org.bouncycastle.asn1.x509.AlgorithmIdentifier; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.asn1.x9.X962Parameters; @@ -35,13 +34,11 @@ import org.bouncycastle.crypto.params.ECPublicKeyParameters; import org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util; import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil; import org.bouncycastle.jcajce.provider.asymmetric.util.KeyUtil; -// BEGIN android-removed +// Android-removed: Unsupported algorithms // import org.bouncycastle.jce.ECGOST3410NamedCurveTable; -// END android-removed import org.bouncycastle.jce.interfaces.ECPointEncoder; -// BEGIN android-removed +// Android-removed: Unsupported algorithms // import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; -// END android-removed import org.bouncycastle.jce.spec.ECNamedCurveSpec; import org.bouncycastle.math.ec.ECCurve; import org.bouncycastle.math.ec.custom.sec.SecP256K1Point; @@ -55,9 +52,8 @@ public class JCEECPublicKey private org.bouncycastle.math.ec.ECPoint q; private ECParameterSpec ecSpec; private boolean withCompression; - // BEGIN android-removed + // Android-removed: Unsupported algorithms // private GOST3410PublicKeyAlgParameters gostParams; - // END android-removed public JCEECPublicKey( String algorithm, @@ -67,9 +63,8 @@ public class JCEECPublicKey this.q = key.q; this.ecSpec = key.ecSpec; this.withCompression = key.withCompression; - // BEGIN android-removed + // Android-removed: Unsupported algorithms // this.gostParams = key.gostParams; - // END android-removed } public JCEECPublicKey( @@ -192,56 +187,58 @@ public class JCEECPublicKey private void populateFromPubKeyInfo(SubjectPublicKeyInfo info) { - // BEGIN android-removed - // if (info.getAlgorithmId().getAlgorithm().equals(CryptoProObjectIdentifiers.gostR3410_2001)) - // { - // DERBitString bits = info.getPublicKeyData(); - // ASN1OctetString key; - // this.algorithm = "ECGOST3410"; - // - // try - // { - // key = (ASN1OctetString) ASN1Primitive.fromByteArray(bits.getBytes()); - // } - // catch (IOException ex) - // { - // throw new IllegalArgumentException("error recovering public key"); - // } - // - // byte[] keyEnc = key.getOctets(); - // byte[] x = new byte[32]; - // byte[] y = new byte[32]; - // - // for (int i = 0; i != x.length; i++) - // { - // x[i] = keyEnc[32 - 1 - i]; - // } - // - // for (int i = 0; i != y.length; i++) - // { - // y[i] = keyEnc[64 - 1 - i]; - // } - // - // gostParams = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters()); - // - // ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet())); - // - // ECCurve curve = spec.getCurve(); - // EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed()); - // - // this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y), false); - // - // ecSpec = new ECNamedCurveSpec( - // ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()), - // ellipticCurve, - // new ECPoint( - // spec.getG().getAffineXCoord().toBigInteger(), - // spec.getG().getAffineYCoord().toBigInteger()), - // spec.getN(), spec.getH()); - // - // } - // else - // END android-removed + // BEGIN Android-removed: Unsupported algorithms + /* + if (info.getAlgorithmId().getAlgorithm().equals(CryptoProObjectIdentifiers.gostR3410_2001)) + { + DERBitString bits = info.getPublicKeyData(); + ASN1OctetString key; + this.algorithm = "ECGOST3410"; + + try + { + key = (ASN1OctetString) ASN1Primitive.fromByteArray(bits.getBytes()); + } + catch (IOException ex) + { + throw new IllegalArgumentException("error recovering public key"); + } + + byte[] keyEnc = key.getOctets(); + byte[] x = new byte[32]; + byte[] y = new byte[32]; + + for (int i = 0; i != x.length; i++) + { + x[i] = keyEnc[32 - 1 - i]; + } + + for (int i = 0; i != y.length; i++) + { + y[i] = keyEnc[64 - 1 - i]; + } + + gostParams = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters()); + + ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet())); + + ECCurve curve = spec.getCurve(); + EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed()); + + this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y), false); + + ecSpec = new ECNamedCurveSpec( + ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()), + ellipticCurve, + new ECPoint( + spec.getG().getAffineXCoord().toBigInteger(), + spec.getG().getAffineYCoord().toBigInteger()), + spec.getN(), spec.getH()); + + } + else + */ + // END Android-removed: Unsupported algorithms { X962Parameters params = new X962Parameters((ASN1Primitive)info.getAlgorithmId().getParameters()); ECCurve curve; @@ -330,54 +327,56 @@ public class JCEECPublicKey ASN1Encodable params; SubjectPublicKeyInfo info; - // BEGIN android-removed - // if (algorithm.equals("ECGOST3410")) - // { - // if (gostParams != null) - // { - // params = gostParams; - // } - // else - // { - // if (ecSpec instanceof ECNamedCurveSpec) - // { - // params = new GOST3410PublicKeyAlgParameters( - // ECGOST3410NamedCurves.getOID(((ECNamedCurveSpec)ecSpec).getName()), - // CryptoProObjectIdentifiers.gostR3411_94_CryptoProParamSet); - // } - // else - // { // strictly speaking this may not be applicable... - // 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()); - // - // params = new X962Parameters(ecP); - // } - // } - // - // BigInteger bX = this.q.getAffineXCoord().toBigInteger(); - // BigInteger bY = this.q.getAffineYCoord().toBigInteger(); - // byte[] encKey = new byte[64]; - // - // extractBytes(encKey, 0, bX); - // extractBytes(encKey, 32, bY); - // - // try - // { - // info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, params), new DEROctetString(encKey)); - // } - // catch (IOException e) - // { - // return null; - // } - // } - // else - // END android-removed + // BEGIN Android-removed: Unsupported algorithms + /* + if (algorithm.equals("ECGOST3410")) + { + if (gostParams != null) + { + params = gostParams; + } + else + { + if (ecSpec instanceof ECNamedCurveSpec) + { + params = new GOST3410PublicKeyAlgParameters( + ECGOST3410NamedCurves.getOID(((ECNamedCurveSpec)ecSpec).getName()), + CryptoProObjectIdentifiers.gostR3411_94_CryptoProParamSet); + } + else + { // strictly speaking this may not be applicable... + 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()); + + params = new X962Parameters(ecP); + } + } + + BigInteger bX = this.q.getAffineXCoord().toBigInteger(); + BigInteger bY = this.q.getAffineYCoord().toBigInteger(); + byte[] encKey = new byte[64]; + + extractBytes(encKey, 0, bX); + extractBytes(encKey, 32, bY); + + try + { + info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_2001, params), new DEROctetString(encKey)); + } + catch (IOException e) + { + return null; + } + } + else + */ + // END Android-removed: Unsupported algorithms { if (ecSpec instanceof ECNamedCurveSpec) { |