Hi Markus,

 

psa_set_key_algorithm() should be called when properly setting up the policy for permitted algorithm on a key. From what I could quickly see it seems that the positive-tests in the Crypto regression are setting them correctly.

 

An example snippet of what I am referring to:

 

    /* Setup the key policy */

    psa_set_key_usage_flags(&key_attributes, PSA_KEY_USAGE_VERIFY_HASH);

    psa_set_key_algorithm(&key_attributes, alg);

    psa_set_key_type(&key_attributes, key_type);

 

Are you referring to some particular test that is not setting the algorithm field in the key attributes? Could you point me to that? It might very well be that setting it has been overlooked when writing some _negative_ test that wasn’t aiming at preparing the object correctly because it was just trying to cause a failure, hence it did not care about that algorithm policy field. But in general, I can confirm that it’s good practice to set the algorithm and if any of the tests are not aligned to this pattern, they must be fixed upstream for consistency.

 

Thanks,

Antonio

 

From: Swarowsky, Markus via TF-M <tf-m@lists.trustedfirmware.org>
Sent: Thursday, October 13, 2022 13:14
To: Chris.Brand--- via TF-M <tf-m@lists.trustedfirmware.org>
Subject: [TF-M] TF-M psa crypto test do not set the algorithms in psa_key_attributes_t

 

Hello,

I was adding sanity checks to the psa_crypto_driver_wrappers to validate bits/type and policy->alg  of the given psa_key_attributes_t attributes for the psa_generate_key, psa_import_key, and psa_copy_key calls. 
To check it the given combination is within the psa specification. 

In the PSA crypto spec it says: 
The key permitted-algorithm policy is required for keys that will be used for a cryptographic operation, see Permitted algorithms. [https://armmbed.github.io/mbed-crypto/html/api/keys/management.html?highlight=psa_generate_key#c.psa_generate_key]
Which is most likely the case for all key types except of PSA_KEY_TYPE_RAW_DATA

But after adding the sanity checks the TF-M crypto tests(test_c*_testing_* and TFM_S/NS_CRYPTO_TEST_10*) failed.
I took a look at these tests, it turned out that they don't set the algorithm flag for the key attributes. 

My question now is, is the algorithm flag skipped on purpose or just missed during the test case creation as It should be set according to the psa crypto spec?

 



Thanks for the help and the feedback 

Markus Swarowsky | R & D Engineer
M +47 404 66 922 | Trondheim, Norway

nordicsemi.com | devzone.nordicsemi.com

Facebook | LinkedIn | Twitter | YouTube | Instagram

 

Nordic_logo_signature