Lably
Skip to content

Salt (cryptography)

Random data used as an additional input to a hash function

  • 6 min read
  • 5 chapters

Related on Lably

Through Password and Hash function

Typically, a unique salt is randomly generated for each password. The salt and the password (or its version after key stretching) are concatenated and fed to a cryptographic hash function, and the output hash value is then stored with the salt in a database. The salt does not need to be encrypted, because knowing the salt would not help the attacker.

Salting is broadly used in cybersecurity, from Unix system credentials to Internet security.

Salts are related to cryptographic nonces.

Example

Without a salt, identical passwords will map to identical hash values, which could make it easier for a hacker to guess the passwords from their hash value.

Instead, a salt is generated and appended to each password, which causes the resultant hash to output different values for the same original password.

The salt and hash are then stored in the database. To later test if a password a user enters is correct, the same process can be performed on it (appending that user's salt to the password and calculating the resultant hash): if the result does not match the stored hash, it could not have been the correct password that was entered.

In practice, a salt is usually generated using a cryptographically secure pseudorandom number generator (CSPRNG). CSPRNGs are designed to produce unpredictable random numbers which can be alphanumeric. While generally discouraged due to lower security, some systems use timestamps or simple counters as a source of salt. Sometimes, a salt may be generated by combining a random value with additional information, such as a timestamp or user-specific data, to ensure uniqueness across different systems or time periods.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Computing and communication