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

Fix crypt_and_hash decrypt issue when used with stream cipher #7728

Conversation

waleed-elmelegy-arm
Copy link
Contributor

@waleed-elmelegy-arm waleed-elmelegy-arm commented Jun 9, 2023

crypt_and_hash decryption fails when used with a stream cipher mode of operation due to the input not being multiple of block size, this only applies to block cipher modes and not stream ciphers.This change exempts CTR, CFB & OFB modes from this check.

Description

fixes #7417
crypt_and_hash decryption fails when used with a stream cipher mode of operation due to the input not being multiple of block size, this only applies to block cipher modes and not stream ciphers.This change exempts CTR, CFB & OFB modes from this check.

PR checklist

Please tick as appropriate and edit the reasons (e.g.: "backport: not needed because this is a new feature")

crypt_and_hash decryption fails when used with a stream cipher
mode of operation due to the input not being multiple of block
size, this only applies to block cipher modes and not stream
ciphers.This change exempts CTR, CFB & OFB modes from this check.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
@waleed-elmelegy-arm waleed-elmelegy-arm added needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review needs-ci Needs to pass CI tests needs-backports Backports are missing or are pending review and approval. size-xs Estimated task size: extra small (a few hours at most) labels Jun 9, 2023
@waleed-elmelegy-arm waleed-elmelegy-arm self-assigned this Jun 9, 2023
@@ -406,6 +406,9 @@ int main(int argc, char *argv[])
* Check the file size.
*/
if (mbedtls_cipher_info_get_mode(cipher_info) != MBEDTLS_MODE_GCM &&
mbedtls_cipher_info_get_mode(cipher_info) != MBEDTLS_MODE_CTR &&
mbedtls_cipher_info_get_mode(cipher_info) != MBEDTLS_MODE_CFB &&
mbedtls_cipher_info_get_mode(cipher_info) != MBEDTLS_MODE_OFB &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there's quite a bit of duplication here. And while it's not main library code, so quality bar is a bit lower, it still might be better to use a local variable for the mode. And while doing that, how about locals for the results of mbedtls_md_get_size() and mbedtls_cipher_get_block_size()?

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
@tom-cosgrove-arm
Copy link
Contributor

This looks good. Just needs a ChangeLog entry and, as it's a bug fix for an example program, a backport (if the example program is in the LTS and has the same bug!)

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@davidhorstmann-arm davidhorstmann-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@tom-cosgrove-arm tom-cosgrove-arm added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Jun 23, 2023
@tom-cosgrove-arm
Copy link
Contributor

While a couple of OpenCI jobs failed, the corresponding jobs succeeding on the Internal CI, so CI is green

@davidhorstmann-arm davidhorstmann-arm removed the needs-backports Backports are missing or are pending review and approval. label Jun 23, 2023
@gilles-peskine-arm gilles-peskine-arm added needs-backports Backports are missing or are pending review and approval. and removed needs-ci Needs to pass CI tests labels Jun 23, 2023
@daverodgman daverodgman removed the needs-backports Backports are missing or are pending review and approval. label Jun 30, 2023
@daverodgman daverodgman merged commit c23d222 into Mbed-TLS:development Jun 30, 2023
13 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports size-xs Estimated task size: extra small (a few hours at most)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crypt_and_hash decrypt fail with AES-128-CTR alg
5 participants