|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Random | +--java.security.SecureRandom | +--net.vattp.security.ESecureRandom
Untamed: Cryptographically Strong Random Number Generator
This class provides a cryptographically strong random number generator based on user provided sources of entropy and the MD5 hash algorithm. It maintains an estimate of the amount of entropy supplied. If there is a request for secure random data, a call on nextBytes(), when there is less than 80 bits of randomness available, it will use super.getSeed() to bring the level up to 80 bits.
The calls inherited from Random and SecureRandom are implemented in terms of the strengthened functionality.
Note by msm: Beware, ESecureRandom inheits from SecureRandom, which synchronizes on itself, so ESecureRandom also syncronizes on itself.
Although this class isn't declared Persistent, the relevant instance is expected to be a scalpel-key.
java.util.Random
,
java.security.SecureRandom
,
Serialized FormField Summary | |
private static int |
HASH_SIZE
|
private static int |
MAX_ENTROPY
Size of the entropy pool in bits. |
private static int |
MIN_ENTROPY
|
private int |
myAvailableEntropy
|
private int |
myBufferedEntropy
The amount of entropy in the buffer we keep before adding it to the pool. |
private long |
myDigestNumber
|
private byte[] |
myEntropyBuffer
The buffer we keep for entropy before adding it to the pool |
private byte[] |
myEntropyPool
|
private MessageDigest |
myMD
|
private int |
myPoolCursor
|
private static int |
SWISSDATA_SIZE
|
private static ESecureRandom |
theESecureRandom
The instance of this singleton class |
private static int |
theLastDX
|
private static int |
theLastDY
|
private static int[] |
theLastKeys
Last keys seen |
private static int |
theLastX
|
private static int |
theLastY
|
private static TimerJitterEntropy |
theTimeJitterEntropy
static entropy generator reference to start the entropy generation thread |
Fields inherited from class java.security.SecureRandom |
|
Fields inherited from class java.util.Random |
|
Constructor Summary | |
private |
ESecureRandom(byte[] seed,
int entropy)
This constructor takes a user-provided seed and entropy estimate. |
Method Summary | |
int |
availableEntropy()
Enabled: Get the amount of entropy the generator now holds. |
static ESecureRandom |
getESecureRandom()
Enabled: Return the singular instance of a SecureRandomCrew. |
static ESecureRandom |
getESecureRandom(byte[] entropy,
int bitEstimate)
Enabled: Return the singular instance of a SecureRandomCrew. |
private byte[] |
long2bytes(long number)
|
void |
nextBytes(byte[] bytes)
Enabled: This method provides the secure random output. |
BigInteger |
nextSwiss()
Enabled: MSM: Added this method, so this object acts as a capability for making new unguessable BigIntegers that have new entropy. |
static void |
provideEntropy(byte[] entropy,
int bitEstimate)
Enabled: This method accepts entropy and adds it to the pool. |
static void |
setKeySeed(int key,
int modifiers,
int type)
Enabled: This method accepts a keyboard event to input entropy. |
static void |
setMouseSeed(int x,
int y,
int type)
Enabled: This method accepts a mouse event to input entropy. |
void |
setSeed(byte[] seed)
Enabled: This method is included for compatibility with the super class. |
void |
setSeed(byte[] seed,
int entropy)
Enabled: This method is the preferred way to provide entropy for later use. |
Methods inherited from class java.security.SecureRandom |
generateSeed, getInstance, getInstance, getInstance, getProvider, getSeed, next, setSeed |
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 |
Field Detail |
private static final int SWISSDATA_SIZE
private static TimerJitterEntropy theTimeJitterEntropy
private static ESecureRandom theESecureRandom
private static final transient int[] theLastKeys
private static transient int theLastX
private static transient int theLastY
private static transient int theLastDX
private static transient int theLastDY
private static final int HASH_SIZE
private static final int MAX_ENTROPY
This constant limits the amount of actual entropy that goes into building the secure random output. N.B. must be a multiple of HASH_SIZE.
private static final int MIN_ENTROPY
private final transient byte[] myEntropyPool
private transient int myPoolCursor
private int myAvailableEntropy
private MessageDigest myMD
private long myDigestNumber
private int myBufferedEntropy
private byte[] myEntropyBuffer
Constructor Detail |
private ESecureRandom(byte[] seed, int entropy)
seed
- the seed.entropy
- an estimate of the amount of entropy in seed in bits.
IllegalArgumentException
- entropy estimate is less than 1 bit.
IllegalArgumentException
- entropy estimate is greater than 8
bits for every byte of the seed.Method Detail |
public int availableEntropy()
public static ESecureRandom getESecureRandom()
public static ESecureRandom getESecureRandom(byte[] entropy, int bitEstimate)
private byte[] long2bytes(long number)
public void nextBytes(byte[] bytes)
nextBytes
in class SecureRandom
bytes
- the byte array which will receive the secure random output.public static void provideEntropy(byte[] entropy, int bitEstimate)
entropy
- a byte array containing the entropy.bitEstimate
- an estimate of the amount of entropy in
entropy in bits.
IllegalArgumentException
- entropy estimate is less
than 1 bit.
IllegalArgumentException
- entropy estimate is greater than 8
bits for every byte of the seed.public static void setKeySeed(int key, int modifiers, int type)
key
- the keyboard code.modifiers
- the modifier keys pressed.type
- the mouse event type code.public static void setMouseSeed(int x, int y, int type)
x
- the mouse event x value.y
- the mouse event y value.type
- the mouse event type code.public void setSeed(byte[] seed)
setSeed
in class SecureRandom
seed
- the seed.SecureRandom.getSeed(int)
public void setSeed(byte[] seed, int entropy)
seed
- the seed.entropy
- an estimate of the amount of entropy in seed in bits.
IllegalArgumentException
- entropy estimate is less than 0 bits.
IllegalArgumentException
- entropy estimate is greater than 8
bits for every byte of the seed.public BigInteger nextSwiss()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |