public abstract class VarLengthSeedGenerator extends SeedGenerator
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:
SeedGenerator
), classes that subclass
VarLengthSeedGenerator
are able to provide seeds of variable
length. Use VarLengthSeedGenerator.setDefault()
to set the
default variable length seed generator and
VarLengthSeedGenerator.getDefault()
to obtain an instance of
the according variable length seed generator. Contrary to ordinary seed
generators this call allows the user to set the length of the seed returned by
getSeed()
.
VarLengthSeedGenerator
have to check whether the seed length
has changed via VarLengthSeedGenerator.hasSeedLengthChanged()
inside getSeed()
.
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.
SeedGenerator
seedGenListener
Modifier | Constructor and Description |
---|---|
protected |
VarLengthSeedGenerator(int numBits)
Constructs a new variable length seed generator.
|
Modifier and Type | Method and Description |
---|---|
static VarLengthSeedGenerator |
getDefault(int numBits)
Get a new instance of the default seed generator.
|
int |
getSeedLength()
Gets the bitlength of the seed.
|
protected boolean |
hasSeedLengthChanged()
Returns true, if the seed length has changed in the meantime.
|
void |
reinit(int numBits)
Sets the number of bits to generate.
|
static void |
setDefault(java.lang.Class clazz)
Set the default seed generator.
|
protected void |
setSeedLength(int numBits)
Sets the bitlength of the seed.
|
callSeedGenListener, getDefault, getDefaultSeedGenerator, getSeed, getStatus, seedAvailable, setDefaultSeedGenerator, setSeedGenListener
protected VarLengthSeedGenerator(int numBits)
numBits
- the seed length in bitspublic void reinit(int numBits)
getSeed()
gets called.numBits
- the number of bits to generatepublic static void setDefault(java.lang.Class clazz)
clazz
- the class that implements the default seed generator to be usedjava.lang.IllegalArgumentException
- if there was an error with the SeedGeneratorpublic static VarLengthSeedGenerator getDefault(int numBits)
numBits
.numBits
- the bitlength of the seedIllegalSeedGeneratorException
protected boolean hasSeedLengthChanged()
public int getSeedLength()
protected void setSeedLength(int numBits)