org.logi.crypto.random
Class RandomMD5

java.lang.Object
  |
  +--java.util.Random
        |
        +--org.logi.crypto.random.RandomMD5
All Implemented Interfaces:
Seedable, java.io.Serializable

public class RandomMD5
extends java.util.Random
implements Seedable

This class implements an MD5-based PRNG and must be seeded from another RNG such as PureSpinner.

Random bytes are generated in blocks of 16 bytes. Output-block number i is r_i = H(s_0...s_i). s_0 is the initial seed which is permuted in each round to form s_i = s_{i-1} + r_i and H is the MD5 hash-function where the final step of appending the length of the message is omitted.

s_0 and each r_i is taken from the entropy source. The number of bits in these values should be large enough to ensure that an appreciable amount of entropy is collected. The default constructor will create an object which gets entropy from a PureSpinner object, is seeded with 256 bytes and injects 4 bytes in every round.

This RNG is similar to using MD5 in OFB mode, with a secret IV. In each round we have r_i = H(s_0...s_i) = H(s_0...s_{i-1}) + h(H(s_0...s_{i-1}), s_i), where h is the MD5 round function. We can discard the xor since the left side is known, so the security of the PRNG hinges on the difficulty of predicting a bit of h(x,y) where x is known and of the form given above.

The initial seeding may take a while, depending on the entropy source. Therefore the seeding is done in a separate thread which is launched when an object is created. If random bits are requested before the seeding is completed, the request will block.

Version:
1.0.6
Author:
Logi Ragnarsson (logir@logi.org)
See Also:
PureSpinner, Serialized Form

Constructor Summary
RandomMD5()
          Create a new instance of the RandomMD5 class.
RandomMD5(java.util.Random seeder, int seedSize, int round)
          Creates a new instance of the RandomMD5 class.
 
Method Summary
 void nextBytes(byte[] bytes)
          Generates a user specified number of random bytes.
 void setSeed(byte[] seed, int off, int len)
          Add the bytes from seed[off..off+len-1] to the entropy pool.
 void setSeed(long seed)
          Add the number seed to the entropy pool.
 
Methods inherited from class java.util.Random
nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomMD5

public RandomMD5(java.util.Random seeder,
                 int seedSize,
                 int round)
Creates a new instance of the RandomMD5 class. It will be initialized with seedSize bytes from seeder and collects round bytes from it for every 16 bytes it outputs.

RandomMD5

public RandomMD5()
Create a new instance of the RandomMD5 class. It will be initialized with 256 bytes of noise gathered from the scheduler and injects 4 bytes of entropy for each round.
See Also:
PureSpinner
Method Detail

setSeed

public void setSeed(byte[] seed,
                    int off,
                    int len)
Add the bytes from seed[off..off+len-1] to the entropy pool.
Specified by:
setSeed in interface Seedable

setSeed

public void setSeed(long seed)
Add the number seed to the entropy pool.
Specified by:
setSeed in interface Seedable
Overrides:
setSeed in class java.util.Random

nextBytes

public void nextBytes(byte[] bytes)
Generates a user specified number of random bytes.
Overrides:
nextBytes in class java.util.Random


Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL