Definition
A salt is a value, normally not secret, that is given to a password hash or a key derivation function §5.20 together with the secret input, so that the same secret gives different results under different salts. A password hash is a deliberately slow function whose output a server stores in place of the password; a key derivation function turns a secret into cryptographic keys. In password storage every record gets its own salt. In key derivation the salt strengthens the step that turns an imperfect secret into a key.
The idea
A service stores, for each user, a hash of the password rather than the password: a fixed-length value computed by a one-way function, which lets the server check a login without keeping the password. The file of hashes leaks. Two users chose the password maple, so without a salt their stored values are identical, and the attacker sees at once that they share a password. Worse, the attacker can hash a list of ten million common passwords once, even before the leak, and look up every stored value in that one table.
A salt breaks this sharing. The service picks a different random salt for each record and hashes the salt together with the password. The two maple records now hold different values, and a table computed for one salt is useless for every other record. The attacker must repeat the work for each record and cannot start before seeing the salts. A picture: each record writes its password in a private dialect, and the salt names the dialect. The picture fails in one respect: the dialect is not secret. The attacker reads the salt from the stolen record and can try guesses against that one record at full speed, so a weak password stays weak.
Key derivation uses a salt differently. In HKDF §5.21 (HMAC-based Extract-and-Expand Key Derivation Function), the extraction step computes HMAC §5.8 (hash-based message authentication code), a keyed hash function, with the salt as the key and the secret as the message. A random salt that the attacker did not choose lets this step turn many kinds of imperfect secret into a good key, and one salt may serve many derivations.
How it works
Salting a stored password. NIST Special Publication (SP) 800-63B-4, NIST’s guideline for authentication §1.6, requires that stored passwords be salted and hashed with a password hashing §15.10 scheme, which takes a password, a salt and a cost factor.
When a password is set, generate a new salt, for example 16 bytes from a CSPRNG §5.27 (cryptographically secure pseudorandom number generator).
Compute the password hash from the password, the salt and the cost settings, with a slow function such as PBKDF2 (Password-Based Key Derivation Function 2) or Argon2.
Store the salt, the hash, and the name of the algorithm §14.1 with its cost settings in the user’s record.
At login, read the salt from the record, recompute the hash from the password typed in, and compare.
The standards set these requirements on password salts.
SP 800-63B-4: at least 32 bits long, and chosen so as to minimize salt values shared between stored hashes.
SP 800-132, NIST’s recommendation for password-based key derivation: the randomly generated part of the salt must be at least 128 bits long and must come from an approved random bit generator [322]. A fixed label for the purpose may precede it, , where is the random part and joins two strings, to keep different applications apart.
RFC 9106, which defines Argon2: 16 bytes recommended, and the salt should be unique for each password. A 128-bit salt is enough for all applications; 64 bits is acceptable when space is short.
Salting a key derivation. The extraction step of HKDF computes the pseudorandom key (PRK) as , where IKM, input keying material, is the secret. RFC 5869, which defines HKDF, describes its salt as follows.
It is not secret, and it can be reused with many IKM values.
Ideally it is a random string as long as the hash output, which is 32 bytes for SHA-256 §5.2 (Secure Hash Algorithm with a 256-bit output). A shorter or less random salt still helps.
If no salt is available, HKDF uses a string of zero bytes as long as the hash output.
It must be independent of the IKM and must not be chosen or manipulated by an attacker. A salt built from values that two parties exchange must therefore be authenticated before use.
SP 800-56C Rev. 2, NIST’s recommendation for key derivation during key establishment, likewise does not require a random salt and allows a fixed default value such as all zero bytes [323].
Worked example
Work for the attacker. A leaked file holds password records, and the attacker has a list of likely passwords.
Without a salt, each guess is hashed once and looked up among all records: hash computations test every guess against every record, and all of them can be done before the leak.
With a distinct salt in every record, each guess must be hashed again for every salt: hash computations, a million times more, and none of them can be done before the salts are known.
Against one chosen record the work is hash computations in both cases.
The salt multiplies the cost of attacking everyone. It leaves the cost of attacking one user unchanged; only a slow password hash raises the cost of each computation.
How long a random salt must be. Draw each salt at random and count the expected number of pairs of records that receive the same salt. There are pairs among the million records, and each pair matches with probability for salts of bits:
: pairs;
: about pairs;
: about pairs.
So if salts of 32 bits, the minimum length that SP 800-63B-4 allows, are drawn at random, about 116 pairs among a million users share a salt, and each such pair can be attacked with one computation per guess. SP 800-63B-4 asks that salts be chosen to minimize such repeats; with random 128-bit salts, the length SP 800-132 requires for the random part, no repeat is expected at all.
Stated precisely
Let be a password hash of the password with the salt . Let the stolen file hold the records for , where , let the attacker hold a list of candidate passwords, and let be the number of distinct values among . Testing every candidate against every record costs evaluations of . With no salt, or one salt shared by all records, ; with a distinct salt per record, . The probability of recovering the password of one record does not depend on the salt: it is the probability that is in .
Computing a table before the leak is impossible only if the salt cannot be predicted before it is chosen. For a salt known in advance, such as a user name, a table for that salt can be computed in advance.
For salts of bits drawn independently and uniformly, the expected number of pairs with equal salts is , and the probability that at least one pair is equal is at most that number. This is the birthday bound §5.6.
For HKDF, the role of the salt is part of the HKDF security claim: if HMAC acts as a randomness extractor, a function that turns an input that is hard to guess but not uniformly random into output that cannot be told apart from uniformly random bytes, then with a salt that is random, independent of the IKM and not chosen by the attacker, the extraction step turns any IKM with enough min-entropy §5.26, a measure of how hard the IKM is to guess in one try, into a key that cannot be told apart from random. The HKDF entry states the claim and its assumptions in full.
Limits and common mistakes
A salt adds no secret. Whoever has the record has the salt, so a password that is easy to guess stays easy to guess for that record. Only the cost of each guess, which a slow password hash sets, and the strength of the password itself protect a single user. HKDF and SHA-256 alone are fast and therefore the wrong tools for passwords.
A salt is not a pepper §5.49. A password pepper is a secret value, kept apart from the database, that is mixed into every password hash; it protects only while it stays secret.
Unique is not the same as unpredictable. A user name or a record number is unique within one service, so it stops one table from covering every record. But it is known before the leak, so a table for one targeted account can be prepared in advance, and the same user name on two services gives the same salt.
A salt is not a nonce §5.18. HKDF allows one salt to be reused for many derivations; a password salt should not repeat between records; a nonce, the value an encryption mode takes with each message, must never repeat under one key. The name salt does not say which rule applies; the specification of the function that receives the value does.
In HKDF, keeping keys for different purposes apart, called domain separation §5.22, is the job of the info input, not of the salt. RFC 5869 describes info as the input that binds the derived keys to application- and context-specific information.
The salt must be stored with the hash. Without it the stored hash can no longer be checked.
Questions answered
When must salt be random, unique, or merely domain-specific?
A salt must be unique for each stored password, and random generation is the standard way to make it unique; a salt for a key derivation step should be random when the application can obtain one, but it may be reused or fixed; a salt that is merely domain-specific, the same for every input in one application, is acceptable only where the salt’s job is not to keep users apart. A salt is a usually public value fed into a password hash or a key derivation function together with the secret. In detail:
Password storage: unique, and random. Each stored password needs its own salt, so that equal passwords give different stored values and one precomputed table cannot serve every record. Random generation gives uniqueness without coordination and defeats tables computed before the salt existed: NIST Special Publication (SP) 800-132 requires at least 128 random bits in the salt of its password-based key derivation, RFC 9106 recommends 16 bytes, and NIST SP 800-63B-4 sets a floor of 32 bits chosen to minimize repeats. The salt need not be secret.
Key derivation: random if possible, reuse allowed. In HKDF (HMAC-based Extract-and-Expand Key Derivation Function) the salt is ideally random and as long as the hash output; it may be reused, need not be secret, and may be a fixed default when nothing better is available. It must be independent of the secret input and not chosen by an attacker.
Domain-specific: as an addition, or where separation is the only goal. A fixed label per application may precede the random part of a password salt, as SP 800-132 allows, and a fixed salt per application can serve HKDF. A fixed salt shared by all users must never be the only salt for stored passwords, because it puts every user back into one table.
The rule comes from the specification of the function that receives the salt, not from the word salt.
Related entries: Key derivation function (KDF) (§5.20), HKDF (§5.21), Entropy and min-entropy (§5.26), Nonce (§5.18), Password pepper: a separate secret, compromise cases, and replacement (§5.49), Password hashing and memory-hard KDF (§15.10), Birthday bound (§5.6), Domain separation (§5.22). Further reading: [9, 138, 199, 322, 323].