Skip to content
Weakened by quantumhmac-md5

HMAC-MD5

HMAC built on MD5, found in old protocols such as RADIUS extensions, legacy APIs and CRAM-MD5.

Why it's at risk

HMAC-MD5 is not broken as a MAC in practice, because HMAC does not rely on collision resistance, but RFC 6151 advises against it in new protocols and MD5's weaknesses leave little margin. Move to HMAC-SHA-256.

Used for
MAC
Family
Message authentication code (HMAC)
Classical security
128 bits
Against a quantum computer
~64 bits
Standards
RFC 2104, RFC 6151
Read the guideWhat encryption actually does

Migration guides

Concrete code changes to move off HMAC-MD5. Pick your stack.

node:crypto · javascriptNode.js: replace MD5 and SHA-1 (hashes, HMACs and password hashing)Production-ready

Why

MD5 and SHA-1 are broken by ordinary computers: collisions are cheap (seconds for MD5; demonstrated in practice for SHA-1, including chosen-prefix collisions). They must not be used for signatures, certificates, integrity against attackers, or passwords. This is not a quantum problem, it is a today problem, and fixing it is usually quick.

Choose the replacement by purpose:

PurposeUse
Integrity / fingerprints / content addressingSHA-256 (or SHA-384/512, SHA3-256)
Message authentication with a keyHMAC-SHA-256
Password storageArgon2id (or scrypt; bcrypt is acceptable) — never a plain hash
Non-security checksums (cache keys, dedup with no attacker)MD5 is tolerable, but SHA-256 avoids scanner noise and future misuse

Before

js
import { createHash, createHmac } from 'node:crypto';

const etag = createHash('md5').update(body).digest('hex');
const sig = createHmac('sha1', secret).update(payload).digest('hex');
const pwHash = createHash('sha1').update(password + salt).digest('hex'); // never do this

After

js
import { createHash, createHmac, timingSafeEqual, scrypt, randomBytes } from 'node:crypto';
import { promisify } from 'node:util';

const etag = createHash('sha256').update(body).digest('hex');

const sig = createHmac('sha256', secret).update(payload).digest();
const expected = Buffer.from(receivedSignatureHex, 'hex');
const ok = expected.length === sig.length && timingSafeEqual(expected, sig); // constant-time compare

// Passwords: Argon2id via a maintained package (e.g. `argon2`), or scrypt built into Node:
const salt = randomBytes(16);
const hash = await promisify(scrypt)(password, salt, 32, { N: 2 ** 17, r: 8, p: 1, maxmem: 256 * 1024 * 1024 });
// store: algorithm id + params + salt + hash, e.g. "scrypt$17$8$1$<salt b64>$<hash b64>"

Gotchas

  • Stored data: existing MD5/SHA-1 digests (file manifests, dedup tables) need a migration plan: dual-write both hashes, backfill, then switch reads.
  • Password migration: you cannot re-hash without the password. Re-hash on next successful login, or wrap the old hash (argon2id(sha1(password))) immediately and mark the record.
  • Interop: external APIs that require HMAC-SHA1 (some webhooks, OAuth 1.0a, TOTP authenticator apps) may force you to keep it at that boundary; HMAC-SHA1 is not broken in the way plain SHA-1 is.
  • Git still uses SHA-1 object IDs by default (with collision detection); that is outside your code.
  • scrypt memory: N=2^17, r=8 needs about 128 MiB, so raise maxmem (default 32 MiB) as shown, and size your servers accordingly.

Verify

npx -y pqe-cli scan . should no longer report md5/sha1 findings outside allow-listed boundaries; add a unit test that the HMAC output length is 32 bytes.

hashlib / hmac / argon2-cffi · pythonPython: replace MD5 and SHA-1, and store passwords with Argon2idProduction-ready

Why

MD5 and SHA-1 collisions are practical with ordinary computers, so they are unsafe for signatures, integrity against attackers and password storage. Pick the replacement by purpose: SHA-256 for integrity, HMAC-SHA-256 for keyed authentication, Argon2id for passwords.

Before

python
import hashlib, hmac

digest = hashlib.md5(data).hexdigest()
tag = hmac.new(secret, payload, hashlib.sha1).hexdigest()
pw = hashlib.sha1((password + salt).encode()).hexdigest()   # never do this

After

python
import hashlib, hmac

digest = hashlib.sha256(data).hexdigest()

tag = hmac.new(secret, payload, hashlib.sha256).digest()
ok = hmac.compare_digest(tag, received_tag)                 # constant time

# Passwords: pip install argon2-cffi
from argon2 import PasswordHasher
ph = PasswordHasher()                                       # Argon2id with RFC 9106 low-memory defaults
stored = ph.hash(password)                                  # encodes params + salt + hash
ph.verify(stored, password)                                 # raises on mismatch
if ph.check_needs_rehash(stored):
    stored = ph.hash(password)

If you need MD5 for a non-security purpose (e.g. a legacy cache key), say so explicitly: hashlib.md5(data, usedforsecurity=False) (Python 3.9+). It also keeps FIPS-mode systems from rejecting the call.

Gotchas

  • PBKDF2 (hashlib.pbkdf2_hmac) is acceptable when FIPS is required; use SHA-256 with at least 600,000 iterations (OWASP guidance) and a 16-byte random salt.
  • Migrating passwords: re-hash on next login, or wrap old hashes (argon2id(old_sha1_hex)) right away and flag the records.
  • Django/Flask-Security etc. have their own hasher settings (PASSWORD_HASHERS); put Argon2 first rather than calling hashlib yourself.
  • External protocols that mandate HMAC-SHA1 (TOTP apps, some webhooks) can stay at that boundary.

Verify

npx -y pqe-cli scan . should show no remaining md5/sha1 findings outside intentional, documented spots.