HKDF follows the "extract-then-expand" paradigm, where the KDF logically consists of two modules. The first stage takes the input keying material and "extracts" from it a fixed-length pseudorandom key K. The second stage "expands" the key K into several additional pseudorandom keys (the output of the KDF).
HKDF was first described by Hugo Krawczyk.
This implementation is thread safe without the need for synchronization.
Simple Example:
byte[] pseudoRandomKey = HKDF.fromHmacSha256().extract(null, lowEntropyInput);
byte[] outputKeyingMaterial = HKDF.fromHmacSha256().expand(pseudoRandomKey, null, 64);
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private static HKDF | hkdfHmacSha256
Cache instances |
| private static HKDF | |
| private final HkdfMacFactory |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public byte[] | Returns: new byte array of output keying material (OKM)a pseudo random key of at least hmac hash length in bytes (usually, the output from the extract step) pseudoRandomKey, byte[] optional context and application specific information; may be null info, int length of output keying material in bytes outLengthBytes)Step 2 of RFC 5869 (Section 2.3) To "expand" the generated output of an already reasonably random input such as an existing shared key into a larger cryptographically independent output, thereby producing multiple keys deterministically from that initial shared key, so that the same process may produce those same secret keys safely on multiple devices, as long as the same inputs are used. |
| public byte[] | Returns: new byte array of output keying material (OKM)a pseudo random key of at least hmac hash length in bytes (usually, the output from the extract step) pseudoRandomKey, byte[] optional context and application specific information; may be null info, int length of output keying material in bytes outLengthBytes)Use this if you require |
| public byte[] | Returns: a new byte array pseudo random key (of hash length in bytes) (PRK) which can be used to expandoptional salt value (a non-secret random value) (can be null)
if not provided, it is set to an array of hash length of zeros. salt, byte[] data to be extracted (IKM) inputKeyingMaterial)Step 1 of RFC 5869 (Section 2.2) The first stage takes the input keying material and "extracts" from it a fixed-length pseudorandom key K. |
| public byte[] | Returns: a new byte array pseudo random key (of hash length in bytes) (PRK) which can be used to expandoptional salt value (a non-secret random value) (can be null) salt, byte[] data to be extracted (IKM) inputKeyingMaterial)Use this if you require |
| public byte[] | Returns: new byte array of output keying material (OKM)optional salt value (a non-secret random value); saltExtract, byte[] data to be extracted (IKM) inputKeyingMaterial, byte[] optional context and application specific information; may be null infoExpand, int length of output keying material in bytes outLengthByte)Convenience method for extract & expand in a single method |
| public byte[] | Returns: new byte array of output keying material (OKM)optional salt value (a non-secret random value); saltExtract, byte[] data to be extracted (IKM) inputKeyingMaterial, byte[] optional context and application specific information; may be null infoExpand, int length of output keying material in bytes outLengthByte)Convenience method for extract & expand in a single method |
| public static HKDF | Returns: a new instance of HKDFused for HKDF macFactory)Create a new HKDF instance for given macFactory. |
| public static HKDF | |
| public static HKDF | |
| pack-priv HkdfMacFactory |
| hkdfHmacSha256 | back to summary |
|---|---|
| private static HKDF hkdfHmacSha256 Cache instances | |
| hkdfHmacSha512 | back to summary |
|---|---|
| private static HKDF hkdfHmacSha512 | |
| macFactory | back to summary |
|---|---|
| private final HkdfMacFactory macFactory | |
| HKDF | back to summary |
|---|---|
| private HKDF(HkdfMacFactory macFactory) | |
| expand | back to summary |
|---|---|
| public byte[] expand(byte[] pseudoRandomKey, byte[] info, int outLengthBytes) Step 2 of RFC 5869 (Section 2.3) To "expand" the generated output of an already reasonably random input such as an existing shared key into a larger cryptographically independent output, thereby producing multiple keys deterministically from that initial shared key, so that the same process may produce those same secret keys safely on multiple devices, as long as the same inputs are used. About Info (from RFC 5869): While the 'info' value is optional in the definition of HKDF, it is often of great importance in applications. Its main objective is to bind the derived key material to application- and context-specific information. For example, 'info' may contain a protocol number, algorithm identifiers, user identities, etc. In particular, it may prevent the derivation of the same keying material for different contexts (when the same input key material (IKM) is used in such different contexts).
| |
| expand | back to summary |
|---|---|
| public byte[] expand(SecretKey pseudoRandomKey, byte[] info, int outLengthBytes) Use this if you require
See
| |
| extract | back to summary |
|---|---|
| public byte[] extract(byte[] salt, byte[] inputKeyingMaterial) Step 1 of RFC 5869 (Section 2.2) The first stage takes the input keying material and "extracts" from it a fixed-length pseudorandom key K. The goal of the "extract" stage is to "concentrate" and provide a more uniformly unbiased and higher entropy but smaller output. This is done by utilising the diffusion properties of cryptographic MACs. About Salts (from RFC 5869): HKDF is defined to operate with and without random salt. This is done to accommodate applications where a salt value is not available. We stress, however, that the use of salt adds significantly to the strength of HKDF, ensuring independence between different uses of the hash function, supporting "source-independent" extraction, and strengthening the analytical results that back the HKDF design.
| |
| extract | back to summary |
|---|---|
| public byte[] extract(SecretKey salt, byte[] inputKeyingMaterial) Use this if you require
See
| |
| extractAndExpand | back to summary |
|---|---|
| public byte[] extractAndExpand(byte[] saltExtract, byte[] inputKeyingMaterial, byte[] infoExpand, int outLengthByte) Convenience method for extract & expand in a single method
| |
| extractAndExpand | back to summary |
|---|---|
| public byte[] extractAndExpand(SecretKey saltExtract, byte[] inputKeyingMaterial, byte[] infoExpand, int outLengthByte) Convenience method for extract & expand in a single method
| |
| from | back to summary |
|---|---|
| public static HKDF from(HkdfMacFactory macFactory) Create a new HKDF instance for given macFactory.
| |
| fromHmacSha256 | back to summary |
|---|---|
| public static HKDF fromHmacSha256() Return a shared instance using HMAC with Sha256. Even though shared, this instance is thread-safe.
| |
| fromHmacSha512 | back to summary |
|---|---|
| public static HKDF fromHmacSha512() Return a shared instance using HMAC with Sha512. Even though shared, this instance is thread-safe.
| |
| getMacFactory | back to summary |
|---|---|
| pack-priv HkdfMacFactory getMacFactory() Get the used mac factory
| |
| Modifier and Type | Field and Description |
|---|---|
| private final HkdfMacFactory |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv byte[] | Returns: new byte array of output keying material (OKM)a pseudorandom key of at least hmac hash length in bytes (usually, the output from the extract step) pseudoRandomKey, byte[] optional context and application specific information; may be null info, int length of output keying material in bytes (must be <= 255 * mac hash length) outLengthBytes)Step 2 of RFC 5869. |
| macFactory | back to summary |
|---|---|
| private final HkdfMacFactory macFactory | |
| Expander | back to summary |
|---|---|
| pack-priv Expander(HkdfMacFactory macFactory) | |
| execute | back to summary |
|---|---|
| pack-priv byte[] execute(SecretKey pseudoRandomKey, byte[] info, int outLengthBytes) Step 2 of RFC 5869.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final HkdfMacFactory |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv byte[] | Returns: a new byte array pseudorandom key (of hash length in bytes) (PRK) which can be used to expandoptional salt value (a non-secret random value);
if not provided, it is set to an array of hash length of zeros. salt, byte[] data to be extracted (IKM) inputKeyingMaterial)Step 1 of RFC 5869 |
| macFactory | back to summary |
|---|---|
| private final HkdfMacFactory macFactory | |
| Extractor | back to summary |
|---|---|
| pack-priv Extractor(HkdfMacFactory macFactory) | |
| execute | back to summary |
|---|---|
| pack-priv byte[] execute(SecretKey salt, byte[] inputKeyingMaterial) Step 1 of RFC 5869
| |