de.flexiprovider.core.random
Class BBSRandom
java.lang.Object
|
+--java.security.SecureRandomSpi
|
+--de.flexiprovider.api.SecureRandom
|
+--de.flexiprovider.core.random.BBSRandom
- All Implemented Interfaces:
- java.io.Serializable
- public final class BBSRandom
- extends SecureRandom
This is an implementation of a pseudorandom number based on a paper written
by L. Blum, M. Blum and M. Shub in 1982. The BBS (or X2-mod-N)
generator is proved to be as secure as the factorization of the Modulus
(which is a 1024 bit number).
The implementation follows the JCA conventions and subclasses the proper
engine class (SecureRandom). This class is normaly not instantiated directly.
You should use the factory-method provided by the JCA framework (i.e. call
java.security.SecureRandom.getInstance(...)). The generator works in
three steps:
- The generator uses an internal 200 bit seed, so it is inefficient to do
something like a "brute force" attack (i.e. enumerate all possible seeds).
The seed can be set using the
setSeed(byte[] bytes) member function.
If it is not set explicitly, then it is generated by a seed generator.
- In order to generate the parameters used during the generation, the
internal seed is expanded using a Linear Congruential Generator (LCG). This
generator is not secure in a cryptographical manner, but as no output of the
(LCG) is visible to the outside world, this is no problem. The parameters are
the seed X and the modulus N which is the product of two different prime
numbers P,Q of equal bit length. N is at least a 1024 bit number. The
parameters are generated after the instantiation and after each call to
setSeed(byte[]). The generation takes place within the
nextBytes(byte[] bytes) member function.
- Using these parameters, the generator iteratively determines a new X by
raising X to the power of 2 modulo N. During each iteration the
log2(|N|)-least-significant bits of the binary
representation of X are collected and form the output of the generator.
Timings:
|   |
Seed generation |
Parameter generation |
Byte generation |
| 10000 bytes |
20000 bytes |
| PII-233, with JIT |
10.036 s |
8.042 s |
5.708 s |
11.405 s |
- Author:
- Marcus Lippert, Martin Döring
- See Also:
- "java.security.SecureRandom",
"java.security.SecureRandomSpi",
"de.flexiprovider.common.util.SeedGenerator", Serialized Form
|
Constructor Summary |
BBSRandom()
Default constructor of BBSRandom, to be called by SecureRandom's
getInstance(...) method according to a factory pattern. |
|
Method Summary |
byte[] |
generateSeed(int numBytes)
Returns the requested number of seed bytes. |
void |
nextBytes(byte[] bytes)
Generates a user-specified number of random bytes. |
void |
setSeed(byte[] newSeed)
Modifies the seed of this random object in the following way:
If this method is called before the object is seeded, i.e it is the
first call of this method and no bytes have been generated by this object
yet, the seed is set in a way that entirely depends on the given
parameter and therefore is reproducible.
If this method is called to an object already seeded, the new seed
depends on both the current inner state and the given parameter.
|
| Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BBSRandom
public BBSRandom()
- Default constructor of BBSRandom, to be called by SecureRandom's
getInstance(...) method according to a factory pattern.
generateSeed
public byte[] generateSeed(int numBytes)
- Returns the requested number of seed bytes.
- Overrides:
generateSeed in class SecureRandom
- Parameters:
numBytes - number of random bytes to generate- Returns:
- a byte array containig the pseudo-random bytes
nextBytes
public void nextBytes(byte[] bytes)
- Generates a user-specified number of random bytes.
- Overrides:
nextBytes in class SecureRandom
- Parameters:
bytes - byte array the generated bytes will be stored in
setSeed
public void setSeed(byte[] newSeed)
- Modifies the seed of this random object in the following way:
- If this method is called before the object is seeded, i.e it is the
first call of this method and no bytes have been generated by this object
yet, the seed is set in a way that entirely depends on the given
parameter and therefore is reproducible.
- If this method is called to an object already seeded, the new seed
depends on both the current inner state and the given parameter.
- Overrides:
setSeed in class SecureRandom
- Parameters:
newSeed - the byte array containing a new seed