package org.bouncycastle.crypto.signers;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class Ed448Signer implements org.bouncycastle.crypto.Signer {
    private final org.bouncycastle.crypto.signers.Ed448Signer.Buffer g = new org.bouncycastle.crypto.signers.Ed448Signer.Buffer();
    private final byte[] h;
    private boolean i;
    private org.bouncycastle.crypto.params.Ed448PrivateKeyParameters j;
    private org.bouncycastle.crypto.params.Ed448PublicKeyParameters k;

    private static final class Buffer extends java.io.ByteArrayOutputStream {
        private Buffer() {
        }

        synchronized byte[] a(org.bouncycastle.crypto.params.Ed448PrivateKeyParameters ed448PrivateKeyParameters, byte[] bArr) {
            byte[] bArr2;
            bArr2 = new byte[114];
            ed448PrivateKeyParameters.h(0, bArr, ((java.io.ByteArrayOutputStream) this).buf, 0, ((java.io.ByteArrayOutputStream) this).count, bArr2, 0);
            reset();
            return bArr2;
        }

        synchronized boolean d(org.bouncycastle.crypto.params.Ed448PublicKeyParameters ed448PublicKeyParameters, byte[] bArr, byte[] bArr2) {
            if (114 != bArr2.length) {
                reset();
                return false;
            }
            boolean zJ = ed448PublicKeyParameters.j(0, bArr, ((java.io.ByteArrayOutputStream) this).buf, 0, ((java.io.ByteArrayOutputStream) this).count, bArr2, 0);
            reset();
            return zJ;
        }

        @Override // java.io.ByteArrayOutputStream
        public synchronized void reset() {
            org.bouncycastle.util.Arrays.H(((java.io.ByteArrayOutputStream) this).buf, 0, ((java.io.ByteArrayOutputStream) this).count, (byte) 0);
            ((java.io.ByteArrayOutputStream) this).count = 0;
        }
    }

    public Ed448Signer(byte[] bArr) {
        if (bArr == null) {
            throw new java.lang.NullPointerException("'context' cannot be null");
        }
        this.h = org.bouncycastle.util.Arrays.j(bArr);
    }

    @Override // org.bouncycastle.crypto.Signer
    public boolean a(byte[] bArr) {
        org.bouncycastle.crypto.params.Ed448PublicKeyParameters ed448PublicKeyParameters;
        if (this.i || (ed448PublicKeyParameters = this.k) == null) {
            throw new java.lang.IllegalStateException("Ed448Signer not initialised for verification");
        }
        return this.g.d(ed448PublicKeyParameters, this.h, bArr);
    }

    @Override // org.bouncycastle.crypto.Signer
    public byte[] b() {
        org.bouncycastle.crypto.params.Ed448PrivateKeyParameters ed448PrivateKeyParameters;
        if (!this.i || (ed448PrivateKeyParameters = this.j) == null) {
            throw new java.lang.IllegalStateException("Ed448Signer not initialised for signature generation.");
        }
        return this.g.a(ed448PrivateKeyParameters, this.h);
    }

    public void c() {
        this.g.reset();
    }

    @Override // org.bouncycastle.crypto.Signer
    public void init(boolean z, org.bouncycastle.crypto.CipherParameters cipherParameters) {
        this.i = z;
        if (cipherParameters instanceof org.bouncycastle.crypto.params.ParametersWithRandom) {
            cipherParameters = ((org.bouncycastle.crypto.params.ParametersWithRandom) cipherParameters).a();
        }
        org.bouncycastle.crypto.params.Ed448PublicKeyParameters ed448PublicKeyParameters = null;
        if (z) {
            this.j = (org.bouncycastle.crypto.params.Ed448PrivateKeyParameters) cipherParameters;
        } else {
            this.j = null;
            ed448PublicKeyParameters = (org.bouncycastle.crypto.params.Ed448PublicKeyParameters) cipherParameters;
        }
        this.k = ed448PublicKeyParameters;
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.signers.Utils.a("Ed448", 224, cipherParameters, z));
        c();
    }

    @Override // org.bouncycastle.crypto.Signer
    public void update(byte b) throws java.io.IOException {
        this.g.write(b);
    }

    @Override // org.bouncycastle.crypto.Signer
    public void update(byte[] bArr, int i, int i2) throws java.io.IOException {
        this.g.write(bArr, i, i2);
    }
}
