Package at.favre.lib.crypto.singlstepkdf
Interface HFunction
-
- All Known Implementing Classes:
HFunction.MacHFunction,HFunction.MessageDigestHFunction
public interface HFunctionThe auxiliary function used to produce blocks of keying material during the execution of the one-step key-derivation method. Basically an abstraction of eitherMessageDigestorMacOptions for the Auxiliary Function H:
- hash(x), where hash is an approved hash function
- HMAC-hash(salt, x), where HMAC-hash is an implementation of the HMAC algorithm
- KMAC#(salt, x, H_outputBits, S), where KMAC# is a particular implementation of either KMAC128 or KMAC256
An example on how to use a H-function
final HFunction func = factory.createInstance(); final int inputBlockLength = func.getHFuncInputBlockLengthBytes(); byte[] out = new byte[hashLength]; func.update(keyData); out = func.calculate()
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classHFunction.MacHFunctionHMAC implementation of the H functionstatic classHFunction.MessageDigestHFunctionHash implementation of the H function.static classHFunction.Util
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte[]calculate()After adding the input throughupdate(byte[])calculate the output of the H-functionintgetHFuncInputBlockLengthBytes()Formally: a positive integer that indicates the length of the input block size of the auxiliary function, H.intgetHFuncOutputBytes()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.voidinit(byte[] key)Optional keying of the H function.booleanrequireInit()If the function requires a key to be provided in theinit(byte[])voidreset()Resets the function for further use.voidupdate(byte[] array)Update the function with a new input that will internally add to the already available input
-
-
-
Method Detail
-
init
void init(byte[] key)
Optional keying of the H function. This is not supported with hash type functions and may throw anUnsupportedOperationException. Call this beforeupdate(byte[])- 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
boolean requireInit()
If the function requires a key to be provided in theinit(byte[])- Returns:
- true if user must initialize with init()
-
getHFuncInputBlockLengthBytes
int getHFuncInputBlockLengthBytes()
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
- Returns:
- input block size length in byte (sha-256 is e.g. 64, sha-512: 128)
-
getHFuncOutputBytes
int getHFuncOutputBytes()
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.
- Returns:
- output length in byte
-
update
void update(byte[] array)
Update the function with a new input that will internally add to the already available input- Parameters:
array- to process
-
calculate
byte[] calculate()
After adding the input throughupdate(byte[])calculate the output of the H-function- Returns:
- output (usually a hash)
-
reset
void reset()
Resets the function for further use.
-
-