what-the-bank/sources/org/bouncycastle/crypto/tls/TlsDSASigner.java

72 lines
3.4 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.tls;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.CryptoException;
import org.bouncycastle.crypto.DSA;
import org.bouncycastle.crypto.Signer;
import org.bouncycastle.crypto.digests.NullDigest;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.ParametersWithRandom;
import org.bouncycastle.crypto.signers.DSADigestSigner;
/* loaded from: classes6.dex */
public abstract class TlsDSASigner extends AbstractTlsSigner {
protected abstract DSA createDSAImpl(short s);
protected abstract short getSignatureAlgorithm();
protected CipherParameters makeInitParameters(boolean z, CipherParameters cipherParameters) {
return cipherParameters;
}
@Override // org.bouncycastle.crypto.tls.TlsSigner
public boolean verifyRawSignature(SignatureAndHashAlgorithm signatureAndHashAlgorithm, byte[] bArr, AsymmetricKeyParameter asymmetricKeyParameter, byte[] bArr2) throws CryptoException {
Signer makeSigner = makeSigner(signatureAndHashAlgorithm, true, false, asymmetricKeyParameter);
if (signatureAndHashAlgorithm == null) {
makeSigner.update(bArr2, 16, 20);
} else {
makeSigner.update(bArr2, 0, bArr2.length);
}
return makeSigner.verifySignature(bArr);
}
protected Signer makeSigner(SignatureAndHashAlgorithm signatureAndHashAlgorithm, boolean z, boolean z2, CipherParameters cipherParameters) {
if ((signatureAndHashAlgorithm != null) != TlsUtils.isTLSv12(this.context)) {
throw new IllegalStateException();
}
if (signatureAndHashAlgorithm != null && signatureAndHashAlgorithm.getSignature() != getSignatureAlgorithm()) {
throw new IllegalStateException();
}
short hash = signatureAndHashAlgorithm == null ? (short) 2 : signatureAndHashAlgorithm.getHash();
DSADigestSigner dSADigestSigner = new DSADigestSigner(createDSAImpl(hash), z ? new NullDigest() : TlsUtils.createHash(hash));
dSADigestSigner.init(z2, makeInitParameters(z2, cipherParameters));
return dSADigestSigner;
}
@Override // org.bouncycastle.crypto.tls.TlsSigner
public byte[] generateRawSignature(SignatureAndHashAlgorithm signatureAndHashAlgorithm, AsymmetricKeyParameter asymmetricKeyParameter, byte[] bArr) throws CryptoException {
int length;
int i;
Signer makeSigner = makeSigner(signatureAndHashAlgorithm, true, true, new ParametersWithRandom(asymmetricKeyParameter, this.context.getSecureRandom()));
if (signatureAndHashAlgorithm == null) {
i = 16;
length = 20;
} else {
length = bArr.length;
i = 0;
}
makeSigner.update(bArr, i, length);
return makeSigner.generateSignature();
}
@Override // org.bouncycastle.crypto.tls.TlsSigner
public Signer createVerifyer(SignatureAndHashAlgorithm signatureAndHashAlgorithm, AsymmetricKeyParameter asymmetricKeyParameter) {
return makeSigner(signatureAndHashAlgorithm, false, false, asymmetricKeyParameter);
}
@Override // org.bouncycastle.crypto.tls.TlsSigner
public Signer createSigner(SignatureAndHashAlgorithm signatureAndHashAlgorithm, AsymmetricKeyParameter asymmetricKeyParameter) {
return makeSigner(signatureAndHashAlgorithm, false, true, asymmetricKeyParameter);
}
}