refactor: remove pointless zero padding in Encrypted#304
Open
allamiro wants to merge 1 commit into
Open
Conversation
The plaintext was extended by 16 zero bytes before AES-GCM encryption and the last 16 bytes stripped after decryption. GCM is a stream mode and needs no padding; the constant was also named LENGTH_IV while the actual GCM nonce is 12 bytes. The roundtrip only worked because both sides applied the same offset.
8635445 to
4f22a28
Compare
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.
Fixes #286.
Problem
Encrypted::encryptappended 16 zero bytes to the plaintext anddecryptstripped the last 16 bytes again. AES-GCM needs no padding, and theLENGTH_IV = 16constant didn't even match the real 96-bit GCM nonce — the code only worked because both sides applied the same offset. Confusing for anyone auditing the crypto.Change
Padding and the misleading constant removed;
decryptreturns the full plaintext. The format only lives in the in-memoryDbCache(never persisted), so there are no compatibility concerns.Testing
cargo test: 9/9 pass, including the encryption roundtrip and full database roundtrip tests.Summary by cubic
Remove pointless zero padding in
EncryptedAES-GCM to simplify the logic and avoid offset bugs.decryptnow returns the full plaintext;LENGTH_IVis removed, and this only affects in-memoryDbCache(no compatibility impact).LENGTH_IVconstant (nonce remains 96-bit as before).Written for commit 8635445. Summary will update on new commits.