Move NIST_KW to PSA API #180

Merged
bjwtaylor merged 86 commits from kw-api-rework into development 2025-05-13 04:21:13 -05:00
bjwtaylor commented 2025-02-24 02:18:58 -06:00 (Migrated from github.com)

Description

Rework of the KW API to update to the TF-PSA-CRYPTO interface, removal of support for KW from cipher.c and conversion of the legacy self test to a standard unit test. needs https://github.com/Mbed-TLS/mbedtls/pull/9983 resolves Mbed-TLS/mbedtls#9382

PR checklist

## Description Rework of the KW API to update to the TF-PSA-CRYPTO interface, removal of support for KW from cipher.c and conversion of the legacy self test to a standard unit test. needs https://github.com/Mbed-TLS/mbedtls/pull/9983 resolves Mbed-TLS/mbedtls#9382 ## PR checklist - [x] **changelog** provided - [x] **framework PR** not required - [x] **mbedtls PR** provided Mbed-TLS/mbedtls https://github.com/Mbed-TLS/mbedtls/pull/9983 - [x] 3.6 PR not required (API break) - **tests** provided
mpg commented 2025-02-25 05:21:36 -06:00 (Migrated from github.com)

Note: test failures are expected here; the CI on the companion PR https://github.com/Mbed-TLS/mbedtls/pull/9983 is green so that's good.

Note: test failures are expected here; the CI on the companion PR https://github.com/Mbed-TLS/mbedtls/pull/9983 is green so that's good.
mpg commented 2025-02-25 05:25:10 -06:00 (Migrated from github.com)

Note for future PRs: please do smaller, atomic commits. I realise that when changing an API, a lot of things need to be changed at the same time, but here I think at least the part where you remove support for NIST-KW in Cipher could have been a separate commit. (Perhaps there were other opportunities for splitting things up, I haven't looked deep yet.)

Edit: good candidates for separate commits include renaming variables, moving the selftest function to a different file, changing the existing test function to use exact-sized buffers.

I'm not requesting a history rewrite here (note that the other reviewer might), but in the future please try to make atomic commits.

Note for future PRs: please do smaller, atomic commits. I realise that when changing an API, a lot of things need to be changed at the same time, but here I think at least the part where you remove support for NIST-KW in Cipher could have been a separate commit. (Perhaps there were other opportunities for splitting things up, I haven't looked deep yet.) Edit: good candidates for separate commits include renaming variables, moving the selftest function to a different file, changing the existing test function to use exact-sized buffers. I'm not requesting a history rewrite here (note that the other reviewer might), but in the future please try to make atomic commits.
mpg (Migrated from github.com) reviewed 2025-02-25 06:00:43 -06:00
mpg (Migrated from github.com) left a comment

Just a high-level first pass, releasing the comments I have so far.

Just a high-level first pass, releasing the comments I have so far.
mpg (Migrated from github.com) commented 2025-02-25 05:53:13 -06:00

Please explain that this key must be for AES with ECB_NO_PADDING and must allow USAGE_ENCRYPT (I'm assuming). Similarly for the unwrap function, except I'll guess it'll be USAGE_DECRYPT (I didn't check, though).

Please explain that this key must be for AES with `ECB_NO_PADDING` and must allow `USAGE_ENCRYPT` (I'm assuming). Similarly for the unwrap function, except I'll guess it'll be `USAGE_DECRYPT` (I didn't check, though).
mpg (Migrated from github.com) commented 2025-02-25 05:33:43 -06:00

Looks like this file is now empty - if so, let's delete it.

Looks like this file is now empty - if so, let's delete it.
@ -1,28 +1,27 @@
NIST KW self test
mbedtls_nist_kw_self_test:
#Test vectors taken from NIST
mpg (Migrated from github.com) commented 2025-02-25 05:38:34 -06:00

Seems wrong to have to add this dependency declaration on every single test case here. Unless I'm mistaken, the NIST-KW function will need this regardless of what parameters are passed. So, I think NIST_KW_C should auto-enable what it needs in include/psa/crypto_adjust_config_dependencies.h.

Also, since since can only be used with AES, NIST_KW_C should also auto-enable WANT_ALG_AES there. (And then we can remove the check in check_config.h, and edit the documentation in include/psa/crypto_config.h.)

Seems wrong to have to add this dependency declaration on every single test case here. Unless I'm mistaken, the NIST-KW function will need this regardless of what parameters are passed. So, I think `NIST_KW_C` should auto-enable what it needs in `include/psa/crypto_adjust_config_dependencies.h`. Also, since since can only be used with AES, `NIST_KW_C` should also auto-enable `WANT_ALG_AES` there. (And then we can remove the check in `check_config.h`, and edit the documentation in `include/psa/crypto_config.h`.)
@ -3,0 +4,4 @@
int alg,
int key_type,
mbedtls_svc_key_id_t *key_id,
const data_t *key)
mpg (Migrated from github.com) commented 2025-02-25 05:43:34 -06:00

Looks to me like it also depends on WANT_ALG_AES. Unless the whole module does now?

Looks to me like it also depends on `WANT_ALG_AES`. Unless the whole module does now?
bjwtaylor (Migrated from github.com) reviewed 2025-02-25 07:35:08 -06:00
bjwtaylor (Migrated from github.com) commented 2025-02-25 07:35:08 -06:00

ack

ack
bjwtaylor (Migrated from github.com) reviewed 2025-02-25 07:35:25 -06:00
@ -1,28 +1,27 @@
NIST KW self test
mbedtls_nist_kw_self_test:
#Test vectors taken from NIST
bjwtaylor (Migrated from github.com) commented 2025-02-25 07:35:25 -06:00

ack

ack
bjwtaylor (Migrated from github.com) reviewed 2025-02-25 07:35:34 -06:00
@ -3,0 +4,4 @@
int alg,
int key_type,
mbedtls_svc_key_id_t *key_id,
const data_t *key)
bjwtaylor (Migrated from github.com) commented 2025-02-25 07:35:34 -06:00

ack

ack
bjwtaylor (Migrated from github.com) reviewed 2025-02-25 07:35:46 -06:00
bjwtaylor (Migrated from github.com) commented 2025-02-25 07:35:46 -06:00

ack

ack
bjwtaylor (Migrated from github.com) reviewed 2025-02-25 09:25:17 -06:00
bjwtaylor (Migrated from github.com) commented 2025-02-25 09:25:17 -06:00

Interesting when you click on the link it says the file has been deleted and it doesn't appear if you clone, so I think it's already gone?

Interesting when you click on the link it says the file has been deleted and it doesn't appear if you clone, so I think it's already gone?
bjwtaylor (Migrated from github.com) reviewed 2025-02-26 07:29:41 -06:00
@ -1,28 +1,27 @@
NIST KW self test
mbedtls_nist_kw_self_test:
#Test vectors taken from NIST
bjwtaylor (Migrated from github.com) commented 2025-02-26 07:29:41 -06:00

So I've added this in, however it appears to cause issues. My understanding is that the test is overriding these configs by calling

config.py full
 ....
config.py unset PSA_WANT_ALG_CBC_NO_PADDING
....
make CFLAGS=-Werror -O2

So I think we will need these configs in the test unless we change this behavior, let me know what you think.

So I've added this in, however it appears to cause issues. My understanding is that the test is overriding these configs by calling ``` config.py full .... config.py unset PSA_WANT_ALG_CBC_NO_PADDING .... make CFLAGS=-Werror -O2 ``` So I think we will need these configs in the test unless we change this behavior, let me know what you think.
mpg (Migrated from github.com) reviewed 2025-02-27 02:29:39 -06:00
@ -1,28 +1,27 @@
NIST KW self test
mbedtls_nist_kw_self_test:
#Test vectors taken from NIST
mpg (Migrated from github.com) commented 2025-02-27 02:29:39 -06:00

Ah, good point about test configs, though I think it's actually the other way round: if a component in all.sh disables ECB_NO_PADDING while leaving NIST_KW_C enable, then include/psa/crypto_adjust_config_dependencies.h will override it and enable ECB_NO_PADDING anyway. So, if a test component really needs ECB_NO_PADDING disabled, it shoud disable NIST_KW_C too.

Let me take a look at the components that disable ECB_NO_PADDING, there are 4 matches for unset.*ECB_NO_PADDING, all in tests/scripts/components-configuration-crypto.sh (still on the Mbed TLS side...)

  1. component_test_full_no_cipher already disables NIST_KW_C so no question here.
  2. component_test_full_no_ccm_star_no_tag wants to have no built-in cipher, so we'll need to add unset NIST_KW_C with a comment that it would re-enable ECB_NO_PADDING.
  3. component_build_aes_variations already disables NIST_KW_C so no question here.
  4. config_block_cipher_no_decrypt already disables NIST_KW_C so again nothing to change there.
Ah, good point about test configs, though I think it's actually the other way round: if a component in `all.sh` disables `ECB_NO_PADDING` while leaving `NIST_KW_C` enable, then `include/psa/crypto_adjust_config_dependencies.h` will override it and enable `ECB_NO_PADDING` anyway. So, if a test component really needs `ECB_NO_PADDING` disabled, it shoud disable `NIST_KW_C` too. Let me take a look at the components that disable `ECB_NO_PADDING`, there are 4 matches for `unset.*ECB_NO_PADDING`, all in `tests/scripts/components-configuration-crypto.sh` (still on the Mbed TLS side...) 1. `component_test_full_no_cipher` already disables `NIST_KW_C` so no question here. 2. `component_test_full_no_ccm_star_no_tag` wants to have no built-in cipher, so we'll need to add `unset NIST_KW_C` with a comment that it would re-enable `ECB_NO_PADDING`. 3. `component_build_aes_variations` already disables `NIST_KW_C` so no question here. 4. `config_block_cipher_no_decrypt` already disables `NIST_KW_C` so again nothing to change there.
gilles-peskine-arm (Migrated from github.com) reviewed 2025-02-27 03:10:36 -06:00
@ -1,28 +1,27 @@
NIST KW self test
mbedtls_nist_kw_self_test:
#Test vectors taken from NIST
gilles-peskine-arm (Migrated from github.com) commented 2025-02-27 03:10:35 -06:00

FYI if you need to check configuration changes in all.sh components, you can compare the PASS/SKIP status of test_suite_config test cases in outcomes.csv (outcomes.csv.xz attachment to the PR-head job) before/after the change.

FYI if you need to check configuration changes in `all.sh` components, you can compare the PASS/SKIP status of `test_suite_config` test cases in `outcomes.csv` (`outcomes.csv.xz` attachment to the PR-head job) before/after the change.
bjwtaylor (Migrated from github.com) reviewed 2025-03-06 01:50:36 -06:00
@ -1,28 +1,27 @@
NIST KW self test
mbedtls_nist_kw_self_test:
#Test vectors taken from NIST
bjwtaylor (Migrated from github.com) commented 2025-03-06 01:50:36 -06:00

This should now be resolved, I've removed the dependencies in the function file and moved them into the test files.

This should now be resolved, I've removed the dependencies in the function file and moved them into the test files.
bjwtaylor (Migrated from github.com) reviewed 2025-03-06 02:07:25 -06:00
@ -3,0 +4,4 @@
int alg,
int key_type,
mbedtls_svc_key_id_t *key_id,
const data_t *key)
bjwtaylor (Migrated from github.com) commented 2025-03-06 02:07:25 -06:00

PSA_WANT_KEY_TYPE_AES has been added to include/psa/crypto_adjust_config_dependencies.h

PSA_WANT_KEY_TYPE_AES has been added to include/psa/crypto_adjust_config_dependencies.h
bjwtaylor (Migrated from github.com) reviewed 2025-03-06 02:11:18 -06:00
bjwtaylor (Migrated from github.com) commented 2025-03-06 02:11:18 -06:00

Now updated

Now updated
valeriosetti (Migrated from github.com) requested changes 2025-03-17 08:17:18 -05:00
valeriosetti (Migrated from github.com) left a comment

I did an initial pass to familiarize with the PR and left a few minor comments.

Some failures in the CI seems to be related to test/selftest.c still relying on the "old" self test function that is being removed in this PR. Checking the CI https://github.com/Mbed-TLS/mbedtls/pull/9983 would be the only way to see if overall (mbedtls + tf-psa-crypto) this PR is OK, but the tf-psa-crypto reference in 9983 is not updated. Can you please update it?

I did an initial pass to familiarize with the PR and left a few minor comments. Some failures in the CI seems to be related to `test/selftest.c` still relying on the "old" self test function that is being removed in this PR. Checking the CI https://github.com/Mbed-TLS/mbedtls/pull/9983 would be the only way to see if overall (mbedtls + tf-psa-crypto) this PR is OK, but the `tf-psa-crypto` reference in 9983 is not updated. Can you please update it?
@ -0,0 +1,5 @@
API changes
valeriosetti (Migrated from github.com) commented 2025-03-17 07:30:15 -05:00
     argument, these functions now takes a mbedtls_svc_key_id_t key type.
```suggestion argument, these functions now takes a mbedtls_svc_key_id_t key type. ```
valeriosetti (Migrated from github.com) commented 2025-03-17 07:36:34 -05:00
 * \param key                The key wrapping psa key ID to use for encryption. The key should have the following attributes:
* - type: PSA_KEY_TYPE_AES
* - algorithm: PSA_ALG_ECB_NO_PADDING
* - usage flag: PSA_KEY_USAGE_ENCRYPT + other flags if required by the application.

A similar comment apply also for the unwrap function

```suggestion * \param key The key wrapping psa key ID to use for encryption. The key should have the following attributes: * - type: PSA_KEY_TYPE_AES * - algorithm: PSA_ALG_ECB_NO_PADDING * - usage flag: PSA_KEY_USAGE_ENCRYPT + other flags if required by the application. ``` A similar comment apply also for the unwrap function
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
valeriosetti (Migrated from github.com) commented 2025-03-17 07:44:03 -05:00

Once you'll switch ret to be of type psa_status_t, all these ret != 0 should become ret != PSA_SUCCESS

Once you'll switch `ret` to be of type `psa_status_t`, all these `ret != 0` should become `ret != PSA_SUCCESS`
@ -222,1 +196,3 @@
if (ret != 0) {
ret = psa_cipher_update(&wrap_operation,
inbuff, 16, outbuff, sizeof(outbuff), &olen);
if (ret != PSA_SUCCESS) {
valeriosetti (Migrated from github.com) commented 2025-03-17 07:40:34 -05:00

ret should be of type psa_status_t now that you are using PSA functions.

`ret` should be of type `psa_status_t` now that you are using PSA functions.
@ -3,0 +4,4 @@
int alg,
int key_type,
mbedtls_svc_key_id_t *key_id,
const data_t *key)
valeriosetti (Migrated from github.com) commented 2025-03-17 08:08:16 -05:00

I think you added these mbedtls_printf to mimic the behvior the of the self test function that was used before. However I don't think there are useful in test_suite_xxx files, so we can remove them as well as the verbose parameter.

I think you added these `mbedtls_printf` to mimic the behvior the of the self test function that was used before. However I don't think there are useful in `test_suite_xxx` files, so we can remove them as well as the `verbose` parameter.
valeriosetti (Migrated from github.com) commented 2025-03-17 08:10:23 -05:00

There should be TEST_MEMORY_COMPARE for this kind of test

There should be `TEST_MEMORY_COMPARE` for this kind of test
bjwtaylor (Migrated from github.com) reviewed 2025-03-18 05:18:31 -05:00
@ -3,0 +4,4 @@
int alg,
int key_type,
mbedtls_svc_key_id_t *key_id,
const data_t *key)
bjwtaylor (Migrated from github.com) commented 2025-03-18 05:18:31 -05:00

So the TEST_MEMORY_COMPARE as far as I can tell can only do the second part. Is it best to split it into two operations for the length compare and the mem compare?

So the TEST_MEMORY_COMPARE as far as I can tell can only do the second part. Is it best to split it into two operations for the length compare and the mem compare?
gilles-peskine-arm (Migrated from github.com) reviewed 2025-03-18 06:16:33 -05:00
@ -3,0 +4,4 @@
int alg,
int key_type,
mbedtls_svc_key_id_t *key_id,
const data_t *key)
gilles-peskine-arm (Migrated from github.com) commented 2025-03-18 06:16:33 -05:00

TEST_MEMORY_COMPARE compares both the length and the content. It was introduced after we noticed some tests were only comparing the content but not the length.

Note that your implementation here is wrong: you're asserting that the lengths OR the (partial) content match, instead of AND.

TEST_MEMORY_COMPARE also has the advantage that it prints the lengths on failure. And provides us a single place to change if we want to print the content on failure.

`TEST_MEMORY_COMPARE` compares both the length and the content. It was introduced after we noticed some tests were only comparing the content but not the length. Note that your implementation here is wrong: you're asserting that the lengths OR the (partial) content match, instead of AND. `TEST_MEMORY_COMPARE` also has the advantage that it prints the lengths on failure. And provides us a single place to change if we want to print the content on failure.
mpg (Migrated from github.com) requested changes 2025-03-25 05:48:58 -05:00
mpg (Migrated from github.com) left a comment

Just reviewing the new commits since my previous partial review - still not a complete review.

Just reviewing the new commits since my previous partial review - still not a complete review.
mpg (Migrated from github.com) commented 2025-03-25 05:42:41 -05:00

Note to self: check what tests we have about usage.

Note to self: check what tests we have about usage.
mpg (Migrated from github.com) commented 2025-03-25 05:43:36 -05:00

I think the change from DE to ENcrypt was not intended?

I think the change from DE to ENcrypt was not intended?
@ -48,4 +48,8 @@
#define PSA_WANT_ALG_CMAC 1
mpg (Migrated from github.com) commented 2025-03-25 05:24:23 -05:00

Nit: the outer parentheses are not needed.

Nit: the outer parentheses are not needed.
mpg (Migrated from github.com) commented 2025-03-25 05:25:07 -05:00

ITYM PSA_WANT_ALG_AES here (and also in the comment in crypto_config.h).

ITYM `PSA_WANT_ALG_AES` here (and also in the comment in `crypto_config.h`).
@ -763,1 +760,4 @@
* Enable the 128-bit key wrapping modes from NIST SP 800-38F:
* KW (also known as RFC 3394) and KWP (RFC 5649).
* Currently these modes are only supported with AES.
*
mpg (Migrated from github.com) commented 2025-03-25 05:27:22 -05:00

We should update "Requires" to "Auto-enables".

In the past, we used "Requires" because it was up to users to enable dependencies for things they wanted. Now we are doing it for them in the various crypto_adjust_config files, so they're no longer required to do it. We can still keep the info here if they're curious, but should not give the impression that there's something they need to do about it.

We should update "Requires" to "Auto-enables". In the past, we used "Requires" because it was up to users to enable dependencies for things they wanted. Now we are doing it for them in the various `crypto_adjust_config` files, so they're no longer required to do it. We can still keep the info here if they're curious, but should not give the impression that there's something they need to do about it.
mpg (Migrated from github.com) commented 2025-03-25 05:36:17 -05:00

I'm not sure I agree with this removal. NIST_KW_C uses ALG_ECB_NO_PADDING which is still listed as incompatible with this feature.

I'm not sure I agree with this removal. `NIST_KW_C` uses `ALG_ECB_NO_PADDING` which is still listed as incompatible with this feature.
@ -6,3 +25,3 @@
* depends_on:MBEDTLS_NIST_KW_C
* depends_on:MBEDTLS_NIST_KW_C:PSA_WANT_KEY_TYPE_AES
* END_DEPENDENCIES
*/
mpg (Migrated from github.com) commented 2025-03-25 05:45:18 -05:00

Thanks, but please also remove all other calls to mbedtls_printf() from this function, and the verbose parameter as well.

Thanks, but please also remove all other calls to `mbedtls_printf()` from this function, and the `verbose` parameter as well.
@ -15,1 +33,3 @@
/* END_CASE */
unsigned char *out = NULL;
size_t olen = 0;
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT;
mpg (Migrated from github.com) commented 2025-03-25 05:48:00 -05:00

Thanks but there's another occurrence in this function, can you fix it as well?

Thanks but there's another occurrence in this function, can you fix it as well?
mpg (Migrated from github.com) reviewed 2025-03-25 05:51:56 -05:00
mpg (Migrated from github.com) commented 2025-03-25 05:51:56 -05:00

Indeed, the diff view now says "the file was deleted". There must have been a glitch last time, either in the diff view or between the chair and the keyboard. Anyway, marking as resolved.

Indeed, the diff view now says "the file was deleted". There must have been a glitch last time, either in the diff view or between the chair and the keyboard. Anyway, marking as resolved.
mpg (Migrated from github.com) reviewed 2025-03-25 06:04:52 -05:00
@ -1,28 +1,27 @@
NIST KW self test
mbedtls_nist_kw_self_test:
#Test vectors taken from NIST
mpg (Migrated from github.com) commented 2025-03-25 06:04:52 -05:00

The dependencies are updated here and the all.sh component in https://github.com/Mbed-TLS/mbedtls/pull/9983 so marking this conversation as resolved.

The dependencies are updated here and the `all.sh` component in https://github.com/Mbed-TLS/mbedtls/pull/9983 so marking this conversation as resolved.
mpg (Migrated from github.com) reviewed 2025-03-25 06:08:24 -05:00
@ -48,4 +48,8 @@
#define PSA_WANT_ALG_CMAC 1
mpg (Migrated from github.com) commented 2025-03-25 06:08:23 -05:00

Fixed in a later commit.

Fixed in a later commit.
mpg (Migrated from github.com) reviewed 2025-03-31 05:53:34 -05:00
mpg (Migrated from github.com) left a comment

Still not a complete review (that's a pretty large PR, so I'm proceeding step by step).

Still not a complete review (that's a pretty large PR, so I'm proceeding step by step).
@ -0,0 +1,5 @@
API changes
mpg (Migrated from github.com) commented 2025-03-31 05:05:28 -05:00

I'd remove "type" at the, I think it's potentially confusing, and not helpful: "now take a mbedtls_svc_key_id_t key".

I'd remove "type" at the, I think it's potentially confusing, and not helpful: "now take a mbedtls_svc_key_id_t key".
mpg (Migrated from github.com) commented 2025-03-31 05:17:06 -05:00

PSA all caps (it's an acronym) (and also a trademark or something).

PSA all caps (it's an acronym) (and also a trademark or something).
mpg (Migrated from github.com) commented 2025-03-31 05:18:29 -05:00

PSA all caps

PSA all caps
mpg (Migrated from github.com) commented 2025-03-31 05:28:08 -05:00

Typos: extra "and" (1st one), extra period (end of line). Can we just go back to the text as it was before this PR?

Typos: extra "and" (1st one), extra period (end of line). Can we just go back to the text as it was before this PR?
@ -3,0 +4,4 @@
int alg,
int key_type,
mbedtls_svc_key_id_t *key_id,
const data_t *key)
mpg (Migrated from github.com) commented 2025-03-31 05:33:33 -05:00

Thanks for adding AES there - unless I'm mistaken you've also added ECB_NO_PADDING in the same place, so we no longer need to declared it as a dependency here.

Thanks for adding AES there - unless I'm mistaken you've also added `ECB_NO_PADDING` in the same place, so we no longer need to declared it as a dependency here.
mpg (Migrated from github.com) commented 2025-03-31 05:37:53 -05:00

Same point about dependencies. (Multiple occurrences, I won't comment on each of them after this one.)

Same point about dependencies. (Multiple occurrences, I won't comment on each of them after this one.)
@ -264,0 +148,4 @@
TEST_CALLOC(result, result_size);
PSA_ASSERT(setup_psa_key(PSA_KEY_USAGE_ENCRYPT, PSA_ALG_ECB_NO_PADDING,
mpg (Migrated from github.com) commented 2025-03-31 05:45:18 -05:00

This test obviously makes no sense as it was with the new API, so removing it is the correct move of course.

But this test served the purpose of checking what happens when we select an unsuitable parameters for the key. We should have a new test function that serves the same purpose. The documentation now says we want a key with type AES, alg ECB and usage ENCRYPT for wrap / DECRYPT for unwrap. What happens when we pass a key with the wrong type, or wrong alg, or wrong usage? We should have tests for that.

This test obviously makes no sense as it was with the new API, so removing it is the correct move of course. But this test served the purpose of checking what happens when we select an unsuitable parameters for the key. We should have a new test function that serves the same purpose. The documentation now says we want a key with type AES, alg ECB and usage ENCRYPT for wrap / DECRYPT for unwrap. What happens when we pass a key with the wrong type, or wrong alg, or wrong usage? We should have tests for that.
@ -302,0 +227,4 @@
/* BEGIN_CASE */
void mbedtls_nist_kw_unwrap_key_test(int mode,
data_t *key,
mpg (Migrated from github.com) commented 2025-03-31 05:48:20 -05:00

Please only set ENCRYPT here, for the wrap test.

I understand that for tests that call both wrap and unwrap it's convenient to set both, so that we don't have to have twice as many keys. But here we're only doing wrap, so we should really test that it works with only ENCRYPT set, as the documentation says.

Please only set `ENCRYPT` here, for the wrap test. I understand that for tests that call both wrap and unwrap it's convenient to set both, so that we don't have to have twice as many keys. But here we're only doing wrap, so we should really test that it works with only ENCRYPT set, as the documentation says.
mpg (Migrated from github.com) commented 2025-03-31 05:48:47 -05:00

Similarly to my comment on the previous function, please only set DECRYPT here.

Similarly to my comment on the previous function, please only set DECRYPT here.
bjwtaylor (Migrated from github.com) reviewed 2025-04-02 01:58:58 -05:00
@ -264,0 +148,4 @@
TEST_CALLOC(result, result_size);
PSA_ASSERT(setup_psa_key(PSA_KEY_USAGE_ENCRYPT, PSA_ALG_ECB_NO_PADDING,
bjwtaylor (Migrated from github.com) commented 2025-04-02 01:58:58 -05:00

Many thanks for your comment, it's a very good spot. I think I was wrongly assuming that the the system would check the values of usage, algorithm and key_type when you call the relevant setup function here github.com/bjwtaylor/TF-PSA-Crypto@f9c79995ce/drivers/builtin/src/nist_kw.c (L70) and then return an error. I've added some tests and dug into this in more detail and it appears it does some checks here github.com/bjwtaylor/TF-PSA-Crypto@f9c79995ce/core/psa_crypto.c (L1091), however they don't seem sufficient and some of the tests I've added can trigger segmentation faults if they use parameters that are not allowed. So I think we have two potential solutions:

  1. Improve checking in tf-psa-crypto.
  2. Add some basic guards in the kw code.
    the first option seems the better one as it would solve the problem for everyone, though it's more complex and will effect some tests which appear to exploit this 'feature'. I'm also not sure of the history is there a reason it is currently coded like this? Do you know if there is a good reason it should be like this and therefore we should go for option 2?
Many thanks for your comment, it's a very good spot. I think I was wrongly assuming that the the system would check the values of usage, algorithm and key_type when you call the relevant setup function here https://github.com/bjwtaylor/TF-PSA-Crypto/blob/f9c79995cef31779522da37976a0a8be2e7e6224/drivers/builtin/src/nist_kw.c#L70 and then return an error. I've added some tests and dug into this in more detail and it appears it does some checks here https://github.com/bjwtaylor/TF-PSA-Crypto/blob/f9c79995cef31779522da37976a0a8be2e7e6224/core/psa_crypto.c#L1091, however they don't seem sufficient and some of the tests I've added can trigger segmentation faults if they use parameters that are not allowed. So I think we have two potential solutions: 1. Improve checking in tf-psa-crypto. 2. Add some basic guards in the kw code. the first option seems the better one as it would solve the problem for everyone, though it's more complex and will effect some tests which appear to exploit this 'feature'. I'm also not sure of the history is there a reason it is currently coded like this? Do you know if there is a good reason it should be like this and therefore we should go for option 2?
mpg (Migrated from github.com) reviewed 2025-04-02 02:34:21 -05:00
@ -264,0 +148,4 @@
TEST_CALLOC(result, result_size);
PSA_ASSERT(setup_psa_key(PSA_KEY_USAGE_ENCRYPT, PSA_ALG_ECB_NO_PADDING,
mpg (Migrated from github.com) commented 2025-04-02 02:34:21 -05:00

Some checks are expected to be done by setup indeed, for example when calling psa_cipher_encrypt_setup(&wrap_operation, key, PSA_ALG_ECB_NO_PADDING) with a key that doesn't support/allow this algorithm or doesn't allow encrypt, we should be getting an error.

But OTOH the fact that the key type must be AES (as opposed to other block ciphers like Aria or Camellia which support the same set of operations) is specific to NIST-KW, so we can't expect PSA functions to magically guess and instead we need to add checks in the NIST-KW code.

Some checks are expected to be done by setup indeed, for example when calling `psa_cipher_encrypt_setup(&wrap_operation, key, PSA_ALG_ECB_NO_PADDING)` with a key that doesn't support/allow this algorithm or doesn't allow encrypt, we should be getting an error. But OTOH the fact that the key type must be AES (as opposed to other block ciphers like Aria or Camellia which support the same set of operations) is specific to NIST-KW, so we can't expect PSA functions to magically guess and instead we need to add checks in the NIST-KW code.
mpg (Migrated from github.com) reviewed 2025-04-02 02:49:08 -05:00
@ -264,0 +148,4 @@
TEST_CALLOC(result, result_size);
PSA_ASSERT(setup_psa_key(PSA_KEY_USAGE_ENCRYPT, PSA_ALG_ECB_NO_PADDING,
mpg (Migrated from github.com) commented 2025-04-02 02:49:08 -05:00

Regardless of whether we expect the check to be done by psa_cipher_{en,de}crypt_setup(&wrap_operation, key, PSA_ALG_ECB_NO_PADDING) or directly by the NIST-KW code, we should have a test case covering it.

Regardless of whether we expect the check to be done by `psa_cipher_{en,de}crypt_setup(&wrap_operation, key, PSA_ALG_ECB_NO_PADDING)` or directly by the NIST-KW code, we should have a test case covering it.
mpg commented 2025-04-04 03:03:43 -05:00 (Migrated from github.com)

@bjwtaylor Please avoid rewriting commits that have been already reviewed, unless it becomes necessary to resolve conflicts. It's OK to rewrite commits that have not been reviewed, but rewriting commits that have been reviewed make it harder for reviewers to see what's changed since their last review.

As a team, we find that review bandwidth is often a limiting factor, so we try to optimise our process to make things easier for reviewers.

@bjwtaylor Please avoid rewriting commits that have been already reviewed, unless it becomes necessary to resolve conflicts. It's OK to rewrite commits that have not been reviewed, but rewriting commits that have been reviewed make it harder for reviewers to see what's changed since their last review. As a team, we find that review bandwidth is often a limiting factor, so we try to optimise our process to make things easier for reviewers.
mpg (Migrated from github.com) reviewed 2025-04-04 05:41:23 -05:00
mpg (Migrated from github.com) left a comment

Just reviewing new things since my last review. Thanks for addressing my feedback, I think we have good test coverage now!

Just reviewing new things since my last review. Thanks for addressing my feedback, I think we have good test coverage now!
@ -123,0 +63,4 @@
/*
* Currently NIST KW only supports PSA_KEY_TYPE_AES, so verify this is
* set in the key attributes.
*/
mpg (Migrated from github.com) commented 2025-04-04 03:22:01 -05:00

Once you've called get_key_attributes, you need to call psa_reset_key_attributes before you return. Quoting from the spec:

A typical sequence to query a key’s attributes is as follows:

  1. Call psa_get_key_attributes().
  2. Call psa_get_key_xxx() functions to retrieve the required attribute(s).
  3. Call psa_reset_key_attributes() to free any resources that can be used by the attribute object.

You probably want to add ad call to reset_attributes() after the existing cleanup label.

Once you've called `get_key_attributes`, you need to call [`psa_reset_key_attributes`](https://arm-software.github.io/psa-api/crypto/1.1/api/keys/attributes.html#c.psa_reset_key_attributes) before you return. Quoting from [the spec](https://arm-software.github.io/psa-api/crypto/1.1/api/keys/attributes.html): > A typical sequence to query a key’s attributes is as follows: > 1. Call [psa_get_key_attributes()](https://arm-software.github.io/psa-api/crypto/1.1/api/keys/attributes.html#c.psa_get_key_attributes). > 2. Call psa_get_key_xxx() functions to retrieve the required attribute(s). > 3. Call [psa_reset_key_attributes()](https://arm-software.github.io/psa-api/crypto/1.1/api/keys/attributes.html#c.psa_reset_key_attributes) to free any resources that can be used by the attribute object. You probably want to add ad call to `reset_attributes()` after the existing `cleanup` label.
mpg (Migrated from github.com) commented 2025-04-04 03:24:43 -05:00

That's not correct. Before jumping to cleanup we need to set ret to a meaningful non-zero value, otherwise the function will return success.

That's not correct. Before jumping to cleanup we need to set `ret` to a meaningful non-zero value, otherwise the function will return success.
mpg (Migrated from github.com) commented 2025-04-04 03:25:11 -05:00

This should be ret = ...; goto cleanup.

This should be `ret = ...; goto cleanup`.
@ -306,0 +287,4 @@
outbuff + *output_length,
sizeof(outbuff) - *output_length,
&part_length);
if (ret != PSA_SUCCESS) {
mpg (Migrated from github.com) commented 2025-04-04 03:25:25 -05:00

Same remarks as for the other function.

Same remarks as for the other function.
@ -480,2 +445,4 @@
depends_on:!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
mbedtls_nist_kw_wrap:MBEDTLS_KW_MODE_KWP:"5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8":"c37b7e6492584340bed12207808941155068f738":"138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6a"
KWP AES-192 wrap rfc 5649 [#2]
mpg (Migrated from github.com) commented 2025-04-04 03:31:13 -05:00

Well actually shouldn't we have the same tests with MODE_KWP as well?

Well actually shouldn't we have the same tests with `MODE_KWP` as well?
mpg (Migrated from github.com) commented 2025-04-04 03:27:59 -05:00

Thank you, the following 6 cases are exactly the coverage I wanted :)

You'll probably need to declare a few dependencies for some of them though (PSA_WANT_ALG_ECB_NO_PADDING resp. PSA_WANT_KEY_TYPE_ARIA).

Thank you, the following 6 cases are exactly the coverage I wanted :) You'll probably need to declare a few dependencies for some of them though (`PSA_WANT_ALG_ECB_NO_PADDING` resp. `PSA_WANT_KEY_TYPE_ARIA`).
mpg (Migrated from github.com) commented 2025-04-04 03:36:06 -05:00

Honestly all this is a bit redundant, we're already testing this in the other positive cases. Here we could remove the msg and expected_result parameters and computations of expected output length, and just go with unsigned char input[16] = {0}; + unsigned char output[32]; (or whatever value is large enough for a 16-byte input, but I think 32 should do it).

This would reduce noise a bit in the test data. Not a blocker though.

Honestly all this is a bit redundant, we're already testing this in the other positive cases. Here we could remove the `msg` and `expected_result` parameters and computations of expected output length, and just go with `unsigned char input[16] = {0};` + `unsigned char output[32];` (or whatever value is large enough for a 16-byte input, but I think 32 should do it). This would reduce noise a bit in the test data. Not a blocker though.
mpg (Migrated from github.com) commented 2025-04-04 03:36:33 -05:00

Minor: we should use TEST_EQUAL.

Minor: we should use `TEST_EQUAL`.
mpg (Migrated from github.com) commented 2025-04-04 03:36:46 -05:00

See comment above about simplifying this function.

See comment above about simplifying this function.
mpg (Migrated from github.com) commented 2025-04-04 05:40:23 -05:00

Style: the coma should be at the end of the previous line.

Style: the coma should be at the end of the previous line.
mpg (Migrated from github.com) commented 2025-04-04 03:37:25 -05:00

Same thoughts as for the wrap test function; also optional. (However if you simplify both functions, we might even consider merging them as they'd end up being pretty similar.)

Same thoughts as for the wrap test function; also optional. (However if you simplify both functions, we might even consider merging them as they'd end up being pretty similar.)
valeriosetti (Migrated from github.com) requested changes 2025-04-04 08:41:23 -05:00
@ -0,0 +1,5 @@
API changes
valeriosetti (Migrated from github.com) commented 2025-04-04 08:19:19 -05:00

I think we should also mention (probably in a separate bullet point still in "API changes") the fact that the cipher module is no more able to dispatch to the nist_kw one.

I think we should also mention (probably in a separate bullet point still in "API changes") the fact that the `cipher` module is no more able to dispatch to the `nist_kw` one.
valeriosetti (Migrated from github.com) commented 2025-04-04 08:16:01 -05:00

Adding the comment here because it's the 1st edited line of this file, but actually the comment refers to line 50. You can remove also this block from there

#if defined(MBEDTLS_NIST_KW_C)
#include "mbedtls/nist_kw.h"
#endif
Adding the comment here because it's the 1st edited line of this file, but actually the comment refers to line 50. You can remove also this block from there ``` #if defined(MBEDTLS_NIST_KW_C) #include "mbedtls/nist_kw.h" #endif ```
valeriosetti (Migrated from github.com) commented 2025-04-04 08:16:46 -05:00

On line 51 of this file you can remove this block

#if defined(MBEDTLS_NIST_KW_C)
#include "mbedtls/nist_kw.h"
#endif
On line 51 of this file you can remove this block ``` #if defined(MBEDTLS_NIST_KW_C) #include "mbedtls/nist_kw.h" #endif ```
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
valeriosetti (Migrated from github.com) commented 2025-04-04 08:32:17 -05:00

I'm not sure about this, so this is likely going to be a question for @mpg: do we really need this check?
Rationale behind my question is that if the key was not setup correctly in PSA then all operations using it will fail automatically on the following PSA calls.
Instead if we want to stick with this pattern, here we're just checking the key type, but I think we should also (at least) verify the key's associated algorithm is correct. Isn't it?

I'm not sure about this, so this is likely going to be a question for @mpg: do we really need this check? Rationale behind my question is that if the key was not setup correctly in PSA then all operations using it will fail automatically on the following PSA calls. Instead if we want to stick with this pattern, here we're just checking the key type, but I think we should also (at least) verify the key's associated algorithm is correct. Isn't it?
@ -48,4 +48,8 @@
#define PSA_WANT_ALG_CMAC 1
valeriosetti (Migrated from github.com) commented 2025-04-04 08:41:05 -05:00

In case we really need to keep this change (see my other comment about check_config.h) this should be as follows

#define PSA_WANT_ALG_ECB_NO_PADDING  1
#define PSA_WANT_KEY_TYPE_AES  1
In case we really need to keep this change (see my other comment about `check_config.h`) this should be as follows ```suggestion #define PSA_WANT_ALG_ECB_NO_PADDING 1 #define PSA_WANT_KEY_TYPE_AES 1 ```
@ -104,4 +102,1 @@
#error "MBEDTLS_NIST_KW_C defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
valeriosetti (Migrated from github.com) commented 2025-04-04 08:40:04 -05:00

Since we are targetting 4.0 release, which is a major number change, I don't fully agree with this change. Major release means that we can ask the user to change its build configuration, so I prefer to do things in the proper way, i.e:

  • keep the check here, just replacing legacy symbols with PSA ones and
  • don't modify crypto_adjust_config_dependencies.h.

I guess this is another question for @mpg since it's a more general design decision.

Since we are targetting 4.0 release, which is a major number change, I don't fully agree with this change. Major release means that we can ask the user to change its build configuration, so I prefer to do things in the proper way, i.e: - keep the check here, just replacing legacy symbols with PSA ones and - don't modify `crypto_adjust_config_dependencies.h`. I guess this is another question for @mpg since it's a more general design decision.
bjwtaylor (Migrated from github.com) reviewed 2025-04-07 03:13:05 -05:00
bjwtaylor (Migrated from github.com) commented 2025-04-07 03:13:05 -05:00

So the aria dependency was added here https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180/commits/7c30261225af3bb2951f44312e31011e3f435599. The PSA_WANT_ALG_ECB_NO_PADDING was on all the test cases however we removed it and added it to crypto_config.h, do we still need to add it here also?

So the aria dependency was added here https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180/commits/7c30261225af3bb2951f44312e31011e3f435599. The PSA_WANT_ALG_ECB_NO_PADDING was on all the test cases however we removed it and added it to crypto_config.h, do we still need to add it here also?
bjwtaylor (Migrated from github.com) reviewed 2025-04-07 03:14:57 -05:00
bjwtaylor (Migrated from github.com) commented 2025-04-07 03:14:57 -05:00

Decided in the end to not merge them, but to move out the common functionality into a separate function to simplify. Let me know what you think?

Decided in the end to not merge them, but to move out the common functionality into a separate function to simplify. Let me know what you think?
bjwtaylor (Migrated from github.com) reviewed 2025-04-07 03:20:19 -05:00
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
bjwtaylor (Migrated from github.com) commented 2025-04-07 03:20:19 -05:00

@mpg asked for this. The idea is system will check the alg and the usage as it knows from the key declaration what they should be. However the key_type is specified by the nist_kw spec, so it has no way of knowing whether it is correct, This is why this check is needed. @mpg @valeriosetti let me know if you are happy with the current implementation, or if it needs more work?

@mpg asked for this. The idea is system will check the alg and the usage as it knows from the key declaration what they should be. However the key_type is specified by the nist_kw spec, so it has no way of knowing whether it is correct, This is why this check is needed. @mpg @valeriosetti let me know if you are happy with the current implementation, or if it needs more work?
mpg (Migrated from github.com) reviewed 2025-04-07 03:24:40 -05:00
mpg (Migrated from github.com) commented 2025-04-07 03:24:40 -05:00

Ah, bad typo of mine here. I meant to write that the test cases that use CBC as the "bad" algorithm should probably depend on PSA_WANT_ALG_CBC_NO_PADDING, sorry. You're absolutely right about ECB or course.

Ah, bad typo of mine here. I meant to write that the test cases that use *CBC* as the "bad" algorithm should probably depend on `PSA_WANT_ALG_CBC_NO_PADDING`, sorry. You're absolutely right about ECB or course.
mpg (Migrated from github.com) reviewed 2025-04-07 03:35:32 -05:00
@ -104,4 +102,1 @@
#error "MBEDTLS_NIST_KW_C defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
mpg (Migrated from github.com) commented 2025-04-07 03:35:32 -05:00

In the "past" (that is, 3.x) we had a hybrid world where MBEDTLS_ symbols were like "if you want to enable this symbol you'll need to figure out all its dependencies and enable them yourself" and PSA_WANT symbols where like "just ask for what you want and we'll handle dependencies for you" (one big reason for that is it support accelerators/drivers a lot better).

In 1.0 most of the public crypto feature symbols will be PSA_WANT. (Ideally that would be all of them, but we're keeping some legacy symbols for crypto mechanisms that are not in PSA yet, like NIST-KW here, or LMS.) So I think it makes sense for those few remaining legacy symbols to obey the same logic as the PSA_WANT symbols, rather than retaining a hybrid model just for them.

In the "past" (that is, 3.x) we had a hybrid world where `MBEDTLS_` symbols were like "if you want to enable this symbol you'll need to figure out all its dependencies and enable them yourself" and `PSA_WANT` symbols where like "just ask for what you want and we'll handle dependencies for you" (one big reason for that is it support accelerators/drivers a lot better). In 1.0 most of the public crypto feature symbols will be `PSA_WANT`. (Ideally that would be all of them, but we're keeping some legacy symbols for crypto mechanisms that are not in PSA yet, like NIST-KW here, or LMS.) So I think it makes sense for those few remaining legacy symbols to obey the same logic as the `PSA_WANT` symbols, rather than retaining a hybrid model just for them.
mpg (Migrated from github.com) reviewed 2025-04-07 03:43:27 -05:00
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
mpg (Migrated from github.com) commented 2025-04-07 03:43:27 -05:00

Yes exactly. If the key type was something like ECDSA, then clearly psa_encrypt_setup() would throw an error as there's no way an ECDSA key can do symmetric encryption. But if the key type is Aria, Camellia or (3)DES, then that's something that absolutely works with psa_encrypt_setup(..., ECB) (and all other operations we're doing). It just happens not to be allowed by the NIST spec. So we need to add a manual check.

The documentation says that we require key type AES, with alg ECB and usage en/decrypt (for wrap resp. unwrap) - the last two parts are checked for us by psa_en/decrypt_setup() but the first part only partially (it would reject non-block ciphers but accept other block ciphers than AES), hence this check.

@valeriosetti does that make sense?

Yes exactly. If the key type was something like ECDSA, then clearly `psa_encrypt_setup()` would throw an error as there's no way an ECDSA key can do symmetric encryption. But if the key type is Aria, Camellia or (3)DES, then that's something that absolutely works with `psa_encrypt_setup(..., ECB)` (and all other operations we're doing). It just happens not to be allowed by the NIST spec. So we need to add a manual check. The documentation says that we require key type AES, with alg ECB and usage en/decrypt (for wrap resp. unwrap) - the last two parts are checked for us by `psa_en/decrypt_setup()` but the first part only partially (it would reject non-block ciphers but accept other block ciphers than AES), hence this check. @valeriosetti does that make sense?
mpg (Migrated from github.com) reviewed 2025-04-07 03:45:05 -05:00
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
mpg (Migrated from github.com) commented 2025-04-07 03:45:05 -05:00

Actually the fact that you asked may be a hint that we should have a comment in the code along the lines of "Algorithm and usage will be checked implicitly when trying to use the key, but we need an explicit check for the key type to ensure we're accepting only AES and not other block ciphers."

Actually the fact that you asked may be a hint that we should have a comment in the code along the lines of "Algorithm and usage will be checked implicitly when trying to use the key, but we need an explicit check for the key type to ensure we're accepting only AES and not other block ciphers."
mpg (Migrated from github.com) reviewed 2025-04-07 03:46:12 -05:00
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
mpg (Migrated from github.com) commented 2025-04-07 03:46:12 -05:00

Because indeed such checks are a bit unusual when using PSA, most of the type we're trying to be generic and just rely on the psa_ functions to check type alg and usage for us.

Because indeed such checks are a bit unusual when using PSA, most of the type we're trying to be generic and just rely on the `psa_` functions to check type alg and usage for us.
mpg (Migrated from github.com) reviewed 2025-04-07 03:47:23 -05:00
@ -0,0 +1,5 @@
API changes
mpg (Migrated from github.com) commented 2025-04-07 03:47:23 -05:00

Well, the cipher module will become internal in 1.0, so I don't think we need to announced changes to it. But it also doesn't hurt - we'll have a final pass over the ChangeLog to consolidate entries before the release anyway.

Well, the cipher module will become internal in 1.0, so I don't think we need to announced changes to it. But it also doesn't hurt - we'll have a final pass over the ChangeLog to consolidate entries before the release anyway.
bjwtaylor (Migrated from github.com) reviewed 2025-04-07 05:31:09 -05:00
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
bjwtaylor (Migrated from github.com) commented 2025-04-07 05:31:09 -05:00

Agreed, more comments on the rational are probably useful here. I'll add something.

Agreed, more comments on the rational are probably useful here. I'll add something.
gilles-peskine-arm (Migrated from github.com) reviewed 2025-04-07 10:39:31 -05:00
@ -123,0 +63,4 @@
/*
* Currently NIST KW only supports PSA_KEY_TYPE_AES, so verify this is
* set in the key attributes.
*/
gilles-peskine-arm (Migrated from github.com) commented 2025-04-07 10:39:31 -05:00

Currently nothing breaks if you don't call psa_reset_key_attributes(). But it used to be the case for some key types, and it may be the case again in the future. (What can break is a memory leak, if there is a pointer in the attribute structure to extra data in a heap-allocated buffer. Which is currently not the case, but has been the case for RSA keys in the past, and we may have a case for it in the future.)

Because nothing actually breaks if you don't reset the attributes, we may already have places where it's not done, so it wouldn't be a big deal to not do it.

Currently nothing breaks if you don't call `psa_reset_key_attributes()`. But it used to be the case for some key types, and it may be the case again in the future. (What can break is a memory leak, if there is a pointer in the attribute structure to extra data in a heap-allocated buffer. Which is currently not the case, but has been the case for RSA keys in the past, and we may have a case for it in the future.) Because nothing actually breaks if you don't reset the attributes, we may already have places where it's not done, so it wouldn't be a big deal to not do it.
valeriosetti (Migrated from github.com) reviewed 2025-04-08 09:15:03 -05:00
valeriosetti (Migrated from github.com) commented 2025-04-08 09:15:02 -05:00

Thanks for fixing this. Unfortunately I found another occurrence of MBEDTLS_NIST_KW_C at line 100 in this file, but I think it should be removed as well.

Thanks for fixing this. Unfortunately I found another occurrence of `MBEDTLS_NIST_KW_C` at line 100 in this file, but I think it should be removed as well.
valeriosetti (Migrated from github.com) reviewed 2025-04-08 09:17:12 -05:00
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
valeriosetti (Migrated from github.com) commented 2025-04-08 09:17:12 -05:00

Thanks guys for the explanation and the fix!

Thanks guys for the explanation and the fix!
valeriosetti (Migrated from github.com) requested changes 2025-04-08 09:32:10 -05:00
valeriosetti (Migrated from github.com) left a comment

I'm basically OK with the current status. I only left some minor comment. (+ https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180#discussion_r2033301960)

I'm basically OK with the current status. I only left some minor comment. (+ https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180#discussion_r2033301960)
valeriosetti (Migrated from github.com) commented 2025-04-08 09:27:54 -05:00

That's really minor, I know, but in case you have some other change to add, can you please align the indentation with other entries below?
Note: this is not worth a commit if there's nothing else to do ;)

That's really minor, I know, but in case you have some other change to add, can you please align the indentation with other entries below? Note: this is not worth a commit if there's nothing else to do ;)
@ -1578,9 +1574,9 @@ static int mbedtls_cipher_aead_decrypt(mbedtls_cipher_context_t *ctx,
}
valeriosetti (Migrated from github.com) commented 2025-04-08 09:20:05 -05:00
 * Packet-oriented encryption for AEAD: public function.

here and also below for the mbedtls_cipher_auth_decrypt_ext function (sorry, but I cannot make the comment directly there)

```suggestion * Packet-oriented encryption for AEAD: public function. ``` here and also below for the `mbedtls_cipher_auth_decrypt_ext` function (sorry, but I cannot make the comment directly there)
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
valeriosetti (Migrated from github.com) commented 2025-04-08 09:30:12 -05:00
     * PSA API are able to check the algorithm and usage as this is specified

TF-PSA-Crypto is the repo. The same holds also for line 321 in mbedtls_nist_kw_unwrap

```suggestion * PSA API are able to check the algorithm and usage as this is specified ``` TF-PSA-Crypto is the repo. The same holds also for line 321 in `mbedtls_nist_kw_unwrap`
valeriosetti (Migrated from github.com) reviewed 2025-04-10 02:40:45 -05:00
@ -104,4 +102,1 @@
#error "MBEDTLS_NIST_KW_C defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
valeriosetti (Migrated from github.com) commented 2025-04-10 02:40:45 -05:00

Oh OK, that's the part that I was missing. Thanks for the explanation!

Oh OK, that's the part that I was missing. Thanks for the explanation!
valeriosetti (Migrated from github.com) reviewed 2025-04-10 06:43:57 -05:00
valeriosetti (Migrated from github.com) reviewed 2025-04-14 02:17:07 -05:00
valeriosetti (Migrated from github.com) left a comment
No description provided.
Relying on the CI of the [PR on the main repo](https://github.com/Mbed-TLS/mbedtls/pull/9983) which is fully green, this PR looks OK to me
gilles-peskine-arm (Migrated from github.com) requested changes 2025-04-16 11:49:25 -05:00
gilles-peskine-arm (Migrated from github.com) left a comment

I have reviewed everything except nist_kw.c. I'll review it once the updated tests pass.

In some places, the same problem appears more than once and I only made one comment (e.g. if I make a comment about wrap, please check if it also applies to unwrap).

I have reviewed everything except `nist_kw.c`. I'll review it once the updated tests pass. In some places, the same problem appears more than once and I only made one comment (e.g. if I make a comment about wrap, please check if it also applies to unwrap).
@ -0,0 +1,5 @@
API changes
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 09:42:56 -05:00

cipher.h will not be a public API, so please remove this line.

`cipher.h` will not be a public API, so please remove this line.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 09:45:16 -05:00

mbedtls_svc_key_id_t is a nonstandard alias for the standard type psa_key_id_t in most configurations, so we should avoid mentioning mbedtls_svc_key_id_t in documentation. In any case I don't think we need to give an explicit type name here:

The functions mbedtls_nist_kw_wrap() and mbedtls_nist_kw_unwrap() now take a PSA key identifier instead of a plain-text key via a custom context.

`mbedtls_svc_key_id_t` is a nonstandard alias for the standard type `psa_key_id_t` in most configurations, so we should avoid mentioning `mbedtls_svc_key_id_t` in documentation. In any case I don't think we need to give an explicit type name here: > The functions mbedtls_nist_kw_wrap() and mbedtls_nist_kw_unwrap() now take a PSA key identifier instead of a plain-text key via a custom context.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 09:47:02 -05:00

Should we also mention that the output size and output length parameters have been swapped, to make them follow the PSA order? Or is that too much detail for the changelog entry?

Should we also mention that the output size and output length parameters have been swapped, to make them follow the PSA order? Or is that too much detail for the changelog entry?
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 09:31:07 -05:00

Please use the Doxygen syntax to link macro names in the documentation.

 *                               - type: #PSA_KEY_TYPE_AES

and so on below (#PSA_ALG_ECB_NO_PADDING, #MBEDTLS_KW_MODE_KW, #PSA_ERROR_DATA_INVALID, ...).

Please use the Doxygen syntax to link macro names in the documentation. ```suggestion * - type: #PSA_KEY_TYPE_AES ``` and so on below (`#PSA_ALG_ECB_NO_PADDING`, `#MBEDTLS_KW_MODE_KW`, `#PSA_ERROR_DATA_INVALID`, ...).
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 09:32:06 -05:00

PSA_ERROR_DATA_INVALID is intended for invalid data read from storage. Here the appropriate error would be PSA_ERROR_INVALID_ARGUMENT.

`PSA_ERROR_DATA_INVALID` is intended for invalid data read from storage. Here the appropriate error would be `PSA_ERROR_INVALID_ARGUMENT`.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 10:17:14 -05:00

We're now moving from module-specific errors to PSA-standard errors, although it's unclear whether we'll finish this migration before the 1.0 release. Please change the documentation to something more generic like

Another error code on failure of the underlying cipher.

We're now moving from module-specific errors to PSA-standard errors, although it's unclear whether we'll finish this migration before the 1.0 release. Please change the documentation to something more generic like > Another error code on failure of the underlying cipher.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 10:19:47 -05:00

For unwrapping, we should also document which error is returned when the ciphertext is invalid. That's PSA_ERROR_INVALID_SIGNATURE (same as with “proper” AEAD algorithms, the PSA equivalent of MBEDTLS_ERR_CIPHER_AUTH_FAILED).

I see that the code returns PSA_ERROR_CORRUPTION_DETECTED. This error code is a “can't happen” error that must not be returned on invalid user input.

For unwrapping, we should also document which error is returned when the ciphertext is invalid. That's `PSA_ERROR_INVALID_SIGNATURE` (same as with “proper” AEAD algorithms, the PSA equivalent of `MBEDTLS_ERR_CIPHER_AUTH_FAILED`). I see that the code returns `PSA_ERROR_CORRUPTION_DETECTED`. This error code is a “can't happen” error that must not be returned on invalid user input.
@ -1616,4 +1588,2 @@
#if defined(MBEDTLS_CIPHER_MODE_AEAD)
/* AEAD case: check length before passing on to shared function */
if (output_len < ilen + tag_len) {
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:43:05 -05:00

Please update cipher.h as well.

Please update `cipher.h` as well.
@ -763,1 +760,4 @@
* Enable the 128-bit key wrapping modes from NIST SP 800-38F:
* KW (also known as RFC 3394) and KWP (RFC 5649).
* Currently these modes are only supported with AES.
*
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 09:54:20 -05:00

KW and KWP could be used with other block ciphers (e.g. Camellia-KW is specified in RFC 3657). So I think we should continue to require at least one supported block cipher, rather than automatically enabling AES.

Expanding KW to allow other block ciphers is out of scope here, but we shouldn't make it difficult if we want to do it in TF-PSA-Crypto 1.x.

As a consequence, in addition to not auto-enabling AES, I think we should keep a guard on PSA_WANT_KEY_TYPE_AES around any part of the code that is specific to AES, in particular the test data.

KW and KWP could be used with other block ciphers (e.g. Camellia-KW is specified in [RFC 3657](https://datatracker.ietf.org/doc/html/rfc3657#section-3.2)). So I think we should continue to require at least one supported block cipher, rather than automatically enabling AES. Expanding KW to allow other block ciphers is out of scope here, but we shouldn't make it difficult if we want to do it in TF-PSA-Crypto 1.x. As a consequence, in addition to not auto-enabling AES, I think we should keep a guard on `PSA_WANT_KEY_TYPE_AES` around any part of the code that is specific to AES, in particular the test data.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 10:03:36 -05:00

This change looks wrong. How could the same input have been previously valid, but now is no longer valid?

This change looks wrong. How could the same input have been previously valid, but now is no longer valid?
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 10:24:56 -05:00
mbedtls_nist_kw_wrap_key_test:MBEDTLS_KW_MODE_KWP:"000102030405060708090A0B0C0D0E0F":PSA_KEY_USAGE_ENCRYPT:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_ARIA:PSA_ERROR_NOT_PERMITTED

And at least one other case above. Currently :: is treated a single separator in data files, but we should avoid depending on this arcane detail.

```suggestion mbedtls_nist_kw_wrap_key_test:MBEDTLS_KW_MODE_KWP:"000102030405060708090A0B0C0D0E0F":PSA_KEY_USAGE_ENCRYPT:PSA_ALG_ECB_NO_PADDING:PSA_KEY_TYPE_ARIA:PSA_ERROR_NOT_PERMITTED ``` And at least one other case above. Currently `::` is treated a single separator in data files, but we should avoid depending on this arcane detail.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:15:30 -05:00

For an output buffer that's too short, the PSA error is PSA_ERROR_BUFFER_TOO_SMALL.

For an output buffer that's too short, the PSA error is `PSA_ERROR_BUFFER_TOO_SMALL`.
@ -1,176 +1,80 @@
/* BEGIN_HEADER */
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 10:43:48 -05:00

Please use PSA_ASSERT for all things that can fail, so that the test framework reports exactly what failed, rather than reporting that setup_psa_key has failed. The common idiom for that is something like:

int auxiliary_function(...) {
    int ok = 0;
    PSA_ASSERT(psa_foo());
    TEST_EQUAL(actual_result, expected_result);
    ok = 1;
exit:
    return ok;
}
Please use `PSA_ASSERT` for all things that can fail, so that the test framework reports exactly what failed, rather than reporting that `setup_psa_key` has failed. The common idiom for that is something like: ``` int auxiliary_function(...) { int ok = 0; PSA_ASSERT(psa_foo()); TEST_EQUAL(actual_result, expected_result); ok = 1; exit: return ok; } ```
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 10:45:29 -05:00

Please use PSA_INIT() in test code. It's equivalent to PSA_ASSERT(psa_crypto_init()), but using PSA_INIT gives us the ability to customize it in some test builds (which we currently do for PSA_DONE but not for PSA_INIT itself, I think, but it could happen).

Please use `PSA_INIT()` in test code. It's equivalent to `PSA_ASSERT(psa_crypto_init())`, but using `PSA_INIT` gives us the ability to customize it in some test builds (which we currently do for `PSA_DONE` but not for `PSA_INIT` itself, I think, but it could happen).
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 10:47:45 -05:00

There are no test vectors around here. I guess the comment belongs in the .data file.

There are no test vectors around here. I guess the comment belongs in the `.data` file.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 10:57:47 -05:00

This isn't what is called “self test” in the context of cryptographic modules: a self-test is a test that is contained in the library code. (It's a kind of useless thing that is a historical survivance that security evaluations often insist on. Having good self-tests is outside the scope of 1.0, though we're trying to keep the selftest program useful.)

This function does a wrap-unwrap test with known data, so a good name would be nist_kw_wrap_unwrap. I'm not sure we need it given that we already have known answer tests for wrap and for unwrap, but it's fine to have it.

This isn't what is called “self test” in the context of cryptographic modules: a self-test is a test that is contained in the library code. (It's a kind of useless thing that is a historical survivance that security evaluations often insist on. Having good self-tests is outside the scope of 1.0, though we're trying to keep the `selftest` program useful.) This function does a wrap-unwrap test with known data, so a good name would be `nist_kw_wrap_unwrap`. I'm not sure we need it given that we already have known answer tests for wrap and for unwrap, but it's fine to have it.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:00:49 -05:00

Please avoid using an mbedtls_ or psa_ prefix for test entry points. Using those prefixes can cause confusion between test entry points and library functions — they have their own namespace in C (because the C function has mbedtls_test_ prefixed to it), but things like tag lookup gets confused.

(Historically some test files give the same name to the library function and to the main test function that tests it, but it has caused confusion, so we shouldn't do it in new code.)

Please avoid using an `mbedtls_` or `psa_` prefix for test entry points. Using those prefixes can cause confusion between test entry points and library functions — they have their own namespace in C (because the C function has `mbedtls_test_` prefixed to it), but things like tag lookup gets confused. (Historically some test files give the same name to the library function and to the main test function that tests it, but it has caused confusion, so we shouldn't do it in new code.)
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:03:48 -05:00
    TEST_MEMORY_COMPARE(out, olen, kw_res->x, kw_res->len);

Please don't do it yourself. We have a history of getting this wrong — such as here where it should be out_len == olen && … instead of out_len == olen || ….

```suggestion TEST_MEMORY_COMPARE(out, olen, kw_res->x, kw_res->len); ``` Please don't do it yourself. We have a history of getting this wrong — such as here where it should be `out_len == olen && …` instead of `out_len == olen || …`.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:05:51 -05:00

Rather than hard-coding a size, we should allocate an output buffer of exactly the expected size. This way, we can validate that the tested function doesn't insist on having a larger output buffer.

unsigned char out = NULL;
TEST_CALLOC(out, out_len);

and mbedtls_free(out) in the cleanup code.

(Sometimes we also test that the function works correctly when the output buffer is larger than needed, but we only do it when a white-box approach suggests that it might be a concern, which is not the case here.)

When we test with Asan (which we often do), it validates that the code doesn't try to access beyond the end of the buffer.

Rather than hard-coding a size, we should allocate an output buffer of exactly the expected size. This way, we can validate that the tested function doesn't insist on having a larger output buffer. ``` unsigned char out = NULL; TEST_CALLOC(out, out_len); ``` and `mbedtls_free(out)` in the cleanup code. (Sometimes we also test that the function works correctly when the output buffer is larger than needed, but we only do it when a white-box approach suggests that it might be a concern, which is not the case here.) When we test with Asan (which we often do), it validates that the code doesn't try to access beyond the end of the buffer.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:06:51 -05:00

Isn't kw_out_len redundant as a parameter? Isn't it always kw_res->len?

Isn't `kw_out_len` redundant as a parameter? Isn't it always `kw_res->len`?
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:08:29 -05:00

Please don't combine an uninitialized variable and an initialized variable on the same line. It's hard to read, and in particular it's hard to notice that olen is not initialized.

Please don't combine an uninitialized variable and an initialized variable on the same line. It's hard to read, and in particular it's hard to notice that `olen` is not initialized.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:11:04 -05:00

Please avoid lines wider than 80 characters. It's not an absolute rule, for example it's ok to go a little beyond when there's a long identifier or a long string, or when indenting existing code just a little more. (The code style checker has a hard stop at 100.) Here PSA_ALG_ECB_NO_PADDING should just be on the next line.

Please avoid lines wider than 80 characters. It's not an absolute rule, for example it's ok to go a little beyond when there's a long identifier or a long string, or when indenting existing code just a little more. (The code style checker has a hard stop at 100.) Here `PSA_ALG_ECB_NO_PADDING` should just be on the next line.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:18:03 -05:00

Now that there are no contexts, what test coverage does this function bring?

(I'm inclined to remove it, so I haven't reviewed its updated code.)

Now that there are no contexts, what test coverage does this function bring? (I'm inclined to remove it, so I haven't reviewed its updated code.)
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:21:27 -05:00

I prefer to initialize things as early as possible, thus

    uint8_t key_array[16] = { 0 };
    data_t key = { .len = sizeof(key_array), .x = key_array };

rather than relying on assignments and memset further below. This way there's no risk of forgetting to initialize on some code paths (e.g. in case of an early error).

I prefer to initialize things as early as possible, thus ```suggestion uint8_t key_array[16] = { 0 }; data_t key = { .len = sizeof(key_array), .x = key_array }; ``` rather than relying on assignments and memset further below. This way there's no risk of forgetting to initialize on some code paths (e.g. in case of an early error).
@ -267,1 +162,4 @@
mbedtls_free(result);
psa_destroy_key(key_id);
PSA_DONE();
}
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:23:47 -05:00

In new code, we prefer TEST_EQUAL(…, res) which shows the values on both sides if the test fails. We normally don't rewrite old code when making minor changes like you're doing here (with respect to this part of the test code), but feel free to change to TEST_EQUAL if it helps you diagnose test failures.

In new code, we prefer `TEST_EQUAL(…, res)` which shows the values on both sides if the test fails. We normally don't rewrite old code when making minor changes like you're doing here (with respect to this part of the test code), but feel free to change to `TEST_EQUAL` if it helps you diagnose test failures.
@ -302,0 +229,4 @@
void mbedtls_nist_kw_unwrap_key_test(int mode,
data_t *key,
int usage,
int alg,
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:29:52 -05:00
    unsigned char *result = NULL;
    TEST_CALLOC(result, result_size);

Allocating memory can fail! Also TEST_CALLOC is consistent about a length of 0 (always NULL, whereas the C standard leaves it implementation-defined).

```suggestion unsigned char *result = NULL; TEST_CALLOC(result, result_size); ``` Allocating memory can fail! Also `TEST_CALLOC` is consistent about a length of 0 (always `NULL`, whereas the C standard leaves it implementation-defined).
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:31:16 -05:00

Minor: style (I'm surprised that uncrustify doesn't complain):

    PSA_ASSERT(mbedtls_nist_kw_wrap(key_id, mode, msg->x, msg->len,
                                    result, result_size, &result_length));
Minor: style (I'm surprised that uncrustify doesn't complain): ```suggestion PSA_ASSERT(mbedtls_nist_kw_wrap(key_id, mode, msg->x, msg->len, result, result_size, &result_length)); ```
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:39:02 -05:00

Redundant with the TEST_MEMORY_COMPARE just below.

Redundant with the `TEST_MEMORY_COMPARE` just below.
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:32:15 -05:00

As above, please combine the declaration with initialization whenever practical, and avoid declaring multiple variables on the same line (especially if they're initialized).

As above, please combine the declaration with initialization whenever practical, and avoid declaring multiple variables on the same line (especially if they're initialized).
gilles-peskine-arm (Migrated from github.com) commented 2025-04-16 11:41:03 -05:00

goto exit just before exit: is pointless.

`goto exit` just before `exit:` is pointless.
bjwtaylor (Migrated from github.com) reviewed 2025-04-17 02:22:22 -05:00
bjwtaylor (Migrated from github.com) commented 2025-04-17 02:22:22 -05:00

Good point I will investigate.

Good point I will investigate.
bjwtaylor (Migrated from github.com) reviewed 2025-04-17 05:19:55 -05:00
@ -1,176 +1,80 @@
/* BEGIN_HEADER */
bjwtaylor (Migrated from github.com) commented 2025-04-17 05:19:55 -05:00

OK, I think it's still useful as it test the known data from the NIST KW spec I will rename it as suggested though.

OK, I think it's still useful as it test the known data from the NIST KW spec I will rename it as suggested though.
bjwtaylor (Migrated from github.com) reviewed 2025-04-17 07:30:58 -05:00
@ -1,176 +1,80 @@
/* BEGIN_HEADER */
bjwtaylor (Migrated from github.com) commented 2025-04-17 07:30:58 -05:00

I've adjusted this line and others that are similar, let me know what you think.

I've adjusted this line and others that are similar, let me know what you think.
bjwtaylor (Migrated from github.com) reviewed 2025-04-17 07:38:22 -05:00
bjwtaylor (Migrated from github.com) commented 2025-04-17 07:38:22 -05:00

This comment is on the input buffer and refers to the output. However am a right to assume this comment refers to both the correct code is PSA_ERROR_BUFFER_TOO_SMALL for a input or output buffer?

This comment is on the input buffer and refers to the output. However am a right to assume this comment refers to both the correct code is PSA_ERROR_BUFFER_TOO_SMALL for a input or output buffer?
bjwtaylor (Migrated from github.com) reviewed 2025-04-17 07:40:56 -05:00
@ -1,176 +1,80 @@
/* BEGIN_HEADER */
bjwtaylor (Migrated from github.com) commented 2025-04-17 07:40:56 -05:00

Now removed.

Now removed.
bjwtaylor (Migrated from github.com) reviewed 2025-04-17 09:18:13 -05:00
@ -0,0 +1,5 @@
API changes
bjwtaylor (Migrated from github.com) commented 2025-04-17 09:18:13 -05:00

Think this is probably too much. I've updated the changelog as per the other comments, as discussed in stand up there have been multiple iterations of this. Let me know what you think of the current one.

Think this is probably too much. I've updated the changelog as per the other comments, as discussed in stand up there have been multiple iterations of this. Let me know what you think of the current one.
bjwtaylor (Migrated from github.com) reviewed 2025-04-17 09:29:42 -05:00
@ -763,1 +760,4 @@
* Enable the 128-bit key wrapping modes from NIST SP 800-38F:
* KW (also known as RFC 3394) and KWP (RFC 5649).
* Currently these modes are only supported with AES.
*
bjwtaylor (Migrated from github.com) commented 2025-04-17 09:29:42 -05:00

This makes a very good point, let's discuss with @mpg when he gets back as he requested we move the parameters here so is probably will be interested in this discussion.

This makes a very good point, let's discuss with @mpg when he gets back as he requested we move the parameters here so is probably will be interested in this discussion.
mpg (Migrated from github.com) reviewed 2025-04-23 03:27:21 -05:00
@ -763,1 +760,4 @@
* Enable the 128-bit key wrapping modes from NIST SP 800-38F:
* KW (also known as RFC 3394) and KWP (RFC 5649).
* Currently these modes are only supported with AES.
*
mpg (Migrated from github.com) commented 2025-04-23 03:27:21 -05:00

Ah, I wasn't aware of that RFC or that NIST-KW(P) could be used with other block ciphers. Since it's (as the name suggests) a NIST thing, I only checked NIST standard, which naturally only mentions NIST-approved block ciphers, that is AES only these days.

Indeed that changes things, so in light of this we should only auto-enable ECB but not AES, and as a consequence declare a dependency on PSA_WANT_KEY_TYPE_AES for all current test data. (More precisely, the test function if AES is hard-coded in the function, or the data when the the function takes the cipher as an input parameter and the data passes AES. That is, the place that makes us use AES should have the dependency on AES.)

In the library code we should make sure that if PSA_WANT_KEY_TYPE_AES is not enabled, then the function always return an error (until we start actually supporting ciphers other than AES).

Ah, I wasn't aware of that RFC or that NIST-KW(P) could be used with other block ciphers. Since it's (as the name suggests) a NIST thing, I only checked NIST standard, which naturally only mentions NIST-approved block ciphers, that is AES only these days. Indeed that changes things, so in light of this we should only auto-enable ECB but not AES, and as a consequence declare a dependency on `PSA_WANT_KEY_TYPE_AES` for all current test data. (More precisely, the test function if AES is hard-coded in the function, or the data when the the function takes the cipher as an input parameter and the data passes AES. That is, the place that makes us use AES should have the dependency on AES.) In the library code we should make sure that if `PSA_WANT_KEY_TYPE_AES` is not enabled, then the function always return an error (until we start actually supporting ciphers other than AES).
bjwtaylor (Migrated from github.com) reviewed 2025-04-23 04:52:06 -05:00
@ -763,1 +760,4 @@
* Enable the 128-bit key wrapping modes from NIST SP 800-38F:
* KW (also known as RFC 3394) and KWP (RFC 5649).
* Currently these modes are only supported with AES.
*
bjwtaylor (Migrated from github.com) commented 2025-04-23 04:52:06 -05:00

Sounds good, I'll update to reflect these changes. I think for the last bit we can still use the implementation previously suggested and tested here https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180/commits/2161e78f7d9ea69d983e1cb79fcc79f6291df293. Though let me know if you think we need something further.

Sounds good, I'll update to reflect these changes. I think for the last bit we can still use the implementation previously suggested and tested here https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180/commits/2161e78f7d9ea69d983e1cb79fcc79f6291df293. Though let me know if you think we need something further.
mpg commented 2025-04-29 02:36:18 -05:00 (Migrated from github.com)

From the CI:

[2025-04-25T10:51:18.674Z] test/selftest.c:313:18: error: use of undeclared identifier 'mbedtls_nist_kw_self_test'
[2025-04-25T10:51:18.674Z]     { "nist_kw", mbedtls_nist_kw_self_test },
[2025-04-25T10:51:18.674Z]                  ^
[2025-04-25T10:51:18.674Z] 1 error generated.

Seem legit, we've removed this function from the library, we probably want to stop calling it in the programs :)

From the CI: ``` [2025-04-25T10:51:18.674Z] test/selftest.c:313:18: error: use of undeclared identifier 'mbedtls_nist_kw_self_test' [2025-04-25T10:51:18.674Z] { "nist_kw", mbedtls_nist_kw_self_test }, [2025-04-25T10:51:18.674Z] ^ [2025-04-25T10:51:18.674Z] 1 error generated. ``` Seem legit, we've removed this function from the library, we probably want to stop calling it in the programs :)
bjwtaylor commented 2025-04-29 02:51:50 -05:00 (Migrated from github.com)

@mpg, yes had the same conversation with @gilles-peskine-arm. The PR pair is quite interdependent due to the self test. So the plan is I've updated the mbedtls part to remove the submodule update, this removes the self test which I'm hoping will mean it will pass. That means we can merge this part and then this PR, though lets wait for the CI to prove this. We may need to do further splitting.

@mpg, yes had the same conversation with @gilles-peskine-arm. The PR pair is quite interdependent due to the self test. So the plan is I've updated the mbedtls part to remove the submodule update, this removes the self test which I'm hoping will mean it will pass. That means we can merge this part and then this PR, though lets wait for the CI to prove this. We may need to do further splitting.
mpg commented 2025-05-06 02:29:57 -05:00 (Migrated from github.com)

Ping @gilles-peskine-arm @valeriosetti for re-review.

Ping @gilles-peskine-arm @valeriosetti for re-review.
gilles-peskine-arm (Migrated from github.com) requested changes 2025-05-06 12:50:56 -05:00
gilles-peskine-arm (Migrated from github.com) left a comment

I've now done a full review. 701b188923a1a7282c5f3e356f90d79c92a3e7a7 looks good to me apart from a couple of documentation issues and a few problems in error conditions/reporting.

Some of my comments on mbedtls_nist_kw_wrap() also apply to unwrapping.

I've now done a full review. 701b188923a1a7282c5f3e356f90d79c92a3e7a7 looks good to me apart from a couple of documentation issues and a few problems in error conditions/reporting. Some of my comments on `mbedtls_nist_kw_wrap()` also apply to unwrapping.
gilles-peskine-arm (Migrated from github.com) commented 2025-05-05 12:53:06 -05:00

Here and elsewhere:

 * \return                   #PSA_ERROR_INVALID_ARGUMENT for invalid input length.

(\c typesets the next word as code verbatim, that's not what we need here.)

Here and elsewhere: ```suggestion * \return #PSA_ERROR_INVALID_ARGUMENT for invalid input length. ``` (`\c` typesets the next word as code verbatim, that's not what we need here.)
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 12:33:58 -05:00
  • size and length are swapped.
  • size isn't an [in]: that annotation is just for pointers.
  • The documentation for length is missing the information that this is about the value stored at that address when the function returns.
 * \param output_size        The capacity of the output buffer.
 * \param[out] output_length On success, the number of bytes written to the output buffer. \c 0 on failure.
* size and length are swapped. * size isn't an `[in]`: that annotation is just for pointers. * The documentation for length is missing the information that this is about the value stored at that address when the function returns. ```suggestion * \param output_size The capacity of the output buffer. * \param[out] output_length On success, the number of bytes written to the output buffer. \c 0 on failure. ```
@ -121,2 +52,4 @@
}
static int verify_input(mbedtls_svc_key_id_t *key)
{
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 11:11:12 -05:00

More accurately, all we ask of the PSA API is to perform ECB, so any block cipher key type would be accepted (but other key types would be rejected). The code here only works with 128-bit block ciphers, so at a minimum it needs to reject block ciphers with a different block size (which, in the PSA API, is just DES). Additionally, we don't allow block ciphers other than AES (which, currently, would be Camellia and ARIA), which is a self-imposed limitation (just because we don't have tests).

More accurately, all we ask of the PSA API is to perform ECB, so any block cipher key type would be accepted (but other key types would be rejected). The code here only works with 128-bit block ciphers, so at a minimum it needs to reject block ciphers with a different block size (which, in the PSA API, is just DES). Additionally, we don't allow block ciphers other than AES (which, currently, would be Camellia and ARIA), which is a self-imposed limitation (just because we don't have tests).
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 11:25:44 -05:00

NOT_PERMITTED is meant to indicate some kind of key-specific policy restriction. That's not what is going on here. Either INVALID_ARGUMENT or NOT_SUPPORTED would work, with NOT_SUPPORTED being more accurate for 128-bit block ciphers other than AES and INVALID_ARGUMENT being more accurate for other key types.

I'm not sure if it's worth it, but you could check accurate does-it-make-sense (i.e. not invalid argument) with

// Weird that we don't have this already, it seems like an omission in the standard macros
#define PSA_KEY_TYPE_IS_CIPHER(type) ((type & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC)
psa_key_type_t key_type = psa_get_key_type(&attributes);
if (!PSA_KEY_TYPE_IS_CIPHER(key_type)) …
if (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) != 128) …
`NOT_PERMITTED` is meant to indicate some kind of key-specific policy restriction. That's not what is going on here. Either `INVALID_ARGUMENT` or `NOT_SUPPORTED` would work, with `NOT_SUPPORTED` being more accurate for 128-bit block ciphers other than AES and `INVALID_ARGUMENT` being more accurate for other key types. I'm not sure if it's worth it, but you could check accurate does-it-make-sense (i.e. not invalid argument) with ``` // Weird that we don't have this already, it seems like an omission in the standard macros #define PSA_KEY_TYPE_IS_CIPHER(type) ((type & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC) psa_key_type_t key_type = psa_get_key_type(&attributes); if (!PSA_KEY_TYPE_IS_CIPHER(key_type)) … if (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) != 128) … ```
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 12:18:00 -05:00

The type checks in wrap and unwrap are the same. Consider making them an auxiliary function.

The type checks in wrap and unwrap are the same. Consider making them an auxiliary function.
@ -221,2 +196,2 @@
inbuff, 16, outbuff, &olen);
if (ret != 0) {
ret = psa_cipher_update(&wrap_operation,
inbuff, 16, outbuff, sizeof(outbuff), &olen);
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 11:50:15 -05:00

If this call ever processes some data, I don't think it would be correct. After encrypting a block, further things happen in outbuff. If a call to psa_cipher_update with a 16-byte input does not process the given block fully, the output is already wrong at this point.

So I think we should remove the call to finish, and maybe assert that olen == 16 after the call to update above.

If this call ever processes some data, I don't think it would be correct. After encrypting a block, further things happen in `outbuff`. If a call to `psa_cipher_update` with a 16-byte input does not process the given block fully, the output is already wrong at this point. So I think we should remove the call to `finish`, and maybe assert that `olen == 16` after the call to update above.
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 11:54:19 -05:00

This doesn't look right: there is a buffer overflow on error when 1 <= output_size <= semiblocks * KW_SEMIBLOCK_LENGTH - 1. I'm not sure if this case is reached: it depends on exactly how the goto cleanup are positioned with respect to ouptut_size checks and semiblocks updates. But it's at least fragile.

We only need to clean up if there may be confidential data in output, so we could check that output_size is sufficiently large here. I'm not 100% sure about the number of semiblocks here though. Alternatively we could keep it simple and do memset(output, 0, output_size), which is inefficient if there is an error and output_size is very large, but that isn't an important scenario.

This is partly preexisting, but only partly: there are more error cases now, and output_size is fully validated now, so there may be new cases that could trigger an overflow.

This doesn't look right: there is a buffer overflow on error when `1 <= output_size <= semiblocks * KW_SEMIBLOCK_LENGTH - 1`. I'm not sure if this case is reached: it depends on exactly how the `goto cleanup` are positioned with respect to `ouptut_size` checks and `semiblocks` updates. But it's at least fragile. We only need to clean up if there may be confidential data in `output`, so we could check that `output_size` is sufficiently large here. I'm not 100% sure about the number of semiblocks here though. Alternatively we could keep it simple and do `memset(output, 0, output_size)`, which is inefficient if there is an error and `output_size` is very large, but that isn't an important scenario. This is partly preexisting, but only partly: there are more error cases now, and `output_size` is fully validated now, so there may be new cases that could trigger an overflow.
@ -306,1 +291,4 @@
goto cleanup;
}
*output_length = (semiblocks - 1) * KW_SEMIBLOCK_LENGTH;
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 11:44:37 -05:00

Non-blocker: mbedtls_buffer_offset is only needed to handle empty buffers correctly ({.p=NULL, .len=0} is a valid empty buffer, but p + len is not valid C when p == NULL even when len == 0). KW and KWP do not accept empty input, and this function has already made size checks that guarantee that output_size > 0, so output + update_output_length would be correct here.

Non-blocker: `mbedtls_buffer_offset` is only needed to handle empty buffers correctly (`{.p=NULL, .len=0}` is a valid empty buffer, but `p + len` is not valid C when `p == NULL` even when `len == 0`). KW and KWP do not accept empty input, and this function has already made size checks that guarantee that `output_size > 0`, so `output + update_output_length` would be correct here.
@ -309,3 +296,4 @@
if (ret != PSA_SUCCESS) {
memset(output, 0, (semiblocks - 1) * KW_SEMIBLOCK_LENGTH);
}
mbedtls_platform_zeroize(inbuff, sizeof(inbuff));
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 12:22:26 -05:00

As previously noted, when the output buffer is too small, the error code should be PSA_ERROR_BUFFER_TOO_SMALL. The error INVALID_ARGUMENT conveys that some data is bad (whether it's an unknown value in an enum-like integer, a known value that isn't in an appropriate category, an integer out of range, a badly formatted string, etc.). If an error can be solved by allocating more memory for a buffer, without changing any data, that error should be conveyed by BUFFER_TOO_SMALL.

As [previously noted](https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180#discussion_r2047281373), when the output buffer is too small, the error code should be `PSA_ERROR_BUFFER_TOO_SMALL`. The error `INVALID_ARGUMENT` conveys that some data is bad (whether it's an unknown value in an enum-like integer, a known value that isn't in an appropriate category, an integer out of range, a badly formatted string, etc.). If an error can be solved by allocating more memory for a buffer, without changing any data, that error should be conveyed by `BUFFER_TOO_SMALL`.
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 12:15:02 -05:00

There is a buffer overflow here if the value of *output_length on entry happens to be large. The obvious fix would be to set *output_length = 0 earlier, before the first goto cleanup.

There is a buffer overflow here if the value of `*output_length` on entry happens to be large. The obvious fix would be to set `*output_length = 0` earlier, before the first `goto cleanup`.
@ -48,4 +48,8 @@
#define PSA_WANT_ALG_CMAC 1
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 11:06:09 -05:00

As discussed previously, KW doesn't intrinsically require AES, it's just an implementation limitation. So MBEDTLS_NIST_KW_C should not auto-enable AES. (It should auto-enable PSA_WANT_ALG_ECB_NO_PADDING, because that's an internal detail of how MBEDTLS_NIST_KW_C is implemented — auto-enabling ECB would not be necessary if PSA supported KW natively, and MBEDTLS_NIST_KW_C would instead auto-enable PSA_WANT_ALG_NIST_KW.)

As [discussed previously](https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180#discussion_r2047120769), KW doesn't intrinsically require AES, it's just an implementation limitation. So `MBEDTLS_NIST_KW_C` should not auto-enable AES. (It should auto-enable `PSA_WANT_ALG_ECB_NO_PADDING`, because that's an internal detail of how `MBEDTLS_NIST_KW_C` is implemented — auto-enabling ECB would not be necessary if PSA supported KW natively, and `MBEDTLS_NIST_KW_C` would instead auto-enable `PSA_WANT_ALG_NIST_KW`.)
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 11:06:26 -05:00
#if defined(MBEDTLS_NIST_KW_C)
```suggestion #if defined(MBEDTLS_NIST_KW_C) ```
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 11:08:17 -05:00

Preexisting: the fact that only AES is approved by NIST is a bit besides the point. AES is the only 128-bit block cipher that NIST approves of in general, this isn't specific to KW/KWP. What matters here is that our library only supports AES.

Preexisting: the fact that only AES is approved by NIST is a bit besides the point. AES is the only 128-bit block cipher that NIST approves of in general, this isn't specific to KW/KWP. What matters here is that _our library_ only supports AES.
gilles-peskine-arm (Migrated from github.com) commented 2025-05-06 12:25:18 -05:00

Sorry, I had missed your question here. PSA_ERROR_BUFFER_TOO_SMALL specifically means that an output buffer is not large enough for the output data. The error INVALID_ARGUMENT conveys that some data is bad (whether it's an unknown value in an enum-like integer, a known value that isn't in an appropriate category, an integer out of range, a badly formatted string, etc.). If an error can be solved by allocating more memory for a buffer, without changing any data, that error should be conveyed by BUFFER_TOO_SMALL.

Sorry, I had missed your question here. [`PSA_ERROR_BUFFER_TOO_SMALL`](https://arm-software.github.io/psa-api/status-code/1.0/api/status-codes.html#c.PSA_ERROR_BUFFER_TOO_SMALL) specifically means that an output buffer is not large enough for the output data. The error `INVALID_ARGUMENT` conveys that some data is bad (whether it's an unknown value in an enum-like integer, a known value that isn't in an appropriate category, an integer out of range, a badly formatted string, etc.). If an error can be solved by allocating more memory for a buffer, without changing any data, that error should be conveyed by `BUFFER_TOO_SMALL`.
bjwtaylor (Migrated from github.com) reviewed 2025-05-07 02:18:04 -05:00
@ -48,4 +48,8 @@
#define PSA_WANT_ALG_CMAC 1
bjwtaylor (Migrated from github.com) commented 2025-05-07 02:18:04 -05:00

Apologies, I'd added it in the test and forgot to remove it in module dependencies. I've also optimised the test dependency declarations. Let me know what you think?

Apologies, I'd added it in the test and forgot to remove it in module dependencies. I've also optimised the test dependency declarations. Let me know what you think?
bjwtaylor (Migrated from github.com) reviewed 2025-05-07 02:33:27 -05:00
bjwtaylor (Migrated from github.com) commented 2025-05-07 02:33:27 -05:00

I've reworded this, let me know what you think.

I've reworded this, let me know what you think.
bjwtaylor (Migrated from github.com) reviewed 2025-05-07 05:11:33 -05:00
bjwtaylor (Migrated from github.com) commented 2025-05-07 05:11:33 -05:00

Should now be resolved.

Should now be resolved.
bjwtaylor (Migrated from github.com) reviewed 2025-05-07 05:20:14 -05:00
bjwtaylor (Migrated from github.com) commented 2025-05-07 05:20:14 -05:00

OK, I've updated the error codes. Hopefully I've understood what we want correctly and they are now correct, though let me know what you think and if you want me to make some amendments I can.

OK, I've updated the error codes. Hopefully I've understood what we want correctly and they are now correct, though let me know what you think and if you want me to make some amendments I can.
gilles-peskine-arm (Migrated from github.com) requested changes 2025-05-07 08:44:01 -05:00
gilles-peskine-arm (Migrated from github.com) left a comment

We're getting close but a few things still aren't quite right.

We're getting close but a few things still aren't quite right.
gilles-peskine-arm (Migrated from github.com) commented 2025-05-07 08:43:30 -05:00

Non-blocker: output_size is still not a pointer so it should not be annotated [in] (but Doxygen and clang -Wdocumentation don't care).

Non-blocker: `output_size` is still not a pointer so it should not be annotated `[in]` (but Doxygen and `clang -Wdocumentation` don't care).
@ -38,76 +39,6 @@ static const unsigned char NIST_KW_ICV1[] = { 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6
/*! The 32-bit default integrity check value (ICV) for KWP mode. */
static const unsigned char NIST_KW_ICV2[] = { 0xA6, 0x59, 0x59, 0xA6 };
gilles-peskine-arm (Migrated from github.com) commented 2025-05-07 08:38:06 -05:00

As previously discussed, this isn't some kind of policy violation, so the error code should not be NOT_PERMITTED. Either INVALID_ARGUMENT or NOT_SUPPORTED would be ok.

As [previously discussed](https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/180#discussion_r2075846139), this isn't some kind of policy violation, so the error code should not be `NOT_PERMITTED`. Either `INVALID_ARGUMENT` or `NOT_SUPPORTED` would be ok.
@ -120,86 +51,131 @@ static void calc_a_xor_t(unsigned char A[KW_SEMIBLOCK_LENGTH], uint64_t t)
}
gilles-peskine-arm (Migrated from github.com) commented 2025-05-07 08:33:03 -05:00

Please make attributes a local variable (and don't forget to clean up on error paths), since it isn't used outside this function.

Please make `attributes` a local variable (and don't forget to clean up on error paths), since it isn't used outside this function.
@ -221,2 +196,2 @@
inbuff, 16, outbuff, &olen);
if (ret != 0) {
ret = psa_cipher_update(&wrap_operation,
inbuff, 16, outbuff, sizeof(outbuff), &olen);
gilles-peskine-arm (Migrated from github.com) commented 2025-05-07 08:39:05 -05:00

This is not addressed.

This is not addressed.
gilles-peskine-arm (Migrated from github.com) commented 2025-05-07 08:41:47 -05:00

This is not addressed. I'm not sure there's actually a bug right now, but at the very least this code depends on the invariant that output_size >= semiblocks * KW_SEMIBLOCK_LENGTH and this invariant is not documented.

This is not addressed. I'm not sure there's actually a bug right now, but at the very least this code depends on the invariant that `output_size >= semiblocks * KW_SEMIBLOCK_LENGTH` and this invariant is not documented.
@ -757,13 +757,13 @@
/**
gilles-peskine-arm (Migrated from github.com) commented 2025-05-07 08:31:12 -05:00

ECB is an implementation detail. It isn't relevant here.

The wording is also a little weird because KW and KWP are all the modes that can be used with AES, anyway. (SP 800-38F defines three modes, and the third mode is only for 64-bit block ciphers, which means DES in NIST specifications.)

Also, preexisting: these modes are often known from the RFC rather than from NIST, so it would be helpful to cite the RFC here as well.

 * Enable the 128-bit key wrapping modes from NIST SP 800-38F:
 * KW (also known as RFC 3394) and KWP (RFC 5649).
 * Currently these modes are only supported with AES.
ECB is an implementation detail. It isn't relevant here. The wording is also a little weird because KW and KWP are all the modes that can be used with AES, anyway. (SP 800-38F defines three modes, and the third mode is only for 64-bit block ciphers, which means DES in NIST specifications.) Also, preexisting: these modes are often known from the RFC rather than from NIST, so it would be helpful to cite the RFC here as well. ```suggestion * Enable the 128-bit key wrapping modes from NIST SP 800-38F: * KW (also known as RFC 3394) and KWP (RFC 5649). * Currently these modes are only supported with AES. ```
@ -169,3 +159,2 @@
NIST KWP wrap AES-128 CAVS 21.4 PLAINTEXT LENGTH = 4096 count 1
depends_on:MBEDTLS_AES_C
mbedtls_nist_kw_wrap:MBEDTLS_CIPHER_ID_AES:MBEDTLS_KW_MODE_KWP:"6b8ba9cc9b31068ba175abfcc60c1338":"8af887c58dfbc38ee0423eefcc0e032dcc79dd116638ca65ad75dca2a2459f13934dbe61a62cb26d8bbddbabf9bf52bbe137ef1d3e30eacf0fe456ec808d6798dc29fe54fa1f784aa3c11cf39405009581d3f1d596843813a6685e503fac8535e0c06ecca8561b6a1f22c578eefb691912be2e1667946101ae8c3501e6c66eb17e14f2608c9ce6fbab4a1597ed49ccb3930b1060f98c97d8dc4ce81e35279c4d30d1bf86c9b919a3ce4f0109e77929e58c4c3aeb5de1ec5e0afa38ae896df9121c72c255141f2f5c9a51be5072547cf8a3b067404e62f9615a02479cf8c202e7feb2e258314e0ebe62878a5c4ecd4e9df7dab2e1fa9a7b532c2169acedb7998d5cd8a7118848ce7ee9fb2f68e28c2b279ddc064db70ad73c6dbe10c5e1c56a709c1407f93a727cce1075103a4009ae2f7731b7d71756eee119b828ef4ed61eff164935532a94fa8fe62dc2e22cf20f168ae65f4b6785286c253f365f29453a479dc2824b8bdabd962da3b76ae9c8a720155e158fe389c8cc7fa6ad522c951b5c236bf964b5b1bfb098a39835759b95404b72b17f7dbcda936177ae059269f41ecdac81a49f5bbfd2e801392a043ef06873550a67fcbc039f0b5d30ce490baa979dbbaf9e53d45d7e2dff26b2f7e6628ded694217a39f454b288e7906b79faf4a407a7d207646f93096a157f0d1dca05a7f92e318fc1ff62ce2de7f129b187053":"aea19443d7f8ad7d4501c1ecadc6b5e3f1c23c29eca608905f9cabdd46e34a55e1f7ac8308e75c903675982bda99173a2ba57d2ccf2e01a02589f89dfd4b3c7fd229ec91c9d0c46ea5dee3c048cd4611bfeadc9bf26daa1e02cb72e222cf3dab120dd1e8c2dd9bd58bbefa5d14526abd1e8d2170a6ba8283c243ec2fd5ef07030b1ef5f69f9620e4b17a3639341005887b9ffc793533594703e5dcae67bd0ce7a3c98ca65815a4d067f27e6e66d6636cebb789732566a52ac3970e14c37310dc2fcee0e739a16291029fd2b4d534e30445474b26711a8b3e1ee3cc88b09e8b1745b6cc0f067624ecb232db750b01fe5457fdea77b251b10fe95d3eeedb083bdf109c41dba26cc9654f787bf95735ff07070b175cea8b62302e6087b91a0415474605691099f1a9e2b626c4b3bb7aeb8ead9922bc3617cb427c669b88be5f98aea7edb8b0063bec80af4c081f89778d7c7242ddae88e8d3aff1f80e575e1aab4a5d115bc27636fd14d19bc59433f697635ecd870d17e7f5b004dee4001cddc34ab6e377eeb3fb08e9476970765105d93e4558fe3d4fc6fe053aab9c6cf032f1116e70c2d65f7c8cdeb6ad63ac4291f93d467ebbb29ead265c05ac684d20a6bef09b71830f717e08bcb4f9d3773bec928f66eeb64dc451e958e357ebbfef5a342df28707ac4b8e3e8c854e8d691cb92e87c0d57558e44cd754424865c229c9e1abb28e003b6819400b"
mbedtls_nist_kw_wrap:MBEDTLS_KW_MODE_KWP:"6b8ba9cc9b31068ba175abfcc60c1338":"8af887c58dfbc38ee0423eefcc0e032dcc79dd116638ca65ad75dca2a2459f13934dbe61a62cb26d8bbddbabf9bf52bbe137ef1d3e30eacf0fe456ec808d6798dc29fe54fa1f784aa3c11cf39405009581d3f1d596843813a6685e503fac8535e0c06ecca8561b6a1f22c578eefb691912be2e1667946101ae8c3501e6c66eb17e14f2608c9ce6fbab4a1597ed49ccb3930b1060f98c97d8dc4ce81e35279c4d30d1bf86c9b919a3ce4f0109e77929e58c4c3aeb5de1ec5e0afa38ae896df9121c72c255141f2f5c9a51be5072547cf8a3b067404e62f9615a02479cf8c202e7feb2e258314e0ebe62878a5c4ecd4e9df7dab2e1fa9a7b532c2169acedb7998d5cd8a7118848ce7ee9fb2f68e28c2b279ddc064db70ad73c6dbe10c5e1c56a709c1407f93a727cce1075103a4009ae2f7731b7d71756eee119b828ef4ed61eff164935532a94fa8fe62dc2e22cf20f168ae65f4b6785286c253f365f29453a479dc2824b8bdabd962da3b76ae9c8a720155e158fe389c8cc7fa6ad522c951b5c236bf964b5b1bfb098a39835759b95404b72b17f7dbcda936177ae059269f41ecdac81a49f5bbfd2e801392a043ef06873550a67fcbc039f0b5d30ce490baa979dbbaf9e53d45d7e2dff26b2f7e6628ded694217a39f454b288e7906b79faf4a407a7d207646f93096a157f0d1dca05a7f92e318fc1ff62ce2de7f129b187053":"aea19443d7f8ad7d4501c1ecadc6b5e3f1c23c29eca608905f9cabdd46e34a55e1f7ac8308e75c903675982bda99173a2ba57d2ccf2e01a02589f89dfd4b3c7fd229ec91c9d0c46ea5dee3c048cd4611bfeadc9bf26daa1e02cb72e222cf3dab120dd1e8c2dd9bd58bbefa5d14526abd1e8d2170a6ba8283c243ec2fd5ef07030b1ef5f69f9620e4b17a3639341005887b9ffc793533594703e5dcae67bd0ce7a3c98ca65815a4d067f27e6e66d6636cebb789732566a52ac3970e14c37310dc2fcee0e739a16291029fd2b4d534e30445474b26711a8b3e1ee3cc88b09e8b1745b6cc0f067624ecb232db750b01fe5457fdea77b251b10fe95d3eeedb083bdf109c41dba26cc9654f787bf95735ff07070b175cea8b62302e6087b91a0415474605691099f1a9e2b626c4b3bb7aeb8ead9922bc3617cb427c669b88be5f98aea7edb8b0063bec80af4c081f89778d7c7242ddae88e8d3aff1f80e575e1aab4a5d115bc27636fd14d19bc59433f697635ecd870d17e7f5b004dee4001cddc34ab6e377eeb3fb08e9476970765105d93e4558fe3d4fc6fe053aab9c6cf032f1116e70c2d65f7c8cdeb6ad63ac4291f93d467ebbb29ead265c05ac684d20a6bef09b71830f717e08bcb4f9d3773bec928f66eeb64dc451e958e357ebbfef5a342df28707ac4b8e3e8c854e8d691cb92e87c0d57558e44cd754424865c229c9e1abb28e003b6819400b"
gilles-peskine-arm (Migrated from github.com) commented 2025-05-07 08:19:20 -05:00

Test data that is specific to a particular key type should pass the key type as an argument and should have a dependency on the key type.

But never mind, let's stop flip-flopping on this and just go with what we have and fix it later as part of the technical debt backlog. It's pretty low priority.

Test data that is specific to a particular key type should pass the key type as an argument and should have a dependency on the key type. But never mind, let's stop flip-flopping on this and just go with what we have and fix it later as part of the technical debt backlog. It's pretty low priority.
bjwtaylor (Migrated from github.com) reviewed 2025-05-08 02:07:56 -05:00
@ -169,3 +159,2 @@
NIST KWP wrap AES-128 CAVS 21.4 PLAINTEXT LENGTH = 4096 count 1
depends_on:MBEDTLS_AES_C
mbedtls_nist_kw_wrap:MBEDTLS_CIPHER_ID_AES:MBEDTLS_KW_MODE_KWP:"6b8ba9cc9b31068ba175abfcc60c1338":"8af887c58dfbc38ee0423eefcc0e032dcc79dd116638ca65ad75dca2a2459f13934dbe61a62cb26d8bbddbabf9bf52bbe137ef1d3e30eacf0fe456ec808d6798dc29fe54fa1f784aa3c11cf39405009581d3f1d596843813a6685e503fac8535e0c06ecca8561b6a1f22c578eefb691912be2e1667946101ae8c3501e6c66eb17e14f2608c9ce6fbab4a1597ed49ccb3930b1060f98c97d8dc4ce81e35279c4d30d1bf86c9b919a3ce4f0109e77929e58c4c3aeb5de1ec5e0afa38ae896df9121c72c255141f2f5c9a51be5072547cf8a3b067404e62f9615a02479cf8c202e7feb2e258314e0ebe62878a5c4ecd4e9df7dab2e1fa9a7b532c2169acedb7998d5cd8a7118848ce7ee9fb2f68e28c2b279ddc064db70ad73c6dbe10c5e1c56a709c1407f93a727cce1075103a4009ae2f7731b7d71756eee119b828ef4ed61eff164935532a94fa8fe62dc2e22cf20f168ae65f4b6785286c253f365f29453a479dc2824b8bdabd962da3b76ae9c8a720155e158fe389c8cc7fa6ad522c951b5c236bf964b5b1bfb098a39835759b95404b72b17f7dbcda936177ae059269f41ecdac81a49f5bbfd2e801392a043ef06873550a67fcbc039f0b5d30ce490baa979dbbaf9e53d45d7e2dff26b2f7e6628ded694217a39f454b288e7906b79faf4a407a7d207646f93096a157f0d1dca05a7f92e318fc1ff62ce2de7f129b187053":"aea19443d7f8ad7d4501c1ecadc6b5e3f1c23c29eca608905f9cabdd46e34a55e1f7ac8308e75c903675982bda99173a2ba57d2ccf2e01a02589f89dfd4b3c7fd229ec91c9d0c46ea5dee3c048cd4611bfeadc9bf26daa1e02cb72e222cf3dab120dd1e8c2dd9bd58bbefa5d14526abd1e8d2170a6ba8283c243ec2fd5ef07030b1ef5f69f9620e4b17a3639341005887b9ffc793533594703e5dcae67bd0ce7a3c98ca65815a4d067f27e6e66d6636cebb789732566a52ac3970e14c37310dc2fcee0e739a16291029fd2b4d534e30445474b26711a8b3e1ee3cc88b09e8b1745b6cc0f067624ecb232db750b01fe5457fdea77b251b10fe95d3eeedb083bdf109c41dba26cc9654f787bf95735ff07070b175cea8b62302e6087b91a0415474605691099f1a9e2b626c4b3bb7aeb8ead9922bc3617cb427c669b88be5f98aea7edb8b0063bec80af4c081f89778d7c7242ddae88e8d3aff1f80e575e1aab4a5d115bc27636fd14d19bc59433f697635ecd870d17e7f5b004dee4001cddc34ab6e377eeb3fb08e9476970765105d93e4558fe3d4fc6fe053aab9c6cf032f1116e70c2d65f7c8cdeb6ad63ac4291f93d467ebbb29ead265c05ac684d20a6bef09b71830f717e08bcb4f9d3773bec928f66eeb64dc451e958e357ebbfef5a342df28707ac4b8e3e8c854e8d691cb92e87c0d57558e44cd754424865c229c9e1abb28e003b6819400b"
mbedtls_nist_kw_wrap:MBEDTLS_KW_MODE_KWP:"6b8ba9cc9b31068ba175abfcc60c1338":"8af887c58dfbc38ee0423eefcc0e032dcc79dd116638ca65ad75dca2a2459f13934dbe61a62cb26d8bbddbabf9bf52bbe137ef1d3e30eacf0fe456ec808d6798dc29fe54fa1f784aa3c11cf39405009581d3f1d596843813a6685e503fac8535e0c06ecca8561b6a1f22c578eefb691912be2e1667946101ae8c3501e6c66eb17e14f2608c9ce6fbab4a1597ed49ccb3930b1060f98c97d8dc4ce81e35279c4d30d1bf86c9b919a3ce4f0109e77929e58c4c3aeb5de1ec5e0afa38ae896df9121c72c255141f2f5c9a51be5072547cf8a3b067404e62f9615a02479cf8c202e7feb2e258314e0ebe62878a5c4ecd4e9df7dab2e1fa9a7b532c2169acedb7998d5cd8a7118848ce7ee9fb2f68e28c2b279ddc064db70ad73c6dbe10c5e1c56a709c1407f93a727cce1075103a4009ae2f7731b7d71756eee119b828ef4ed61eff164935532a94fa8fe62dc2e22cf20f168ae65f4b6785286c253f365f29453a479dc2824b8bdabd962da3b76ae9c8a720155e158fe389c8cc7fa6ad522c951b5c236bf964b5b1bfb098a39835759b95404b72b17f7dbcda936177ae059269f41ecdac81a49f5bbfd2e801392a043ef06873550a67fcbc039f0b5d30ce490baa979dbbaf9e53d45d7e2dff26b2f7e6628ded694217a39f454b288e7906b79faf4a407a7d207646f93096a157f0d1dca05a7f92e318fc1ff62ce2de7f129b187053":"aea19443d7f8ad7d4501c1ecadc6b5e3f1c23c29eca608905f9cabdd46e34a55e1f7ac8308e75c903675982bda99173a2ba57d2ccf2e01a02589f89dfd4b3c7fd229ec91c9d0c46ea5dee3c048cd4611bfeadc9bf26daa1e02cb72e222cf3dab120dd1e8c2dd9bd58bbefa5d14526abd1e8d2170a6ba8283c243ec2fd5ef07030b1ef5f69f9620e4b17a3639341005887b9ffc793533594703e5dcae67bd0ce7a3c98ca65815a4d067f27e6e66d6636cebb789732566a52ac3970e14c37310dc2fcee0e739a16291029fd2b4d534e30445474b26711a8b3e1ee3cc88b09e8b1745b6cc0f067624ecb232db750b01fe5457fdea77b251b10fe95d3eeedb083bdf109c41dba26cc9654f787bf95735ff07070b175cea8b62302e6087b91a0415474605691099f1a9e2b626c4b3bb7aeb8ead9922bc3617cb427c669b88be5f98aea7edb8b0063bec80af4c081f89778d7c7242ddae88e8d3aff1f80e575e1aab4a5d115bc27636fd14d19bc59433f697635ecd870d17e7f5b004dee4001cddc34ab6e377eeb3fb08e9476970765105d93e4558fe3d4fc6fe053aab9c6cf032f1116e70c2d65f7c8cdeb6ad63ac4291f93d467ebbb29ead265c05ac684d20a6bef09b71830f717e08bcb4f9d3773bec928f66eeb64dc451e958e357ebbfef5a342df28707ac4b8e3e8c854e8d691cb92e87c0d57558e44cd754424865c229c9e1abb28e003b6819400b"
bjwtaylor (Migrated from github.com) commented 2025-05-08 02:07:56 -05:00

So, I was taking a look at this code and noticed we can add the dependency on the functions as every function is currently dependent on AES. So I've added it here github.com/bjwtaylor/TF-PSA-Crypto@d6b9e396c8/tests/suites/test_suite_nist_kw.function (L24) and removed it from the data. Currently the key has to be passed anyway and the key type is encoded in the parameters, so I'm not sure we need it passed into the function also? Though I can add this if you think it would be useful. Let me know what you think?

So, I was taking a look at this code and noticed we can add the dependency on the functions as every function is currently dependent on AES. So I've added it here https://github.com/bjwtaylor/TF-PSA-Crypto/blob/d6b9e396c877bb27adf2ab0e83a674f9243b57c1/tests/suites/test_suite_nist_kw.function#L24 and removed it from the data. Currently the key has to be passed anyway and the key type is encoded in the parameters, so I'm not sure we need it passed into the function also? Though I can add this if you think it would be useful. Let me know what you think?
bjwtaylor (Migrated from github.com) reviewed 2025-05-08 04:14:49 -05:00
@ -221,2 +196,2 @@
inbuff, 16, outbuff, &olen);
if (ret != 0) {
ret = psa_cipher_update(&wrap_operation,
inbuff, 16, outbuff, sizeof(outbuff), &olen);
bjwtaylor (Migrated from github.com) commented 2025-05-08 04:14:49 -05:00

Apologies this one got lost in the the noise. So, I've removed the finish and added a check for the length. I wasn't sure on the error code, I went with PSA_ERROR_BAD_STATE as it seemed most appropriate. Let me know if you want me to change it though.

Apologies this one got lost in the the noise. So, I've removed the finish and added a check for the length. I wasn't sure on the error code, I went with PSA_ERROR_BAD_STATE as it seemed most appropriate. Let me know if you want me to change it though.
bjwtaylor (Migrated from github.com) reviewed 2025-05-08 04:36:45 -05:00
@ -221,2 +196,2 @@
inbuff, 16, outbuff, &olen);
if (ret != 0) {
ret = psa_cipher_update(&wrap_operation,
inbuff, 16, outbuff, sizeof(outbuff), &olen);
bjwtaylor (Migrated from github.com) commented 2025-05-08 04:36:45 -05:00

Apologies, also seems to have got lost in the noise. I've updated to include the suggested output_size addition. Let me know if this is sufficient or if you think we need to do something more efficient?

Apologies, also seems to have got lost in the noise. I've updated to include the suggested output_size addition. Let me know if this is sufficient or if you think we need to do something more efficient?
bjwtaylor (Migrated from github.com) reviewed 2025-05-08 04:40:42 -05:00
bjwtaylor (Migrated from github.com) commented 2025-05-08 04:40:42 -05:00

I've removed the annotation.

I've removed the annotation.
gilles-peskine-arm (Migrated from github.com) requested changes 2025-05-08 14:45:20 -05:00
gilles-peskine-arm (Migrated from github.com) left a comment

LGTM except for a risk of a memory leak in the future.

LGTM except for a risk of a memory leak in the future.
@ -139,0 +95,4 @@
ret = verify_input(&key);
if (ret != PSA_SUCCESS) {
goto cleanup;
}
gilles-peskine-arm (Migrated from github.com) commented 2025-05-08 14:38:44 -05:00

psa_get_key_attributes may allocate memory. It currently doesn't, but it did in some cases in the past and it might do so in the future. So to avoid a potential memory leak, we should call psa_reset_key_attributes on the error paths. (Especially in the bad-type case — given that we write generally the library to be robust, if psa_get_key_attributes fails, we would normally arrange for it to clean up the output structure.)

`psa_get_key_attributes` may allocate memory. It currently doesn't, but it did in some cases in the past and it might do so in the future. So to avoid a potential memory leak, we should call `psa_reset_key_attributes` on the error paths. (Especially in the bad-type case — given that we write generally the library to be robust, if `psa_get_key_attributes` fails, we would normally arrange for it to clean up the output structure.)
gilles-peskine-arm (Migrated from github.com) commented 2025-05-08 14:39:59 -05:00

BAD_STATE doesn't really make sense here since there's no context that's left in a bad state. But since this is a “shouldn't happen” error, it doesn't really matter. Technically CORRUPTION_DETECTED would be the most fitting error.

`BAD_STATE` doesn't really make sense here since there's no context that's left in a bad state. But since this is a “shouldn't happen” error, it doesn't really matter. Technically `CORRUPTION_DETECTED` would be the most fitting error.
@ -169,3 +159,2 @@
NIST KWP wrap AES-128 CAVS 21.4 PLAINTEXT LENGTH = 4096 count 1
depends_on:MBEDTLS_AES_C
mbedtls_nist_kw_wrap:MBEDTLS_CIPHER_ID_AES:MBEDTLS_KW_MODE_KWP:"6b8ba9cc9b31068ba175abfcc60c1338":"8af887c58dfbc38ee0423eefcc0e032dcc79dd116638ca65ad75dca2a2459f13934dbe61a62cb26d8bbddbabf9bf52bbe137ef1d3e30eacf0fe456ec808d6798dc29fe54fa1f784aa3c11cf39405009581d3f1d596843813a6685e503fac8535e0c06ecca8561b6a1f22c578eefb691912be2e1667946101ae8c3501e6c66eb17e14f2608c9ce6fbab4a1597ed49ccb3930b1060f98c97d8dc4ce81e35279c4d30d1bf86c9b919a3ce4f0109e77929e58c4c3aeb5de1ec5e0afa38ae896df9121c72c255141f2f5c9a51be5072547cf8a3b067404e62f9615a02479cf8c202e7feb2e258314e0ebe62878a5c4ecd4e9df7dab2e1fa9a7b532c2169acedb7998d5cd8a7118848ce7ee9fb2f68e28c2b279ddc064db70ad73c6dbe10c5e1c56a709c1407f93a727cce1075103a4009ae2f7731b7d71756eee119b828ef4ed61eff164935532a94fa8fe62dc2e22cf20f168ae65f4b6785286c253f365f29453a479dc2824b8bdabd962da3b76ae9c8a720155e158fe389c8cc7fa6ad522c951b5c236bf964b5b1bfb098a39835759b95404b72b17f7dbcda936177ae059269f41ecdac81a49f5bbfd2e801392a043ef06873550a67fcbc039f0b5d30ce490baa979dbbaf9e53d45d7e2dff26b2f7e6628ded694217a39f454b288e7906b79faf4a407a7d207646f93096a157f0d1dca05a7f92e318fc1ff62ce2de7f129b187053":"aea19443d7f8ad7d4501c1ecadc6b5e3f1c23c29eca608905f9cabdd46e34a55e1f7ac8308e75c903675982bda99173a2ba57d2ccf2e01a02589f89dfd4b3c7fd229ec91c9d0c46ea5dee3c048cd4611bfeadc9bf26daa1e02cb72e222cf3dab120dd1e8c2dd9bd58bbefa5d14526abd1e8d2170a6ba8283c243ec2fd5ef07030b1ef5f69f9620e4b17a3639341005887b9ffc793533594703e5dcae67bd0ce7a3c98ca65815a4d067f27e6e66d6636cebb789732566a52ac3970e14c37310dc2fcee0e739a16291029fd2b4d534e30445474b26711a8b3e1ee3cc88b09e8b1745b6cc0f067624ecb232db750b01fe5457fdea77b251b10fe95d3eeedb083bdf109c41dba26cc9654f787bf95735ff07070b175cea8b62302e6087b91a0415474605691099f1a9e2b626c4b3bb7aeb8ead9922bc3617cb427c669b88be5f98aea7edb8b0063bec80af4c081f89778d7c7242ddae88e8d3aff1f80e575e1aab4a5d115bc27636fd14d19bc59433f697635ecd870d17e7f5b004dee4001cddc34ab6e377eeb3fb08e9476970765105d93e4558fe3d4fc6fe053aab9c6cf032f1116e70c2d65f7c8cdeb6ad63ac4291f93d467ebbb29ead265c05ac684d20a6bef09b71830f717e08bcb4f9d3773bec928f66eeb64dc451e958e357ebbfef5a342df28707ac4b8e3e8c854e8d691cb92e87c0d57558e44cd754424865c229c9e1abb28e003b6819400b"
mbedtls_nist_kw_wrap:MBEDTLS_KW_MODE_KWP:"6b8ba9cc9b31068ba175abfcc60c1338":"8af887c58dfbc38ee0423eefcc0e032dcc79dd116638ca65ad75dca2a2459f13934dbe61a62cb26d8bbddbabf9bf52bbe137ef1d3e30eacf0fe456ec808d6798dc29fe54fa1f784aa3c11cf39405009581d3f1d596843813a6685e503fac8535e0c06ecca8561b6a1f22c578eefb691912be2e1667946101ae8c3501e6c66eb17e14f2608c9ce6fbab4a1597ed49ccb3930b1060f98c97d8dc4ce81e35279c4d30d1bf86c9b919a3ce4f0109e77929e58c4c3aeb5de1ec5e0afa38ae896df9121c72c255141f2f5c9a51be5072547cf8a3b067404e62f9615a02479cf8c202e7feb2e258314e0ebe62878a5c4ecd4e9df7dab2e1fa9a7b532c2169acedb7998d5cd8a7118848ce7ee9fb2f68e28c2b279ddc064db70ad73c6dbe10c5e1c56a709c1407f93a727cce1075103a4009ae2f7731b7d71756eee119b828ef4ed61eff164935532a94fa8fe62dc2e22cf20f168ae65f4b6785286c253f365f29453a479dc2824b8bdabd962da3b76ae9c8a720155e158fe389c8cc7fa6ad522c951b5c236bf964b5b1bfb098a39835759b95404b72b17f7dbcda936177ae059269f41ecdac81a49f5bbfd2e801392a043ef06873550a67fcbc039f0b5d30ce490baa979dbbaf9e53d45d7e2dff26b2f7e6628ded694217a39f454b288e7906b79faf4a407a7d207646f93096a157f0d1dca05a7f92e318fc1ff62ce2de7f129b187053":"aea19443d7f8ad7d4501c1ecadc6b5e3f1c23c29eca608905f9cabdd46e34a55e1f7ac8308e75c903675982bda99173a2ba57d2ccf2e01a02589f89dfd4b3c7fd229ec91c9d0c46ea5dee3c048cd4611bfeadc9bf26daa1e02cb72e222cf3dab120dd1e8c2dd9bd58bbefa5d14526abd1e8d2170a6ba8283c243ec2fd5ef07030b1ef5f69f9620e4b17a3639341005887b9ffc793533594703e5dcae67bd0ce7a3c98ca65815a4d067f27e6e66d6636cebb789732566a52ac3970e14c37310dc2fcee0e739a16291029fd2b4d534e30445474b26711a8b3e1ee3cc88b09e8b1745b6cc0f067624ecb232db750b01fe5457fdea77b251b10fe95d3eeedb083bdf109c41dba26cc9654f787bf95735ff07070b175cea8b62302e6087b91a0415474605691099f1a9e2b626c4b3bb7aeb8ead9922bc3617cb427c669b88be5f98aea7edb8b0063bec80af4c081f89778d7c7242ddae88e8d3aff1f80e575e1aab4a5d115bc27636fd14d19bc59433f697635ecd870d17e7f5b004dee4001cddc34ab6e377eeb3fb08e9476970765105d93e4558fe3d4fc6fe053aab9c6cf032f1116e70c2d65f7c8cdeb6ad63ac4291f93d467ebbb29ead265c05ac684d20a6bef09b71830f717e08bcb4f9d3773bec928f66eeb64dc451e958e357ebbfef5a342df28707ac4b8e3e8c854e8d691cb92e87c0d57558e44cd754424865c229c9e1abb28e003b6819400b"
gilles-peskine-arm (Migrated from github.com) commented 2025-05-08 14:44:39 -05:00

The general rule is that the place that mentions a feature explicitly should have the corresponding dependency. So any test case that has PSA_KEY_TYPE_AES in a parameter should have depends_on:PSA_WANT_KEY_TYPE_AES, and any function whose code uses PSA_KEY_TYPE_AES should have depends_on:PSA_WANT_KEY_TYPE_AES.

But this is not critical. It doesn't make the tests wrong, or reduce the test coverage. It just makes the code a little harder to understand. At this point I just want to get this merged.

The general rule is that the place that mentions a feature explicitly should have the corresponding dependency. So any test case that has `PSA_KEY_TYPE_AES` in a parameter should have `depends_on:PSA_WANT_KEY_TYPE_AES`, and any function whose code uses `PSA_KEY_TYPE_AES` should have `depends_on:PSA_WANT_KEY_TYPE_AES`. But this is not critical. It doesn't make the tests wrong, or reduce the test coverage. It just makes the code a little harder to understand. At this point I just want to get this merged.
valeriosetti (Migrated from github.com) reviewed 2025-05-09 08:26:54 -05:00
gilles-peskine-arm (Migrated from github.com) reviewed 2025-05-12 06:34:39 -05:00
gilles-peskine-arm (Migrated from github.com) left a comment
No description provided.
LGTM at b19bac702ce977c9288fae63290e48620a572ad3
gilles-peskine-arm commented 2025-05-12 06:35:24 -05:00 (Migrated from github.com)

This has two approvals, but needs a rebase or a merge to handle a conflict in nist_kw.h.

This has two approvals, but needs a rebase or a merge to handle a conflict in `nist_kw.h`.
gilles-peskine-arm (Migrated from github.com) approved these changes 2025-05-12 10:24:42 -05:00
gilles-peskine-arm (Migrated from github.com) left a comment

Looks good to me after rebase.

Prior to the rebase, there was a conflict in nist_kw.h which was both modified and moved. The move confuses git range-diff, you can help it with by specifying an orderfile:

echo '*/nist_kw.h' >orderfile.txt
git -c diff.orderfile=orderfile.txt range-diff development b19bac702ce977c9288fae63290e48620a572ad3 upstream/pr/180

This show only cosmetic differences in the patches.

Looks good to me after rebase. Prior to the rebase, there was a conflict in `nist_kw.h` which was both modified and moved. The move confuses `git range-diff`, you can help it with by specifying an [orderfile](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-code-Oltorderfilegtcode): ``` echo '*/nist_kw.h' >orderfile.txt git -c diff.orderfile=orderfile.txt range-diff development b19bac702ce977c9288fae63290e48620a572ad3 upstream/pr/180 ``` This show only cosmetic differences in the patches.
mpg (Migrated from github.com) approved these changes 2025-05-13 02:41:15 -05:00
mpg (Migrated from github.com) left a comment

b19bac702ce977c9288fae63290e48620a572ad3 was approved by Valerio, so I only reviewed the rebase since that commit, and found it good.

(Thank you Gilles for the orderfile trick, it would have taken me a moment to remember how it was called an how to use it).

b19bac702ce977c9288fae63290e48620a572ad3 was approved by Valerio, so I only reviewed the rebase since that commit, and found it good. (Thank you Gilles for the orderfile trick, it would have taken me a moment to remember how it was called an how to use it).
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto!180
No description provided.