java.lang.Object
gnu.crypto.prng.BasePRNGStandalone
gnu.crypto.prng.FortunaStandalone.Generator
All Implemented Interfaces:
IRandomStandalone, Serializable, Cloneable
Enclosing class:
FortunaStandalone

private static class FortunaStandalone.Generatorextends BasePRNGStandalone implements Cloneable
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

    Fields
    Modifier and Type
    Field
    Description
    private final byte[]
    The counter incremented between generations.
    private Object
    Current encryption key built from the keying material.
    AES key buffer reused to avoid reallocating.
    private final MessageDigest
    The SHA-256 digest used for reseeding.
    private final byte[]
    The current 32-byte key.
    private static final int
    Most bytes one generator instance may return.
    private boolean
    True once the generator has been seeded.

    Fields inherited from class BasePRNGStandalone

    buffer, initialised, name, ndx
    Modifier and Type
    Field
    Description
    protected byte[]
    A temporary buffer to serve random bytes.
    protected boolean
    Indicate if this instance has already been initialised or not.
    protected final String
    The canonical name prefix of the PRNG algorithm.
    protected int
    The index into buffer of where the next byte will come from.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PRNG generator instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    addRandomByte(byte b)
    Add a random byte to the generator seed.
    final void
    addRandomBytes(byte[] seed, int offset, int length)
    Add random bytes to the generator seed.
    Return a copy of this object.
    final void
    Fill the PRNG output block.
    private final void
    Increment `counter' as a sixteen-byte little-endian unsigned integer by one.
    final byte
    Return the next random byte.
    final void
    nextBytes(byte[] out, int offset, int length)
    Fill the output buffer with random bytes.
    private final void
    Resets the cipher's key.
    void
    setup(Map<String,byte[]> attributes)
    Set up the PRNG instance.

    Methods inherited from class BasePRNGStandalone

    addRandomBytes, init, isInitialised, name, nextBytes
    Modifier and Type
    Method
    Description
    void
    addRandomBytes(byte[] buffer)
    Supplement, or possibly replace, the random state of this PRNG with a sequence of new random bytes.
    void
    init(Map<String,byte[]> attributes)
    Initialises the pseudo-random number generator scheme with the appropriate attributes.
    boolean
    Check whether this instance has been initialised.
    Returns the canonical name of this instance.
    void
    nextBytes(byte[] out)
    Fill the output byte array with random bytes.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LIMIT

      private static final int LIMIT
      Most bytes one generator instance may return.
      See Also:
    • hash

      private final MessageDigest hash
      The SHA-256 digest used for reseeding.
    • counter

      private final byte[] counter
      The counter incremented between generations.
    • key

      private final byte[] key
      The current 32-byte key.
    • cryptixKey

      private Object cryptixKey
      Current encryption key built from the keying material.
    • cryptixKeyBuf

      private CryptixAESKeyCache.KeyCacheEntry cryptixKeyBuf
      AES key buffer reused to avoid reallocating.
    • seeded

      private boolean seeded
      True once the generator has been seeded.
  • Constructor Details

    • Generator

      public Generator()
      PRNG generator instance.
  • Method Details

    • clone

      public Object clone()
      Return a copy of this object.
      Specified by:
      clone in interface IRandomStandalone
      Overrides:
      clone in class BasePRNGStandalone
      Returns:
      a clone copy of this instance.
    • nextByte

      public final byte nextByte()
      Return the next random byte.
      Specified by:
      nextByte in interface IRandomStandalone
      Overrides:
      nextByte in class BasePRNGStandalone
      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:
      nextBytes in interface IRandomStandalone
      Overrides:
      nextBytes in class BasePRNGStandalone
      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 within 0 and out.length.
      length - the maximum number of required random bytes. This method does nothing if this parameter is less than 1.
    • addRandomByte

      public final void addRandomByte(byte b)
      Add a random byte to the generator seed.
      Specified by:
      addRandomByte in interface IRandomStandalone
      Overrides:
      addRandomByte in class BasePRNGStandalone
      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:
      addRandomBytes in interface IRandomStandalone
      Overrides:
      addRandomBytes in class BasePRNGStandalone
      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:
      fillBlock in class BasePRNGStandalone
    • setup

      public void setup(Map<String,byte[]> attributes)
      Set up the PRNG instance.
      Specified by:
      setup in class BasePRNGStandalone
      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.