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

Use switch statement instead if-else in psa_aead_check_nonce_length() and psa_aead_set_lengths(). Fixes #5065 #5072

Merged
merged 4 commits into from
Oct 18, 2021

Conversation

mprse
Copy link
Contributor

@mprse mprse commented Oct 13, 2021

Description

Fixes #5065.

Without this fix added test component (component_test_psa_crypto_config_chachapoly_disabled) fails as follows:

Build warning:
psa_crypto.c: In function ‘psa_aead_check_nonce_length’:
psa_crypto.c:3654:1: error: control reaches end of non-void function [-Werror=return-type]

Test failures:

FAILED (1173 / 1225 tests (131 skipped))

e.g.:
PSA Multipart State Checks, AES - GCM ............................. FAILED
  ( ( psa_aead_set_lengths( &operation, additional_data->len, input_data->len ) ) ) == ( ((psa_status_t)0) )
  at line 4746, suites/test_suite_psa_crypto.function

PSA AEAD decrypt: AES-CCM, invalid nonce length 6 ................. FAILED
  ( status ) == ( expected_result )
  at line 3773, suites/test_suite_psa_crypto.function

With the fix all tests pass for component_test_psa_crypto_config_chachapoly_disabled and there is no compilator warning.

Status

READY

Requires Backporting

No

Migrations

NO

Additional comments

I'm not sure if the name and description of the added test component is consistent with the requirements.

mprse added 2 commits October 13, 2021 13:27
…PSA_WANT_ALG_CHACHA20_POLY1305

Signed-off-by: Przemyslaw Stekiel <[email protected]>
…th and psa_aead_set_lengths (fixes Mbed-TLS#5065)

Signed-off-by: Przemyslaw Stekiel <[email protected]>
@mprse mprse added bug needs-review Every commit must be reviewed by at least two team members, needs-backports Backports are missing or are pending review and approval. needs-reviewer This PR needs someone to pick it up for review labels Oct 13, 2021
Signed-off-by: Przemyslaw Stekiel <[email protected]>
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

Some minor documentation issues, other than that LGTM

Comment on lines 2 to 4
* Use switch statement instead if-else in
psa_aead_check_nonce_length()
and psa_aead_set_lengths(). Fixes #5065.
Copy link
Contributor

Choose a reason for hiding this comment

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

Changelog entries are for users of the library, not for its developers. (Developers have the git commit messages.) “Use switch statement” is an implementation detail, it isn't relevant for users. Instead, the changelog entry should explain the consequence of the bug. For example:

Fix compile-time or run-time errors in PSA AEAD functions when ChachaPoly is disabled. Fixes #5065.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

@@ -1596,6 +1596,19 @@ component_test_psa_crypto_config_no_driver() {
make test
}

component_test_psa_crypto_config_chachapoly_disabled() {
# full - MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305
msg "build: full - MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
Copy link
Contributor

Choose a reason for hiding this comment

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

The description says that MBEDTLS_CHACHAPOLY_C is enabled, but the code disables it. The status of MBEDTLS_CHACHAPOLY_C is irrelevant for this test. So please remove it from both the description and the code. This is full minus GCM and Chachapoly for PSA.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The description says that MBEDTLS_CHACHAPOLY_C is disabled (full -(minus) MBEDTLS_CHACHAPOLY_C).

I think it is relevant for the test as without this I wasn't able to reproduce the issue( with BEDTLS_CHACHAPOLY_C PSA_WANT_ALG_CHACHA20_POLY1305 is always defined):
https://github.com/ARMmbed/mbedtls/blob/2bb5e9c973cf7a37eacb50a65537c921b60f2fac/include/mbedtls/config_psa.h#L647-L650

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed - to minus in description.

Copy link
Contributor

Choose a reason for hiding this comment

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

The status of MBEDTLS_CHACHAPOLY_C is irrelevant, but the status of PSA_WANT_ALG_CHACHA20_POLY1305 is. There are two ways you can have PSA_WANT_ALG_CHACHA20_POLY1305 enabled:

  • MBEDTLS_CHACHAPOLY_C enabled. (PSA chachapoly implemented with Mbed TLS's built-in implementation.)
  • MBEDTLS_PSA_CRYPTO_CONFIG enabled and MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305 enabled. (PSA chachapoly implemented with a third-party driver.)

The test needs to pick one, but it's not particularly important which one it picks.

Signed-off-by: Przemyslaw Stekiel <[email protected]>
@mprse
Copy link
Contributor Author

mprse commented Oct 18, 2021

It seems that backport to 2.xis not needed.

@gilles-peskine-arm
Copy link
Contributor

The bug is in a part of the code that doesn't exist in 2.x, so there's no fix to backport. But please backport the new test.

@mprse
Copy link
Contributor Author

mprse commented Oct 18, 2021

Created backport PR #5083

@AndrzejKurek AndrzejKurek self-requested a review October 18, 2021 15:03
@gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm removed the needs-reviewer This PR needs someone to pick it up for review label Oct 18, 2021
Copy link
Member

@paul-elliott-arm paul-elliott-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

@paul-elliott-arm paul-elliott-arm removed the needs-review Every commit must be reviewed by at least two team members, label Oct 18, 2021
@gilles-peskine-arm gilles-peskine-arm added approved Design and code approved - may be waiting for CI or backports and removed needs-backports Backports are missing or are pending review and approval. labels Oct 18, 2021
@gilles-peskine-arm gilles-peskine-arm merged commit bf21c07 into Mbed-TLS:development Oct 18, 2021
@paul-elliott-arm paul-elliott-arm added the needs-backports Backports are missing or are pending review and approval. label Oct 18, 2021
gilles-peskine-arm added a commit that referenced this pull request Oct 18, 2021
backport 2.x: backport only new test in all.sh from #5072
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this pull request Jul 20, 2023
The original goal (Mbed-TLS#5072) was to run
a test with ChaChaPoly disabled in PSA. It was actually implemented with GCM
also partially disabled (legacy GCM enabled but PSA GCM disabled), which
distracted from the objective. It's actually useful to test both with and
without GCM, so test both. Don't test inconsistencies between legacy and PSA
support because that's not a common case and not one we have particular
reasons to test.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this pull request Jul 21, 2023
The original goal (Mbed-TLS#5072) was to run
a test with ChaChaPoly disabled in PSA. It was actually implemented with GCM
also partially disabled (legacy GCM enabled but PSA GCM disabled), which
distracted from the objective. It's actually useful to test both with and
without GCM, so test both. Don't test inconsistencies between legacy and PSA
support because that's not a common case and not one we have particular
reasons to test.

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this pull request Aug 22, 2023
The original goal (Mbed-TLS#5072) was to run
a test with ChaChaPoly disabled in PSA. It was actually implemented with GCM
also partially disabled (legacy GCM enabled but PSA GCM disabled), which
distracted from the objective. It's actually useful to test both with and
without GCM, so test both. Don't test inconsistencies between legacy and PSA
support because that's not a common case and not one we have particular
reasons to test.

Signed-off-by: Gilles Peskine <[email protected]>
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 bug needs-backports Backports are missing or are pending review and approval.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PSA AEAD code doesn't work when Chachapoly is disabled
3 participants