Cryptographic Hash Functions
Also Known As
SHA-256
SHA-3
BLAKE3
MD5
SHA-1
cryptographic hash
TL;DR
One-way functions producing a fixed-length digest — SHA-256, SHA-3, and BLAKE3 are secure for data integrity; MD5 and SHA-1 are broken and must not be used for security.
Explanation
Cryptographic hash functions must be: deterministic (same input = same output), fast to compute, pre-image resistant (cannot reverse), second pre-image resistant (cannot find collision for a given input), and collision resistant (cannot find any two inputs with the same hash). SHA-256/SHA-512 (SHA-2 family): widely deployed, no known practical attacks. SHA-3 (Keccak): different construction, quantum-resistant design. BLAKE3: fast, secure, modern. MD5 and SHA-1: broken collision resistance — do not use for security. In PHP: hash('sha256', $data), hash('sha3-256', $data).
Common Misconception
✗ SHA-256 is suitable for password hashing — SHA-256 is fast (billions of operations per second on a GPU), making it unusable for passwords; use bcrypt or Argon2id instead.
Why It Matters
Using MD5 or SHA-1 for data integrity checks opens the door to collision attacks where two different inputs produce the same hash — file signature forgery and certificate attacks both exploit this.
Common Mistakes
- MD5 for file integrity checksums — collisions have been demonstrated; use SHA-256.
- SHA-256 for password hashing — fast algorithm; use password_hash() with Argon2id.
- Not using HMAC for message authentication — a bare hash can be length-extended; use hash_hmac().
- Comparing hashes with == instead of hash_equals() — timing attack vulnerability.
Code Examples
✗ Vulnerable
// MD5 for integrity — broken:
$checksum = md5_file($uploadedFile); // Collisions possible
// SHA-256 for password — wrong tool:
$hash = hash('sha256', $password); // Fast = GPU crackable
// Timing-vulnerable comparison:
if ($computed === $provided) { /* vulnerable to timing attack */ }
✓ Fixed
// SHA-256 for file integrity:
$checksum = hash_file('sha256', $uploadedFile); // Secure for integrity
// Argon2id for passwords:
$hash = password_hash($password, PASSWORD_ARGON2ID);
// HMAC for message authentication:
$mac = hash_hmac('sha256', $message, $secretKey);
// Constant-time comparison:
if (hash_equals($expected, $computed)) { /* safe */ }
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
32
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 13
Perplexity 4
Google 3
Unknown AI 2
Ahrefs 2
SEMrush 2
Majestic 1
Also referenced
How they use it
crawler 25
crawler_json 2
Related categories
⚡
DEV INTEL
Tools & Severity
🟠 High
⚙ Fix effort: Medium
⚡ Quick Fix
Choose the right hash for the use case: SHA-256 for data integrity checksums, HMAC-SHA-256 for authentication tags, Argon2id for passwords — never MD5 or SHA1 for any security use
📦 Applies To
PHP 5.1+
web
cli
queue-worker
🔗 Prerequisites
🔍 Detection Hints
md5() sha1() for security; hash without HMAC for authentication; SHA-256 for passwords instead of Argon2id
Auto-detectable:
✓ Yes
semgrep
psalm
phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Medium
False Positives: Medium
✓ Auto-fixable
Fix: Low
Context: Line
CWE-327
CWE-328