Skip to content

refactor: remove pointless zero padding in Encrypted#304

Open
allamiro wants to merge 1 commit into
lixmal:masterfrom
allamiro:fix/encrypted-padding
Open

refactor: remove pointless zero padding in Encrypted#304
allamiro wants to merge 1 commit into
lixmal:masterfrom
allamiro:fix/encrypted-padding

Conversation

@allamiro

@allamiro allamiro commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #286.

Problem

Encrypted::encrypt appended 16 zero bytes to the plaintext and decrypt stripped the last 16 bytes again. AES-GCM needs no padding, and the LENGTH_IV = 16 constant 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; decrypt returns the full plaintext. The format only lives in the in-memory DbCache (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 Encrypted AES-GCM to simplify the logic and avoid offset bugs. decrypt now returns the full plaintext; LENGTH_IV is removed, and this only affects in-memory DbCache (no compatibility impact).

  • Refactors
    • Stop appending/removing 16 zero bytes; GCM needs no padding.
    • Remove misleading LENGTH_IV constant (nonce remains 96-bit as before).

Written for commit 8635445. Summary will update on new commits.

Review in cubic

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.
@allamiro allamiro force-pushed the fix/encrypted-padding branch from 8635445 to 4f22a28 Compare June 13, 2026 00:17
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.

Encrypted: pointless 16-byte zero padding and misleading LENGTH_IV constant

1 participant