69 lines
2.6 KiB
Java
69 lines
2.6 KiB
Java
package org.bouncycastle.pqc.crypto;
|
|
|
|
import org.bouncycastle.crypto.CipherParameters;
|
|
import org.bouncycastle.crypto.Digest;
|
|
import org.bouncycastle.crypto.Signer;
|
|
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
|
|
import org.bouncycastle.crypto.params.ParametersWithRandom;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class DigestingMessageSigner implements Signer {
|
|
private boolean forSigning;
|
|
private final Digest messDigest;
|
|
private final MessageSigner messSigner;
|
|
|
|
@Override // org.bouncycastle.crypto.Signer
|
|
public boolean verifySignature(byte[] bArr) {
|
|
if (this.forSigning) {
|
|
throw new IllegalStateException("DigestingMessageSigner not initialised for verification");
|
|
}
|
|
byte[] bArr2 = new byte[this.messDigest.getDigestSize()];
|
|
this.messDigest.doFinal(bArr2, 0);
|
|
return this.messSigner.verifySignature(bArr2, bArr);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Signer
|
|
public void update(byte[] bArr, int i, int i2) {
|
|
this.messDigest.update(bArr, i, i2);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Signer
|
|
public void update(byte b) {
|
|
this.messDigest.update(b);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Signer
|
|
public void reset() {
|
|
this.messDigest.reset();
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Signer
|
|
public void init(boolean z, CipherParameters cipherParameters) {
|
|
this.forSigning = z;
|
|
AsymmetricKeyParameter asymmetricKeyParameter = cipherParameters instanceof ParametersWithRandom ? (AsymmetricKeyParameter) ((ParametersWithRandom) cipherParameters).getParameters() : (AsymmetricKeyParameter) cipherParameters;
|
|
if (z && !asymmetricKeyParameter.isPrivate()) {
|
|
throw new IllegalArgumentException("Signing Requires Private Key.");
|
|
}
|
|
if (!z && asymmetricKeyParameter.isPrivate()) {
|
|
throw new IllegalArgumentException("Verification Requires Public Key.");
|
|
}
|
|
reset();
|
|
this.messSigner.init(z, cipherParameters);
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.Signer
|
|
public byte[] generateSignature() {
|
|
if (!this.forSigning) {
|
|
throw new IllegalStateException("DigestingMessageSigner not initialised for signature generation.");
|
|
}
|
|
byte[] bArr = new byte[this.messDigest.getDigestSize()];
|
|
this.messDigest.doFinal(bArr, 0);
|
|
return this.messSigner.generateSignature(bArr);
|
|
}
|
|
|
|
public DigestingMessageSigner(MessageSigner messageSigner, Digest digest) {
|
|
this.messSigner = messageSigner;
|
|
this.messDigest = digest;
|
|
}
|
|
}
|