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
    • 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-90
      int 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.1
      protected 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.2
      void zeroize()
      This function zeroizes the class so that nothing is in memory
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_DIGEST_ALG

        public static final java.lang.String DEFAULT_DIGEST_ALG
        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
      • 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
      • 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 class java.security.SecureRandomSpi
      • internalGenerateSeed

        protected byte[] internalGenerateSeed(int numBytes)
      • engineNextBytes

        protected void engineNextBytes(byte[] bytes)
        Part of SecureRandomSpi.
        Specified by:
        engineNextBytes in class java.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 class java.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 interface IHashDrbg
        Parameters:
        algorithm -
        bitStrengthRequested -
        entropySource - may be null, if will drive with SecureRandomSpi
        predictionResistant - 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 interface IHashDrbg
        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
        Specified by:
        generate in interface IHashDrbg
        Parameters:
        requested_no_of_bytes -
        requested_security_strength -
        prediction_resistant -
        additionalInput -
        Returns:
        bytes generated
      • reseed

        public void reseed(byte[] addlInput)
        From NIST SP 800-90, Appendix F.1.2
        Specified by:
        reseed in interface IHashDrbg
      • 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 class java.lang.Object
© Portions Copyright 2003, 2014, 2015, 2016 IBM Corporation. All rights reserved.
© Portions Copyright 2003, 2014 Oracle and/or its affiliates. All rights reserved.