gnu.crypto.prng

## Class FortunaStandalone

- java.lang.Object
- - gnu.crypto.prng.BasePRNGStandalone
  - - gnu.crypto.prng.FortunaStandalone

- All Implemented Interfaces:
    IRandomStandalone, Serializable, Cloneable
  Direct Known Subclasses:
    AsyncFortunaStandalone

      public class FortunaStandalone
      extends BasePRNGStandalone
      implements Serializable

  The Fortuna continuously-seeded pseudo-random number generator. This generator is composed of two major pieces: the entropy accumulator and the generator function. The former takes in random bits and incorporates them into the generator's state. The latter takes this base entropy and generates pseudo-random bits from it.

  There are some things users of this class must be aware of:

  Adding Random Data
    This class does not do any polling of random sources, but rather provides an interface for adding random events. Applications that use this code must provide this mechanism. We use this design because an application writer who knows the system he is targeting is in a better position to judge what random data is available.
  Storing the Seed
    This class implements `Serializable` in such a way that it writes a 64 byte seed to the stream, and reads it back again when being deserialized. This is the extent of seed file management, however, and those using this class are encouraged to think deeply about when, how often, and where to store the seed.

  References:

  - Niels Ferguson and Bruce Schneier, Practical Cryptography, pp. 155--184. Wiley Publishing, Indianapolis. (2003 Niels Ferguson and Bruce Schneier). ISBN 0-471-22357-3.
  Modified by jrandom for I2P to use a standalone gnu-crypto SHA256, Cryptix's AES, to strip out some unnecessary dependencies and increase the buffer size. Renamed from Fortuna to FortunaStandalone so it doesn't conflict with the gnu-crypto implementation, which has been imported into GNU/classpath NOTE: As of 0.8.8, uses the java.security.MessageDigest instead of GNU Sha256Standalone
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected IRandomStandalone` | `generator`
    `protected long` | `lastReseed`
    `(package private) static int` | `MIN_POOL_SIZE`
    `(package private) static int` | `NUM_POOLS`
    `protected int` | `pool0Count`
    `protected MessageDigest[]` | `pools` null if using DevRandom
    `protected int` | `reseedCount`
    `static String` | `SEED`

    - ### Fields inherited from class gnu.crypto.prng.BasePRNGStandalone

      `buffer, initialised, name, ndx`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FortunaStandalone()`
    `FortunaStandalone(boolean useDevRandom)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addRandomByte(byte b)` Supplement, or possibly replace, the random state of this PRNG with a random byte.
    `void` | `addRandomBytes(byte[] buf, int offset, int length)` Supplement, or possibly replace, the random state of this PRNG with a sequence of new random bytes.
    `void` | `fillBlock()` Unused, see AsyncFortunaStandalone
    `void` | `seed(byte[] val)` Unused, see AsyncFortunaStandalone
    `void` | `setup(Map<String,byte[]> attributes)`

    - ### Methods inherited from class gnu.crypto.prng.BasePRNGStandalone

      `addRandomBytes, clone, init, isInitialised, name, nextByte, nextBytes, nextBytes`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### generator

          protected final IRandomStandalone generator

    - #### lastReseed

          protected long lastReseed

    - #### MIN_POOL_SIZE

          static final int MIN_POOL_SIZE

      See Also:
        Constant Field Values

    - #### NUM_POOLS

          static final int NUM_POOLS

      See Also:
        Constant Field Values

    - #### pool0Count

          protected int pool0Count

    - #### pools

          protected final MessageDigest[] pools

      null if using DevRandom

    - #### reseedCount

          protected int reseedCount

    - #### SEED

          public static final String SEED

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FortunaStandalone

          public FortunaStandalone()

    - #### FortunaStandalone

          public FortunaStandalone(boolean useDevRandom)

  - ### Method Detail

    - #### addRandomByte

          public void addRandomByte(byte b)

      Description copied from interface: `IRandomStandalone`

      Supplement, or possibly replace, the random state of this PRNG with a random byte.

      Implementations are not required to implement this method in any meaningful way; this may be a no-operation, and implementations may throw an `UnsupportedOperationException`.

      Specified by:
        `addRandomByte` in interface `IRandomStandalone`
      Overrides:
        `addRandomByte` in class `BasePRNGStandalone`
      Parameters:
        `b` - The byte to add.

    - #### addRandomBytes

          public void addRandomBytes(byte[] buf,
                                     int offset,
                                     int length)

      Description copied from interface: `IRandomStandalone`

      Supplement, or possibly replace, the random state of this PRNG with a sequence of new random bytes.

      Implementations are not required to implement this method in any meaningful way; this may be a no-operation, and implementations may throw an `UnsupportedOperationException`.

      Specified by:
        `addRandomBytes` in interface `IRandomStandalone`
      Overrides:
        `addRandomBytes` in class `BasePRNGStandalone`
      Parameters:
        `buf` - 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 void fillBlock()

      Unused, see AsyncFortunaStandalone
      Specified by:
        `fillBlock` in class `BasePRNGStandalone`

    - #### seed

          public void seed(byte[] val)

      Unused, see AsyncFortunaStandalone

    - #### setup

          public void setup(Map<String,byte[]> attributes)

      Specified by:
        `setup` in class `BasePRNGStandalone`