How passwords are stored: salt and many rounds

· 2 min read

#how-it-works#security

A well-built site does not keep your password itself. My reading: it keeps a value derived from the password, mixed with a random salt and run through many rounds of work.

The short version

RFC 8018 defines PBKDF2. It takes a password, a salt and an iteration count, and produces a derived key. The salt is extra data mixed in; it may be random and should be at least eight octets (64 bits). The iteration count c is how many rounds the work repeats, and the RFC says it raises the security strength of a password by log2(c) bits, so each guess costs more.

From password to stored value A password and a random salt both go into PBKDF2, which repeats its work c times. The output is the stored value. Password what you type Random salt 8 octets or more PBKDF2 c rounds of work Stored value the derived key 1 2 3
Arrows 1 and 2 feed PBKDF2; arrow 3 is the result the site keeps.

Step by step

  1. Pick a random salt, at least eight octets long.
  2. Feed the password, the salt and the iteration count c into PBKDF2.
  3. Get back a derived key of the length you asked for.
  4. Store that value, not the password (my reading; the RFC does not say this).
  5. At login the site usually repeats the derivation with the stored salt and compares the results (common practice, not in the RFC).

Why it matters

The RFC says the salt makes a large set of keys possible for one password. My reading: two accounts with the same password need not end up with the same stored value. Pick the iteration count from current guidance, not from this post.

Sources