Course contentsShow
← Security
Lesson 137 of 3,0523. Symmetric Cryptography Deep DiveFree lesson

Key Derivation Functions (KDFs) Overview

Understand the purpose of KDFs in deriving cryptographic keys from passwords or master keys for specific uses.

Key Derivation Functions (KDFs) Overview

You'll learn what KDFs are and why we can't simply use passwords directly as encryption keys.

The Problem: Passwords Aren't Keys

Imagine you've learned all about AES encryption and authenticated encryption modes like AES-GCM. Now you want to encrypt a file with a password. Can you just use "mypassword123" directly as the AES key?

No! Passwords have two critical problems:

  1. Wrong format: AES-256 needs exactly 256 bits (32 bytes) of random-looking data. Passwords are variable-length text with low entropy.
  2. Weak entropy: Most user passwords are predictable and short, making them vulnerable to brute-force attacks.

What KDFs Do

A Key Derivation Function is a cryptographic algorithm that transforms weak input material (like passwords or master keys) into strong cryptographic keys suitable for encryption, authentication, or other purposes.

Think of a KDF as a "key stretching machine" that takes your short, memorable password and:

  • Expands it to the exact key size needed (128, 256 bits, etc.)
  • Makes it computationally expensive to guess by applying many iterations
  • Produces output that looks uniformly random
  • Can derive multiple different keys from the same master secret for different purposes

Why This Matters

Without a KDF, an attacker could quickly try millions of common passwords to decrypt your data. A proper KDF forces each password guess to take significant time, making attacks impractical.

KDFs also let you derive multiple keys from one master password: one for encryption, another for authentication, all securely isolated from each other.

Key Takeaway: KDFs transform weak passwords or master keys into strong cryptographic keys with the right size, entropy, and computational cost to resist brute-force attacks.