From 39f03fcf1a4d840b27f0cbf8389c2b70beb1c4f4 Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Tue, 20 Aug 2019 11:11:55 +0100 Subject: [PATCH] psa: Add PSA_KEY_ID_INIT A macro useful for initializing psa_key_id_t, whether MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER is set or not. Without this macro, it is necessary to know if MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER as with it the key ID is non-scalar and needs to be initialized with {0, 0}, and 0 otherwise when key ID is scalar. --- include/psa/crypto_platform.h | 1 + include/psa/crypto_struct.h | 2 +- include/psa/crypto_types.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/psa/crypto_platform.h b/include/psa/crypto_platform.h index 86af08f91b..572f40cd56 100644 --- a/include/psa/crypto_platform.h +++ b/include/psa/crypto_platform.h @@ -89,6 +89,7 @@ typedef struct * `psa_key_file_id_t` argument. As a workaround, make `psa_key_id_t` an * alias for `psa_key_file_id_t` when building for a multi-client service. */ typedef psa_key_file_id_t psa_key_id_t; +#define PSA_KEY_ID_INIT {0, 0} #else /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */ diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h index b1db42338c..5296202e95 100644 --- a/include/psa/crypto_struct.h +++ b/include/psa/crypto_struct.h @@ -379,7 +379,7 @@ typedef struct psa_key_attributes_flag_t flags; } psa_core_key_attributes_t; -#define PSA_CORE_KEY_ATTRIBUTES_INIT {0, 0, 0, PSA_KEY_POLICY_INIT, 0, 0} +#define PSA_CORE_KEY_ATTRIBUTES_INIT {0, 0, PSA_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0, 0} struct psa_key_attributes_s { diff --git a/include/psa/crypto_types.h b/include/psa/crypto_types.h index 9af4957df3..b79c3b5230 100644 --- a/include/psa/crypto_types.h +++ b/include/psa/crypto_types.h @@ -120,6 +120,7 @@ typedef uint32_t psa_key_lifetime_t; * psa_key_id_t in crypto_platform.h instead of here. */ #if !defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER) typedef uint32_t psa_key_id_t; +#define PSA_KEY_ID_INIT 0 #endif /**@}*/