com.ibm.crypto.fips.provider
Class HASHDRBG
- java.lang.Object
-
- java.security.SecureRandomSpi
-
- com.ibm.crypto.fips.provider.HASHDRBG
-
- All Implemented Interfaces:
- IHashDrbg, java.io.Serializable
public final class HASHDRBG extends java.security.SecureRandomSpi implements IHashDrbg
This class implements the HASH_DRBG algorithm found in NIST SP 800-90. It can use any of the SHA family as the underlying hash function, and can provide different security strengths based on the underlying hash algorithm. It will need entropy input of at least the "security strength" specified to seed it. If no seed is provided, we obtain one from CPUJitter, which uses a CPU Jitter for entropy. The known answer tests can be found in http://csrc.nist.gov/groups/STM/cavp/documents/drbg/drbgtestvectors.zip- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description protected byte[]
C
static java.lang.String
DEFAULT_DIGEST_ALG
static int
DEFAULT_STRENGTH
protected java.nio.ByteBuffer
entropy
protected java.security.MessageDigest
hash
protected java.lang.String
hashAlgName
protected boolean
initDone
static int
MAX_SEED_LENGTH
static int
MAX_STRENGTH
static int
MIN_SEED_LENGTH
static int
MIN_STRENGTH
protected long
reseed_counter
protected boolean
resistant
protected int
security_strength
protected int
seed_byte_count
static int
SHA1_MAX_STRENGTH
static int
SHA224_MAX_STRENGTH
protected CPUJitter
sr
protected int
ss_bytes
protected byte[]
V
-
Constructor Summary
Constructors Constructor and Description HASHDRBG()
Construct a hash-based deterministic random bit generator with the appropriate algorithm for this amount of strength.HASHDRBG(java.lang.String hashAlgorithm, int security_Strength)
Constructor for subclasses that wish to constrain choices, perhaps to fit in better with SecureRandomSpi.
-
Method Summary
Methods Modifier and Type Method and Description protected byte[]
engineGenerateSeed(int numBytes)
Part of SecureRandomSpi.protected void
engineNextBytes(byte[] bytes)
Part of SecureRandomSpi.protected void
engineSetSeed(byte[] seed)
Part of SecureRandomSpi.protected void
finalize()
This function zeroizes the class so that nothing is in memory when GC is done.byte[]
generate(int requested_no_of_bytes, boolean prediction_resistant_requested, byte[] additionalInput)
From section 10.1.1.4 of NIST SP 800-90int
init(java.lang.String algorithm, int bitStrengthRequested, java.nio.ByteBuffer entropySource, boolean predictionResistant)
Initialize with the name of a hash algorithm to use, the randomness strength requested, and a source of entropy.void
instantiate(byte[] nonce, byte[] personalization)
From NIST SP 800-90, Appendix F.1.1protected byte[]
internalGenerateSeed(int numBytes)
protected int
internalInit(java.lang.String algorithm, int bitStrengthRequested, java.nio.ByteBuffer entropySource, boolean predictionResistant)
protected void
internalNextBytes(byte[] bytes)
protected void
internalSetSeed(byte[] seed)
void
reseed(byte[] addlInput)
From NIST SP 800-90, Appendix F.1.2void
zeroize()
This function zeroizes the class so that nothing is in memory
-
-
-
Field Detail
-
MIN_STRENGTH
public static final int MIN_STRENGTH
- See Also:
- Constant Field Values
-
MAX_STRENGTH
public static final int MAX_STRENGTH
- See Also:
- Constant Field Values
-
SHA1_MAX_STRENGTH
public static final int SHA1_MAX_STRENGTH
- See Also:
- Constant Field Values
-
SHA224_MAX_STRENGTH
public static final int SHA224_MAX_STRENGTH
- See Also:
- Constant Field Values
-
MIN_SEED_LENGTH
public static final int MIN_SEED_LENGTH
- See Also:
- Constant Field Values
-
MAX_SEED_LENGTH
public static final int MAX_SEED_LENGTH
- See Also:
- Constant Field Values
-
DEFAULT_DIGEST_ALG
public static final java.lang.String DEFAULT_DIGEST_ALG
- See Also:
- Constant Field Values
-
DEFAULT_STRENGTH
public static final int DEFAULT_STRENGTH
- See Also:
- Constant Field Values
-
hashAlgName
protected java.lang.String hashAlgName
-
security_strength
protected int security_strength
-
ss_bytes
protected int ss_bytes
-
seed_byte_count
protected int seed_byte_count
-
entropy
protected java.nio.ByteBuffer entropy
-
hash
protected java.security.MessageDigest hash
-
V
protected byte[] V
-
C
protected byte[] C
-
reseed_counter
protected long reseed_counter
-
sr
protected CPUJitter sr
-
resistant
protected boolean resistant
-
initDone
protected boolean initDone
-
-
Constructor Detail
-
HASHDRBG
public HASHDRBG()
Construct a hash-based deterministic random bit generator with the appropriate algorithm for this amount of strength.- Parameters:
security_Strength
-- See Also:
SP 800-57A for current values. The number passed in at initialization time will determine the length of entropy data needed.
At time of writing, NIST SP 800-57A included 80 bits, which NIST SP 800-90 omits. The remaining supported strengths are:
- 112 bits
- SHA1
- SHA224
- SHA256
- SHA392
- SHA512
- 128 bits
- SHA1
- SHA224
- SHA256
- SHA392
- SHA512
- 192 bits
- SHA224
- SHA256
- SHA392
- SHA512
- 256 bits
- SHA256
- SHA392
- SHA512
- 112 bits
-
HASHDRBG
public HASHDRBG(java.lang.String hashAlgorithm, int security_Strength)
Constructor for subclasses that wish to constrain choices, perhaps to fit in better with SecureRandomSpi.- Parameters:
hashAlgorithm
-security_Strength
-
-
-
Method Detail
-
engineGenerateSeed
protected byte[] engineGenerateSeed(int numBytes)
Part of SecureRandomSpi.- Specified by:
engineGenerateSeed
in classjava.security.SecureRandomSpi
-
internalGenerateSeed
protected byte[] internalGenerateSeed(int numBytes)
-
engineNextBytes
protected void engineNextBytes(byte[] bytes)
Part of SecureRandomSpi.- Specified by:
engineNextBytes
in classjava.security.SecureRandomSpi
-
internalNextBytes
protected void internalNextBytes(byte[] bytes)
-
engineSetSeed
protected void engineSetSeed(byte[] seed)
Part of SecureRandomSpi. If instantiating, the first part of the seed is the entropy, and if there is anything left, it is treated as the nonce. If already instantiated, then this is interpreted as a reseed call, otherwise the data layout is treated same as instantiation.- Specified by:
engineSetSeed
in classjava.security.SecureRandomSpi
-
internalSetSeed
protected void internalSetSeed(byte[] seed)
-
init
public int init(java.lang.String algorithm, int bitStrengthRequested, java.nio.ByteBuffer entropySource, boolean predictionResistant) throws java.lang.IllegalArgumentException
Initialize with the name of a hash algorithm to use, the randomness strength requested, and a source of entropy.- Specified by:
init
in interfaceIHashDrbg
- Parameters:
algorithm
-bitStrengthRequested
-entropySource
- may be null, if will drive with SecureRandomSpipredictionResistant
- whether additional entropy will be supplied through the entropySource before generate operations- Returns:
- the number of bits of security strength the DRBG will provide (and the entropy the caller must supply through entropySource (if supplied by caller))
- Throws:
java.lang.IllegalArgumentException
- See Also:
3 of NIST SP800-57 Part1, for Hash function security strengths
-
internalInit
protected int internalInit(java.lang.String algorithm, int bitStrengthRequested, java.nio.ByteBuffer entropySource, boolean predictionResistant) throws java.lang.IllegalArgumentException
- Parameters:
algorithm
-bitStrengthRequested
-entropySource
-predictionResistant
-- Returns:
- Throws:
java.lang.IllegalArgumentException
-
instantiate
public void instantiate(byte[] nonce, byte[] personalization)
From NIST SP 800-90, Appendix F.1.1- Specified by:
instantiate
in interfaceIHashDrbg
- Parameters:
nonce
- caller-supplied nonce (optional, may be NULL)personalization
- caller-supplied personalization data (optional, may be NULL) From NIST SP 800-90, Section 10.1.1.2
-
generate
public byte[] generate(int requested_no_of_bytes, boolean prediction_resistant_requested, byte[] additionalInput)
From section 10.1.1.4 of NIST SP 800-90
-
reseed
public void reseed(byte[] addlInput)
From NIST SP 800-90, Appendix F.1.2
-
zeroize
public void zeroize()
This function zeroizes the class so that nothing is in memory
-
finalize
protected void finalize()
This function zeroizes the class so that nothing is in memory when GC is done.- Overrides:
finalize
in classjava.lang.Object
-
-