ccs.chaos
Class SemiSecureRandom

java.lang.Object
  extended by java.util.Random
      extended by ccs.chaos.SemiSecureRandom
All Implemented Interfaces:
java.io.Serializable

public class SemiSecureRandom
extends java.util.Random

A PRNG designed primarily for producing the long random bytestrings required for overwriting sensitive data. It uses the statistically strong, fast, but predictable conventional PRNG, and reseeds it frequently using the default ChaosMage. This provides a good tradeoff between security and performance (the default ChaosMage is too slow to use directly). NB. Only nextBytes is automatically reseeded in this way; the other distributions and utility methods provided by the class are not. If you need these you'll have to reseed manually. This class is not designed for such use. MT-Safe.

See Also:
Serialized Form

Constructor Summary
SemiSecureRandom()
           
 
Method Summary
 int getInterval()
          Get the number of bytes produced between reseeds.
 void nextBytes(byte[] bytes)
          Obtain random bytes.
 void reseed()
          Reseed the predictable (fast) generator from the unpredictable (slow) one.
 void setInterval(int interval)
          Sets the number of bytes produced between reseeds.
 
Methods inherited from class java.util.Random
next, nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SemiSecureRandom

public SemiSecureRandom()
Method Detail

setInterval

public void setInterval(int interval)
Sets the number of bytes produced between reseeds.

Parameters:
interval - The number

getInterval

public int getInterval()
Get the number of bytes produced between reseeds.


reseed

public void reseed()
Reseed the predictable (fast) generator from the unpredictable (slow) one.


nextBytes

public void nextBytes(byte[] bytes)
Obtain random bytes. This is the interface you should use.

Overrides:
nextBytes in class java.util.Random
Parameters:
bytes - The byte array to fill with random numbers. NB. the whole array will be taken from the fast generator, with no reseeds in mid-array even if the array is longer than the interval.