what-the-bank/sources/org/bouncycastle/crypto/prng/SP800SecureRandomBuilder.java

127 lines
5.0 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.prng;
import java.security.SecureRandom;
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.Mac;
import org.bouncycastle.crypto.prng.drbg.CTRSP800DRBG;
import org.bouncycastle.crypto.prng.drbg.HMacSP800DRBG;
import org.bouncycastle.crypto.prng.drbg.HashSP800DRBG;
import org.bouncycastle.crypto.prng.drbg.SP80090DRBG;
/* loaded from: classes6.dex */
public class SP800SecureRandomBuilder {
private int entropyBitsRequired;
private final EntropySourceProvider entropySourceProvider;
private byte[] personalizationString;
private final SecureRandom random;
private int securityStrength;
public SP800SecureRandomBuilder setSecurityStrength(int i) {
this.securityStrength = i;
return this;
}
public SP800SecureRandomBuilder setPersonalizationString(byte[] bArr) {
this.personalizationString = bArr;
return this;
}
public SP800SecureRandomBuilder setEntropyBitsRequired(int i) {
this.entropyBitsRequired = i;
return this;
}
public SP800SecureRandom buildHash(Digest digest, byte[] bArr, boolean z) {
return new SP800SecureRandom(this.random, this.entropySourceProvider.get(this.entropyBitsRequired), new HashDRBGProvider(digest, bArr, this.personalizationString, this.securityStrength), z);
}
public SP800SecureRandom buildHMAC(Mac mac, byte[] bArr, boolean z) {
return new SP800SecureRandom(this.random, this.entropySourceProvider.get(this.entropyBitsRequired), new HMacDRBGProvider(mac, bArr, this.personalizationString, this.securityStrength), z);
}
public SP800SecureRandom buildCTR(BlockCipher blockCipher, int i, byte[] bArr, boolean z) {
return new SP800SecureRandom(this.random, this.entropySourceProvider.get(this.entropyBitsRequired), new CTRDRBGProvider(blockCipher, i, bArr, this.personalizationString, this.securityStrength), z);
}
/* loaded from: classes6.dex */
static class CTRDRBGProvider implements DRBGProvider {
private final BlockCipher blockCipher;
private final int keySizeInBits;
private final byte[] nonce;
private final byte[] personalizationString;
private final int securityStrength;
@Override // org.bouncycastle.crypto.prng.DRBGProvider
public SP80090DRBG get(EntropySource entropySource) {
return new CTRSP800DRBG(this.blockCipher, this.keySizeInBits, this.securityStrength, entropySource, this.personalizationString, this.nonce);
}
public CTRDRBGProvider(BlockCipher blockCipher, int i, byte[] bArr, byte[] bArr2, int i2) {
this.blockCipher = blockCipher;
this.keySizeInBits = i;
this.nonce = bArr;
this.personalizationString = bArr2;
this.securityStrength = i2;
}
}
/* loaded from: classes6.dex */
static class HMacDRBGProvider implements DRBGProvider {
private final Mac hMac;
private final byte[] nonce;
private final byte[] personalizationString;
private final int securityStrength;
@Override // org.bouncycastle.crypto.prng.DRBGProvider
public SP80090DRBG get(EntropySource entropySource) {
return new HMacSP800DRBG(this.hMac, this.securityStrength, entropySource, this.personalizationString, this.nonce);
}
public HMacDRBGProvider(Mac mac, byte[] bArr, byte[] bArr2, int i) {
this.hMac = mac;
this.nonce = bArr;
this.personalizationString = bArr2;
this.securityStrength = i;
}
}
/* loaded from: classes6.dex */
static class HashDRBGProvider implements DRBGProvider {
private final Digest digest;
private final byte[] nonce;
private final byte[] personalizationString;
private final int securityStrength;
@Override // org.bouncycastle.crypto.prng.DRBGProvider
public SP80090DRBG get(EntropySource entropySource) {
return new HashSP800DRBG(this.digest, this.securityStrength, entropySource, this.personalizationString, this.nonce);
}
public HashDRBGProvider(Digest digest, byte[] bArr, byte[] bArr2, int i) {
this.digest = digest;
this.nonce = bArr;
this.personalizationString = bArr2;
this.securityStrength = i;
}
}
public SP800SecureRandomBuilder(EntropySourceProvider entropySourceProvider) {
this.securityStrength = 256;
this.entropyBitsRequired = 256;
this.random = null;
this.entropySourceProvider = entropySourceProvider;
}
public SP800SecureRandomBuilder(SecureRandom secureRandom, boolean z) {
this.securityStrength = 256;
this.entropyBitsRequired = 256;
this.random = secureRandom;
this.entropySourceProvider = new BasicEntropySourceProvider(secureRandom, z);
}
public SP800SecureRandomBuilder() {
this(new SecureRandom(), false);
}
}