356 lines
18 KiB
Java
356 lines
18 KiB
Java
package org.bouncycastle.jcajce.provider.asymmetric.ecgost;
|
|
|
|
import java.io.IOException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.ObjectOutputStream;
|
|
import java.math.BigInteger;
|
|
import java.security.interfaces.ECPrivateKey;
|
|
import java.security.spec.ECParameterSpec;
|
|
import java.security.spec.ECPoint;
|
|
import java.util.Enumeration;
|
|
import org.bouncycastle.asn1.ASN1Encodable;
|
|
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
|
import org.bouncycastle.asn1.ASN1Primitive;
|
|
import org.bouncycastle.asn1.DERBitString;
|
|
import org.bouncycastle.asn1.cryptopro.GOST3410PublicKeyAlgParameters;
|
|
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
|
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
|
|
import org.bouncycastle.crypto.params.ECDomainParameters;
|
|
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
|
import org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util;
|
|
import org.bouncycastle.jcajce.provider.asymmetric.util.PKCS12BagAttributeCarrierImpl;
|
|
import org.bouncycastle.jce.interfaces.ECPointEncoder;
|
|
import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier;
|
|
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
|
import org.bouncycastle.jce.spec.ECPrivateKeySpec;
|
|
import org.bouncycastle.util.Strings;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class BCECGOST3410PrivateKey implements ECPrivateKey, org.bouncycastle.jce.interfaces.ECPrivateKey, PKCS12BagAttributeCarrier, ECPointEncoder {
|
|
static final long serialVersionUID = 7245981689601667138L;
|
|
private String algorithm;
|
|
private transient PKCS12BagAttributeCarrierImpl attrCarrier;
|
|
private transient BigInteger d;
|
|
private transient ECParameterSpec ecSpec;
|
|
private transient GOST3410PublicKeyAlgParameters gostParams;
|
|
private transient DERBitString publicKey;
|
|
private boolean withCompression;
|
|
|
|
public String toString() {
|
|
StringBuffer stringBuffer = new StringBuffer("EC Private Key");
|
|
String lineSeparator = Strings.lineSeparator();
|
|
stringBuffer.append(lineSeparator);
|
|
stringBuffer.append(" S: ").append(this.d.toString(16)).append(lineSeparator);
|
|
return stringBuffer.toString();
|
|
}
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.ECPointEncoder
|
|
public void setPointFormat(String str) {
|
|
this.withCompression = !"UNCOMPRESSED".equalsIgnoreCase(str);
|
|
}
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
|
public void setBagAttribute(ASN1ObjectIdentifier aSN1ObjectIdentifier, ASN1Encodable aSN1Encodable) {
|
|
this.attrCarrier.setBagAttribute(aSN1ObjectIdentifier, aSN1Encodable);
|
|
}
|
|
|
|
public int hashCode() {
|
|
return getD().hashCode() ^ engineGetSpec().hashCode();
|
|
}
|
|
|
|
@Override // java.security.interfaces.ECPrivateKey
|
|
public BigInteger getS() {
|
|
return this.d;
|
|
}
|
|
|
|
@Override // java.security.interfaces.ECKey
|
|
public ECParameterSpec getParams() {
|
|
return this.ecSpec;
|
|
}
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.ECKey
|
|
public org.bouncycastle.jce.spec.ECParameterSpec getParameters() {
|
|
ECParameterSpec eCParameterSpec = this.ecSpec;
|
|
if (eCParameterSpec == null) {
|
|
return null;
|
|
}
|
|
return EC5Util.convertSpec(eCParameterSpec, this.withCompression);
|
|
}
|
|
|
|
@Override // java.security.Key
|
|
public String getFormat() {
|
|
return "PKCS#8";
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:19:0x00b3 */
|
|
/* JADX WARN: Removed duplicated region for block: B:25:0x00bf */
|
|
@Override // java.security.Key
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
public byte[] getEncoded() {
|
|
/*
|
|
r11 = this;
|
|
org.bouncycastle.asn1.cryptopro.GOST3410PublicKeyAlgParameters r0 = r11.gostParams
|
|
java.lang.String r1 = "DER"
|
|
r2 = 0
|
|
if (r0 == 0) goto L2c
|
|
r0 = 32
|
|
byte[] r0 = new byte[r0]
|
|
r3 = 0
|
|
java.math.BigInteger r4 = r11.getS()
|
|
r11.extractBytes(r0, r3, r4)
|
|
org.bouncycastle.asn1.pkcs.PrivateKeyInfo r3 = new org.bouncycastle.asn1.pkcs.PrivateKeyInfo // Catch: java.io.IOException -> L2b
|
|
org.bouncycastle.asn1.x509.AlgorithmIdentifier r4 = new org.bouncycastle.asn1.x509.AlgorithmIdentifier // Catch: java.io.IOException -> L2b
|
|
org.bouncycastle.asn1.ASN1ObjectIdentifier r5 = org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers.gostR3410_2001 // Catch: java.io.IOException -> L2b
|
|
org.bouncycastle.asn1.cryptopro.GOST3410PublicKeyAlgParameters r6 = r11.gostParams // Catch: java.io.IOException -> L2b
|
|
r4.<init>(r5, r6) // Catch: java.io.IOException -> L2b
|
|
org.bouncycastle.asn1.DEROctetString r5 = new org.bouncycastle.asn1.DEROctetString // Catch: java.io.IOException -> L2b
|
|
r5.<init>(r0) // Catch: java.io.IOException -> L2b
|
|
r3.<init>(r4, r5) // Catch: java.io.IOException -> L2b
|
|
byte[] r0 = r3.getEncoded(r1) // Catch: java.io.IOException -> L2b
|
|
return r0
|
|
L2b:
|
|
return r2
|
|
L2c:
|
|
java.security.spec.ECParameterSpec r0 = r11.ecSpec
|
|
boolean r3 = r0 instanceof org.bouncycastle.jce.spec.ECNamedCurveSpec
|
|
if (r3 == 0) goto L51
|
|
org.bouncycastle.jce.spec.ECNamedCurveSpec r0 = (org.bouncycastle.jce.spec.ECNamedCurveSpec) r0
|
|
java.lang.String r0 = r0.getName()
|
|
org.bouncycastle.asn1.ASN1ObjectIdentifier r0 = org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil.getNamedCurveOid(r0)
|
|
if (r0 != 0) goto L4b
|
|
org.bouncycastle.asn1.ASN1ObjectIdentifier r0 = new org.bouncycastle.asn1.ASN1ObjectIdentifier
|
|
java.security.spec.ECParameterSpec r3 = r11.ecSpec
|
|
org.bouncycastle.jce.spec.ECNamedCurveSpec r3 = (org.bouncycastle.jce.spec.ECNamedCurveSpec) r3
|
|
java.lang.String r3 = r3.getName()
|
|
r0.<init>(r3)
|
|
L4b:
|
|
org.bouncycastle.asn1.x9.X962Parameters r3 = new org.bouncycastle.asn1.x9.X962Parameters
|
|
r3.<init>(r0)
|
|
goto L9e
|
|
L51:
|
|
if (r0 != 0) goto L63
|
|
org.bouncycastle.asn1.x9.X962Parameters r0 = new org.bouncycastle.asn1.x9.X962Parameters
|
|
org.bouncycastle.asn1.DERNull r3 = org.bouncycastle.asn1.DERNull.INSTANCE
|
|
r0.<init>(r3)
|
|
java.math.BigInteger r3 = r11.getS()
|
|
int r3 = org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil.getOrderBitLength(r2, r3)
|
|
goto Laf
|
|
L63:
|
|
java.security.spec.EllipticCurve r0 = r0.getCurve()
|
|
org.bouncycastle.math.ec.ECCurve r4 = org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util.convertCurve(r0)
|
|
org.bouncycastle.asn1.x9.X962Parameters r0 = new org.bouncycastle.asn1.x9.X962Parameters
|
|
org.bouncycastle.asn1.x9.X9ECParameters r9 = new org.bouncycastle.asn1.x9.X9ECParameters
|
|
java.security.spec.ECParameterSpec r3 = r11.ecSpec
|
|
java.security.spec.ECPoint r3 = r3.getGenerator()
|
|
boolean r5 = r11.withCompression
|
|
org.bouncycastle.math.ec.ECPoint r5 = org.bouncycastle.jcajce.provider.asymmetric.util.EC5Util.convertPoint(r4, r3, r5)
|
|
java.security.spec.ECParameterSpec r3 = r11.ecSpec
|
|
java.math.BigInteger r6 = r3.getOrder()
|
|
java.security.spec.ECParameterSpec r3 = r11.ecSpec
|
|
int r3 = r3.getCofactor()
|
|
long r7 = (long) r3
|
|
java.math.BigInteger r7 = java.math.BigInteger.valueOf(r7)
|
|
java.security.spec.ECParameterSpec r3 = r11.ecSpec
|
|
java.security.spec.EllipticCurve r3 = r3.getCurve()
|
|
byte[] r8 = r3.getSeed()
|
|
r3 = r9
|
|
r3.<init>(r4, r5, r6, r7, r8)
|
|
r0.<init>(r9)
|
|
r3 = r0
|
|
L9e:
|
|
java.security.spec.ECParameterSpec r0 = r11.ecSpec
|
|
java.math.BigInteger r0 = r0.getOrder()
|
|
java.math.BigInteger r4 = r11.getS()
|
|
int r0 = org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil.getOrderBitLength(r0, r4)
|
|
r10 = r3
|
|
r3 = r0
|
|
r0 = r10
|
|
Laf:
|
|
org.bouncycastle.asn1.DERBitString r4 = r11.publicKey
|
|
if (r4 == 0) goto Lbf
|
|
org.bouncycastle.asn1.sec.ECPrivateKey r4 = new org.bouncycastle.asn1.sec.ECPrivateKey
|
|
java.math.BigInteger r5 = r11.getS()
|
|
org.bouncycastle.asn1.DERBitString r6 = r11.publicKey
|
|
r4.<init>(r3, r5, r6, r0)
|
|
goto Lc8
|
|
Lbf:
|
|
org.bouncycastle.asn1.sec.ECPrivateKey r4 = new org.bouncycastle.asn1.sec.ECPrivateKey
|
|
java.math.BigInteger r5 = r11.getS()
|
|
r4.<init>(r3, r5, r0)
|
|
Lc8:
|
|
org.bouncycastle.asn1.pkcs.PrivateKeyInfo r3 = new org.bouncycastle.asn1.pkcs.PrivateKeyInfo // Catch: java.io.IOException -> Le1
|
|
org.bouncycastle.asn1.x509.AlgorithmIdentifier r5 = new org.bouncycastle.asn1.x509.AlgorithmIdentifier // Catch: java.io.IOException -> Le1
|
|
org.bouncycastle.asn1.ASN1ObjectIdentifier r6 = org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers.gostR3410_2001 // Catch: java.io.IOException -> Le1
|
|
org.bouncycastle.asn1.ASN1Primitive r0 = r0.toASN1Primitive() // Catch: java.io.IOException -> Le1
|
|
r5.<init>(r6, r0) // Catch: java.io.IOException -> Le1
|
|
org.bouncycastle.asn1.ASN1Primitive r0 = r4.toASN1Primitive() // Catch: java.io.IOException -> Le1
|
|
r3.<init>(r5, r0) // Catch: java.io.IOException -> Le1
|
|
byte[] r0 = r3.getEncoded(r1) // Catch: java.io.IOException -> Le1
|
|
return r0
|
|
Le1:
|
|
return r2
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: org.bouncycastle.jcajce.provider.asymmetric.ecgost.BCECGOST3410PrivateKey.getEncoded():byte[]");
|
|
}
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.ECPrivateKey
|
|
public BigInteger getD() {
|
|
return this.d;
|
|
}
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
|
public Enumeration getBagAttributeKeys() {
|
|
return this.attrCarrier.getBagAttributeKeys();
|
|
}
|
|
|
|
@Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier
|
|
public ASN1Encodable getBagAttribute(ASN1ObjectIdentifier aSN1ObjectIdentifier) {
|
|
return this.attrCarrier.getBagAttribute(aSN1ObjectIdentifier);
|
|
}
|
|
|
|
@Override // java.security.Key
|
|
public String getAlgorithm() {
|
|
return this.algorithm;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (!(obj instanceof BCECGOST3410PrivateKey)) {
|
|
return false;
|
|
}
|
|
BCECGOST3410PrivateKey bCECGOST3410PrivateKey = (BCECGOST3410PrivateKey) obj;
|
|
return getD().equals(bCECGOST3410PrivateKey.getD()) && engineGetSpec().equals(bCECGOST3410PrivateKey.engineGetSpec());
|
|
}
|
|
|
|
org.bouncycastle.jce.spec.ECParameterSpec engineGetSpec() {
|
|
ECParameterSpec eCParameterSpec = this.ecSpec;
|
|
return eCParameterSpec != null ? EC5Util.convertSpec(eCParameterSpec, this.withCompression) : BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();
|
|
}
|
|
|
|
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
|
|
objectOutputStream.defaultWriteObject();
|
|
objectOutputStream.writeObject(getEncoded());
|
|
}
|
|
|
|
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
|
objectInputStream.defaultReadObject();
|
|
populateFromPrivKeyInfo(PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray((byte[]) objectInputStream.readObject())));
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:27:0x01a9 */
|
|
/* JADX WARN: Removed duplicated region for block: B:28:0x01b4 */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
private void populateFromPrivKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo r11) throws java.io.IOException {
|
|
/*
|
|
Method dump skipped, instructions count: 453
|
|
To view this dump add '--comments-level debug' option
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: org.bouncycastle.jcajce.provider.asymmetric.ecgost.BCECGOST3410PrivateKey.populateFromPrivKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo):void");
|
|
}
|
|
|
|
private DERBitString getPublicKeyDetails(BCECGOST3410PublicKey bCECGOST3410PublicKey) {
|
|
try {
|
|
return SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(bCECGOST3410PublicKey.getEncoded())).getPublicKeyData();
|
|
} catch (IOException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private void extractBytes(byte[] bArr, int i, BigInteger bigInteger) {
|
|
byte[] byteArray = bigInteger.toByteArray();
|
|
if (byteArray.length < 32) {
|
|
byte[] bArr2 = new byte[32];
|
|
System.arraycopy(byteArray, 0, bArr2, 32 - byteArray.length, byteArray.length);
|
|
byteArray = bArr2;
|
|
}
|
|
for (int i2 = 0; i2 != 32; i2++) {
|
|
bArr[i + i2] = byteArray[(byteArray.length - 1) - i2];
|
|
}
|
|
}
|
|
|
|
public BCECGOST3410PrivateKey(ECPrivateKeySpec eCPrivateKeySpec) {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
this.d = eCPrivateKeySpec.getD();
|
|
this.ecSpec = eCPrivateKeySpec.getParams() != null ? EC5Util.convertSpec(EC5Util.convertCurve(eCPrivateKeySpec.getParams().getCurve(), eCPrivateKeySpec.getParams().getSeed()), eCPrivateKeySpec.getParams()) : null;
|
|
}
|
|
|
|
public BCECGOST3410PrivateKey(BCECGOST3410PrivateKey bCECGOST3410PrivateKey) {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
this.d = bCECGOST3410PrivateKey.d;
|
|
this.ecSpec = bCECGOST3410PrivateKey.ecSpec;
|
|
this.withCompression = bCECGOST3410PrivateKey.withCompression;
|
|
this.attrCarrier = bCECGOST3410PrivateKey.attrCarrier;
|
|
this.publicKey = bCECGOST3410PrivateKey.publicKey;
|
|
this.gostParams = bCECGOST3410PrivateKey.gostParams;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public BCECGOST3410PrivateKey(PrivateKeyInfo privateKeyInfo) throws IOException {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
populateFromPrivKeyInfo(privateKeyInfo);
|
|
}
|
|
|
|
public BCECGOST3410PrivateKey(java.security.spec.ECPrivateKeySpec eCPrivateKeySpec) {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
this.d = eCPrivateKeySpec.getS();
|
|
this.ecSpec = eCPrivateKeySpec.getParams();
|
|
}
|
|
|
|
public BCECGOST3410PrivateKey(ECPrivateKey eCPrivateKey) {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
this.d = eCPrivateKey.getS();
|
|
this.algorithm = eCPrivateKey.getAlgorithm();
|
|
this.ecSpec = eCPrivateKey.getParams();
|
|
}
|
|
|
|
public BCECGOST3410PrivateKey(String str, ECPrivateKeyParameters eCPrivateKeyParameters, BCECGOST3410PublicKey bCECGOST3410PublicKey, org.bouncycastle.jce.spec.ECParameterSpec eCParameterSpec) {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
ECDomainParameters parameters = eCPrivateKeyParameters.getParameters();
|
|
this.algorithm = str;
|
|
this.d = eCPrivateKeyParameters.getD();
|
|
this.ecSpec = eCParameterSpec == null ? new ECParameterSpec(EC5Util.convertCurve(parameters.getCurve(), parameters.getSeed()), new ECPoint(parameters.getG().getAffineXCoord().toBigInteger(), parameters.getG().getAffineYCoord().toBigInteger()), parameters.getN(), parameters.getH().intValue()) : new ECParameterSpec(EC5Util.convertCurve(eCParameterSpec.getCurve(), eCParameterSpec.getSeed()), new ECPoint(eCParameterSpec.getG().getAffineXCoord().toBigInteger(), eCParameterSpec.getG().getAffineYCoord().toBigInteger()), eCParameterSpec.getN(), eCParameterSpec.getH().intValue());
|
|
this.gostParams = bCECGOST3410PublicKey.getGostParams();
|
|
this.publicKey = getPublicKeyDetails(bCECGOST3410PublicKey);
|
|
}
|
|
|
|
public BCECGOST3410PrivateKey(String str, ECPrivateKeyParameters eCPrivateKeyParameters, BCECGOST3410PublicKey bCECGOST3410PublicKey, ECParameterSpec eCParameterSpec) {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
ECDomainParameters parameters = eCPrivateKeyParameters.getParameters();
|
|
this.algorithm = str;
|
|
this.d = eCPrivateKeyParameters.getD();
|
|
if (eCParameterSpec == null) {
|
|
this.ecSpec = new ECParameterSpec(EC5Util.convertCurve(parameters.getCurve(), parameters.getSeed()), new ECPoint(parameters.getG().getAffineXCoord().toBigInteger(), parameters.getG().getAffineYCoord().toBigInteger()), parameters.getN(), parameters.getH().intValue());
|
|
} else {
|
|
this.ecSpec = eCParameterSpec;
|
|
}
|
|
this.gostParams = bCECGOST3410PublicKey.getGostParams();
|
|
this.publicKey = getPublicKeyDetails(bCECGOST3410PublicKey);
|
|
}
|
|
|
|
public BCECGOST3410PrivateKey(String str, ECPrivateKeyParameters eCPrivateKeyParameters) {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
this.algorithm = str;
|
|
this.d = eCPrivateKeyParameters.getD();
|
|
this.ecSpec = null;
|
|
}
|
|
|
|
protected BCECGOST3410PrivateKey() {
|
|
this.algorithm = "ECGOST3410";
|
|
this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
|
|
}
|
|
}
|