2.4 KiB
2.4 KiB
ADR-0002: chronogrid_crypto – Argon2id KDF & OS Keychain Strategy
- Status: Accepted
- Date: 2026-08-09
- Deciders: Michael Kell
Context & Problem Statement
Task 1.2 requires implementing a chronogrid_crypto crate that provides:
- A master-key derivation function using Argon2id with parameters mandated by
docs/ARCHITECTURE/02-security-and-crypto.md. - Cross-platform OS keychain bindings for secure credential persistence (Windows, Linux). Android is deferred to the Flutter KeyStore bridge.
Options Considered
- Hand-roll Argon2id via raw
blake2+ memory-hard loop — maximum control but high risk of implementation bugs in a security-critical path. - Use the
argon2crate (RustCrypto) — well-audited, widely used, supports Argon2id with configurable parameters out of the box. - Use
ringorsodiumoxide— neither provides Argon2id natively; would still need theargon2crate.
For keychain:
- Direct Win32 / libsecret FFI — full control, but significant per-platform maintenance burden.
keyringcrate — abstracts Windows Credential Manager, Linux SecretService, and macOS Keychain behind a single API.
Decision Outcome
Chosen Options:
argon2crate v0.5 (RustCrypto) for KDF — spec-compliant, zero-copy output, and widely audited.keyringcrate v3 for cross-platform OS keychain — minimal code, covers Windows + Linux targets. Android is excluded viacfg(not(target_os = "android"))and will be handled by the Flutter KeyStore bridge.
Key design choices:
- Argon2id parameters: memory = 65 536 KiB (64 MiB), time_cost = 3, parallelism = 4, salt = 16 bytes, output = 32 bytes.
DerivedKeystruct wraps key + salt and implementsZeroize + Dropfor automatic memory scrubbing.Debugimpl onDerivedKeyredacts key material to prevent accidental log leaks.- Raw bytes are Base64-encoded before keychain insertion for UTF-8 credential backend compatibility, using inline encode/decode helpers (no extra dependency).
Consequences & Trade-offs
- Positive: Spec-compliant crypto with secure memory handling; single cross-platform keychain API; 8 unit tests + 1 doc-test provide baseline confidence.
- Negative:
keyringv3 does not support Android — Android keychain must be wired separately via Flutter platform channels (planned for Task 1.5). Inline Base64 is minimal but could be replaced bybase64crate if other crates need it later.