Search in sources :

Example 1 with EntropySourceProvider

use of com.github.zhenwei.core.crypto.prng.EntropySourceProvider 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);
    }
}
Also used : SHA512Digest(com.github.zhenwei.core.crypto.digests.SHA512Digest) SP800SecureRandom(com.github.zhenwei.core.crypto.prng.SP800SecureRandom) SecureRandom(java.security.SecureRandom) SP800SecureRandomBuilder(com.github.zhenwei.core.crypto.prng.SP800SecureRandomBuilder) EntropySource(com.github.zhenwei.core.crypto.prng.EntropySource) EntropySourceProvider(com.github.zhenwei.core.crypto.prng.EntropySourceProvider)

Aggregations

SHA512Digest (com.github.zhenwei.core.crypto.digests.SHA512Digest)1 EntropySource (com.github.zhenwei.core.crypto.prng.EntropySource)1 EntropySourceProvider (com.github.zhenwei.core.crypto.prng.EntropySourceProvider)1 SP800SecureRandom (com.github.zhenwei.core.crypto.prng.SP800SecureRandom)1 SP800SecureRandomBuilder (com.github.zhenwei.core.crypto.prng.SP800SecureRandomBuilder)1 SecureRandom (java.security.SecureRandom)1