APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.security.provider

pack-priv abstract Class SeedGenerator

extends Object
Class Inheritance
Known Direct Subclasses
sun.security.provider.SeedGenerator.ThreadedSeedGenerator, sun.security.provider.SeedGenerator.URLSeedGenerator
Imports
java.security.*, java.io.*, java.util.Properties, .Enumeration, .Random, java.net.*, java.nio.file.DirectoryStream, .Files, .Path, sun.security.util.Debug

This class generates seeds for the SHA1PRNG cryptographically strong random number generator.

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.

Authors
Joshua Bloch, Gadi Guy

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final Debug
private static SeedGenerator

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static void
public static void
generateSeed(byte[] result)

Fill result with bytes from the queue.

pack-priv abstract void
getSeedBytes(byte[] result)

pack-priv static byte[]
getSystemEntropy()

Retrieve some system information, hashed.

private static byte[]
longToByteArray(long l)

Helper function to convert a long into a byte array (least significant byte first).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
private static final Debug debug
instanceback to summary
private static SeedGenerator instance

Constructor Detail

SeedGeneratorback to summary
pack-priv SeedGenerator()

Method Detail

addNetworkAdapterInfoback to summary
private static void addNetworkAdapterInfo(MessageDigest md)
generateSeedback to summary
public static void generateSeed(byte[] result)

Fill result with bytes from the queue. Wait for it if it isn't ready.

getSeedBytesback to summary
pack-priv abstract void getSeedBytes(byte[] result)
getSystemEntropyback to summary
pack-priv static byte[] getSystemEntropy()

Retrieve some system information, hashed.

longToByteArrayback to summary
private static byte[] longToByteArray(long l)

Helper function to convert a long into a byte array (least significant byte first).

sun.security.provider back to summary

private Class SeedGenerator.ThreadedSeedGenerator

extends SeedGenerator
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SeedGenerator.ThreadedSeedGenerator.BogusThread

This inner thread causes the thread scheduler to become 'noisy', thus adding entropy to the system load.

Field Summary

Modifier and TypeField and Description
private int
private int
private final byte[]
private static final byte[]
pack-priv ThreadGroup
private int

Constructor Summary

AccessConstructor and Description
pack-priv
ThreadedSeedGenerator()

The constructor is only called once to construct the one instance we actually use.

Method Summary

Modifier and TypeMethod and Description
pack-priv byte
pack-priv void
public final void
run()

Implements java.lang.Runnable.run.

This method does the actual work.

Inherited from sun.security.provider.SeedGenerator:
generateSeedgetSystemEntropy

Field Detail

countback to summary
private int count
endback to summary
private int end
poolback to summary
private final byte[] pool
rndTabback to summary
private static final byte[] rndTab
seedGroupback to summary
pack-priv ThreadGroup seedGroup
startback to summary
private int start

Constructor Detail

ThreadedSeedGeneratorback 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.

Method Detail

getSeedByteback to summary
pack-priv byte getSeedByte()
getSeedBytesback to summary
pack-priv void getSeedBytes(byte[] result)

Implements abstract sun.security.provider.SeedGenerator.getSeedBytes.

Annotations
@Override
runback to summary
public final void run()

Implements java.lang.Runnable.run.

This method does the actual work. It collects random bytes and pushes them into the queue.

Annotations
@Override
sun.security.provider back to summary

private Class SeedGenerator.ThreadedSeedGenerator.BogusThread

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • sun.security.provider.SeedGenerator.ThreadedSeedGenerator.BogusThread
All Implemented Interfaces
java.lang.Runnable

This inner thread causes the thread scheduler to become 'noisy', thus adding entropy to the system load. At least one instance of this class is generated for every seed byte.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public final void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BogusThreadback to summary
private BogusThread()

Method Detail

runback to summary
public final void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
sun.security.provider back to summary

pack-priv Class SeedGenerator.URLSeedGenerator

extends SeedGenerator
Class Inheritance
Known Direct Subclasses
sun.security.provider.NativeSeedGenerator

Field Summary

Modifier and TypeField and Description
private final String
private InputStream

Constructor Summary

AccessConstructor and Description
pack-priv
URLSeedGenerator(String egdurl)

The constructor is only called once to construct the one instance we actually use.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
private void
init()

Inherited from sun.security.provider.SeedGenerator:
generateSeedgetSystemEntropy

Field Detail

deviceNameback to summary
private final String deviceName
seedStreamback to summary
private InputStream seedStream

Constructor Detail

URLSeedGeneratorback 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.

Method Detail

getSeedBytesback to summary
pack-priv void getSeedBytes(byte[] result)

Implements abstract sun.security.provider.SeedGenerator.getSeedBytes.

Annotations
@Override
initback to summary
private void init() throws IOException