Skip to content

fix(paillier): stop caching private-key decryption state; review follow-ups - #38

Merged
piotr-roslaniec merged 4 commits into
devfrom
fix/dev-review-followups
Oct 2, 2026
Merged

piotr-roslaniec merged 4 commits into
devfrom
fix/dev-review-followups

Conversation

@piotr-roslaniec

Copy link
Copy Markdown

Follow-ups to the review fixes pushed directly to dev (873b8ad..fa6ef4d), per decisions recorded on #37.

Changes

  • Drop the private-key Paillier cache (crypto/paillier/ct_cache.go, PrivateKey.Decrypt). The cache kept copies of LambdaN, its byte encoding, and the decryption coefficient in a package-global map for the key's lifetime and never zeroed them. It measured no Decrypt gain on a reused 2048-bit key (median 70.7 ms before vs 70.6 ms after the cache). Decrypt rebuilds its state per call again; ExpCTWithBitLen wipes its padded exponent. Kept: up-front key validation, ErrInvalidModulus/ErrMalformedKey error returns in both timing modes, and the public-key N^2 cache (Encrypt ~10% faster, half the allocations).
  • CI: go directive check. The Vet job fails if go.mod's go directive differs from the minimum stated in README. It would have caught test: add holistic signing boundary regressions #33 lowering the directive to 1.25.6.
  • Changelog: the review fixes were credited to "(PR Integrate dev hardening set into master #37)", the dev->master tracking PR. They are now attributed to their commits.

Verification

  • go test -shuffle=on ./crypto/paillier ./crypto/mta: pass
  • go test -race -count=3 on concurrent same-key, key-mutation, by-value-copy, and malformed-key Decrypt tests: pass
  • go vet ./crypto/paillier: pass
  • go directive check run locally: passes on current files, fails when go.mod is set to 1.25.6

A per-key cache of LambdaN, its byte encoding, and the decryption coefficient measured no Decrypt speedup (70.7 vs 70.6 ms) while keeping unzeroed secret-derived copies in package-global state. Decrypt rebuilds its state per call again; key validation and error returns are kept, as is the public-key N^2 cache.
@piotr-roslaniec
piotr-roslaniec merged commit f8bbaff into dev Oct 2, 2026
4 checks passed
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