|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.Random
java.security.SecureRandom
org.hd.d.efs.Whitener
public final class Whitener
This class whitens one source of random numbers with another. This has an overall interface of SecureRandom, and takes two SecureRandom generators (which must not be the same nor null) and XORs their output to gain a new whitened stream.
The one-argument constructor automatically uses a private instance of the default implementation of SecureRandom() as the whitener.
An application of this might be where although some part of a system might want to use a shared EntropyPool, it is particularly paranoid about security and may wish to whiten the output with its own SecureRandom instance to ensure that even compromise of the shared generator is unlikely to compromise its own generator quickly.
All we need to override is nextBytes() and the seed() calls.
| Constructor Summary | |
|---|---|
Whitener(java.security.SecureRandom main)
Construct a combo generator with a main source and a private whitener. |
|
Whitener(java.security.SecureRandom main,
java.security.SecureRandom whitener)
Construct a combo generator with main and whitener sources. |
|
| Method Summary | |
|---|---|
byte[] |
generateSeed(int numBytes)
Returns seed bytes from both generators XORed together. |
void |
nextBytes(byte[] result)
Generates a user-specified number of random bytes. |
void |
setSeed(byte[] seed)
Reseeds both underlying generators with this seed. |
void |
setSeed(long seed)
Reseeds both underlying generators with this seed. |
| Methods inherited from class java.security.SecureRandom |
|---|
getAlgorithm, getInstance, getInstance, getInstance, getProvider, getSeed, next |
| Methods inherited from class java.util.Random |
|---|
nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Whitener(java.security.SecureRandom main,
java.security.SecureRandom whitener)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic Whitener(java.security.SecureRandom main)
| Method Detail |
|---|
public void setSeed(byte[] seed)
setSeed in class java.security.SecureRandomseed - the seed.public void setSeed(long seed)
long seed. The given seed supplements,
rather than replaces, the existing seed. Thus, repeated calls
are guaranteed never to reduce randomness.
This method is defined for compatibility with
java.util.Random.
setSeed in class java.security.SecureRandomseed - the seed.public void nextBytes(byte[] result)
nextBytes in class java.security.SecureRandomresult - the array to be filled in with random bytes.public byte[] generateSeed(int numBytes)
generateSeed in class java.security.SecureRandomnumBytes - the number of seed bytes to generate.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||