Skip to content

crypto: make keystore Argon2 KDF cost parameters self-describing per-key - #501

Open
ezeike wants to merge 1 commit into
mainfrom
feat/keystore-flexible-kdf-params
Open

crypto: make keystore Argon2 KDF cost parameters self-describing per-key#501
ezeike wants to merge 1 commit into
mainfrom
feat/keystore-flexible-kdf-params

Conversation

@ezeike

@ezeike ezeike commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Stores KdfTime/KdfMemoryKB/KdfThreads alongside each EncryptedPrivateKey so DecryptPrivateKey always re-derives with the exact Argon2 parameters used to encrypt that key, instead of a single hardcoded global constant shared by every caller.

  • Zero-value fields fall back to the historical defaults (time=3, memory=32MB, threads=4), so existing keystore.json files decrypt unmodified — fully backward compatible.
  • Adds EncryptPrivateKeyWithParams for callers (e.g. test suites decrypting many keys under high concurrency) that want a cheaper KDF than the 32MB/call default.
  • EncryptPrivateKey keeps its existing signature/behavior, now implemented as a thin wrapper over EncryptPrivateKeyWithParams with the default params.

Scope

Single file: lib/crypto/keystore.go (+37/-12).

Testing

  • go test ./lib/crypto/... -run Keystore -v — all passing (TestKeystoreImportWithOpts, TestKeystoreImportRawWithOpts, TestKeystoreDeleteKeyWithOpts)
  • go build ./lib/crypto/... — clean

🤖 Generated with Claude Code

@ezeike
ezeike force-pushed the feat/keystore-flexible-kdf-params branch 2 times, most recently from daf70ca to 3e0a38a Compare August 5, 2026 20:35
Store KdfTime/KdfMemoryKB/KdfThreads alongside each EncryptedPrivateKey so
DecryptPrivateKey always re-derives with the exact parameters used to encrypt
that key, instead of a single hardcoded global constant shared by every
caller. Zero-value fields fall back to the historical defaults (3, 32MB, 4),
so existing keystore.json files decrypt unmodified.

Adds EncryptPrivateKeyWithParams for callers -- e.g. test suites decrypting
many keys under high concurrency -- that want a cheaper KDF than the
32MB/call default. EncryptPrivateKey keeps its existing signature/behavior.

kdf* fields are only written when they differ from the defaults, so the
common case still marshals identically to a pre-kdf-params keystore.
@ezeike
ezeike force-pushed the feat/keystore-flexible-kdf-params branch from 3e0a38a to 30bd223 Compare August 5, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant