Repository navigation
fix(paillier): stop caching private-key decryption state; review follow-ups - #38
Merged
Merged
Conversation
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.
5 tasks
This was referenced Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-ups to the review fixes pushed directly to
dev(873b8ad..fa6ef4d), per decisions recorded on #37.Changes
crypto/paillier/ct_cache.go,PrivateKey.Decrypt). The cache kept copies ofLambdaN, its byte encoding, and the decryption coefficient in a package-global map for the key's lifetime and never zeroed them. It measured noDecryptgain on a reused 2048-bit key (median 70.7 ms before vs 70.6 ms after the cache).Decryptrebuilds its state per call again;ExpCTWithBitLenwipes its padded exponent. Kept: up-front key validation,ErrInvalidModulus/ErrMalformedKeyerror returns in both timing modes, and the public-key N^2 cache (Encrypt ~10% faster, half the allocations).go.mod'sgodirective 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.Verification
go test -shuffle=on ./crypto/paillier ./crypto/mta: passgo test -race -count=3on concurrent same-key, key-mutation, by-value-copy, and malformed-key Decrypt tests: passgo vet ./crypto/paillier: pass