package org.bouncycastle.jce.provider; 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.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.KeyUtil; 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 JCEElGamalPrivateKey implements ElGamalPrivateKey, DHPrivateKey, PKCS12BagAttributeCarrier { static final long serialVersionUID = 4819350091141529678L; private PKCS12BagAttributeCarrierImpl attrCarrier = new PKCS12BagAttributeCarrierImpl(); ElGamalParameterSpec elSpec; BigInteger x; @Override // org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier public void setBagAttribute(ASN1ObjectIdentifier aSN1ObjectIdentifier, ASN1Encodable aSN1Encodable) { this.attrCarrier.setBagAttribute(aSN1ObjectIdentifier, aSN1Encodable); } @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() { return KeyUtil.getEncodedPrivateKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(this.elSpec.getP(), this.elSpec.getG())), new ASN1Integer(getX())); } @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"; } private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.writeObject(getX()); objectOutputStream.writeObject(this.elSpec.getP()); objectOutputStream.writeObject(this.elSpec.getG()); } private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { this.x = (BigInteger) objectInputStream.readObject(); this.elSpec = new ElGamalParameterSpec((BigInteger) objectInputStream.readObject(), (BigInteger) objectInputStream.readObject()); } JCEElGamalPrivateKey(ElGamalPrivateKeySpec elGamalPrivateKeySpec) { this.x = elGamalPrivateKeySpec.getX(); this.elSpec = new ElGamalParameterSpec(elGamalPrivateKeySpec.getParams().getP(), elGamalPrivateKeySpec.getParams().getG()); } JCEElGamalPrivateKey(ElGamalPrivateKey elGamalPrivateKey) { this.x = elGamalPrivateKey.getX(); this.elSpec = elGamalPrivateKey.getParameters(); } JCEElGamalPrivateKey(ElGamalPrivateKeyParameters elGamalPrivateKeyParameters) { this.x = elGamalPrivateKeyParameters.getX(); this.elSpec = new ElGamalParameterSpec(elGamalPrivateKeyParameters.getParameters().getP(), elGamalPrivateKeyParameters.getParameters().getG()); } JCEElGamalPrivateKey(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()); } JCEElGamalPrivateKey(DHPrivateKeySpec dHPrivateKeySpec) { this.x = dHPrivateKeySpec.getX(); this.elSpec = new ElGamalParameterSpec(dHPrivateKeySpec.getP(), dHPrivateKeySpec.getG()); } JCEElGamalPrivateKey(DHPrivateKey dHPrivateKey) { this.x = dHPrivateKey.getX(); this.elSpec = new ElGamalParameterSpec(dHPrivateKey.getParams().getP(), dHPrivateKey.getParams().getG()); } protected JCEElGamalPrivateKey() { } }