Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrypting with CBC+PKCS7 requires an extra block on the output buffer #151

Closed
zugzwang opened this issue Mar 2, 2021 · 1 comment
Closed

Comments

@zugzwang
Copy link
Contributor

zugzwang commented Mar 2, 2021

Let c be a N+1-block ciphertext encrypting a plaintext of N blocks (i.e. with one full-block padding).
When calling decrypt on c, the output buffer needs N+2 blocks for decryption to be carried correctly (if it has less than (N+2) * blocksize bytes, it errors with CipherFullBlockExpected).

This is because here

indata.len() + self.block_size()

indata is already N+1 blocks - the space necessary to process the ciphertext. The additional block length needs to be added only when encrypting.

@zugzwang
Copy link
Contributor Author

Though the extra block could be dropped on decryption (and in fact, works for most modes relaxing the requirement above), this is compliant with mbed TLS API documentation - the output buffer needs to hold at least one additional block, therefore, N+2 blocks while decrypting (thanks @jethrogb).

mcr pushed a commit to mcr/rust-mbedtls that referenced this issue Aug 10, 2023
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

No branches or pull requests

1 participant