130 lines
5.5 KiB
Java
130 lines
5.5 KiB
Java
|
package org.bouncycastle.jcajce.provider.asymmetric.elgamal;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.ObjectInputStream;
|
||
|
import java.io.ObjectOutputStream;
|
||
|
import java.math.BigInteger;
|
||
|
import javax.crypto.interfaces.DHPublicKey;
|
||
|
import javax.crypto.spec.DHParameterSpec;
|
||
|
import javax.crypto.spec.DHPublicKeySpec;
|
||
|
import org.bouncycastle.asn1.ASN1Encoding;
|
||
|
import org.bouncycastle.asn1.ASN1Integer;
|
||
|
import org.bouncycastle.asn1.oiw.ElGamalParameter;
|
||
|
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
|
||
|
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
||
|
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
|
||
|
import org.bouncycastle.crypto.params.ElGamalPublicKeyParameters;
|
||
|
import org.bouncycastle.jce.interfaces.ElGamalPublicKey;
|
||
|
import org.bouncycastle.jce.spec.ElGamalParameterSpec;
|
||
|
import org.bouncycastle.jce.spec.ElGamalPublicKeySpec;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class BCElGamalPublicKey implements ElGamalPublicKey, DHPublicKey {
|
||
|
static final long serialVersionUID = 8712728417091216948L;
|
||
|
private transient ElGamalParameterSpec elSpec;
|
||
|
private BigInteger y;
|
||
|
|
||
|
public int hashCode() {
|
||
|
return ((getY().hashCode() ^ getParams().getG().hashCode()) ^ getParams().getP().hashCode()) ^ getParams().getL();
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.jce.interfaces.ElGamalPublicKey, javax.crypto.interfaces.DHPublicKey
|
||
|
public BigInteger getY() {
|
||
|
return this.y;
|
||
|
}
|
||
|
|
||
|
@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 "X.509";
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public byte[] getEncoded() {
|
||
|
try {
|
||
|
return new SubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(this.elSpec.getP(), this.elSpec.getG())), new ASN1Integer(this.y)).getEncoded(ASN1Encoding.DER);
|
||
|
} catch (IOException unused) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // java.security.Key
|
||
|
public String getAlgorithm() {
|
||
|
return "ElGamal";
|
||
|
}
|
||
|
|
||
|
public boolean equals(Object obj) {
|
||
|
if (!(obj instanceof DHPublicKey)) {
|
||
|
return false;
|
||
|
}
|
||
|
DHPublicKey dHPublicKey = (DHPublicKey) obj;
|
||
|
return getY().equals(dHPublicKey.getY()) && getParams().getG().equals(dHPublicKey.getParams().getG()) && getParams().getP().equals(dHPublicKey.getParams().getP()) && getParams().getL() == dHPublicKey.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());
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public BCElGamalPublicKey(ElGamalPublicKeySpec elGamalPublicKeySpec) {
|
||
|
this.y = elGamalPublicKeySpec.getY();
|
||
|
this.elSpec = new ElGamalParameterSpec(elGamalPublicKeySpec.getParams().getP(), elGamalPublicKeySpec.getParams().getG());
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public BCElGamalPublicKey(ElGamalPublicKey elGamalPublicKey) {
|
||
|
this.y = elGamalPublicKey.getY();
|
||
|
this.elSpec = elGamalPublicKey.getParameters();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public BCElGamalPublicKey(ElGamalPublicKeyParameters elGamalPublicKeyParameters) {
|
||
|
this.y = elGamalPublicKeyParameters.getY();
|
||
|
this.elSpec = new ElGamalParameterSpec(elGamalPublicKeyParameters.getParameters().getP(), elGamalPublicKeyParameters.getParameters().getG());
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public BCElGamalPublicKey(SubjectPublicKeyInfo subjectPublicKeyInfo) {
|
||
|
ElGamalParameter elGamalParameter = ElGamalParameter.getInstance(subjectPublicKeyInfo.getAlgorithm().getParameters());
|
||
|
try {
|
||
|
this.y = ((ASN1Integer) subjectPublicKeyInfo.parsePublicKey()).getValue();
|
||
|
this.elSpec = new ElGamalParameterSpec(elGamalParameter.getP(), elGamalParameter.getG());
|
||
|
} catch (IOException unused) {
|
||
|
throw new IllegalArgumentException("invalid info structure in DSA public key");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public BCElGamalPublicKey(DHPublicKeySpec dHPublicKeySpec) {
|
||
|
this.y = dHPublicKeySpec.getY();
|
||
|
this.elSpec = new ElGamalParameterSpec(dHPublicKeySpec.getP(), dHPublicKeySpec.getG());
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public BCElGamalPublicKey(DHPublicKey dHPublicKey) {
|
||
|
this.y = dHPublicKey.getY();
|
||
|
this.elSpec = new ElGamalParameterSpec(dHPublicKey.getParams().getP(), dHPublicKey.getParams().getG());
|
||
|
}
|
||
|
|
||
|
BCElGamalPublicKey(BigInteger bigInteger, ElGamalParameterSpec elGamalParameterSpec) {
|
||
|
this.y = bigInteger;
|
||
|
this.elSpec = elGamalParameterSpec;
|
||
|
}
|
||
|
}
|