65 lines
3.6 KiB
Java
65 lines
3.6 KiB
Java
|
package org.bouncycastle.crypto.tls;
|
||
|
|
||
|
import org.bouncycastle.crypto.AsymmetricBlockCipher;
|
||
|
import org.bouncycastle.crypto.CipherParameters;
|
||
|
import org.bouncycastle.crypto.CryptoException;
|
||
|
import org.bouncycastle.crypto.Digest;
|
||
|
import org.bouncycastle.crypto.Signer;
|
||
|
import org.bouncycastle.crypto.digests.NullDigest;
|
||
|
import org.bouncycastle.crypto.encodings.PKCS1Encoding;
|
||
|
import org.bouncycastle.crypto.engines.RSABlindedEngine;
|
||
|
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
|
||
|
import org.bouncycastle.crypto.params.ParametersWithRandom;
|
||
|
import org.bouncycastle.crypto.params.RSAKeyParameters;
|
||
|
import org.bouncycastle.crypto.signers.GenericSigner;
|
||
|
import org.bouncycastle.crypto.signers.RSADigestSigner;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class TlsRSASigner extends AbstractTlsSigner {
|
||
|
@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);
|
||
|
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() != 1) {
|
||
|
throw new IllegalStateException();
|
||
|
}
|
||
|
Digest nullDigest = z ? new NullDigest() : signatureAndHashAlgorithm == null ? new CombinedHash() : TlsUtils.createHash(signatureAndHashAlgorithm.getHash());
|
||
|
Signer rSADigestSigner = signatureAndHashAlgorithm != null ? new RSADigestSigner(nullDigest, TlsUtils.getOIDForHashAlgorithm(signatureAndHashAlgorithm.getHash())) : new GenericSigner(createRSAImpl(), nullDigest);
|
||
|
rSADigestSigner.init(z2, cipherParameters);
|
||
|
return rSADigestSigner;
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.tls.TlsSigner
|
||
|
public boolean isValidPublicKey(AsymmetricKeyParameter asymmetricKeyParameter) {
|
||
|
return (asymmetricKeyParameter instanceof RSAKeyParameters) && !asymmetricKeyParameter.isPrivate();
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.crypto.tls.TlsSigner
|
||
|
public byte[] generateRawSignature(SignatureAndHashAlgorithm signatureAndHashAlgorithm, AsymmetricKeyParameter asymmetricKeyParameter, byte[] bArr) throws CryptoException {
|
||
|
Signer makeSigner = makeSigner(signatureAndHashAlgorithm, true, true, new ParametersWithRandom(asymmetricKeyParameter, this.context.getSecureRandom()));
|
||
|
makeSigner.update(bArr, 0, bArr.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, new ParametersWithRandom(asymmetricKeyParameter, this.context.getSecureRandom()));
|
||
|
}
|
||
|
|
||
|
protected AsymmetricBlockCipher createRSAImpl() {
|
||
|
return new PKCS1Encoding(new RSABlindedEngine());
|
||
|
}
|
||
|
}
|