Key derivation function (KDF)
A key derivation function (KDF) produces cryptographic keys from a secret input (such as a password or shared secret). It adds structure, salts, and computational cost to improve security and reusability.
Overview
A key derivation function (KDF) is a deterministic algorithm used in cryptography to convert a secret input — for example a password, passphrase, or shared secret — into one or more cryptographic keys suitable for use in encryption, message authentication, or other protocols. KDFs are designed so the derived output appears uniformly random and unpredictable even if the input is low-entropy. They are a core building block in many protocols in modern security systems and cryptography.
Image gallery
1 ImagePurpose and main properties
KDFs serve several purposes: they expand or compress secret material into keys of appropriate length, add domain separation so the same secret can safely be reused for different purposes, and increase the cost for an attacker trying to guess the original secret. Important properties include one-wayness (hard to invert), pseudorandomness of outputs, and support for parameters such as salts, iteration counts or memory-cost settings. When processing passwords KDFs often perform key stretching or memory-hard computations to slow brute-force and hardware-accelerated attacks. Common design elements are salts (random nonces), iteration counts, and optional context or info strings.
Types and examples
- Iterated hash-based KDFs such as PBKDF2.
- Adaptive password hashing algorithms like bcrypt and scrypt, which add cost factors and sometimes memory hardness.
- Modern memory-hard designs such as Argon2, created to resist GPU and ASIC cracking.
- Extract-and-expand constructions such as HKDF used to derive multiple keys from a high-entropy shared secret (for example after a Diffie–Hellman agreement).
History and development
Early KDFs were simple iterations of cryptographic hashes. As password-cracking hardware evolved, designers introduced adjustable cost parameters and memory-hard functions to increase the resources an attacker needs. This evolution led from basic iterated hashes to widely adopted standards and newer algorithms that balance performance with resistance to parallel hardware.
Uses and examples
KDFs are used for password storage, key stretching, deriving symmetric keys from master secrets, and producing keys for different protocol roles. For instance a shared secret produced by Diffie–Hellman is typically fed into a KDF to produce session keys used by ciphers such as AES. KDFs also allow a single secret value to yield multiple domain-separated keys (encryption, MAC, IV generation) safely. They are frequently combined with salts and other context data and are referenced in standards and RFCs.
Security considerations and distinctions
Selecting a KDF involves trade-offs: choose parameters that make legitimate use practical but increase attacker cost. Always use a per-secret salt to avoid precomputation attacks and prefer algorithms with adjustable cost or memory parameters. Distinguish KDFs from simple cryptographic hashes or MACs: while related, KDFs incorporate additional structure (salts, iterations, context) and are intended specifically to produce keys. For guidance consult protocol specifications and trusted cryptographic libraries; further resources are available on general cryptography pages and password-handling guides such as those focused on password security.
Further reading
Technical standards and algorithm descriptions provide implementation details and recommended parameter choices. For an introduction to randomness sources and entropy considerations see material on random inputs and entropy estimation. Practical examples and interoperable formats are discussed in many protocol specifications and implementation guides.
Questions and answers
Q: What is a key derivation function in cryptography?
A: A key derivation function (KDF) is a function used in cryptography to generate a long secret key (also known as a “hash”) from a secret phrase, such as a password.
Q: How does a key derivation function generate a secret key?
A: A key derivation function generates a secret key by applying an algorithm to a secret phrase (e.g., a password) to produce a longer, fixed-length value that looks like a random string of bits.
Q: What does the output of a key derivation function look like?
A: The output of a key derivation function looks like a random string of bits and is designed to be the same for the same input phrase regardless of how many times the function is applied.
Q: What is the purpose of a key derivation function?
A: The purpose of a key derivation function is to produce a long, secure secret key that can be used to encrypt and decrypt data in a secure manner.
Q: Can a key derivation function be used to generate secret keys for different cryptographic algorithms?
A: Yes, a key derivation function can be used to generate secret keys for different cryptographic algorithms as long as they require the same key size and format.
Q: How are key derivation functions used to re-use secret keys in encryption?
A: Key derivation functions are used to re-use secret keys in encryption by generating a new secret key from a shared secret key produced by a key exchange algorithm (like the Diffie-Hellman key exchange) and then using the new key to encrypt and decrypt data using a specific encryption algorithm (like AES).
Q: What is the benefit of using a key derivation function in cryptography?
A: The benefit of using a key derivation function in cryptography is that it enables the creation of long, secure secret keys that can be used for encryption and decryption without having to manually generate and store individual keys for each use case.
Related articles
Author
AlegsaOnline.com Key derivation function (KDF) Leandro Alegsa
URL: https://en.alegsaonline.com/art/53106
Sources
- libsodium.gitbook.io : "Key derivation"
- libsodium.gitbook.io : "Password hashing"
- books.google.com : Hacking and Securing IOS Applications: Stealing Data, Hijacking Software, and How to Prevent It
- nvlpubs.nist.gov : nvlpubs.nist.gov
- security.stackexchange.com : "encryption - Why brute-force the password instead of the key directly?"
- php.net : "PHP: password_verify - Manual"
- password-hashing.net : password-hashing.net/argon2-specs.pdf
- cryptopp.com : "Key Derivation Function - Crypto++ Wiki"