|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.mindbright.util.RandomSeed
Generates a few high quality random numbers which are useful to seed other pseudo random number generators. This class will read frome system devices if possible. But it also has code to collect and handle randomness from user interaction.
The whole concept of cryptographically strong random numbers is very complicated. This class holds a pool of randomness and always estimates how much entropy (randomness) the pool contains. The internal pool is always stirred whenever entropy is extracted.
| Constructor Summary | |
RandomSeed()
Create an instance which does not load random numbers from system devices. |
|
RandomSeed(java.lang.String devRandName,
java.lang.String devURandName)
Create an instance which tries to use system random devices. |
|
| Method Summary | |
void |
addEntropyBits(byte bits,
int count)
Add entropy to the pool of randomness. |
void |
addEntropyGenerator(java.awt.Component c)
Register event handles for a component so entropy can be collected from events. |
void |
addProgress(Progress progress)
Connect to a progress meeter which gives feedback how the initialization goes. |
void |
componentHidden(java.awt.event.ComponentEvent e)
Extract entropy from a component event. |
void |
componentMoved(java.awt.event.ComponentEvent e)
Extract entropy from a component event. |
void |
componentResized(java.awt.event.ComponentEvent e)
Extract entropy from a component event. |
void |
componentShown(java.awt.event.ComponentEvent e)
Extract entropy from a component event. |
void |
focusGained(java.awt.event.FocusEvent e)
Extract entropy from a focus event. |
void |
focusLost(java.awt.event.FocusEvent e)
Extract entropy from a focus event. |
int |
getAvailableBits()
Gets the estimate of how much entropy the randomness pool contains. |
byte[] |
getBytes(int numBytes)
Gets random bytes in a non-blocking way. |
byte[] |
getBytesBlocking(int numBytes)
Gets random bytes in a blocking way. |
byte[] |
getBytesBlocking(int numBytes,
boolean generatorIfPresent)
Gets random bytes in a blocking way. |
static byte[] |
getSystemStateHash()
Get a hash-value which reflects the current system state. |
boolean |
haveDevRandom()
Checks if a blocking random device is available. |
boolean |
haveDevURandom()
Checks if a non-blocking random device is available. |
boolean |
haveEntropyGenerator()
Checks if an entropy generator has been added |
void |
keyPressed(java.awt.event.KeyEvent e)
Extracts entropy from key presses. |
void |
keyReleased(java.awt.event.KeyEvent e)
Extracts entropy from key releases. |
void |
keyTyped(java.awt.event.KeyEvent e)
Extracts entropy from key typed events. |
void |
mouseClicked(java.awt.event.MouseEvent e)
Extract entropy from a mouse event. |
void |
mouseDragged(java.awt.event.MouseEvent e)
Extract entropy from a mouse event. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Extract entropy from a mouse event. |
void |
mouseExited(java.awt.event.MouseEvent e)
Extract entropy from a mouse event. |
void |
mouseMoved(java.awt.event.MouseEvent e)
Extract entropy from a mouse event. |
void |
mousePressed(java.awt.event.MouseEvent e)
Extract entropy from a mouse event. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Extract entropy from a mouse event. |
void |
removeEntropyGenerator(java.awt.Component c)
Unregister event handles for a component. |
void |
removeProgress()
Detach from progress meter. |
void |
resetEntropyCount()
Reset the entropy count to zero. |
static int |
spin(long t)
Creates a random number by checking how many times we can run a loop and yield during a set time. |
static byte[] |
stackDump(java.lang.Throwable t)
Print a stack-dump into a byte array. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public RandomSeed()
public RandomSeed(java.lang.String devRandName,
java.lang.String devURandName)
devRandName - name of blocking random
device. Typically /dev/randomdevURandName - name of non-blocking random
device. Typically /dev/urandom| Method Detail |
public void addProgress(Progress progress)
progress - progress indicatorpublic void removeProgress()
public void addEntropyGenerator(java.awt.Component c)
c - component to attach event handles topublic void removeEntropyGenerator(java.awt.Component c)
c - component to detach from
public void addEntropyBits(byte bits,
int count)
bits - byte containing the random data to addcount - estimate how many bits of entropy the byte holdspublic boolean haveDevRandom()
public boolean haveDevURandom()
public boolean haveEntropyGenerator()
public int getAvailableBits()
public void resetEntropyCount()
public byte[] getBytes(int numBytes)
numBytes - number of bytes to extract
public byte[] getBytesBlocking(int numBytes)
numBytes - number of bytes to extract
public byte[] getBytesBlocking(int numBytes,
boolean generatorIfPresent)
numBytes - number of bytes to extractgeneratorIfPresent - if true then the function waits for
the attached generators to generate enough
randomness. If false the function will use the local
spin generator.
public static byte[] getSystemStateHash()
public static int spin(long t)
t - how many milliseconds the loop should run forpublic void keyPressed(java.awt.event.KeyEvent e)
keyPressed in interface java.awt.event.KeyListenerpublic void keyReleased(java.awt.event.KeyEvent e)
keyReleased in interface java.awt.event.KeyListenerpublic void keyTyped(java.awt.event.KeyEvent e)
keyTyped in interface java.awt.event.KeyListenerpublic void componentHidden(java.awt.event.ComponentEvent e)
componentHidden in interface java.awt.event.ComponentListenerpublic void componentMoved(java.awt.event.ComponentEvent e)
componentMoved in interface java.awt.event.ComponentListenerpublic void componentResized(java.awt.event.ComponentEvent e)
componentResized in interface java.awt.event.ComponentListenerpublic void componentShown(java.awt.event.ComponentEvent e)
componentShown in interface java.awt.event.ComponentListenerpublic void focusGained(java.awt.event.FocusEvent e)
focusGained in interface java.awt.event.FocusListenerpublic void focusLost(java.awt.event.FocusEvent e)
focusLost in interface java.awt.event.FocusListenerpublic void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked in interface java.awt.event.MouseListenerpublic void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered in interface java.awt.event.MouseListenerpublic void mouseExited(java.awt.event.MouseEvent e)
mouseExited in interface java.awt.event.MouseListenerpublic void mousePressed(java.awt.event.MouseEvent e)
mousePressed in interface java.awt.event.MouseListenerpublic void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased in interface java.awt.event.MouseListenerpublic void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged in interface java.awt.event.MouseMotionListenerpublic void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved in interface java.awt.event.MouseMotionListenerpublic static byte[] stackDump(java.lang.Throwable t)
t - throwable to generate stack dump from
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||