SHA-2 family (SHA-224, SHA-256, SHA-384, SHA-512)
Cryptographic hash functions
How it works
SHA-2 is a family of Merkle-Damgard hash functions published by NIST in FIPS 180-4. SHA-256 works on 512-bit blocks with 32-bit words; SHA-512 works on 1024-bit blocks with 64-bit words. SHA-256 is the most widely deployed hash in TLS certificates, code signing and blockchains.
Sizes: Outputs of 224, 256, 384 or 512 bits; also SHA-512/224 and SHA-512/256
Strengths
- No practical collision or preimage attacks against the full functions.
- FIPS-approved and supported everywhere, often with hardware acceleration.
Weaknesses and known attacks
- Length extension: knowing H(secret || message) lets an attacker compute the hash of a longer message without the secret. Use HMAC, not hash(secret || data), for authentication. Truncated variants such as SHA-384 and SHA-512/256 resist this.
- Too fast to use directly for password storage.
Use it for
- Signatures, certificates, file integrity, HMAC, key derivation
Don't use it for
- Password storage on its own (use Argon2id, scrypt, bcrypt or PBKDF2)
- Building a MAC as hash(key || message)
Exam tip
SHA-256 produces a 256-bit (32-byte, 64 hex character) digest. A hash provides integrity, not confidentiality, and it is one-way: you cannot 'decrypt' a hash.
References
Go deeper
Crypto lab: practise encryption, hashing and signatures
Glossary: Hashing
SHA-3
Cryptographic hash functions and extendable-output functions
SHA-1
Cryptographic hash function (deprecated)
HMAC
Message authentication (integrity + origin with a shared key)
BLAKE2/3
Cryptographic hash functions
PBKDF2
Password-based key derivation and password hashing