DRBG#impl.
This class has 5 abstract methods. 3 are defined by SP800-90A:
generateAlgorithm(byte[], byte[])
reseedAlgorithm(byte[], byte[]) (In fact this is not an
abstract method, but any DRBG supporting reseeding must override it.)
instantiateAlgorithm(byte[])
SecureRandomSpi, it
implements all abstract methods there as final.
The initialization process of a DRBG is divided into 2 phases:
configuration is eagerly called to set up parameters,
and instantiation is lazily called only
when nextBytes or reseed is called.
SecureRandom methods like reseed and nextBytes are not thread-safe. An implementation is required to protect shared access to instantiate states (instantiated, nonce) and DRBG states (v, c, key, reseedCounter, etc.).
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| protected String | algorithm
Algorithm used by this instance (SHA-512 or AES-256). |
| protected static final Debug | debug
This field is not null if |
| protected static final int | DEFAULT_STRENGTH
Default strength of a DRBG instance if it is not configured. |
| private static final EntropySource | defaultES
The default |
| private EntropySource | es
The entropy source used by this instance. |
| protected int | highestSupportedSecurityStrength
highest_supported_security_strength of this mechanism for all algorithms it supports. |
| private boolean | |
| protected int | maxAdditionalInputLength
Maximum additional input length in bytes for this DRBG instance. |
| protected int | maxLength
Maximum entropy input length in bytes for this DRBG instance. |
| protected int | maxNumberOfBytesPerRequest
max_number_of_bits_per_request in bytes for this DRBG instance. |
| protected int | maxPersonalizationStringLength
Maximum personalization string length in bytes for this DRBG instance. |
| protected String | mechName
Mechanism name, say, |
| protected int | minLength
Minimum entropy input length in bytes for this DRBG instance. |
| protected byte[] | nonce
The nonce for this instance. |
| protected byte[] | personalizationString
The personalization string used by this instance. |
| private boolean | predictionResistanceFlag
The prediction resistance flag used by this instance. |
| protected String | requestedAlgorithm
Requested algorithm in |
| protected int | requestedInstantiationSecurityStrength
Strength requested in |
| private byte[] | requestedNonce
Requested nonce in |
| protected volatile int | reseedCounter
Reseed counter of a DRBG instance. |
| protected int | reseedInterval
Maximum number of requests between reseeds for this DRBG instance. |
| protected int | securityStrength
Security strength for this instance. |
| protected boolean | supportPredictionResistance
Whether prediction resistance is supported. |
| protected boolean | supportReseeding
Whether reseed is supported. |
| protected boolean | usedf
Whether a derivation function is used. |
| Access | Constructor and Description |
|---|---|
| protected | AbstractDrbg()
A constructor without argument so that an implementation does not
need to always write |
| protected | AbstractDrbg(SecureRandomParameters
the params)SecureRandomParameters object.
This argument can be null.A mechanism shall override this constructor to set up |
| Modifier and Type | Method and Description |
|---|---|
| protected abstract void | chooseAlgorithmAndStrength()
Decides what algorithm and strength to use (SHA-256 or AES-256, 128 or 256). |
| protected final void | configure(SecureRandomParameters
configuration, if null, default configuration (default
strength, pr_false, no personalization string) is used. params)Configure this DRBG. |
| public final byte[] | Returns: the seed bytes.the number of seed bytes to generate. numBytes)Returns the given number of seed bytes. |
| protected SecureRandomParameters | Returns: the current configurationReturns the current configuration as a |
| protected final void | |
| protected final void | |
| public final void | |
| public final synchronized void | |
| protected abstract void | generateAlgorithm(byte[]
fill result here, not null result, byte[] additional input, can be null. If not null,
its length is smaller than additionalInput)maxAdditionalInputLengthThe generate function. |
| private byte[] | |
| private byte[] | |
| protected static int | Returns: the standard strengththe input strength input)Returns the smallest standard strength (112, 128, 192, 256) that is greater or equal to the input. |
| protected abstract void | |
| protected abstract void | |
| private synchronized void | instantiateIfNecessary(byte[]
a user-provided entropy, the length is already good.
If null, will fetch entropy input automatically. entropy)Instantiate if necessary, |
| protected void | reseedAlgorithm(byte[] ei, byte[]
additional input, can be null. If not null,
its length is smaller than additionalInput)maxAdditionalInputLengthThe reseed function. |
| public String |
| algorithm | back to summary |
|---|---|
| protected String algorithm Algorithm used by this instance (SHA-512 or AES-256). Must be assigned
in | |
| debug | back to summary |
|---|---|
| protected static final Debug debug This field is not null if | |
| DEFAULT_STRENGTH | back to summary |
|---|---|
| protected static final int DEFAULT_STRENGTH Default strength of a DRBG instance if it is not configured. 128 is considered secure enough now. A mechanism can change it in a constructor. Remember to sync with "securerandom.drbg.config" in java.security. | |
| defaultES | back to summary |
|---|---|
| private static final EntropySource defaultES The default
This object uses | |
| es | back to summary |
|---|---|
| private EntropySource es The entropy source used by this instance. Set inside
| |
| highestSupportedSecurityStrength | back to summary |
|---|---|
| protected int highestSupportedSecurityStrength highest_supported_security_strength of this mechanism for all algorithms it supports. A mechanism should update the value in its constructor if the value is not 256. | |
| instantiated | back to summary |
|---|---|
| private boolean instantiated | |
| maxAdditionalInputLength | back to summary |
|---|---|
| protected int maxAdditionalInputLength Maximum additional input length in bytes for this DRBG instance.
Should be assigned in | |
| maxLength | back to summary |
|---|---|
| protected int maxLength Maximum entropy input length in bytes for this DRBG instance.
Should be assigned in
In theory this value (and the values below) can be bigger than
| |
| maxNumberOfBytesPerRequest | back to summary |
|---|---|
| protected int maxNumberOfBytesPerRequest max_number_of_bits_per_request in bytes for this DRBG instance.
Should be assigned in | |
| maxPersonalizationStringLength | back to summary |
|---|---|
| protected int maxPersonalizationStringLength Maximum personalization string length in bytes for this DRBG instance.
Should be assigned in | |
| mechName | back to summary |
|---|---|
| protected String mechName Mechanism name, say, | |
| minLength | back to summary |
|---|---|
| protected int minLength Minimum entropy input length in bytes for this DRBG instance.
Must be assigned in | |
| nonce | back to summary |
|---|---|
| protected byte[] nonce The nonce for this instance. Set in | |
| personalizationString | back to summary |
|---|---|
| protected byte[] personalizationString The personalization string used by this instance. Set inside
| |
| predictionResistanceFlag | back to summary |
|---|---|
| private boolean predictionResistanceFlag The prediction resistance flag used by this instance. Set inside
| |
| requestedAlgorithm | back to summary |
|---|---|
| protected String requestedAlgorithm Requested algorithm in | |
| requestedInstantiationSecurityStrength | back to summary |
|---|---|
| protected int requestedInstantiationSecurityStrength Strength requested in | |
| requestedNonce | back to summary |
|---|---|
| private byte[] requestedNonce Requested nonce in | |
| reseedCounter | back to summary |
|---|---|
| protected volatile int reseedCounter Reseed counter of a DRBG instance. A mechanism should increment it
after each random bits generation and reset it in reseed. A mechanism
does not need to compare it to | |
| reseedInterval | back to summary |
|---|---|
| protected int reseedInterval Maximum number of requests between reseeds for this DRBG instance.
Should be assigned in | |
| securityStrength | back to summary |
|---|---|
| protected int securityStrength Security strength for this instance. Must be assigned in
| |
| supportPredictionResistance | back to summary |
|---|---|
| protected boolean supportPredictionResistance Whether prediction resistance is supported. A mechanism should update the value in its constructor if it is not supported. | |
| supportReseeding | back to summary |
|---|---|
| protected boolean supportReseeding Whether reseed is supported. A mechanism should update the value in its constructor if it is not supported. | |
| usedf | back to summary |
|---|---|
| protected boolean usedf Whether a derivation function is used. Requested in
| |
| AbstractDrbg | back to summary |
|---|---|
| protected AbstractDrbg() A constructor without argument so that an implementation does not
need to always write | |
| AbstractDrbg | back to summary |
|---|---|
| protected AbstractDrbg(SecureRandomParameters params) A mechanism shall override this constructor to set up
| |
| chooseAlgorithmAndStrength | back to summary |
|---|---|
| protected abstract void chooseAlgorithmAndStrength() Decides what algorithm and strength to use (SHA-256 or AES-256,
128 or 256). Strength related fields must also be defined or redefined
here. Called in
If
If
Since every call to
Here are some examples of the algorithm and strength chosen (suppose
requested effective (SHA-224, 256) IAE (SHA-256, -1) (SHA-256,128) (SHA-256, 112) (SHA-256,112) (SHA-256, 128) (SHA-256,128) (SHA-3, -1) IAE (null, -1) (SHA-256,128) (null, 112) (SHA-256,112) (null, 192) (SHA-256,192) (null, 256) (SHA-256,256) (null, 384) IAE
| |
| configure | back to summary |
|---|---|
| protected final void configure(SecureRandomParameters params) Configure this DRBG. This method calls
| |
| engineGenerateSeed | back to summary |
|---|---|
| public final byte[] engineGenerateSeed(int numBytes) Returns the given number of seed bytes. A DRBG always uses
The implementation is identical to SHA1PRNG's
| |
| engineGetParameters | back to summary |
|---|---|
| protected SecureRandomParameters engineGetParameters() Returns the current configuration as a
| |
| engineNextBytes | back to summary |
|---|---|
| protected final void engineNextBytes(byte[] result) | |
| engineNextBytes | back to summary |
|---|---|
| protected final void engineNextBytes(byte[] result, SecureRandomParameters params) | |
| engineReseed | back to summary |
|---|---|
| public final void engineReseed(SecureRandomParameters params) | |
| engineSetSeed | back to summary |
|---|---|
| public final synchronized void engineSetSeed(byte[] input) Reseeds this random object with the given seed. A DRBG always expands
or truncates the input to be between
| |
| generateAlgorithm | back to summary |
|---|---|
| protected abstract void generateAlgorithm(byte[] result, byte[] additionalInput) The generate function.
| |
| getEntropyInput | back to summary |
|---|---|
| private byte[] getEntropyInput(boolean isPr) | |
| getEntropyInput | back to summary |
|---|---|
| private byte[] getEntropyInput(int minEntropy, int minLength, int maxLength, boolean pr) | |
| getStandardStrength | back to summary |
|---|---|
| protected static int getStandardStrength(int input) Returns the smallest standard strength (112, 128, 192, 256) that is greater or equal to the input.
| |
| initEngine | back to summary |
|---|---|
| protected abstract void initEngine() Initiates security engines ( | |
| instantiateAlgorithm | back to summary |
|---|---|
| protected abstract void instantiateAlgorithm(byte[] ei) Instantiates a DRBG. Called automatically before the first
Note that the other parameters (nonce, strength, ps) are already stored inside at configuration. | |
| instantiateIfNecessary | back to summary |
|---|---|
| private synchronized void instantiateIfNecessary(byte[] entropy) Instantiate if necessary,
| |
| reseedAlgorithm | back to summary |
|---|---|
| protected void reseedAlgorithm(byte[] ei, byte[] additionalInput) The reseed function.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| Modifier and Type | Field and Description |
|---|---|
| private static final byte[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static synchronized byte[] |
| block | back to summary |
|---|---|
| private static final byte[] block | |
| NonceProvider | back to summary |
|---|---|
| private NonceProvider() | |
| next | back to summary |
|---|---|
| private static synchronized byte[] next() | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final EntropySource | prseeder
Default EntropySource for SecureRandom with prediction resistance, |
| pack-priv static final EntropySource |
| Access | Constructor and Description |
|---|---|
| private |
| prseeder | back to summary |
|---|---|
| pack-priv static final EntropySource prseeder Default EntropySource for SecureRandom with prediction resistance, | |
| seeder | back to summary |
|---|---|
| pack-priv static final EntropySource seeder Default EntropySource for SecureRandom without prediction resistance,
which is backed by a DRBG whose EntropySource is | |
| SeederHolder | back to summary |
|---|---|
| private SeederHolder() | |