package org.bouncycastle.crypto.signers;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class Ed25519ctxSigner implements org.bouncycastle.crypto.Signer {
    private final org.bouncycastle.crypto.signers.Ed25519ctxSigner.Buffer g;
    private final byte[] h;
    private boolean i;
    private org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters j;
    private org.bouncycastle.crypto.params.Ed25519PublicKeyParameters k;

    private static final class Buffer extends java.io.ByteArrayOutputStream {
        synchronized byte[] a(org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters ed25519PrivateKeyParameters, byte[] bArr) {
            byte[] bArr2;
            bArr2 = new byte[64];
            ed25519PrivateKeyParameters.h(1, bArr, ((java.io.ByteArrayOutputStream) this).buf, 0, ((java.io.ByteArrayOutputStream) this).count, bArr2, 0);
            reset();
            return bArr2;
        }

        synchronized boolean d(org.bouncycastle.crypto.params.Ed25519PublicKeyParameters ed25519PublicKeyParameters, byte[] bArr, byte[] bArr2) {
            if (64 != bArr2.length) {
                reset();
                return false;
            }
            boolean zJ = ed25519PublicKeyParameters.j(1, 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;
        }
    }

    @Override // org.bouncycastle.crypto.Signer
    public boolean a(byte[] bArr) {
        org.bouncycastle.crypto.params.Ed25519PublicKeyParameters ed25519PublicKeyParameters;
        if (this.i || (ed25519PublicKeyParameters = this.k) == null) {
            throw new java.lang.IllegalStateException("Ed25519ctxSigner not initialised for verification");
        }
        return this.g.d(ed25519PublicKeyParameters, this.h, bArr);
    }

    @Override // org.bouncycastle.crypto.Signer
    public byte[] b() {
        org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters ed25519PrivateKeyParameters;
        if (!this.i || (ed25519PrivateKeyParameters = this.j) == null) {
            throw new java.lang.IllegalStateException("Ed25519ctxSigner not initialised for signature generation.");
        }
        return this.g.a(ed25519PrivateKeyParameters, 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;
        org.bouncycastle.crypto.params.Ed25519PublicKeyParameters ed25519PublicKeyParameters = null;
        if (z) {
            this.j = (org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters) cipherParameters;
        } else {
            this.j = null;
            ed25519PublicKeyParameters = (org.bouncycastle.crypto.params.Ed25519PublicKeyParameters) cipherParameters;
        }
        this.k = ed25519PublicKeyParameters;
        org.bouncycastle.crypto.CryptoServicesRegistrar.a(org.bouncycastle.crypto.signers.Utils.a("Ed25519", 128, 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);
    }
}
