Skip to content

Glossary

Key stretching

Key stretching deliberately slows down a hash or key-derivation function by repeating its core operation thousands of times, turning a cheap digest into an expensive one to defend against brute force.

Key stretching is the technique of repeating a hash or key-derivation function's core operation many times over so that computing it once takes meaningfully longer, without weakening the output. A raw SHA-256 digest runs in nanoseconds; PBKDF2 stretches that same primitive by chaining thousands of HMAC rounds, so one guess costs thousands of times more.

The idea predates PBKDF2: bcrypt stretched a modified Blowfish schedule as early as 1999, and sha512crypt stretches SHA-512 the same way for /etc/shadow. The iteration count or cost factor is simply how many times the stretch repeats, and raising it raises the cost for a legitimate login and an attacker's guess equally.

Key stretching alone only slows down compute; it says nothing about memory. A memory-hard function like argon2id or scrypt adds a second, harder-to-parallelize cost on top of stretching, which is why modern guidance pairs the two rather than relying on iteration count alone. See why fast hashes are dangerous for what happens when a password hash skips stretching entirely.