Package org.cryptomator.cryptolib.common
Class ReseedingSecureRandom
- java.lang.Object
-
- java.util.Random
-
- java.security.SecureRandom
-
- org.cryptomator.cryptolib.common.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 Summary
Constructors Constructor Description ReseedingSecureRandom(SecureRandom seeder, SecureRandom csprng, long reseedAfter, int seedLength)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.-
Methods inherited from class java.security.SecureRandom
generateSeed, getAlgorithm, getInstance, getInstance, getInstance, getInstanceStrong, getProvider, getSeed, next, nextBytes, setSeed, setSeed
-
-
-
-
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 asSHA1PRNG
, that will be wrapped by this instance.reseedAfter
- How many bytes can be read from thecsprng
, before a new seed will be generated.seedLength
- Number of bytes generated byseeder
in order to seedcsprng
.
-
-
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.
-
-