Class ReseedingSecureRandom

  • All Implemented Interfaces:
    Serializable

    public class ReseedingSecureRandom
    extends SecureRandom
    Wraps a fast CSPRNG, which gets reseeded automatically after a certain amount of bytes has been generated.

    Java 8 Example:

      SecureRandom csprng = ReseedingSecureRandom.create(SecureRandom.getInstanceStrong());
     
    See Also:
    Serialized Form
    • Constructor Detail

      • ReseedingSecureRandom

        public ReseedingSecureRandom​(SecureRandom seeder,
                                     SecureRandom csprng,
                                     long reseedAfter,
                                     int seedLength)
        Parameters:
        seeder - RNG for high-quality random numbers. E.g. SecureRandom.getInstanceStrong() in Java 8+ environments.
        csprng - A fast csprng implementation, such as SHA1PRNG, that will be wrapped by this instance.
        reseedAfter - How many bytes can be read from the csprng, before a new seed will be generated.
        seedLength - Number of bytes generated by seeder in order to seed csprng.
    • Method Detail

      • create

        public static ReseedingSecureRandom create​(SecureRandom seeder)
        Creates a pre-configured automatically reseeding SHA1PRNG instance, reseeding itself with 440 bits from the given seeder after generating 2^30 bytes, thus satisfying recommendations by NIST SP 800-90A Rev 1.
        Parameters:
        seeder - RNG for high-quality random numbers. E.g. SecureRandom.getInstanceStrong() in Java 8+ environments.
        Returns:
        An automatically reseeding SHA1PRNG suitable as CSPRNG for most applications.