package org.bouncycastle.crypto.prng;

/* JADX INFO: loaded from: E:\ios\vf_dex\classes4.dex */
public class SP800SecureRandomBuilder {
    private final org.bouncycastle.crypto.prng.EntropySourceProvider b;
    private byte[] c;
    private int d = 256;
    private int e = 256;
    private final java.security.SecureRandom a = null;

    private static class CTRDRBGProvider implements org.bouncycastle.crypto.prng.DRBGProvider {
        private final org.bouncycastle.crypto.BlockCipher a;
        private final int b;
        private final byte[] c;
        private final byte[] d;
        private final int e;

        @Override // org.bouncycastle.crypto.prng.DRBGProvider
        public org.bouncycastle.crypto.prng.drbg.SP80090DRBG a(org.bouncycastle.crypto.prng.EntropySource entropySource) {
            return new org.bouncycastle.crypto.prng.drbg.CTRSP800DRBG(this.a, this.b, this.e, entropySource, this.d, this.c);
        }

        @Override // org.bouncycastle.crypto.prng.DRBGProvider
        public java.lang.String getAlgorithm() {
            if (this.a instanceof org.bouncycastle.crypto.engines.DESedeEngine) {
                return "CTR-DRBG-3KEY-TDES";
            }
            return "CTR-DRBG-" + this.a.getAlgorithmName() + this.b;
        }
    }

    private static class HMacDRBGProvider implements org.bouncycastle.crypto.prng.DRBGProvider {
        private final org.bouncycastle.crypto.Mac a;
        private final byte[] b;
        private final byte[] c;
        private final int d;

        public HMacDRBGProvider(org.bouncycastle.crypto.Mac mac, byte[] bArr, byte[] bArr2, int i) {
            this.a = mac;
            this.b = bArr;
            this.c = bArr2;
            this.d = i;
        }

        @Override // org.bouncycastle.crypto.prng.DRBGProvider
        public org.bouncycastle.crypto.prng.drbg.SP80090DRBG a(org.bouncycastle.crypto.prng.EntropySource entropySource) {
            return new org.bouncycastle.crypto.prng.drbg.HMacSP800DRBG(this.a, this.d, entropySource, this.c, this.b);
        }

        @Override // org.bouncycastle.crypto.prng.DRBGProvider
        public java.lang.String getAlgorithm() {
            java.lang.StringBuilder sb;
            java.lang.String algorithmName;
            if (this.a instanceof org.bouncycastle.crypto.macs.HMac) {
                sb = new java.lang.StringBuilder();
                sb.append("HMAC-DRBG-");
                algorithmName = org.bouncycastle.crypto.prng.SP800SecureRandomBuilder.d(((org.bouncycastle.crypto.macs.HMac) this.a).b());
            } else {
                sb = new java.lang.StringBuilder();
                sb.append("HMAC-DRBG-");
                algorithmName = this.a.getAlgorithmName();
            }
            sb.append(algorithmName);
            return sb.toString();
        }
    }

    private static class HashDRBGProvider implements org.bouncycastle.crypto.prng.DRBGProvider {
        private final org.bouncycastle.crypto.Digest a;
        private final byte[] b;
        private final byte[] c;
        private final int d;

        public HashDRBGProvider(org.bouncycastle.crypto.Digest digest, byte[] bArr, byte[] bArr2, int i) {
            this.a = digest;
            this.b = bArr;
            this.c = bArr2;
            this.d = i;
        }

        @Override // org.bouncycastle.crypto.prng.DRBGProvider
        public org.bouncycastle.crypto.prng.drbg.SP80090DRBG a(org.bouncycastle.crypto.prng.EntropySource entropySource) {
            return new org.bouncycastle.crypto.prng.drbg.HashSP800DRBG(this.a, this.d, entropySource, this.c, this.b);
        }

        @Override // org.bouncycastle.crypto.prng.DRBGProvider
        public java.lang.String getAlgorithm() {
            return "HASH-DRBG-" + org.bouncycastle.crypto.prng.SP800SecureRandomBuilder.d(this.a);
        }
    }

    public SP800SecureRandomBuilder(org.bouncycastle.crypto.prng.EntropySourceProvider entropySourceProvider) {
        this.b = entropySourceProvider;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static java.lang.String d(org.bouncycastle.crypto.Digest digest) {
        java.lang.String algorithmName = digest.getAlgorithmName();
        int iIndexOf = algorithmName.indexOf(45);
        if (iIndexOf <= 0 || algorithmName.startsWith("SHA3")) {
            return algorithmName;
        }
        return algorithmName.substring(0, iIndexOf) + algorithmName.substring(iIndexOf + 1);
    }

    public org.bouncycastle.crypto.prng.SP800SecureRandom b(org.bouncycastle.crypto.Mac mac, byte[] bArr, boolean z) {
        return new org.bouncycastle.crypto.prng.SP800SecureRandom(this.a, this.b.get(this.e), new org.bouncycastle.crypto.prng.SP800SecureRandomBuilder.HMacDRBGProvider(mac, bArr, this.c, this.d), z);
    }

    public org.bouncycastle.crypto.prng.SP800SecureRandom c(org.bouncycastle.crypto.Digest digest, byte[] bArr, boolean z) {
        return new org.bouncycastle.crypto.prng.SP800SecureRandom(this.a, this.b.get(this.e), new org.bouncycastle.crypto.prng.SP800SecureRandomBuilder.HashDRBGProvider(digest, bArr, this.c, this.d), z);
    }

    public org.bouncycastle.crypto.prng.SP800SecureRandomBuilder e(byte[] bArr) {
        this.c = org.bouncycastle.util.Arrays.j(bArr);
        return this;
    }
}
