Hash Functions
Cryptographic hash functions for data integrity, digital signatures, and content addressing.
Available Hash Functions
BLAKE3
Recommended - Its designers describe it as much faster than MD5, SHA-1, SHA-2, SHA-3 and BLAKE2
- 128-bit security target
- Parallel tree hashing
- Extendable output, 1 to 1,024 bytes in this library
- Keyed hashing (MAC mode)
- Key derivation (KDF mode)
BLAKE2b / BLAKE2s
Specified in RFC 7693 (Informational)
- BLAKE2b: optimised for 64-bit platforms (up to 512-bit output)
- BLAKE2s: optimised for 8- to 32-bit platforms (up to 256-bit output)
- Built-in keyed mode (MAC without HMAC)
- Its designers describe it as faster than MD5, SHA-1, SHA-2 and SHA-3
SHA-256
Standard hash function
- 128-bit collision and 256-bit preimage resistance
- Specified in FIPS 180-4
- Intel SHA extensions, ARMv8 and Power8 code paths in this library
SHA-512
Large output hash function
- 512-bit output, 64-bit words
- 256-bit collision and 512-bit preimage resistance
SHA-3
NIST standard based on KECCAK
- Multiple output sizes (224, 256, 384, 512)
- Sponge construction, different from SHA-2
- Specified in FIPS 202
Legacy Hash Functions
These hash functions are broken for collision resistance. Only use them for legacy system compatibility or for checksums that do not need collision resistance. For new applications, use SHA-256, SHA-3, or BLAKE3.
SHA-1 (deprecated)
First collision computed in 2017
- 160-bit output
- Chosen-prefix collisions computed in 2020
- NIST says it should be phased out by 31 December 2030
- Only for legacy compatibility
MD5 (broken)
First collisions published in 2004
- 128-bit output
- Collisions in 10 seconds or less on a 2.6 GHz Pentium 4 (2007)
- In
Weak::namespace - Never use for security
Common Interface
All hash functions derive from HashTransformation and share its interface:
class HashTransformation : public Algorithm {
public:
// Get algorithm name (from Algorithm)
virtual std::string AlgorithmName() const;
// Get digest size
virtual unsigned int DigestSize() const = 0;
// Update hash with data
virtual void Update(const byte* input, size_t length) = 0;
// Finalize and get result; the object restarts afterwards
virtual void TruncatedFinal(byte* digest, size_t digestSize) = 0;
// Reset to initial state
virtual void Restart();
};Quick Reference
| Algorithm | Output Size | Collision Resistance | Status |
|---|---|---|---|
| BLAKE3 | 32 bytes (1 to 1,024 configurable) | 128-bit | Recommended |
| BLAKE2b | 64 bytes (1 to 64 configurable) | 256-bit | RFC 7693 (Informational) |
| BLAKE2s | 32 bytes (1 to 32 configurable) | 128-bit | RFC 7693 (Informational) |
| SHA-256 | 32 bytes | 128-bit | FIPS 180-4 |
| SHA-512 | 64 bytes | 256-bit | FIPS 180-4 |
| SHA3-256 | 32 bytes | 128-bit | FIPS 202 |
| SHA-1 | 20 bytes | Below 80-bit | Legacy only |
| MD5 | 16 bytes | Broken | Legacy only |
The BLAKE2 figures are RFC 7693’s collision security for the full-length digests. Collision resistance is about half the output length. Preimage resistance is about the full output length for SHA-2 and SHA-3. See Security Levels Explained for BLAKE3’s stated targets.
See Also
- Hash Functions Guide - Conceptual overview with examples
- BLAKE3 Guide - Detailed BLAKE3 guide
- Algorithm Selection Guide - Choosing between the commonly used algorithms
References
- BLAKE3 README
- BLAKE3 specification
- RFC 7693: The BLAKE2 Cryptographic Hash and Message Authentication Code (MAC)
- BLAKE2 home page
- NIST: Hash Functions
- FIPS 180-4: Secure Hash Standard (SHS)
- FIPS 202: SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions
- NIST SP 800-131A Revision 2
- RFC 6151: Updated Security Considerations for the MD5 Message-Digest and the HMAC-MD5 Algorithms
- Stevens, Bursztein, Karpman, Albertini and Markov: The first collision for full SHA-1 (IACR ePrint 2017/190)
- Leurent and Peyrin: SHA-1 is a Shambles (IACR ePrint 2020/014)
- NIST: NIST Retires SHA-1 Cryptographic Algorithm (15 December 2022)