HKDF (Expand Only) Key Derivation
When the key material is already good, just stretch it
- message
- info
- derived_key
HKDF has two phases - extract and expand - and HKDF_Derive does both. This node, HKDFExpand_Derive, does only the second one. It takes input that's already high-entropy and stretches it to the length you need. The "expand only" qualifier is the whole point: if your input is a genuinely random 32 bytes and you need a 32-byte key, expand-only is effectively a no-op with extra steps. But if you need a 64-byte key from a 32-byte random seed, or you want to mint several keys from one master by varying info, this is the node.
When to reach for it
The extraction step exists to scrub entropy out of weak, predictable input (passphrases, low-entropy secrets). If your input material is already good - a random seed, the output of a previous KDF, a hardware random value - the extract phase is wasted work and expand-only is the right call. The classic use: you have a high-entropy master key and want to derive multiple independent subkeys (an encryption key, an HMAC key, a signature key) by expanding the master with different info values. Same master, different info, different keys - that's what this node is for.
The inputs that matter
message(BYTESLIKE) - the pseudorandom key (PRK) to expand. The tooltip is honest: "The message to derive key from. Must be bytes."length- output size in bytes, 16–256, default 32.algorithm- the HMAC hash: SHA-2, SHA-3, BLAKE2, SHA1, MD5, SM3.SHA256covers everything sane.info(optional,BYTESLIKE) - the context label that lets you derive different keys from the same material. Leave it empty and it becomes an empty byte string, which means every expand of the same input gives the same output. Fill it in - "key #1", "key #2" - and you get distinct keys.
The output
derived_key(BYTESLIKE) - the expanded key, ready for a consumer that wants bytes.
Installing it
Part of the ComfyUI ARG Toolkit:
cd ComfyUI/custom_nodes
git clone https://github.com/AzelusLightvale/ComfyUI-ARG-Toolkit
Restart ComfyUI, or install via ComfyUI Manager ("ComfyUI ARG Toolkit") - cryptography provides the HKDFExpand implementation.
Where people get burned
- Using it on a weak secret. Expand-only assumes the input is already good. Feed it a low-entropy passphrase and you get a key that's no stronger than the passphrase - the extract step you skipped was the part that protected you. If your input might be guessable, use
HKDF_Derive(the full version) instead. - No
info, same key everywhere. Forgettinginfowhen you meant to derive multiple keys just gives you the same key repeated. That's not a bug - it's expand behaving exactly as specified. - Length out of range.
lengthis capped at 256 bytes here; ask for more and the dropdown won't let you (min 16, step 16).
The full HKDF node is the safe default for almost everyone. Reach for this one when you understand why you're skipping the extract - usually because the input is a random seed and you want to split it into multiple purpose-bound keys. It's the specialized tool in the pack's KDF drawer, and it does exactly one job well.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| length | INT | 3216–256 | The desired length of the derived key in bytes. |
| message | BYTESLIKE | The message to derive key from. Must be bytes. | |
| algorithm | COMBO | The algorithm to use for hash generation. | |
| infoopt | BYTESLIKE | Application-specific context information. If left empty, will pass an empty byte string. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| derived_key | BYTESLIKE | — |