OPENSSL-KDF(1ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… openssl-kdf β€” like, the whole KDF situation, explained

Hey bestie 🫢 so you're reading the openssl-kdf page from the 1ossl manual β€” that's the one you want. Welcome. This is the command that does Key Derivation Function operations. Which is basically: take a secret (or a password), wave a cryptographic wand at it, and get a shiny brand-new key out the other side. Slay. ✨


✨ SYNOPSIS ✨

openssl kdf [-help] [-cipher] [-digest] [-mac] [-kdfopt nm:v] [-keylen
num] [-out filename] [-binary] [-provider name] [-provider-path path]
[-provparam [name:]key=value] [-propquery propq] kdf_name

🌸 DESCRIPTION 🌸

Okay so, the key derivation functions obviously derive a key. Where from? Either from a secret or from a password. That's it, that's the whole vibe check πŸ’–


πŸŽ€ OPTIONS πŸŽ€

  • -help β€” prints a usage message. You know her. You love her. She's the "wait what were the flags again" flag πŸ™ˆ
  • -keylen num β€” the output size of the derived key. This field is required, no cap, you literally cannot skip it πŸ‘‘
  • -out filename β€” the file you're dumping output into. Don't give it one and it just goes to standard output, the default bestie ✨
  • -binary β€” outputs the derived key in binary form. Skip this and you get hexadecimal text format instead. Choose your fighter πŸ’…
  • -cipher name β€” specifies the cipher the KDF should use. Not all KDFs need a cipher, and using this option on one of those is an error. Read the room, girl 😭
  • -digest name β€” specifies the digest the KDF should use. Same deal: not all KDFs need a digest, and passing it anyway is an error. Wanna see what digests you actually have? Run "openssl list -digest-commands" πŸ¦‹
  • -mac name β€” specifies the MAC the KDF should use. And yes, same energy as the last two: not all KDFs require a MAC, and it's an error to use this option in those cases πŸ’€
  • -kdfopt nm:v β€” passes options through to the KDF algorithm. There's a comprehensive list of parameters over in "PARAMETERS" in EVP_KDF(3). The common parameter names that EVP_KDF_CTX_set_params() uses are:
    • key:string β€” specifies the secret key as an alphanumeric string (so use this only if the key is printable characters only). The string length has to conform to whatever restrictions the KDF algorithm has. Most KDF algorithms want a key specified πŸ”‘
    • hexkey:string β€” the alternative to the key: option, where the secret key is given in hexadecimal form (two hex digits per byte).
    • pass:string β€” specifies the password as an alphanumeric string (use it if the password is printable characters only). The password must be specified for PBKDF2 and scrypt πŸ”₯
    • hexpass:string β€” alternative to the pass: option where the password is specified in hexadecimal form (two hex digits per byte).
    • salt:string β€” specifies a non-secret unique cryptographic salt as an alphanumeric string (use if it contains printable characters only). The length must conform to any restrictions of the KDF algorithm. A salt parameter is required for several KDF algorithms, like EVP_KDF-PBKDF2(7) πŸ§‚
    • hexsalt:string β€” alternative to the salt: option where the salt is specified in hexadecimal form (two hex digits per byte).
    • info:string β€” some KDF implementations, like EVP_KDF-HKDF(7), take an 'info' parameter for binding the derived key material to application- and context-specific information. This specifies the info, fixed info, other info or shared info argument as an alphanumeric string (use if it contains printable characters only). The length must conform to any restrictions of the KDF algorithm.
    • hexinfo:string β€” alternative to the info: option where the info is specified in hexadecimal form (two hex digits per byte).
    • digest:string β€” this option is identical to the -digest option.
    • cipher:string β€” this option is identical to the -cipher option.
    • mac:string β€” this option is identical to the -mac option.
  • -provider name
  • -provider-path path
  • -provparam [name:]key=value
  • -propquery propq β€” all four of these cuties go see "Provider Options" in openssl(1), provider(7), and property(7). Go read those, iykyk πŸ’œ
  • kdf_name β€” specifies the name of a supported KDF algorithm that's gonna get used. The supported algorithm names include TLS1-PRF, HKDF, SSKDF, PBKDF2, SSHKDF, X942KDF-ASN1, X942KDF-CONCAT, X963KDF and SCRYPT. Pick one, bestie, she's waiting πŸ‘‘

πŸ¦‹ EXAMPLES πŸ¦‹

Not me giving you a whole demo reel πŸ’– here's every single one, verbatim, because they're all iconic:

TLS1-PRF to create a hex-encoded derived key from a secret key and seed:

openssl kdf -keylen 16 -kdfopt digest:SHA2-256 -kdfopt key:secret \
            -kdfopt seed:seed TLS1-PRF

HKDF to create a hex-encoded derived key from a secret key, salt and info:

openssl kdf -keylen 10 -kdfopt digest:SHA2-256 -kdfopt key:secret \
            -kdfopt salt:salt -kdfopt info:label HKDF

SSKDF with KMAC to create a hex-encoded derived key from a secret key, salt and info:

openssl kdf -keylen 64 -kdfopt mac:KMAC-128 -kdfopt maclen:20 \
            -kdfopt hexkey:b74a149a161545 -kdfopt hexinfo:348a37a2 \
            -kdfopt hexsalt:3638271ccd68a2 SSKDF

SSKDF with HMAC to create a hex-encoded derived key from a secret key, salt and info:

openssl kdf -keylen 16 -kdfopt mac:HMAC -kdfopt digest:SHA2-256 \
            -kdfopt hexkey:b74a149a -kdfopt hexinfo:348a37a2 \
            -kdfopt hexsalt:3638271c SSKDF

SSKDF with Hash to create a hex-encoded derived key from a secret key, salt and info:

openssl kdf -keylen 14 -kdfopt digest:SHA2-256 \
            -kdfopt hexkey:6dbdc23f045488 \
            -kdfopt hexinfo:a1b2c3d4 SSKDF

SSHKDF to create a hex-encoded derived key from a secret key, hash and session_id:

openssl kdf -keylen 16 -kdfopt digest:SHA2-256 \
            -kdfopt hexkey:0102030405 \
            -kdfopt hexxcghash:06090A \
            -kdfopt hexsession_id:01020304 \
            -kdfopt type:A SSHKDF

PBKDF2 to create a hex-encoded derived key from a password and salt:

openssl kdf -keylen 32 -kdfopt digest:SHA256 -kdfopt pass:password \
            -kdfopt salt:salt -kdfopt iter:2 PBKDF2

scrypt to create a hex-encoded derived key from a password and salt:

openssl kdf -keylen 64 -kdfopt pass:password -kdfopt salt:NaCl \
            -kdfopt n:1024 -kdfopt r:8 -kdfopt p:16 \
            -kdfopt maxmem_bytes:10485760 SCRYPT

⭐ NOTES ⭐

The KDF mechanisms that are available will depend on the options used when building OpenSSL. So like, your build might not have everything. It's giving "depends on your config" πŸ’…


🌈 SEE ALSO 🌈

openssl(1), openssl-pkeyutl(1), EVP_KDF(3), EVP_KDF-SCRYPT(7), EVP_KDF-TLS1_PRF(7), EVP_KDF-PBKDF2(7), EVP_KDF-HKDF(7), EVP_KDF-SS(7), EVP_KDF-SSHKDF(7), EVP_KDF-X942-ASN1(7), EVP_KDF-X942-CONCAT(7), EVP_KDF-X963(7)

Go read them all, bestie, they're literally the whole lore 🫢


πŸ’€ HISTORY πŸ’€

Added in OpenSSL 3.0. Ancient history at this point, but we respect the origin story πŸ‘‘


Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


Okay that's the whole page, bestie β€” go derive some keys, you absolute main character πŸ”₯

Source: OpenSSL 3.5.6, dated 2026-04-07. Manual page OPENSSL-KDF(1ossl) signing off πŸ’–βœ¨

πŸ“¦ where this page comes from