OWASP's five equal Argon2id configs: one took 3x longer on my server, and it was glibc, not Argon2
The OWASP Password Storage Cheat Sheet lists five Argon2id configurations and says they "provide an equal level of defense". They trade memory against passes:
| m (memory) | t (passes) | p |
|---|---|---|
| 46 MiB (47104 KiB) | 1 | 1 |
| 19 MiB (19456 KiB) | 2 | 1 |
| 12 MiB (12288 KiB) | 3 | 1 |
| 9 MiB (9216 KiB) | 4 | 1 |
| 7 MiB (7168 KiB) | 5 | 1 |
Equal defense says nothing about equal cost on your login server, so I timed them. I expected the five to land close together. Four did. The first one took three times longer, and the reason is not Argon2 at all.
Setup
- 8 vCPU AMD EPYC VPS, Ubuntu, glibc 2.39, OpenSSL 3.0.13
- Python 3.12,
argon2-cffi25.1.0 (argon2.low_level.hash_secret_raw, type ID, 32-byte output),bcrypt5.1.0,hashlibfor scrypt and PBKDF2 - One warm-up call, then 7 timed calls, median reported. Run twice, 30 seconds apart, on a box that was not idle (load average around 3.5), so treat single digits of milliseconds as noise.
Argon2id: four configs around 20 to 25 ms, one at 73 ms
| config | run 1 median | run 2 median |
|---|---|---|
| m=46 MiB, t=1 | 73.3 ms | 73.7 ms |
| m=19 MiB, t=2 | 24.8 ms | 26.3 ms |
| m=12 MiB, t=3 | 22.1 ms | 24.8 ms |
| m=9 MiB, t=4 | 23.3 ms | 24.1 ms |
| m=7 MiB, t=5 | 20.8 ms | 19.3 ms |
The 46 MiB config touches about as many memory blocks as the others (46 x 1 is in the same range as 19 x 2 or 7 x 5), so the raw Argon2 work is comparable. The extra 50 ms had to come from somewhere else.
Where the 50 ms goes: page faults
I counted minor page faults per call with resource.getrusage(RUSAGE_SELF).ru_minflt:
| config | median | minor faults per call |
|---|---|---|
| m=46 MiB, t=1 | 69.5 ms | 11777 |
| m=19 MiB, t=2 | 25.1 ms | 540 |
| m=7 MiB, t=5 | 22.3 ms | 0 |
11777 faults x 4 KiB pages is 46 MiB: every call faults in the whole memory area from scratch.
This is glibc malloc. Allocations above the mmap threshold get their own mmap, and are returned to the kernel on free. The threshold is dynamic: after you free a large mmapped block, glibc raises the threshold so the next allocation of that size comes from the heap and gets reused. That dynamic threshold is capped at 32 MiB on 64-bit systems. The 19, 12, 9 and 7 MiB buffers end up reused from the heap after the first call. The 46 MiB buffer is above the cap, so every single hash does a fresh mmap, zero-fills 11777 pages on first touch, and unmaps them at the end.
To check the explanation, I pinned the threshold at 128 KiB (MALLOC_MMAP_THRESHOLD_=131072, which also disables the dynamic adjustment), so every config goes through mmap:
| config | default glibc | threshold pinned at 128 KiB |
|---|---|---|
| m=46 MiB, t=1 | 69.5 ms | 85.1 ms |
| m=19 MiB, t=2 | 25.1 ms (540 faults) | 41.4 ms (4865 faults) |
| m=7 MiB, t=5 | 22.3 ms (0 faults) | 25.7 ms (1793 faults) |
The smaller configs pick up page faults and slow down as soon as they lose buffer reuse. The explanation holds.
The rest of the list, same machine
| algorithm and OWASP parameter | run 1 median |
|---|---|
| scrypt N=2^17, r=8, p=1 | 467.0 ms |
| scrypt N=2^16, r=8, p=2 | 398.2 ms |
| scrypt N=2^15, r=8, p=3 | 285.1 ms |
| scrypt N=2^14, r=8, p=5 | 218.5 ms |
| scrypt N=2^13, r=8, p=10 | 215.8 ms |
| bcrypt cost 10 | 60.8 ms |
| bcrypt cost 12 | 242.2 ms |
| PBKDF2-HMAC-SHA256, 600000 | 176.3 ms |
| PBKDF2-HMAC-SHA512, 220000 | 145.3 ms |
| PBKDF2-HMAC-SHA1, 1400000 | 429.3 ms |
The scrypt configs are also "equal" on paper and spread from 216 to 467 ms here. With hashlib.scrypt, p is computed sequentially, so the cost is roughly N x r x p plus the allocation of 128 x N x r bytes. The 128 MiB config pays the largest allocation, again above the glibc cap. Run 2 showed the same order (605, 443, 322, 249, 224 ms) with more noise on the first line.
What I take from this
- "Equal level of defense" is a statement about attacker cost, not about your server. On a glibc system with this stack, the 46 MiB Argon2id config cost three times the CPU time of the other four for the same OWASP rating.
- If you want the high-memory config, the fault cost is fixable: a long-lived process can keep its own buffer, or you can set
M_MMAP_THRESHOLD/M_TOP_PADexplicitly. Measure after the change, not before. - Measure in your process, not in a fresh one per hash. A one-shot CLI benchmark makes every config pay the first-touch cost and hides the difference I saw.
- All fifteen numbers are far under the one-second budget OWASP mentions, which is the wrong limit to aim for on a login endpoint with concurrent users anyway.
If you want to check a set of parameters you already have in production against the OWASP minimums (Argon2id, scrypt, bcrypt, PBKDF2), I keep a small password hashing parameters checker that reads the same thresholds as the cheat sheet. It runs in the browser and stores nothing.
Script
import time, statistics, hashlib, os from argon2.low_level import hash_secret_raw, Type import bcrypt pw = b"correct horse battery staple" salt = os.urandom(16) N = 7 def bench(f): f() # warm-up xs = [] for _ in range(N): a = time.perf_counter(); f(); xs.append((time.perf_counter() - a) * 1000) return statistics.median(xs) for m, t in [(47104, 1), (19456, 2), (12288, 3), (9216, 4), (7168, 5)]: print("argon2id", m, t, bench(lambda: hash_secret_raw(pw, salt, t, m, 1, 32, Type.ID))) for logN, r, p in [(17, 8, 1), (16, 8, 2), (15, 8, 3), (14, 8, 5), (13, 8, 10)]: print("scrypt", logN, r, p, bench(lambda: hashlib.scrypt( pw, salt=salt, n=2**logN, r=r, p=p, maxmem=256 * 1024 * 1024, dklen=32))) for c in (10, 12): s = bcrypt.gensalt(c) print("bcrypt", c, bench(lambda: bcrypt.hashpw(pw, s))) for h, it in [("sha256", 600000), ("sha512", 220000), ("sha1", 1400000)]: print("pbkdf2", h, it, bench(lambda: hashlib.pbkdf2_hmac(h, pw, salt, it))) Run it with MALLOC_MMAP_THRESHOLD_=131072 set and unset, and count ru_minflt around the calls, to see whether your libc behaves the same way.