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

88 lines
2.5 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.prng;
import com.google.common.primitives.UnsignedBytes;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.SecureRandom;
/* loaded from: classes6.dex */
public class FixedSecureRandom extends SecureRandom {
private byte[] _data;
private int _index;
private int _intPad;
@Override // java.util.Random
public long nextLong() {
return (nextValue() << 56) | (nextValue() << 48) | (nextValue() << 40) | (nextValue() << 32) | (nextValue() << 24) | (nextValue() << 16) | (nextValue() << 8) | nextValue();
}
@Override // java.util.Random
public int nextInt() {
int nextValue = (nextValue() << 24) | (nextValue() << 16);
int i = this._intPad;
if (i == 2) {
this._intPad = i - 1;
} else {
nextValue |= nextValue() << 8;
}
int i2 = this._intPad;
if (i2 != 1) {
return nextValue | nextValue();
}
this._intPad = i2 - 1;
return nextValue;
}
@Override // java.security.SecureRandom, java.util.Random
public void nextBytes(byte[] bArr) {
System.arraycopy(this._data, this._index, bArr, 0, bArr.length);
this._index += bArr.length;
}
public boolean isExhausted() {
return this._index == this._data.length;
}
@Override // java.security.SecureRandom
public byte[] generateSeed(int i) {
byte[] bArr = new byte[i];
nextBytes(bArr);
return bArr;
}
private int nextValue() {
byte[] bArr = this._data;
int i = this._index;
this._index = i + 1;
return bArr[i] & UnsignedBytes.MAX_VALUE;
}
public FixedSecureRandom(byte[][] bArr) {
this(false, bArr);
}
public FixedSecureRandom(byte[] bArr) {
this(false, new byte[][]{bArr});
}
public FixedSecureRandom(boolean z, byte[][] bArr) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
for (int i = 0; i != bArr.length; i++) {
try {
byteArrayOutputStream.write(bArr[i]);
} catch (IOException unused) {
throw new IllegalArgumentException("can't save value array.");
}
}
byte[] byteArray = byteArrayOutputStream.toByteArray();
this._data = byteArray;
if (z) {
this._intPad = byteArray.length % 4;
}
}
public FixedSecureRandom(boolean z, byte[] bArr) {
this(z, new byte[][]{bArr});
}
}