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

crypt_and_hash decrypt fail with AES-128-CTR alg #7417

Closed
z789 opened this issue Apr 10, 2023 · 1 comment · Fixed by #7728
Closed

crypt_and_hash decrypt fail with AES-128-CTR alg #7417

z789 opened this issue Apr 10, 2023 · 1 comment · Fixed by #7728
Assignees
Labels
bug size-s Estimated task size: small (~2d)

Comments

@z789
Copy link

z789 commented Apr 10, 2023

Summary

crypt_and_hash is not working when decrypt with AES-128-CTR alg.

./crypt_and_hash 1 file.txt.enc file.txt.dec AES-128-CTR SHA512 123456
File content not a multiple of the block size (16).

https://github.com/Mbed-TLS/mbedtls/blob/development/programs/aes/crypt_and_hash.c#L405-L414

@ronald-cron-arm
Copy link
Contributor

Thanks for your report. I think I agree with you that there is a bug in crypt_and_hash regarding decryption in CTR mode. Please check if you agree with the below. Would it be possible for you to fix this through a PR?

The program crypt_and_hash when decrypting a file in CTR mode checks that the size of the encrypted message (size of the file minus the size of the HMAC at the end of the file) is a multiple of the block size. This seems wrong as in CTR mode the size of an encrypted message is just the size of the associated plain text. As a consequence, encrypting and then decrypting a message whose length is not a multiple of the block size fails in CTR mode. Example of calls where the last decryption request fails with "File content not a multiple of the block size (16)".

./crypt_and_hash 0 file.txt file.txt.enc AES-128-CTR SHA512 123456
./crypt_and_hash 1 file.txt.enc file AES-128-CTR SHA512 123456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants