---
obj: concept
---

# SHA
SHA-2 (Secure Hash Algorithm 2) is a set of cryptographic hash functions designed by the United States National Security Agency (NSA) and first published in 2001. They are built using the Merkle–Damgård construction, from a one-way compression function itself built using the Davies–Meyer structure from a specialized block cipher.

SHA-2 includes significant changes from its predecessor, SHA-1. The SHA-2 family consists of six hash functions with digests (hash values) that are 224, 256, 384 or 512 bits: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256. SHA-256 and SHA-512 are novel hash functions computed with eight 32-bit and 64-bit words, respectively. They use different shift amounts and additive constants, but their structures are otherwise virtually identical, differing only in the number of rounds. SHA-224 and SHA-384 are truncated versions of SHA-256 and SHA-512 respectively, computed with different initial values. SHA-512/224 and SHA-512/256 are also truncated versions of SHA-512, but the initial values are generated using the method described in Federal Information Processing Standards (FIPS) PUB 180-4.

SHA has libraries for many programming languages and can be used with [OpenSSL](OpenSSL.md) or the `shasum` command.

## Purpose
Hash functions play a crucial role in [cryptography](Cryptography.md) and information security. They take an input (or message) and produce a fixed-size string of characters, which is typically a digest or hash value. The primary purposes of SHA hash functions include:

1. **Data Integrity**: Hash functions ensure the integrity of data by generating a unique hash value for a given input. Any change in the input data will result in a completely different hash, making it easy to detect alterations.
2. **Digital Signatures**: SHA is often used in conjunction with digital signatures to create a secure and verifiable way of confirming the origin and integrity of a message or document.
3. **Password Storage**: Hash functions are employed to store passwords securely. Instead of storing the actual password, systems store the hash of the password, making it more challenging for attackers to obtain the original passwords.