package org.bouncycastle.crypto.signers;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class GenericSigner implements org.bouncycastle.crypto.Signer {
    private final org.bouncycastle.crypto.AsymmetricBlockCipher g;
    private final org.bouncycastle.crypto.Digest h;
    private boolean i;

    @Override // org.bouncycastle.crypto.Signer
    public boolean a(byte[] bArr) {
        if (this.i) {
            throw new java.lang.IllegalStateException("GenericSigner not initialised for verification");
        }
        int digestSize = this.h.getDigestSize();
        byte[] bArr2 = new byte[digestSize];
        this.h.doFinal(bArr2, 0);
        try {
            byte[] bArrProcessBlock = this.g.processBlock(bArr, 0, bArr.length);
            if (bArrProcessBlock.length < digestSize) {
                byte[] bArr3 = new byte[digestSize];
                java.lang.System.arraycopy(bArrProcessBlock, 0, bArr3, digestSize - bArrProcessBlock.length, bArrProcessBlock.length);
                bArrProcessBlock = bArr3;
            }
            return org.bouncycastle.util.Arrays.z(bArrProcessBlock, bArr2);
        } catch (java.lang.Exception unused) {
            return false;
        }
    }

    @Override // org.bouncycastle.crypto.Signer
    public byte[] b() {
        if (!this.i) {
            throw new java.lang.IllegalStateException("GenericSigner not initialised for signature generation.");
        }
        int digestSize = this.h.getDigestSize();
        byte[] bArr = new byte[digestSize];
        this.h.doFinal(bArr, 0);
        return this.g.processBlock(bArr, 0, digestSize);
    }

    public void c() {
        this.h.reset();
    }

    @Override // org.bouncycastle.crypto.Signer
    public void init(boolean z, org.bouncycastle.crypto.CipherParameters cipherParameters) {
        this.i = z;
        org.bouncycastle.crypto.params.AsymmetricKeyParameter asymmetricKeyParameter = cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithRandom ? (org.bouncycastle.crypto.params.AsymmetricKeyParameter) ((org.bouncycastle.crypto.params.ParametersWithRandom) cipherParameters).a() : (org.bouncycastle.crypto.params.AsymmetricKeyParameter) cipherParameters;
        if (z && !asymmetricKeyParameter.f()) {
            throw new java.lang.IllegalArgumentException("signing requires private key");
        }
        if (!z && asymmetricKeyParameter.f()) {
            throw new java.lang.IllegalArgumentException("verification requires public key");
        }
        c();
        this.g.init(z, cipherParameters);
    }

    @Override // org.bouncycastle.crypto.Signer
    public void update(byte b) {
        this.h.update(b);
    }

    @Override // org.bouncycastle.crypto.Signer
    public void update(byte[] bArr, int i, int i2) {
        this.h.update(bArr, i, i2);
    }
}
