package org.bouncycastle.crypto.signers;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class Ed25519phSigner implements org.bouncycastle.crypto.Signer {
    private final org.bouncycastle.crypto.Digest g;
    private final byte[] h;
    private boolean i;
    private org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters j;
    private org.bouncycastle.crypto.params.Ed25519PublicKeyParameters k;

    @Override // org.bouncycastle.crypto.Signer
    public boolean a(byte[] bArr) {
        if (this.i || this.k == null) {
            throw new java.lang.IllegalStateException("Ed25519phSigner not initialised for verification");
        }
        if (64 != bArr.length) {
            this.g.reset();
            return false;
        }
        byte[] bArr2 = new byte[64];
        if (64 == this.g.doFinal(bArr2, 0)) {
            return this.k.j(2, this.h, bArr2, 0, 64, bArr, 0);
        }
        throw new java.lang.IllegalStateException("Prehash digest failed");
    }

    @Override // org.bouncycastle.crypto.Signer
    public byte[] b() {
        if (!this.i || this.j == null) {
            throw new java.lang.IllegalStateException("Ed25519phSigner not initialised for signature generation.");
        }
        byte[] bArr = new byte[64];
        if (64 != this.g.doFinal(bArr, 0)) {
            throw new java.lang.IllegalStateException("Prehash digest failed");
        }
        byte[] bArr2 = new byte[64];
        this.j.h(2, this.h, bArr, 0, 64, bArr2, 0);
        return bArr2;
    }

    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) {
        this.g.update(b);
    }

    @Override // org.bouncycastle.crypto.Signer
    public void update(byte[] bArr, int i, int i2) {
        this.g.update(bArr, i, i2);
    }
}
