X963KDF Key Derivation
The node that turns a shared secret into an actual encryption key
- message
- info
- derived_key
Here's the thing nobody tells you about Diffie-Hellman: the shared secret that comes out of the exchange is a big random number, and you can't just hand it to AES and expect it to work. You need a key derivation function (KDF) to stretch and shape it into a proper key. That's what this node is for. It's part of the ComfyUI ARG Toolkit's "Modern Cryptography" section, and it implements the ANSI X9.63 KDF - the same scheme the EC crypto standards use when they derive keys from a shared secret, and structurally a cousin of the ConcatKDF hash family. I verified the derive path against the underlying cryptography library and it behaves exactly as advertised.
The inputs are unglamorous but precise:
- message - the thing you derive from, in the pack's
BYTESLIKEtype. For this to make sense, it's usually theshared_keyoutput of the pack's ECDH XExchange node. It must be bytes, not a string. - length - the derived key length in bytes. Default 32 (256 bits, which is what AES-256 wants), adjustable from 16 to 256 in steps of 16.
- algorithm - the hash function. The dropdown has 15 options covering the SHA-2 and SHA-3 families, BLAKE2b, BLAKE2s, and a couple of curiosities like SM3 and MD5. SHA-256 is the boring, correct default for basically everything.
- info - optional application-specific context bytes. If you leave it empty it passes an empty byte string; if you use it, both the derive and verify sides must feed in the identical value or the keys won't match.
Output is a single derived_key in BYTESLIKE. You'll feed it into the pack's symmetric encryption or Fernet nodes, or export it to a readable form with the pack's ByteslikeDecode converter.
The one thing the author's own docs stress, and you should too: this KDF is not for password hashing. X9.63 KDF is fast by design, which is the opposite of what you want when protecting a password - that's what scrypt/argon2 are for (the pack has those too, in the same Key Derivation folder). Use this node to turn a high-entropy shared secret into a key; never use it to hash "hunter2".
A note on the BYTESLIKE type, because it trips everyone: it's the pack's custom wire type, so you can't just type bytes into the box. You need a source node - feed message from XExchange's shared_key output, or use ByteslikeEncode (set to Raw Bytes or UTF-8) to turn text into bytes if you're just testing with a literal. info is the same way.
Install is standard for the pack: ComfyUI Manager → search "ComfyUI ARG Toolkit" → install → restart, or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/AzelusLightvale/ComfyUI-ARG-Toolkit
# restart ComfyUI
The pack is one-author and GPLv3, and it leans on the cryptography library for this node - no exotic deps here beyond the pack's usual haul (secretpy, stegano, invisible-watermark, reedsolo, plus the torch/opencv that watermarking drags in). The README is candid that it's an amateur project with tests covering only common cases, so the modern-crypto nodes are exactly where you should double-check before trusting them with anything real. This one checks out, but it's still a toy for learning and ARGs, not a production HSM.
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 | — |