In the Extract and Extract-then-Expand cases, users may call the addIKM and/or addSalt methods repeatedly (and chain these calls).
This provides for use-cases where a portion of the input keying material
(IKM) resides in a non-extractable SecretKey and the whole IKM
cannot be provided as a single object. The same feature is available for
salts.
The above feature is particularly useful for "labeled" HKDF Extract used in TLS 1.3 and HPKE, where the IKM consists of concatenated components, which may include both byte arrays and (possibly non-extractable) secret keys.
Examples:
// this usage depicts the initialization of an HKDF-Extract // AlgorithmParameterSpec AlgorithmParameterSpec derivationSpec = HKDFParameterSpec.ofExtract() .addIKM(label) .addIKM(ikm) .addSalt(salt).extractOnly();
// this usage depicts the initialization of an HKDF-Expand // AlgorithmParameterSpec AlgorithmParameterSpec derivationSpec = HKDFParameterSpec.expandOnly(prk, info, 32);
// this usage depicts the initialization of an HKDF-ExtractExpand // AlgorithmParameterSpec AlgorithmParameterSpec derivationSpec = HKDFParameterSpec.ofExtract() .addIKM(ikm) .addSalt(salt).thenExpand(info, 32);
javax.crypto.KDF
| Modifier and Type | Class and Description |
|---|---|
| public static class | HKDFParameterSpec.
This |
| public static class | HKDFParameterSpec.
Defines the input parameters of an Expand operation as defined in RFC 5869. |
| public static class | HKDFParameterSpec.
Defines the input parameters of an Extract operation as defined in RFC 5869. |
| public static class | HKDFParameterSpec.
Defines the input parameters of an Extract-then-Expand operation as defined in RFC 5869. |
| Modifier and Type | Method and Description |
|---|---|
| public static HKDFParameterSpec. | Returns: anExpand objectthe pseudorandom key (PRK); must not be prk, byte[] nullthe optional context and application specific information (may be
info, int null); the byte array is cloned to prevent subsequent
modificationthe length of the output keying material (must be greater than
0) length)Creates an |
| public static HKDFParameterSpec. | Returns: a newBuilderReturns a |
| expandOnly | back to summary |
|---|---|
| public static HKDFParameterSpec. Creates an Implementation Note HKDF implementations will enforce that the length is
not greater than 255 * HMAC length. Implementations will also
enforce that the prk argument is at least as many bytes as the
HMAC length. Implementations will also enforce that a
| |
| ofExtract | back to summary |
|---|---|
| public static HKDFParameterSpec. Returns a
| |
Builder builds Extract and ExtractThenExpand
objects.
The Builder is initialized via the ofExtract method of
HKDFParameterSpec. As stated in the class description,
addIKM and/or addSalt may be called as needed. Finally,
an object is "built" by calling either extractOnly or
thenExpand for Extract and ExtractThenExpand
use-cases respectively. Note that the Builder is not
thread-safe.
| Modifier and Type | Field and Description |
|---|---|
| private List | |
| private List |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public HKDFParameterSpec. | |
| public HKDFParameterSpec. | Returns: this builderthe input keying material (IKM) value; the ikm)ikm
byte array will be converted to a SecretKeySpec,
which means that the byte array will be cloned inside the
SecretKeySpec constructorAdds input keying material (IKM) to the builder. |
| public HKDFParameterSpec. | |
| public HKDFParameterSpec. | Returns: this builderthe salt value; the salt)salt byte array will be
converted to a SecretKeySpec, which means that the
byte array will be cloned inside the SecretKeySpec
constructorAdds a salt to the builder. |
| public HKDFParameterSpec. | Returns: an immutableExtract objectBuilds an |
| public HKDFParameterSpec. | Returns: an immutableExtractThenExpand objectthe optional context and application specific information
(may be info, int null); the byte array is cloned to prevent
subsequent modificationthe length of the output keying material (must be greater
than 0) length)Builds an |
| ikms | back to summary |
|---|---|
| private List<SecretKey> ikms | |
| salts | back to summary |
|---|---|
| private List<SecretKey> salts | |
| Builder | back to summary |
|---|---|
| private Builder() | |
| addIKM | back to summary |
|---|---|
| public HKDFParameterSpec. Adds input keying material (IKM) to the builder.
Users may call
| |
| addIKM | back to summary |
|---|---|
| public HKDFParameterSpec. Adds input keying material (IKM) to the builder. Note that an
Users may call
| |
| addSalt | back to summary |
|---|---|
| public HKDFParameterSpec. Adds a salt to the builder.
Users may call
| |
| addSalt | back to summary |
|---|---|
| public HKDFParameterSpec. Adds a salt to the builder. Note that a
Users may call
| |
| extractOnly | back to summary |
|---|---|
| public HKDFParameterSpec. Builds an
| |
| thenExpand | back to summary |
|---|---|
| public HKDFParameterSpec. Builds an Implementation Note HKDF implementations will enforce that the length
is not greater than 255 * HMAC length. HKDF implementations
will also enforce that a
| |
| Modifier and Type | Field and Description |
|---|---|
| private final byte[] | |
| private final int | |
| private final SecretKey |
| Access | Constructor and Description |
|---|---|
| private | Expand(SecretKey
the pseudorandom key (PRK); in the case of
prk, byte[] ExtractThenExpand, the prk argument may be
null since the output of extract phase is usedthe optional context and application specific information
(may be info, int null); the byte array is cloned to prevent
subsequent modificationthe length of the output keying material length)Constructor that may be used to initialize an |
| Modifier and Type | Method and Description |
|---|---|
| public byte[] | Returns: a clone of the optional context and application specific information, ornull if not specifiedReturns the optional context and application specific information. |
| public int | Returns: the length of the output keying materialReturns the length of the output keying material. |
| public SecretKey |
| info | back to summary |
|---|---|
| private final byte[] info | |
| length | back to summary |
|---|---|
| private final int length | |
| prk | back to summary |
|---|---|
| private final SecretKey prk | |
| Expand | back to summary |
|---|---|
| private Expand(SecretKey prk, byte[] info, int length) Constructor that may be used to initialize an
| |
| info | back to summary |
|---|---|
| public byte[] info() Returns the optional context and application specific information.
| |
| length | back to summary |
|---|---|
| public int length() Returns the length of the output keying material.
| |
| prk | back to summary |
|---|---|
| public SecretKey prk() Returns the pseudorandom key (PRK).
| |
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private final List |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: the unmodifiableList of input keying material
valuesReturns an unmodifiable |
| public List | Returns: the unmodifiableList of salt valuesReturns an unmodifiable |
| ikms | back to summary |
|---|---|
| private final List<SecretKey> ikms | |
| salts | back to summary |
|---|---|
| private final List<SecretKey> salts | |
| Extract | back to summary |
|---|---|
| private Extract(List<SecretKey> ikms, List<SecretKey> salts) | |
| ikms | back to summary |
|---|---|
| public List Returns an unmodifiable
Input keying material values added by Implementation Note An HKDF implementation should concatenate the input keying materials into a single value to be used in HKDF-Extract. | |
| salts | back to summary |
|---|---|
| public List Returns an unmodifiable
Salt values added by Implementation Note An HKDF implementation should concatenate the salts into a single value to be used in HKDF-Extract. | |
| Modifier and Type | Field and Description |
|---|---|
| private final HKDFParameterSpec. | |
| private final HKDFParameterSpec. |
| Access | Constructor and Description |
|---|---|
| private | ExtractThenExpand(HKDFParameterSpec.
a pre-generated ext,Extractthe optional context and application specific information
(may be info, int null); the byte array is cloned to prevent
subsequent modificationthe length of the output keying material length)Constructor that may be used to initialize an
|
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: the unmodifiableList of input keying material
valuesReturns an unmodifiable |
| public byte[] | Returns: a clone of the optional context and application specific information, ornull if not specifiedReturns the optional context and application specific information. |
| public int | Returns: the length of the output keying materialReturns the length of the output keying material. |
| public List | Returns: the unmodifiableList of salt valuesReturns an unmodifiable |
| exp | back to summary |
|---|---|
| private final HKDFParameterSpec. | |
| ext | back to summary |
|---|---|
| private final HKDFParameterSpec. | |
| ExtractThenExpand | back to summary |
|---|---|
| private ExtractThenExpand(HKDFParameterSpec. Constructor that may be used to initialize an
| |
| ikms | back to summary |
|---|---|
| public List Returns an unmodifiable
Input keying material values added by Implementation Note An HKDF implementation should concatenate the input keying materials into a single value to be used in the HKDF-Extract phase. | |
| info | back to summary |
|---|---|
| public byte[] info() Returns the optional context and application specific information.
| |
| length | back to summary |
|---|---|
| public int length() Returns the length of the output keying material.
| |
| salts | back to summary |
|---|---|
| public List Returns an unmodifiable
Salt values added by Implementation Note An HKDF implementation should concatenate the salts into a single value to be used in the HKDF-Extract phase. | |