Skip to content

Commit 89419b3

Browse files
mswarowskynordicjm
authored andcommitted
[nrf noup] Constant size for psa_core_key_attributes_t struct
-There is an inconsistency between PSA Crypto API specification in Mbed TLS and in the interface exposed by TF-M for key representation where an additional type has been added to hold information about owner. This functionality is controlled by setting the configuration MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER which configures the type Mbed TLS internal type mbedtls_svc_key_id_t to a structure type of two words and not as a single word compatible with the PSA Crypto API type psk_key_id_t. This commit adds a reserved word in psa_core_key_attributes_t after the instance of mbedtls_svc_key_id_t to ensure that this structure is binary compatible with PSA Crypto drivers that are built with MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER. This is a [noup] commit as this problem for our pre-built PSA crypto drivers which is required to be compiled with the configuration MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER enabled to ensure support with and without TF-M using the same library. ref: NCSDK-17464 Signed-off-by: Markus Swarowsky <markus.swarowsky@nordicsemi.no> Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
1 parent 127985b commit 89419b3

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

include/psa/crypto_struct.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,20 +319,44 @@ typedef uint16_t psa_key_attributes_flag_t;
319319
#define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \
320320
0 )
321321

322+
/* Only used when the key id doesn't encode the owners id, to fill the reserved
323+
* field in psa_core_key_attributes_t
324+
*/
325+
#define MBEDTLS_KEY_ATTRIBUTE_RESERVED_INIT (int32_t) 0
326+
322327
typedef struct
323328
{
324329
psa_key_type_t MBEDTLS_PRIVATE(type);
325330
psa_key_bits_t MBEDTLS_PRIVATE(bits);
326331
psa_key_lifetime_t MBEDTLS_PRIVATE(lifetime);
327332
mbedtls_svc_key_id_t MBEDTLS_PRIVATE(id);
333+
/* This ensures that size of struct doesn't change size depending on setting
334+
* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
335+
*/
336+
#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
337+
int32_t MBEDTLS_PRIVATE(reserved);
338+
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
328339
psa_key_policy_t MBEDTLS_PRIVATE(policy);
329340
psa_key_attributes_flag_t MBEDTLS_PRIVATE(flags);
330341
} psa_core_key_attributes_t;
331342

343+
/*
344+
* Changing MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER changes the size
345+
* of psa_core_key_attributes_t, which can lead to incompatibilties.
346+
* This provides a compatible version of initialisation.
347+
*/
348+
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
332349
#define PSA_CORE_KEY_ATTRIBUTES_INIT { PSA_KEY_TYPE_NONE, 0, \
333350
PSA_KEY_LIFETIME_VOLATILE, \
334351
MBEDTLS_SVC_KEY_ID_INIT, \
335352
PSA_KEY_POLICY_INIT, 0 }
353+
#else
354+
#define PSA_CORE_KEY_ATTRIBUTES_INIT { PSA_KEY_TYPE_NONE, 0, \
355+
PSA_KEY_LIFETIME_VOLATILE, \
356+
MBEDTLS_SVC_KEY_ID_INIT, \
357+
MBEDTLS_KEY_ATTRIBUTE_RESERVED_INIT, \
358+
PSA_KEY_POLICY_INIT, 0 }
359+
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
336360

337361
struct psa_key_attributes_s
338362
{

0 commit comments

Comments
 (0)