This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Measure Argon2id cost on THIS stand and derive the login-DoS budget. Usage (inside the app image or any venv with argon2-cffi):
|
||||
python scripts/argon2_bench.py [--runs 20]
|
||||
Budget = concurrency limit (ARGON2_CONCURRENCY per replica) x single-hash time: with c slots one replica can verify at most c / t logins per second;
|
||||
the shared Redis rate limit (30 attempts/min/IP, 10 failures/min/user) keeps the attacker far below that."""
|
||||
import argparse, statistics, time
|
||||
from argon2 import PasswordHasher, Type
|
||||
|
||||
ap = argparse.ArgumentParser(); ap.add_argument("--runs", type=int, default=20); a = ap.parse_args()
|
||||
for m, t, p in ((19456, 2, 1), (47104, 1, 1), (65536, 3, 4)):
|
||||
ph = PasswordHasher(time_cost=t, memory_cost=m, parallelism=p, type=Type.ID)
|
||||
h = ph.hash("benchmark-password"); xs = []
|
||||
for _ in range(a.runs):
|
||||
s = time.perf_counter(); ph.verify(h, "benchmark-password"); xs.append(time.perf_counter() - s)
|
||||
xs.sort()
|
||||
print(f"m={m//1024} MiB t={t} p={p}: median {statistics.median(xs)*1000:.0f} ms, p95 {xs[int(.95*len(xs))-1]*1000:.0f} ms, max logins/s per slot {1/statistics.median(xs):.1f}")
|
||||
Reference in New Issue
Block a user