Skip to content

Commit c83d64c

Browse files
committed
nrf_security: psa_crypto_driver_wrappers.c: use psa_get_*()
probably to be dropped Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
1 parent d710ccc commit c83d64c

1 file changed

Lines changed: 74 additions & 37 deletions

File tree

subsys/nrf_security/src/psa_crypto_driver_wrappers.c

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ psa_status_t psa_driver_wrapper_sign_message_with_context(
209209
size_t context_length, uint8_t *signature, size_t signature_size, size_t *signature_length)
210210
{
211211
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
212-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
212+
psa_key_location_t location =
213+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
213214

214215
switch (location) {
215216
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -271,7 +272,8 @@ psa_status_t psa_driver_wrapper_verify_message_with_context(
271272
size_t context_length, const uint8_t *signature, size_t signature_length)
272273
{
273274
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
274-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
275+
psa_key_location_t location =
276+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
275277

276278
switch (location) {
277279
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -335,7 +337,8 @@ psa_status_t psa_driver_wrapper_sign_hash_with_context(
335337
size_t context_length, uint8_t *signature, size_t signature_size, size_t *signature_length)
336338
{
337339
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
338-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
340+
psa_key_location_t location =
341+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
339342

340343
switch (location) {
341344
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -398,7 +401,8 @@ psa_status_t psa_driver_wrapper_verify_hash_with_context(
398401
size_t context_length, const uint8_t *signature, size_t signature_length)
399402
{
400403
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
401-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
404+
psa_key_location_t location =
405+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
402406

403407
switch (location) {
404408
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -473,8 +477,9 @@ psa_driver_wrapper_get_key_buffer_size_from_key_data(const psa_key_attributes_t
473477
const uint8_t *data, size_t data_length,
474478
size_t *key_buffer_size)
475479
{
476-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
477-
psa_key_type_t key_type = attributes->type;
480+
psa_key_location_t location =
481+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
482+
psa_key_type_t key_type = psa_get_key_type(attributes);
478483

479484
*key_buffer_size = 0;
480485
switch (location) {
@@ -511,9 +516,10 @@ psa_driver_wrapper_get_key_buffer_size_from_key_data(const psa_key_attributes_t
511516
psa_status_t psa_driver_wrapper_get_key_buffer_size(const psa_key_attributes_t *attributes,
512517
size_t *key_buffer_size)
513518
{
514-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
515-
psa_key_type_t key_type = attributes->type;
516-
size_t key_bits = attributes->bits;
519+
psa_key_location_t location =
520+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
521+
psa_key_type_t key_type = psa_get_key_type(attributes);
522+
size_t key_bits = psa_get_key_bits(attributes);
517523

518524
*key_buffer_size = 0;
519525
switch (location) {
@@ -545,7 +551,8 @@ psa_status_t psa_driver_wrapper_generate_key(const psa_key_attributes_t *attribu
545551
size_t *key_buffer_length)
546552
{
547553
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
548-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
554+
psa_key_location_t location =
555+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
549556

550557
switch (location) {
551558
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -561,7 +568,7 @@ psa_status_t psa_driver_wrapper_generate_key(const psa_key_attributes_t *attribu
561568
}
562569
#endif /* PSA_CRYPTO_DRIVER_IRONSIDE */
563570
/* Transparent drivers are limited to generating asymmetric keys */
564-
if (PSA_KEY_TYPE_IS_ASYMMETRIC(attributes->type)) {
571+
if (PSA_KEY_TYPE_IS_ASYMMETRIC(psa_get_key_type(attributes))) {
565572
/* Cycle through all known transparent accelerators */
566573
#if defined(PSA_NEED_CRACEN_KEY_MANAGEMENT_DRIVER)
567574
status = cracen_generate_key(attributes, key_buffer, key_buffer_size,
@@ -773,7 +780,8 @@ psa_status_t psa_driver_wrapper_get_builtin_key(psa_drv_slot_number_t slot_numbe
773780
uint8_t *key_buffer, size_t key_buffer_size,
774781
size_t *key_buffer_length)
775782
{
776-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
783+
psa_key_location_t location =
784+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
777785

778786
switch (location) {
779787
#if defined(PSA_CRYPTO_DRIVER_IRONSIDE)
@@ -808,7 +816,8 @@ psa_status_t psa_driver_wrapper_copy_key(psa_key_attributes_t *attributes,
808816
uint8_t *target_key_buffer, size_t target_key_buffer_size,
809817
size_t *target_key_buffer_length)
810818
{
811-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
819+
psa_key_location_t location =
820+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
812821

813822
switch (location) {
814823
#if defined(PSA_CRYPTO_DRIVER_IRONSIDE)
@@ -838,8 +847,10 @@ psa_status_t psa_driver_wrapper_derive_key(const psa_key_attributes_t *attribute
838847
size_t *key_buffer_length)
839848
{
840849
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
850+
psa_key_location_t location =
851+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
841852

842-
switch (PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime)) {
853+
switch (location) {
843854
case PSA_KEY_LOCATION_LOCAL_STORAGE:
844855
/* Add cases for transparent drivers here */
845856
#ifdef PSA_CRYPTO_DRIVER_IRONSIDE
@@ -891,7 +902,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt(const psa_key_attributes_t *attri
891902
size_t output_size, size_t *output_length)
892903
{
893904
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
894-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
905+
psa_key_location_t location =
906+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
895907

896908
switch (location) {
897909
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -965,7 +977,8 @@ psa_status_t psa_driver_wrapper_cipher_decrypt(const psa_key_attributes_t *attri
965977
size_t output_size, size_t *output_length)
966978
{
967979
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
968-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
980+
psa_key_location_t location =
981+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
969982

970983
switch (location) {
971984
#if defined(PSA_NEED_CRACEN_KMU_DRIVER)
@@ -1024,7 +1037,8 @@ psa_status_t psa_driver_wrapper_cipher_encrypt_setup(psa_cipher_operation_t *ope
10241037
size_t key_buffer_size, psa_algorithm_t alg)
10251038
{
10261039
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1027-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
1040+
psa_key_location_t location =
1041+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
10281042

10291043
switch (location) {
10301044
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -1087,7 +1101,8 @@ psa_status_t psa_driver_wrapper_cipher_decrypt_setup(psa_cipher_operation_t *ope
10871101
size_t key_buffer_size, psa_algorithm_t alg)
10881102
{
10891103
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
1090-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
1104+
psa_key_location_t location =
1105+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
10911106

10921107
switch (location) {
10931108
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -1538,7 +1553,8 @@ psa_status_t psa_driver_wrapper_aead_encrypt(const psa_key_attributes_t *attribu
15381553
size_t *ciphertext_length)
15391554
{
15401555
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1541-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
1556+
psa_key_location_t location =
1557+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
15421558

15431559
switch (location) {
15441560
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -1608,7 +1624,8 @@ psa_status_t psa_driver_wrapper_aead_decrypt(const psa_key_attributes_t *attribu
16081624
size_t *plaintext_length)
16091625
{
16101626
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1611-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
1627+
psa_key_location_t location =
1628+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
16121629

16131630
switch (location) {
16141631
#if defined(PSA_NEED_CRACEN_AEAD_DRIVER)
@@ -1680,7 +1697,8 @@ psa_status_t psa_driver_wrapper_aead_encrypt_setup(psa_aead_operation_t *operati
16801697
size_t key_buffer_size, psa_algorithm_t alg)
16811698
{
16821699
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1683-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
1700+
psa_key_location_t location =
1701+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
16841702

16851703
switch (location) {
16861704
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -1744,7 +1762,8 @@ psa_status_t psa_driver_wrapper_aead_decrypt_setup(psa_aead_operation_t *operati
17441762
size_t key_buffer_size, psa_algorithm_t alg)
17451763
{
17461764
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
1747-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
1765+
psa_key_location_t location =
1766+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
17481767

17491768
switch (location) {
17501769
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -2010,7 +2029,8 @@ psa_status_t psa_driver_wrapper_mac_compute(const psa_key_attributes_t *attribut
20102029
size_t *mac_length)
20112030
{
20122031
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2013-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
2032+
psa_key_location_t location =
2033+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
20142034

20152035
#if !defined(PSA_WANT_ALG_SHA_1)
20162036
if (PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1) {
@@ -2071,7 +2091,8 @@ psa_status_t psa_driver_wrapper_mac_sign_setup(psa_mac_operation_t *operation,
20712091
psa_algorithm_t alg)
20722092
{
20732093
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2074-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
2094+
psa_key_location_t location =
2095+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
20752096

20762097
#if !defined(PSA_WANT_ALG_SHA_1)
20772098
if (PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1) {
@@ -2136,7 +2157,8 @@ psa_status_t psa_driver_wrapper_mac_verify_setup(psa_mac_operation_t *operation,
21362157
psa_algorithm_t alg)
21372158
{
21382159
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2139-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
2160+
psa_key_location_t location =
2161+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
21402162

21412163
#if !defined(PSA_WANT_ALG_SHA_1)
21422164
if (PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1) {
@@ -2479,8 +2501,8 @@ psa_status_t psa_driver_wrapper_key_agreement(const psa_key_attributes_t *attrib
24792501
size_t output_size, size_t *output_length)
24802502
{
24812503
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2482-
2483-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
2504+
psa_key_location_t location =
2505+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
24842506

24852507
switch (location) {
24862508
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -2553,8 +2575,10 @@ psa_status_t psa_driver_wrapper_encapsulate(const psa_key_attributes_t *attribut
25532575
{
25542576
psa_status_t status;
25552577
(void)status;
2578+
psa_key_location_t location =
2579+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
25562580

2557-
switch (PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime)) {
2581+
switch (location) {
25582582
case PSA_KEY_LOCATION_LOCAL_STORAGE:
25592583
/* Add cases for transparent drivers here */
25602584
#ifdef PSA_CRYPTO_DRIVER_IRONSIDE
@@ -2600,8 +2624,10 @@ psa_status_t psa_driver_wrapper_decapsulate(const psa_key_attributes_t *attribut
26002624
{
26012625
psa_status_t status;
26022626
(void)status;
2627+
psa_key_location_t location =
2628+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
26032629

2604-
switch (PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime)) {
2630+
switch (location) {
26052631
case PSA_KEY_LOCATION_LOCAL_STORAGE:
26062632
/* Add cases for transparent drivers here */
26072633
#ifdef PSA_CRYPTO_DRIVER_IRONSIDE
@@ -2646,7 +2672,10 @@ psa_status_t psa_driver_wrapper_pake_setup(psa_pake_operation_t *operation,
26462672
const psa_pake_cipher_suite_t *cipher_suite)
26472673
{
26482674
psa_status_t status;
2649-
switch (PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime)) {
2675+
psa_key_location_t location =
2676+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
2677+
2678+
switch (location) {
26502679
case PSA_KEY_LOCATION_LOCAL_STORAGE:
26512680
/* Add cases for transparent drivers here */
26522681
#ifdef PSA_CRYPTO_DRIVER_IRONSIDE
@@ -2919,8 +2948,8 @@ psa_status_t psa_driver_wrapper_asymmetric_encrypt(
29192948
size_t salt_length, uint8_t *output, size_t output_size, size_t *output_length)
29202949
{
29212950
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2922-
2923-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
2951+
psa_key_location_t location =
2952+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
29242953

29252954
switch (location) {
29262955
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -2976,8 +3005,8 @@ psa_status_t psa_driver_wrapper_asymmetric_decrypt(
29763005
size_t salt_length, uint8_t *output, size_t output_size, size_t *output_length)
29773006
{
29783007
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
2979-
2980-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
3008+
psa_key_location_t location =
3009+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
29813010

29823011
switch (location) {
29833012
case PSA_KEY_LOCATION_LOCAL_STORAGE:
@@ -3054,7 +3083,10 @@ psa_status_t psa_driver_wrapper_wrap_key(const psa_key_attributes_t *wrapping_ke
30543083
const uint8_t *key_data, size_t key_size, uint8_t *data,
30553084
size_t data_size, size_t *data_length)
30563085
{
3057-
switch (PSA_KEY_LIFETIME_GET_LOCATION(wrapping_key_attributes->lifetime)) {
3086+
psa_key_location_t location =
3087+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(wrapping_key_attributes));
3088+
3089+
switch (location) {
30583090
case PSA_KEY_LOCATION_LOCAL_STORAGE:
30593091
#if defined(PSA_NEED_CRACEN_KMU_DRIVER)
30603092
case PSA_KEY_LOCATION_CRACEN_KMU:
@@ -3097,7 +3129,11 @@ psa_status_t psa_driver_wrapper_unwrap_key(const psa_key_attributes_t *attribute
30973129
const uint8_t *data, size_t data_length, uint8_t *key,
30983130
size_t key_size, size_t *key_length)
30993131
{
3100-
switch (PSA_KEY_LIFETIME_GET_LOCATION(wrapping_key_attributes->lifetime)) {
3132+
3133+
psa_key_location_t location =
3134+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(wrapping_key_attributes));
3135+
3136+
switch (location) {
31013137
case PSA_KEY_LOCATION_LOCAL_STORAGE:
31023138
#if defined(PSA_NEED_CRACEN_KMU_DRIVER)
31033139
case PSA_KEY_LOCATION_CRACEN_KMU:
@@ -3216,7 +3252,8 @@ psa_status_t psa_driver_wrapper_get_entropy(uint32_t flags, size_t *estimate_bit
32163252

32173253
psa_status_t psa_driver_wrapper_destroy_builtin_key(const psa_key_attributes_t *attributes)
32183254
{
3219-
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(attributes->lifetime);
3255+
psa_key_location_t location =
3256+
PSA_KEY_LIFETIME_GET_LOCATION(psa_get_key_lifetime(attributes));
32203257

32213258
switch (location) {
32223259
#if defined(PSA_CRYPTO_DRIVER_IRONSIDE)

0 commit comments

Comments
 (0)