Definition
A password pepper is a secret key that a password-checking server mixes into every stored password record and keeps apart from the database of records. A thief who copies only the database then cannot test password guesses offline, because every test needs the pepper. A pepper differs from a salt §5.19, the random value stored openly in each record: the salt is public and different for every record, while the pepper is secret, usually one key for many records, and protects only while it stays out of the thief’s hands.
The idea
A web service stores, for each user, a salt and a password hash: the output of a deliberately slow function of the password and the salt. An attacker who steals a copy of the database can test guesses against each record on its own computers, which is called an offline attack. With a hash that takes 100 ms, a list of 10,000 common passwords takes 1,000 seconds per account on one processor core, and weak passwords fall. Stolen databases and leaked backups are common, and often the thief gets nothing else from the server.
The pepper adds a step that needs a secret the database does not contain. After the slow hash, the server computes HMAC §5.8 (hash-based message authentication code), a keyed function, with the pepper as key, and stores that result. Without the pepper, a stored value is random-looking bytes against which no guess can be checked. Think of a codebook locked in a separate safe: a burglar who steals the files cannot read them without breaking into the safe as well. The picture stops where the safe is opened. A thief who takes the pepper too is back to facing only the salt and the slow hash; the pepper never makes a password stronger.
NIST (National Institute of Standards and Technology) SP 800-63B (Special Publication 800-63B), revision 4, section 3.1.1.2, recommends exactly this extra step: a keyed hashing or encryption operation with a secret key known only to the verifier, generated by an approved random bit generator and stored separately from the hashed passwords, preferably inside a hardware-protected area. NIST does not use the word pepper.
How it works
The construction uses these values.
: the password the user types.
: the salt, random and different for each record, stored in the record. NIST requires at least 32 bits; 16 bytes is common.
: the cost parameters of the password hash, stored in the record.
: a deliberately slow password hashing function §15.10, preferably one that is also memory-hard, meaning that each evaluation needs a large amount of memory, which blunts cheap parallel hardware. Argon2id and scrypt are memory-hard; PBKDF2 (Password-Based Key Derivation Function §5.20 2) is only slow.
: the pepper, a 32-byte key from a cryptographically secure pseudorandom number generator §5.27 (CSPRNG).
: a key identifier, a public number stored in each record that says which pepper version made it.
Setting a password:
Compute .
Compute .
Store , , and . Store neither nor .
Checking a password at login:
Read the user’s record and recompute from the submitted password with the stored and .
Have the pepper’s holder compute with the key that names.
Compare the result with using a constant-time comparison §4.33, one whose running time does not depend on where the two values first differ.
The pepper lives outside the database and its backups: in a hardware security module (HSM), a dedicated device that keeps keys inside and performs operations with them without releasing them; in a key management service; or at least in a configuration secret that is never stored with the database. With an HSM, the server sends and receives the HMAC; the key never leaves the device. The slow hash runs first and the cheap HMAC last, so the HSM does little work per login, and the slow hash keeps its full effect if the pepper ever leaks.
Two variants exist. Encrypting with the pepper key instead of computing an HMAC gives a reversible wrapper, which matters for replacing the key (see below). Mixing the pepper into the password before the slow hash also keeps the database useless without the key, but some password hashes accept limited input; bcrypt, for example, uses only the first 72 bytes, so a long pepper can crowd out the password.
Worked example
Assume that takes 100 ms on one processor core, that the attacker’s list holds 10,000 candidate passwords, and that the pepper is 32 random bytes.
Database only. To test the candidate maple for Alice, the attacker computes in 100 ms, then needs and does not have . Guessing means searching keys, which is infeasible. No guess can be tested offline; the attacker can only try passwords at the login page, where rate limiting §9.38 applies.
Database and pepper. Each candidate costs one slow hash: seconds, about 16.7 minutes, per account on one core; the HMAC adds a negligible amount. For 1,000,000 accounts that is seconds, about 31.7 years on one core or about 11.6 days on 1,000 cores. The salt forces this work to be repeated for every account, and the slow hash sets the price of each guess.
A weak pepper. Suppose a developer chose the pepper from about possibilities, such as a word followed by digits. The attacker registers an account with the known password maple, steals the database, computes for that account once (100 ms), and then tries each candidate pepper with one HMAC. At an assumed 1 microsecond per HMAC, tries take about 1.05 seconds. The pepper is recovered and the attacker is in the previous case. This is why the pepper must be a random key, and why NIST requires an approved random bit generator.
Stated precisely
Let and . Assume:
is uniformly random, at least 128 bits long, and independent of everything in the database (NIST sets a floor of 112 bits of security strength);
HMAC is a pseudorandom function §15.1: with a secret, uniformly random key, its outputs cannot be told apart from random values by any feasible computation;
the attacker holds the whole database, including records for passwords it chose, but neither nor any way to have HMAC computed with .
Then the stored values look like independent random strings to the attacker, and the database gives no way to check a password guess. The attacker’s options are to guess , each guess right with probability or less, or to guess passwords online through the login service.
If assumption 3 fails because leaks, the protection falls exactly to that of the salt and the slow hash: one evaluation of per guess per account. If it fails because the attacker can have HMAC computed with , for example by controlling the server that talks to the HSM, each such request tests one guess, so the attack runs at the rate the key holder allows and stops when the attacker loses that access.
Compromise cases
Each case below states what the attacker holds and what the pepper still does.
Database only, for example through an injection flaw or a stolen backup: offline guessing is impossible, and only online guessing remains.
Database and pepper, for example because the pepper sat in the same backup, in the same configuration file, or in a source code repository, or because the attacker took over the whole server: the pepper adds nothing, and the salt and the slow hash are the remaining protection.
Pepper in an HSM, attacker in control of the application server: the attacker cannot copy the key but can ask the HSM to compute HMACs for its guesses while the control lasts. Limits on the rate of requests and monitoring at the HSM decide how many guesses that buys.
Live server compromise: the attacker reads passwords as users type them. No storage scheme helps.
Pepper leaked, database not: nothing is exposed yet, but a later database theft would be fully exposed, so the pepper must be replaced now.
Pepper lost, for example an HSM failure with no backup: no password can be verified, so every affected user must reset through another channel. This is a failure of availability §1.10.
Replacing the pepper
Key rotation §5.29 for a pepper depends on what the record stores. With , where is the pepper with key identifier 7, computing the value under a new key needs , and needs the password. HMAC cannot be reversed. The usual procedure is:
Generate and keep available.
At each successful login to a record with identifier 7, the server has just computed ; it stores with identifier 8.
After a stated deadline, force a password reset for the records still at identifier 7, then destroy .
Dormant accounts stay under until the deadline.
Wrapping gives immediate protection without the password: replace every by , and verify by computing . After leaks, this restores protection at once for every copy of the database taken after the wrapping: a thief who has such a copy and still needs . It retires nothing: is needed for every verification from then on.
Encrypting instead, with authenticated encryption §5.16, allows all records to be decrypted with and re-encrypted with in one pass, after which can be destroyed. A holder of the key recovers , not the password, which leaves it in the same position as a holder of an HMAC pepper: offline guessing at the cost of the slow hash.
Whatever the scheme, the record’s key identifier selects only among approved key versions, and destroying a key that some record still needs locks those users out. No scheme changes a record copied before the record itself was replaced, for example in an old backup: whoever holds that copy and can still test guesses against it at the cost of the slow hash. After leaks, old copies must therefore be destroyed or brought under as well, and a copy already held by someone who knows is protected only by the salt and the slow hash.
Limits and common mistakes
A pepper does not strengthen a password. A weak password stays weak online, and against anyone who obtains the pepper.
A pepper does not replace the salt or the slow hash. If the pepper leaks, they are the only protection left.
The pepper must be a random key, never a word chosen by a person, and must never be stored where the database is: not in the same backups, logs, configuration files or source code repository.
A key that cannot be exported from an HSM can still be used through it. An attacker in control of the server can use the HSM’s interface, so authentication §1.6, rate limits and monitoring on that interface matter.
An attacker who can write to the database can copy its own record into another user’s row and then log in there with its own password. Including the account identifier in the HMAC input, encoded unambiguously, for example with a length prefix §4.30, makes a copied record fail to verify.
Losing the pepper locks out every user. Keep a backup in separately protected storage, for example a second HSM or shares held by several custodians through threshold secret sharing §5.44, and test that the backup can be restored.
Questions answered
How does a pepper differ from a salt?
A salt is a public random value, different for each password record and stored inside it; a pepper is a secret key, usually shared by many records, stored apart from the database. The salt makes each record’s computation different, so one guess cannot be tested against all accounts at once and tables cannot be computed in advance. It protects nothing in a single stolen record, because the thief has it. The pepper makes stolen records useless for offline guessing for as long as the thief does not also have the pepper.
Their failure cases differ too. A leaked salt is harmless; a leaked pepper removes its protection. A lost salt makes one record unverifiable; a lost pepper makes every record keyed with it unverifiable. Neither makes a weak password strong, and neither replaces a slow password hash.
Does moving a key to an HSM automatically eliminate password guessing?
No: moving the key into a hardware security module (HSM) stops the key from being copied, not from being used to test guesses. Anyone who can send requests to the HSM can still have it compute the keyed step for password guesses. An attacker who controls the application server can do exactly that, one guess per request, for as long as the control lasts. The HSM changes the attack from offline guessing at the attacker’s own speed to guessing at the speed and for the duration that the HSM allows. Authentication of callers, rate limits and monitoring on the HSM interface decide how much guessing that is, and online guessing through the login page remains possible in any case.
Can the final-HMAC-only design rotate its key for every dormant account immediately?
No: a design that stores only the final HMAC (hash-based message authentication code), the keyed hash computed with the pepper, cannot move a dormant account to a new key until its user logs in again. In that design each record stores only , where is the slow password hash and the pepper, and neither the password nor is kept. Computing the value under a new key needs , and HMAC cannot be reversed to get it, so a record can move to the new key only when its user next logs in and supplies the password. Accounts that stay dormant are either forced to reset after a deadline or kept under the old key. Wrapping every record under the new key, , works at once: a thief who copies the database after the wrapping cannot test guesses with a leaked old key alone, although a copy taken before the wrapping, such as an old backup, still allows that. The old key must then be kept for every future check, so wrapping does not retire it. A design that encrypts instead of computing an HMAC can re-key every record at once.
What if the pepper is lost rather than stolen?
If the pepper is lost, no record keyed with it can be verified any more, so even users with the correct password cannot log in, and all of them must reset their passwords through another channel such as a recovery e-mail. Loss harms availability, not secrecy. The defense is a backup of the key in separately protected storage, such as a second hardware security module or shares held by several custodians, with a tested restore procedure. Every backup is also a copy that could be stolen, so it needs the same protection as the original.
Related entries: Salt (§5.19), Password hashing and memory-hard KDF (§15.10), HMAC (§5.8), Entropy and min-entropy (§5.26), Key revocation (§5.32), Authentication coverage (§5.41). Further reading: [199].