The seed is produced using one of two techniques, via a computation of current system activity or from an entropy gathering device.
In the default technique the seed is produced by counting the number of times the VM manages to loop in a given period. This number roughly reflects the machine load at that point in time. The samples are translated using a permutation (s-box) and then XORed together. This process is non-linear and should prevent the samples from "averaging out". The s-box was designed to have even statistical distribution; its specific values are not crucial for the security of the seed. We also create a number of sleeper threads which add entropy to the system by keeping the scheduler busy. Twenty such samples should give us roughly 160 bits of randomness.
These values are gathered in the background by a daemon thread thus allowing the system to continue performing its different activities, which in turn add entropy to the random seed.
The class also gathers miscellaneous system information, some machine dependent, some not. This information is then hashed together with the 20 seed bytes.
The alternative to the above approach is to acquire seed material
from an entropy gathering device, such as /dev/random. This can be
accomplished by setting the value of the securerandom.source
Security property to a URL specifying the location of the entropy
gathering device, or by setting the java.security.egd System
property.
In the event the specified URL cannot be accessed the default threading mechanism is used.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final Debug | |
| private static SeedGenerator |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| public static void | |
| pack-priv abstract void | |
| pack-priv static byte[] | |
| private static byte[] | longToByteArray(long l)
Helper function to convert a long into a byte array (least significant byte first). |
| debug | back to summary |
|---|---|
| private static final Debug debug | |
| instance | back to summary |
|---|---|
| private static SeedGenerator instance | |
| SeedGenerator | back to summary |
|---|---|
| pack-priv SeedGenerator() | |
| addNetworkAdapterInfo | back to summary |
|---|---|
| private static void addNetworkAdapterInfo(MessageDigest md) | |
| generateSeed | back to summary |
|---|---|
| public static void generateSeed(byte[] result) Fill result with bytes from the queue. Wait for it if it isn't ready. | |
| getSeedBytes | back to summary |
|---|---|
| pack-priv abstract void getSeedBytes(byte[] result) | |
| getSystemEntropy | back to summary |
|---|---|
| pack-priv static byte[] getSystemEntropy() Retrieve some system information, hashed. | |
| longToByteArray | back to summary |
|---|---|
| private static byte[] longToByteArray(long l) Helper function to convert a long into a byte array (least significant byte first). | |
| Modifier and Type | Class and Description |
|---|---|
| private static class | SeedGenerator.
This inner thread causes the thread scheduler to become 'noisy', thus adding entropy to the system load. |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private int | |
| private final byte[] | |
| private static final byte[] | |
| pack-priv ThreadGroup | |
| private int |
| Access | Constructor and Description |
|---|---|
| pack-priv | ThreadedSeedGenerator()
The constructor is only called once to construct the one instance we actually use. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv byte | |
| pack-priv void | |
| public final void |
| count | back to summary |
|---|---|
| private int count | |
| end | back to summary |
|---|---|
| private int end | |
| pool | back to summary |
|---|---|
| private final byte[] pool | |
| rndTab | back to summary |
|---|---|
| private static final byte[] rndTab | |
| seedGroup | back to summary |
|---|---|
| pack-priv ThreadGroup seedGroup | |
| start | back to summary |
|---|---|
| private int start | |
| ThreadedSeedGenerator | back to summary |
|---|---|
| pack-priv ThreadedSeedGenerator() The constructor is only called once to construct the one instance we actually use. It instantiates the message digest and starts the thread going. | |
| getSeedByte | back to summary |
|---|---|
| pack-priv byte getSeedByte() | |
| getSeedBytes | back to summary |
|---|---|
| pack-priv void getSeedBytes(byte[] result) Implements abstract sun.
| |
| run | back to summary |
|---|---|
| public final void run() Implements java. This method does the actual work. It collects random bytes and pushes them into the queue.
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public final void |
| BogusThread | back to summary |
|---|---|
| private BogusThread() | |
| run | back to summary |
|---|---|
| public final void run() Implements java. Doc from java. Runs this operation.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private InputStream |
| Access | Constructor and Description |
|---|---|
| pack-priv | URLSeedGenerator(String egdurl)
The constructor is only called once to construct the one instance we actually use. |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| private void |
| deviceName | back to summary |
|---|---|
| private final String deviceName | |
| seedStream | back to summary |
|---|---|
| private InputStream seedStream | |
| URLSeedGenerator | back to summary |
|---|---|
| pack-priv URLSeedGenerator(String egdurl) throws IOException The constructor is only called once to construct the one instance we actually use. It opens the entropy gathering device which will supply the randomness. | |
| getSeedBytes | back to summary |
|---|---|
| pack-priv void getSeedBytes(byte[] result) Implements abstract sun.
| |
| init | back to summary |
|---|---|
| private void init() throws IOException | |