package org.bouncycastle.crypto.params;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public final class Ed25519PrivateKeyParameters extends org.bouncycastle.crypto.params.AsymmetricKeyParameter {
    private final byte[] b;
    private org.bouncycastle.crypto.params.Ed25519PublicKeyParameters c;

    public Ed25519PrivateKeyParameters(java.security.SecureRandom secureRandom) {
        super(true);
        byte[] bArr = new byte[32];
        this.b = bArr;
        org.bouncycastle.math.ec.rfc8032.Ed25519.o(secureRandom, bArr);
    }

    private static byte[] i(byte[] bArr) {
        if (bArr.length == 32) {
            return bArr;
        }
        throw new java.lang.IllegalArgumentException("'buf' must have length 32");
    }

    public org.bouncycastle.crypto.params.Ed25519PublicKeyParameters g() {
        org.bouncycastle.crypto.params.Ed25519PublicKeyParameters ed25519PublicKeyParameters;
        synchronized (this.b) {
            try {
                if (this.c == null) {
                    this.c = new org.bouncycastle.crypto.params.Ed25519PublicKeyParameters(org.bouncycastle.math.ec.rfc8032.Ed25519.p(this.b, 0));
                }
                ed25519PublicKeyParameters = this.c;
            } catch (java.lang.Throwable th) {
                throw th;
            }
        }
        return ed25519PublicKeyParameters;
    }

    public byte[] getEncoded() {
        return org.bouncycastle.util.Arrays.j(this.b);
    }

    public void h(int i, byte[] bArr, byte[] bArr2, int i2, int i3, byte[] bArr3, int i4) {
        byte[] bArr4 = new byte[32];
        g().g(bArr4, 0);
        if (i == 0) {
            if (bArr != null) {
                throw new java.lang.IllegalArgumentException("ctx");
            }
            org.bouncycastle.math.ec.rfc8032.Ed25519.P(this.b, 0, bArr4, 0, bArr2, i2, i3, bArr3, i4);
            return;
        }
        if (i == 1) {
            if (bArr == null) {
                throw new java.lang.NullPointerException("'ctx' cannot be null");
            }
            if (bArr.length > 255) {
                throw new java.lang.IllegalArgumentException("ctx");
            }
            org.bouncycastle.math.ec.rfc8032.Ed25519.Q(this.b, 0, bArr4, 0, bArr, bArr2, i2, i3, bArr3, i4);
            return;
        }
        if (i != 2) {
            throw new java.lang.IllegalArgumentException("algorithm");
        }
        if (bArr == null) {
            throw new java.lang.NullPointerException("'ctx' cannot be null");
        }
        if (bArr.length > 255) {
            throw new java.lang.IllegalArgumentException("ctx");
        }
        if (64 != i3) {
            throw new java.lang.IllegalArgumentException("msgLen");
        }
        org.bouncycastle.math.ec.rfc8032.Ed25519.R(this.b, 0, bArr4, 0, bArr, bArr2, i2, bArr3, i4);
    }

    public Ed25519PrivateKeyParameters(byte[] bArr) {
        this(i(bArr), 0);
    }

    public Ed25519PrivateKeyParameters(byte[] bArr, int i) {
        super(true);
        byte[] bArr2 = new byte[32];
        this.b = bArr2;
        java.lang.System.arraycopy(bArr, i, bArr2, 0, 32);
    }
}
