package org.bouncycastle.jcajce.provider.asymmetric.elgamal; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.math.BigInteger; import java.util.Enumeration; import javax.crypto.interfaces.DHPrivateKey; import javax.crypto.spec.DHParameterSpec; import javax.crypto.spec.DHPrivateKeySpec; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1Encoding; import org.bouncycastle.asn1.ASN1Integer; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.oiw.ElGamalParameter; import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers; import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; import org.bouncycastle.crypto.params.ElGamalPrivateKeyParameters; import org.bouncycastle.jcajce.provider.asymmetric.util.PKCS12BagAttributeCarrierImpl; import org.bouncycastle.jce.interfaces.ElGamalPrivateKey; import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier; import org.bouncycastle.jce.spec.ElGamalParameterSpec; import org.bouncycastle.jce.spec.ElGamalPrivateKeySpec; /* loaded from: classes6.dex */ public class BCElGamalPrivateKey implements ElGamalPrivateKey, DHPrivateKey, PKCS12BagAttributeCarrier { static final long serialVersionUID = 4819350091141529678L; private transient PKCS12BagAttributeCarrierImpl attrCarrier = new PKCS12BagAttributeCarrierImpl(); private transient ElGamalParameterSpec elSpec; private BigInteger x; @Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier public void setBagAttribute(ASN1ObjectIdentifier aSN1ObjectIdentifier, ASN1Encodable aSN1Encodable) { this.attrCarrier.setBagAttribute(aSN1ObjectIdentifier, aSN1Encodable); } public int hashCode() { return ((getX().hashCode() ^ getParams().getG().hashCode()) ^ getParams().getP().hashCode()) ^ getParams().getL(); } @Override // org.bouncycastle.jce.interfaces.ElGamalPrivateKey, javax.crypto.interfaces.DHPrivateKey public BigInteger getX() { return this.x; } @Override // javax.crypto.interfaces.DHKey public DHParameterSpec getParams() { return new DHParameterSpec(this.elSpec.getP(), this.elSpec.getG()); } @Override // org.bouncycastle.jce.interfaces.ElGamalKey public ElGamalParameterSpec getParameters() { return this.elSpec; } @Override // java.security.Key public String getFormat() { return "PKCS#8"; } @Override // java.security.Key public byte[] getEncoded() { try { return new PrivateKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(this.elSpec.getP(), this.elSpec.getG())), new ASN1Integer(getX())).getEncoded(ASN1Encoding.DER); } catch (IOException unused) { return null; } } @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 "ElGamal"; } public boolean equals(Object obj) { if (!(obj instanceof DHPrivateKey)) { return false; } DHPrivateKey dHPrivateKey = (DHPrivateKey) obj; return getX().equals(dHPrivateKey.getX()) && getParams().getG().equals(dHPrivateKey.getParams().getG()) && getParams().getP().equals(dHPrivateKey.getParams().getP()) && getParams().getL() == dHPrivateKey.getParams().getL(); } private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.defaultWriteObject(); objectOutputStream.writeObject(this.elSpec.getP()); objectOutputStream.writeObject(this.elSpec.getG()); } private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { objectInputStream.defaultReadObject(); this.elSpec = new ElGamalParameterSpec((BigInteger) objectInputStream.readObject(), (BigInteger) objectInputStream.readObject()); this.attrCarrier = new PKCS12BagAttributeCarrierImpl(); } /* JADX INFO: Access modifiers changed from: package-private */ public BCElGamalPrivateKey(ElGamalPrivateKeySpec elGamalPrivateKeySpec) { this.x = elGamalPrivateKeySpec.getX(); this.elSpec = new ElGamalParameterSpec(elGamalPrivateKeySpec.getParams().getP(), elGamalPrivateKeySpec.getParams().getG()); } /* JADX INFO: Access modifiers changed from: package-private */ public BCElGamalPrivateKey(ElGamalPrivateKey elGamalPrivateKey) { this.x = elGamalPrivateKey.getX(); this.elSpec = elGamalPrivateKey.getParameters(); } /* JADX INFO: Access modifiers changed from: package-private */ public BCElGamalPrivateKey(ElGamalPrivateKeyParameters elGamalPrivateKeyParameters) { this.x = elGamalPrivateKeyParameters.getX(); this.elSpec = new ElGamalParameterSpec(elGamalPrivateKeyParameters.getParameters().getP(), elGamalPrivateKeyParameters.getParameters().getG()); } /* JADX INFO: Access modifiers changed from: package-private */ public BCElGamalPrivateKey(PrivateKeyInfo privateKeyInfo) throws IOException { ElGamalParameter elGamalParameter = ElGamalParameter.getInstance(privateKeyInfo.getPrivateKeyAlgorithm().getParameters()); this.x = ASN1Integer.getInstance(privateKeyInfo.parsePrivateKey()).getValue(); this.elSpec = new ElGamalParameterSpec(elGamalParameter.getP(), elGamalParameter.getG()); } /* JADX INFO: Access modifiers changed from: package-private */ public BCElGamalPrivateKey(DHPrivateKeySpec dHPrivateKeySpec) { this.x = dHPrivateKeySpec.getX(); this.elSpec = new ElGamalParameterSpec(dHPrivateKeySpec.getP(), dHPrivateKeySpec.getG()); } /* JADX INFO: Access modifiers changed from: package-private */ public BCElGamalPrivateKey(DHPrivateKey dHPrivateKey) { this.x = dHPrivateKey.getX(); this.elSpec = new ElGamalParameterSpec(dHPrivateKey.getParams().getP(), dHPrivateKey.getParams().getG()); } protected BCElGamalPrivateKey() { } }