Class HFunction.MacHFunction

  • All Implemented Interfaces:
    HFunction
    Enclosing interface:
    HFunction

    public static final class HFunction.MacHFunction
    extends Object
    implements HFunction
    HMAC implementation of the H function
    • Constructor Detail

      • MacHFunction

        public MacHFunction​(Mac mac)
    • Method Detail

      • init

        public void init​(byte[] key)
        Description copied from interface: HFunction
        Optional keying of the H function. This is not supported with hash type functions and may throw an UnsupportedOperationException. Call this before HFunction.update(byte[])
        Specified by:
        init in interface HFunction
        Parameters:
        key - to be used; if null is passed, default_salt is used, which is in the case of HMAC an empty byte array the length of the underyling hash function (e.g. 32 bytes for SHA-256)
      • requireInit

        public boolean requireInit()
        Description copied from interface: HFunction
        If the function requires a key to be provided in the HFunction.init(byte[])
        Specified by:
        requireInit in interface HFunction
        Returns:
        true if user must initialize with init()
      • getHFuncInputBlockLengthBytes

        public int getHFuncInputBlockLengthBytes()
        Description copied from interface: HFunction
        Formally: a positive integer that indicates the length of the input block size of the auxiliary function, H.

        The spec describes the length in bits, but for practical reasons it will return bytes.

        This is required to get the salt length of no salt is provided. See the definition in NIST SP 800-56C REV. 1, Table 2

        Specified by:
        getHFuncInputBlockLengthBytes in interface HFunction
        Returns:
        input block size length in byte (sha-256 is e.g. 64, sha-512: 128)
      • getHFuncOutputBytes

        public int getHFuncOutputBytes()
        Description copied from interface: HFunction
        Formally: a positive integer that indicates the length of the output of the auxiliary function, H, that is used to derive blocks of secret keying material.

        The spec describes the length in bits, but for practical reasons it will return bytes.

        Practically the length of output hash/hmac/kmac function. E.g. SHA-256 or HMAC_SHA-256 will output 32 byte long block.

        Specified by:
        getHFuncOutputBytes in interface HFunction
        Returns:
        output length in byte
      • update

        public void update​(byte[] array)
        Description copied from interface: HFunction
        Update the function with a new input that will internally add to the already available input
        Specified by:
        update in interface HFunction
        Parameters:
        array - to process
      • calculate

        public byte[] calculate()
        Description copied from interface: HFunction
        After adding the input through HFunction.update(byte[]) calculate the output of the H-function
        Specified by:
        calculate in interface HFunction
        Returns:
        output (usually a hash)
      • reset

        public void reset()
        Description copied from interface: HFunction
        Resets the function for further use.
        Specified by:
        reset in interface HFunction