use of com.github.zhenwei.core.crypto.prng.SP800SecureRandomBuilder in project LinLong-Java by zhenwei1108.
the class DRBG method createBaseRandom.
private static SecureRandom createBaseRandom(boolean isPredictionResistant) {
if (Properties.getPropertyValue("org.bouncycastle.drbg.entropysource") != null) {
EntropySourceProvider entropyProvider = createEntropySource();
EntropySource initSource = entropyProvider.get(16 * 8);
byte[] personalisationString = isPredictionResistant ? generateDefaultPersonalizationString(initSource.getEntropy()) : generateNonceIVPersonalizationString(initSource.getEntropy());
return new SP800SecureRandomBuilder(entropyProvider).setPersonalizationString(personalisationString).buildHash(new SHA512Digest(), Arrays.concatenate(initSource.getEntropy(), initSource.getEntropy()), isPredictionResistant);
} else {
// needs to be done late, can't use static
SecureRandom randomSource = new HybridSecureRandom();
byte[] personalisationString = isPredictionResistant ? generateDefaultPersonalizationString(randomSource.generateSeed(16)) : generateNonceIVPersonalizationString(randomSource.generateSeed(16));
return new SP800SecureRandomBuilder(randomSource, true).setPersonalizationString(personalisationString).buildHash(new SHA512Digest(), randomSource.generateSeed(32), isPredictionResistant);
}
}
Aggregations