Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.prng;
  
  
Builder class for making SecureRandom objects based on SP 800-90A Deterministic Random Bit Generators (DRBG).
 
 {
     private final SecureRandom random;
 
     private byte[] personalizationString;
     private int securityStrength = 256;
     private int entropyBitsRequired = 256;

    
Basic constructor, creates a builder using an EntropySourceProvider based on the default SecureRandom with predictionResistant set to false.

Any SecureRandom created from a builder constructed like this will make use of input passed to SecureRandom.setSeed() if the default SecureRandom does for its generateSeed() call.

 
     public SP800SecureRandomBuilder()
     {
         this(new SecureRandom(), false);
     }

    
Construct a builder with an EntropySourceProvider based on the passed in SecureRandom and the passed in value for prediction resistance.

Any SecureRandom created from a builder constructed like this will make use of input passed to SecureRandom.setSeed() if the passed in SecureRandom does for its generateSeed() call.

Parameters:
entropySource
predictionResistant
 
     public SP800SecureRandomBuilder(SecureRandom entropySourceboolean predictionResistant)
     {
         this. = entropySource;
         this. = new BasicEntropySourceProvider(predictionResistant);
     }

    
Create a builder which makes creates the SecureRandom objects from a specified entropy source provider.

Note: If this constructor is used any calls to setSeed() in the resulting SecureRandom will be ignored.

Parameters:
entropySourceProvider a provider of EntropySource objects.
 
     public SP800SecureRandomBuilder(EntropySourceProvider entropySourceProvider)
     {
         this. = null;
         this. = entropySourceProvider;
     }

    
Set the personalization string for DRBG SecureRandoms created by this builder

Parameters:
personalizationString the personalisation string for the underlying DRBG.
Returns:
the current builder.
 
     public SP800SecureRandomBuilder setPersonalizationString(byte[] personalizationString)
     {
         this. = personalizationString;
 
         return this;
     }

    
Set the security strength required for DRBGs used in building SecureRandom objects.

Parameters:
securityStrength the security strength (in bits)
Returns:
the current builder.
 
     public SP800SecureRandomBuilder setSecurityStrength(int securityStrength)
     {
         this. = securityStrength;
 
         return this;
     }

    
Set the amount of entropy bits required for seeding and reseeding DRBGs used in building SecureRandom objects.

Parameters:
entropyBitsRequired the number of bits of entropy to be requested from the entropy source on each seed/reseed.
Returns:
the current builder.
 
    public SP800SecureRandomBuilder setEntropyBitsRequired(int entropyBitsRequired)
    {
        this. = entropyBitsRequired;
        return this;
    }

    
Build a SecureRandom based on a SP 800-90A Hash DRBG.

Parameters:
digest digest algorithm to use in the DRBG underneath the SecureRandom.
nonce nonce value to use in DRBG construction.
predictionResistant specify whether the underlying DRBG in the resulting SecureRandom should reseed on each request for bytes.
Returns:
a SecureRandom supported by a Hash DRBG.
    public SP800SecureRandom buildHash(Digest digestbyte[] nonceboolean predictionResistant)
    {
        return new SP800SecureRandom(.get(), new HashDRBGProvider(digestnonce), predictionResistant);
    }

    
Build a SecureRandom based on a SP 800-90A CTR DRBG.

Parameters:
cipher the block cipher to base the DRBG on.
keySizeInBits key size in bits to be used with the block cipher.
nonce nonce value to use in DRBG construction.
predictionResistant specify whether the underlying DRBG in the resulting SecureRandom should reseed on each request for bytes.
Returns:
a SecureRandom supported by a CTR DRBG.
    public SP800SecureRandom buildCTR(BlockCipher cipherint keySizeInBitsbyte[] nonceboolean predictionResistant)
    {
        return new SP800SecureRandom(.get(), new CTRDRBGProvider(cipherkeySizeInBitsnonce), predictionResistant);
    }

    
Build a SecureRandom based on a SP 800-90A HMAC DRBG.

Parameters:
hMac HMAC algorithm to use in the DRBG underneath the SecureRandom.
nonce nonce value to use in DRBG construction.
predictionResistant specify whether the underlying DRBG in the resulting SecureRandom should reseed on each request for bytes.
Returns:
a SecureRandom supported by a HMAC DRBG.
    public SP800SecureRandom buildHMAC(Mac hMacbyte[] nonceboolean predictionResistant)
    {
        return new SP800SecureRandom(.get(), new HMacDRBGProvider(hMacnonce), predictionResistant);
    }

    
Build a SecureRandom based on a SP 800-90A Dual EC DRBG using the NIST point set.

Parameters:
digest digest algorithm to use in the DRBG underneath the SecureRandom.
nonce nonce value to use in DRBG construction.
predictionResistant specify whether the underlying DRBG in the resulting SecureRandom should reseed on each request for bytes.
Returns:
a SecureRandom supported by a Dual EC DRBG.
    public SP800SecureRandom buildDualEC(Digest digestbyte[] nonceboolean predictionResistant)
    {
        return new SP800SecureRandom(.get(), new DualECDRBGProvider(digestnonce), predictionResistant);
    }

    
Build a SecureRandom based on a SP 800-90A Dual EC DRBG according to a defined point set.

Parameters:
pointSet an array of DualECPoints to use for DRB generation.
digest digest algorithm to use in the DRBG underneath the SecureRandom.
nonce nonce value to use in DRBG construction.
predictionResistant specify whether the underlying DRBG in the resulting SecureRandom should reseed on each request for bytes.
Returns:
a SecureRandom supported by a Dual EC DRBG.
    public SP800SecureRandom buildDualEC(DualECPoints[] pointSetDigest digestbyte[] nonceboolean predictionResistant)
    {
        return new SP800SecureRandom(.get(), new ConfigurableDualECDRBGProvider(pointSetdigestnonce), predictionResistant);
    }
    private static class HashDRBGProvider
        implements DRBGProvider
    {
        private final Digest digest;
        private final byte[] nonce;
        private final byte[] personalizationString;
        private final int securityStrength;
        public HashDRBGProvider(Digest digestbyte[] noncebyte[] personalizationStringint securityStrength)
        {
            this. = digest;
            this. = nonce;
            this. = personalizationString;
            this. = securityStrength;
        }
        public SP80090DRBG get(EntropySource entropySource)
        {
            return new HashSP800DRBG(entropySource);
        }
    }
    private static class DualECDRBGProvider
        implements DRBGProvider
    {
        private final Digest digest;
        private final byte[] nonce;
        private final byte[] personalizationString;
        private final int securityStrength;
        public DualECDRBGProvider(Digest digestbyte[] noncebyte[] personalizationStringint securityStrength)
        {
            this. = digest;
            this. = nonce;
            this. = personalizationString;
            this. = securityStrength;
        }
        public SP80090DRBG get(EntropySource entropySource)
        {
            return new DualECSP800DRBG(entropySource);
        }
    }
    private static class ConfigurableDualECDRBGProvider
        implements DRBGProvider
    {
        private final DualECPoints[] pointSet;
        private final Digest digest;
        private final byte[] nonce;
        private final byte[] personalizationString;
        private final int securityStrength;
        public ConfigurableDualECDRBGProvider(DualECPoints[] pointSetDigest digestbyte[] noncebyte[] personalizationStringint securityStrength)
        {
            this. = new DualECPoints[pointSet.length];
            System.arraycopy(pointSet, 0, this., 0, pointSet.length);
            this. = digest;
            this. = nonce;
            this. = personalizationString;
            this. = securityStrength;
        }
        public SP80090DRBG get(EntropySource entropySource)
        {
            return new DualECSP800DRBG(entropySource);
        }
    }
    private static class HMacDRBGProvider
        implements DRBGProvider
    {
        private final Mac hMac;
        private final byte[] nonce;
        private final byte[] personalizationString;
        private final int securityStrength;
        public HMacDRBGProvider(Mac hMacbyte[] noncebyte[] personalizationStringint securityStrength)
        {
            this. = hMac;
            this. = nonce;
            this. = personalizationString;
            this. = securityStrength;
        }
        public SP80090DRBG get(EntropySource entropySource)
        {
            return new HMacSP800DRBG(entropySource);
        }
    }
    private 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;
        public CTRDRBGProvider(BlockCipher blockCipherint keySizeInBitsbyte[] noncebyte[] personalizationStringint securityStrength)
        {
            this. = blockCipher;
            this. = keySizeInBits;
            this. = nonce;
            this. = personalizationString;
            this. = securityStrength;
        }
        public SP80090DRBG get(EntropySource entropySource)
        {
            return new CTRSP800DRBG(entropySource);
        }
    }
New to GrepCode? Check out our FAQ X