Message Authentication Codes
Message Authentication Codes (MACs) provide data integrity and authenticity by using a secret key to generate authentication tags for messages.
Available MAC Algorithms
Universal MACs
HMAC
Hash-based Message Authentication Code using cryptographic hash functions.
- Hash Functions: SHA-256, SHA-512, BLAKE2b, BLAKE3
- Security: Based on underlying hash function
- Tag Size: Full hash output or truncated
- Use Cases: TLS, IPsec, JWT, API authentication
Poly1305
One-time authenticator designed for high-speed authentication.
- Security Level: 128-bit
- Tag Size: 16 bytes
- Key Size: 32 bytes (one-time use)
- Use Cases: ChaCha20-Poly1305, NaCl, libsodium
Specialized MACs
SipHash
Short-input pseudorandom function designed for hash table protection.
- Security Level: 64-bit (against hash flooding)
- Tag Size: 8 bytes
- Key Size: 16 bytes
- Use Cases: Hash tables, data structures, DoS protection
Algorithm Comparison
| Algorithm | Speed | Security | Tag Size | Key Reuse |
|---|---|---|---|---|
| HMAC | Moderate | High | Variable | Yes |
| Poly1305 | Very Fast | High | 16 bytes | No (one-time) |
| SipHash | Very Fast | Moderate | 8 bytes | Yes |
Security Properties
HMAC
- PRF Security: Pseudorandom function under key
- Collision Resistance: Inherits from hash function
- Key Recovery: Computationally infeasible
- Length Extension: Immune by design
Poly1305
- Information-Theoretic: Security doesn’t rely on computational assumptions
- One-Time: Each key must be used only once
- Fast: Optimized for high-speed authentication
- Constant-Time: Resistant to timing attacks
SipHash
- PRF Security: Pseudorandom for short inputs
- Hash Flooding: Protects against algorithmic complexity attacks
- Fast: Designed for high-throughput applications
- Keyed: Prevents precomputed attacks
Selection Guide
For General Authentication
- Recommended: HMAC-SHA256 or HMAC-BLAKE3
- High Security: HMAC-SHA512 or HMAC-BLAKE2b
- Legacy Compatibility: HMAC-SHA1 (avoid if possible)
For High-Speed Applications
- Stream Ciphers: Poly1305 (with unique keys)
- Hash Tables: SipHash
- Network Protocols: Poly1305 or HMAC
For Specific Use Cases
- TLS: HMAC (various hash functions)
- ChaCha20-Poly1305: Poly1305
- Hash Tables: SipHash
- API Authentication: HMAC
- File Integrity: HMAC
Best Practices
HMAC Usage
- Use SHA-256 or stronger hash functions
- Don’t truncate tags below 128 bits for security applications
- Use different keys for different purposes
- Include context information when possible
Poly1305 Usage
- Never reuse keys - use unique key for each message
- Often combined with stream ciphers (ChaCha20)
- Derive keys from master key using KDF
- Verify tags in constant time
SipHash Usage
- Use for hash table keys, not cryptographic authentication
- Rotate keys periodically
- Use SipHash-2-4 variant for security applications
- Consider SipHash-1-3 for performance-critical applications
Implementation Features
All MAC algorithms in MetaMUI Crypto Primitives provide:
- ✅ Constant-time verification
- ✅ Side-channel resistance
- ✅ Proper key handling
- ✅ Standards compliance
- ✅ Cross-platform compatibility