java.lang.Object
gnu.crypto.prng.BasePRNGStandalone
gnu.crypto.prng.FortunaStandalone.Generator
- All Implemented Interfaces:
IRandomStandalone, Serializable, Cloneable
- Enclosing class:
FortunaStandalone
The Fortuna generator function. The generator is a PRNG in its own right; Fortuna itself is basically a wrapper around this generator that manages reseeding in a secure way.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]The counter incremented between generations.private ObjectCurrent encryption key built from the keying material.private CryptixAESKeyCache.KeyCacheEntryAES key buffer reused to avoid reallocating.private final MessageDigestThe SHA-256 digest used for reseeding.private final byte[]The current 32-byte key.private static final intMost bytes one generator instance may return.private booleanTrue once the generator has been seeded.Fields inherited from class BasePRNGStandalone
buffer, initialised, name, ndxModifier and TypeFieldDescriptionprotected byte[]A temporary buffer to serve random bytes.protected booleanIndicate if this instance has already been initialised or not.protected final StringThe canonical name prefix of the PRNG algorithm.protected intThe index into buffer of where the next byte will come from.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionfinal voidaddRandomByte(byte b) Add a random byte to the generator seed.final voidaddRandomBytes(byte[] seed, int offset, int length) Add random bytes to the generator seed.clone()Return a copy of this object.final voidFill the PRNG output block.private final voidIncrement `counter' as a sixteen-byte little-endian unsigned integer by one.final bytenextByte()Return the next random byte.final voidnextBytes(byte[] out, int offset, int length) Fill the output buffer with random bytes.private final voidresetKey()Resets the cipher's key.voidSet up the PRNG instance.Methods inherited from class BasePRNGStandalone
addRandomBytes, init, isInitialised, name, nextBytesModifier and TypeMethodDescriptionvoidaddRandomBytes(byte[] buffer) Supplement, or possibly replace, the random state of this PRNG with a sequence of new random bytes.voidInitialises the pseudo-random number generator scheme with the appropriate attributes.booleanCheck whether this instance has been initialised.name()Returns the canonical name of this instance.voidnextBytes(byte[] out) Fill the output byte array with random bytes.
Field Details
LIMIT
private static final int LIMITMost bytes one generator instance may return.- See Also:
hash
The SHA-256 digest used for reseeding.counter
private final byte[] counterThe counter incremented between generations.key
private final byte[] keyThe current 32-byte key.cryptixKey
Current encryption key built from the keying material.cryptixKeyBuf
AES key buffer reused to avoid reallocating.seeded
private boolean seededTrue once the generator has been seeded.
Constructor Details
Generator
public Generator()PRNG generator instance.
Method Details
clone
Return a copy of this object.- Specified by:
clonein interfaceIRandomStandalone- Overrides:
clonein classBasePRNGStandalone- Returns:
- a clone copy of this instance.
nextByte
public final byte nextByte()Return the next random byte.- Specified by:
nextBytein interfaceIRandomStandalone- Overrides:
nextBytein classBasePRNGStandalone- Returns:
- the next 8 bits of random data generated from this instance.
nextBytes
public final void nextBytes(byte[] out, int offset, int length) Fill the output buffer with random bytes.- Specified by:
nextBytesin interfaceIRandomStandalone- Overrides:
nextBytesin classBasePRNGStandalone- Parameters:
out- the placeholder to contain the generated random bytes.offset- the starting index in out to consider. This method does nothing if this parameter is not within0andout.length.length- the maximum number of required random bytes. This method does nothing if this parameter is less than1.
addRandomByte
public final void addRandomByte(byte b) Add a random byte to the generator seed.- Specified by:
addRandomBytein interfaceIRandomStandalone- Overrides:
addRandomBytein classBasePRNGStandalone- Parameters:
b- The byte to add.
addRandomBytes
public final void addRandomBytes(byte[] seed, int offset, int length) Add random bytes to the generator seed.- Specified by:
addRandomBytesin interfaceIRandomStandalone- Overrides:
addRandomBytesin classBasePRNGStandalone- Parameters:
seed- The buffer of new random bytes to add.offset- The offset from whence to begin reading random bytes.length- The number of random bytes to add.
fillBlock
public final void fillBlock()Fill the PRNG output block.- Specified by:
fillBlockin classBasePRNGStandalone
setup
Set up the PRNG instance.- Specified by:
setupin classBasePRNGStandalone- Parameters:
attributes- the attributes for setup
resetKey
private final void resetKey()Resets the cipher's key. This is done after every reseed, which combines the old key and the seed, and processes that throigh the hash function.incrementCounter
private final void incrementCounter()Increment `counter' as a sixteen-byte little-endian unsigned integer by one.