Package org.bouncycastle.crypto.util
Class JournalingSecureRandom
java.lang.Object
java.util.Random
java.security.SecureRandom
org.bouncycastle.crypto.util.JournalingSecureRandom
- All Implemented Interfaces:
Serializable
,RandomGenerator
A SecureRandom that maintains a journal of its output.
This can be used to recreate an output that was based on randomness
For the transcript to be reusable, the order of the requests for randomness during recreation must be consistent with the initial requests and no other sources of randomness may be used.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that takes an arbitrary SecureRandom as initial randomJournalingSecureRandom
(byte[] transcript, SecureRandom random) Constructor with a prior transcript.JournalingSecureRandom
(SecureRandom random) Base constructor - no prior transcript. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the internalsbyte[]
Return the full transcript, such as would be needed to create a copy of this JournalingSecureRandom,byte[]
Return the transcript so far,final void
nextBytes
(byte[] bytes) Fill bytes with random data, journaling the random data before returning or re-use previously used random data, depending on the state of the transcript.void
reset()
Resets the index to zero such that the randomness will now be reusedMethods inherited from class java.security.SecureRandom
generateSeed, getAlgorithm, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstanceStrong, getParameters, getProvider, getSeed, next, nextBytes, reseed, reseed, setSeed, setSeed, toString
Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
-
Constructor Details
-
JournalingSecureRandom
public JournalingSecureRandom()Default constructor that takes an arbitrary SecureRandom as initial random -
JournalingSecureRandom
Base constructor - no prior transcript.- Parameters:
random
- source of randomness we will be journaling.
-
JournalingSecureRandom
Constructor with a prior transcript. Both the transcript used and any new randomness are journaled.- Parameters:
transcript
- initial transcript of randomness.random
- source of randomness we will be journaling when the transcript runs out.
-
-
Method Details
-
nextBytes
public final void nextBytes(byte[] bytes) Fill bytes with random data, journaling the random data before returning or re-use previously used random data, depending on the state of the transcript.- Specified by:
nextBytes
in interfaceRandomGenerator
- Overrides:
nextBytes
in classSecureRandom
- Parameters:
bytes
- a block of bytes to be filled with random data.
-
clear
public void clear()Clear the internals -
reset
public void reset()Resets the index to zero such that the randomness will now be reused -
getTranscript
public byte[] getTranscript()Return the transcript so far,- Returns:
- a copy of the randomness produced so far.
-
getFullTranscript
public byte[] getFullTranscript()Return the full transcript, such as would be needed to create a copy of this JournalingSecureRandom,- Returns:
- a copy of the original transcript on construction, plus any randomness added since.
-