public abstract class SeedGenerator
extends java.lang.Object
The important point is that an attacker should have a probability no larger than 2-n of guessing the correct n bit seed, nor should he be able to manipulate the random bit generation in a way to increase his probability of guessing it. Note that the attacker could reside on (in order of increasing difficulty for us) on (a) some machine connected to us via the Internet or some other WAN (b) on the same LAN (c) running tasks on the same machine (d) have full control over the OS run on our machine and (e) be the user running the seed generator himself. Obviously applications will usually not be concerned all of these cases, but only the first two or three.
Also note that if a seed of e.g. 64 bit is fed to a PRNG which is later used to generate a 128 bit random encryption key, the effective strength of that key is only 64 bit because an attacker could recreate the deterministic steps used to blow up the seed from 64 to 128 bit. On the other hand it would be no problem at all to generate an arbitrary number of 56 bit keys from our 64 bit seed. In short, this means that the seed should always be at least as long as the longest independent random value that needs to be generated from it.
General API usage:
getSeed()
. Those will often be the output of some message digest
function and therefore be of constant length.
getSeed()
or it might be available immediately. You can check whether the seed is ready
by using a SeedGenListener
, you can call
seedAvailable()
, etc.
getSeed()
. Calling
getSeed()
again will yield the same seed, if you want to generate
more random bits you have to create a new SeedGenerator object.
AWT11SeedGenerator
,
MetaSeedGenerator
,
AutoSeedGenerator
Modifier and Type | Field and Description |
---|---|
protected SeedGenListener |
seedGenListener
The current SeedGenListener of this class.
|
Modifier | Constructor and Description |
---|---|
protected |
SeedGenerator()
Constructor for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
protected void |
callSeedGenListener()
If a SeedGenListener is set, call it with the parameters returned by
getStatus.
|
static SeedGenerator |
getDefault()
Get a new instance of the default seed generator.
|
static SeedGenerator |
getDefaultSeedGenerator()
Deprecated.
use getDefault() instead.
|
abstract byte[] |
getSeed()
Get the generated random seed bits.
|
abstract int[] |
getStatus()
Get the current status of seed generation.
|
boolean |
seedAvailable()
Check whether the seed is available to be fetched via
getSeed() . |
static void |
setDefault(java.lang.Class clazz)
Set the default seed generator.
|
static void |
setDefaultSeedGenerator(SeedGenerator g)
Deprecated.
use setDefault() instead.
|
void |
setSeedGenListener(SeedGenListener seedGenListener)
Sets the SeedGenListener for this object.
|
protected SeedGenListener seedGenListener
protected SeedGenerator()
public static SeedGenerator getDefault()
public static void setDefault(java.lang.Class clazz)
VarLengthSeedGenerator
class, it is also set as default VarLengthSeedGenerator.clazz
- the class that implements the default seed generator to be usedjava.lang.IllegalArgumentException
- if there was an error with the SeedGeneratorpublic abstract byte[] getSeed()
public abstract int[] getStatus()
getStatus()[0]
equals
getStatus()[1]
, the seed is ready to be fetched via
getSeed()
.public final boolean seedAvailable()
getSeed()
. This is implemented by calling
getStatus()
.protected void callSeedGenListener()
public void setSeedGenListener(SeedGenListener seedGenListener)
public static void setDefaultSeedGenerator(SeedGenerator g) throws RandomException
RandomException
public static SeedGenerator getDefaultSeedGenerator()