#!/usr/bin/env python3 """Compare Argon2 candidates in the actual limited API container.""" import json import subprocess from pathlib import Path root = Path(__file__).resolve().parents[1] code = """import concurrent.futures,json,resource,statistics,time from argon2 import PasswordHasher rows=[] for memory,iterations,parallelism in [(19456,2,1),(65536,3,4)]: h=PasswordHasher(memory_cost=memory,time_cost=iterations,parallelism=parallelism) stored=h.hash('Synthetic-password-for-budget') def verify(_): started=time.perf_counter();h.verify(stored,'Synthetic-password-for-budget');return time.perf_counter()-started single=[verify(i) for i in range(6)] started=time.perf_counter() with concurrent.futures.ThreadPoolExecutor(max_workers=2) as pool:durations=list(pool.map(verify,range(8))) rows.append(dict(memory_kib=memory,time_cost=iterations,parallelism=parallelism,single_p50_seconds=statistics.median(single),single_max_seconds=max(single),concurrency=2,batch_seconds=time.perf_counter()-started,batch_max_seconds=max(durations),process_peak_rss_kib=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)) print(json.dumps(rows))""" result = subprocess.check_output( ["docker", "compose", "exec", "-T", "api", "python", "-c", code], cwd=root, text=True ) report = { "candidates": json.loads(result), "api_cpu_limit": 0.5, "api_memory_limit_bytes": 512 * 1024**2, "max_hashes_per_api": 2, "api_replicas": 2, "global_login_ip_limit_per_minute": 120, "global_login_account_limit_per_minute": 10, "measurement": "Six sequential and eight two-thread verifications per candidate; peak RSS is cumulative for this probe process, not container total.", } (root / "evidence/argon-budget.json").write_text(json.dumps(report, indent=2) + "\n") print("Saved measured Argon2 budget; evidence/argon-budget.json")