Skip to content

Commit f0dbce1

Browse files
Declare a psa_key_file_id_t layout with an owner field
Declare the owner as psa_key_owner_id_t, of which an implementation must be provided separately. Make this a configuration option MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER, to make the conditional compilation flow easier to follow. Declare it in config.h to pacify check_names.sh. Support for a specific implementation of psa_key_owner_id_t in storage backends will come in a subsequent commit.
1 parent 2c1c33b commit f0dbce1

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

include/mbedtls/config.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,18 @@
11561156
*/
11571157
//#define MBEDTLS_PSA_HAS_ITS_IO
11581158

1159+
/** \def MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER
1160+
*
1161+
* In PSA key storage, encode the owner of the key.
1162+
*
1163+
* This is only meaningful when building the library as part of a
1164+
* multi-client service. When you activate this option, you must provide
1165+
* an implementation of the type psa_key_owner_id_t and a translation
1166+
* from psa_key_file_id_t to file name in all the storage backends that
1167+
* you wish to support.
1168+
*/
1169+
//#define MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER
1170+
11591171
/**
11601172
* \def MBEDTLS_MEMORY_DEBUG
11611173
*

include/psa/crypto_platform.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,28 @@ typedef uint16_t psa_key_handle_t;
6868
* #psa_key_id_t. */
6969
typedef uint32_t psa_app_key_id_t;
7070

71+
#if defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER)
72+
73+
typedef struct
74+
{
75+
uint32_t key_id;
76+
psa_key_owner_id_t owner;
77+
} psa_key_file_id_t;
78+
#define PSA_KEY_FILE_GET_KEY_ID( file_id ) ( ( file_id ).key_id )
79+
80+
/* Since crypto.h is used as part of the PSA Cryptography API specification,
81+
* it must use standard types for things like the argument of psa_open_key().
82+
* If it wasn't for that constraint, psa_open_key() would take a
83+
* `psa_key_file_id_t` argument. As a workaround, make `psa_key_id_t` an
84+
* alias for `psa_key_file_id_t` when building for a multi-client service. */
85+
typedef psa_key_file_id_t psa_key_id_t;
86+
87+
#else /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
88+
7189
/* By default, a key file identifier is just the application key identifier. */
7290
typedef psa_app_key_id_t psa_key_file_id_t;
7391
#define PSA_KEY_FILE_GET_KEY_ID( id ) ( id )
7492

93+
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
94+
7595
#endif /* PSA_CRYPTO_PLATFORM_H */

include/psa/crypto_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ typedef uint32_t psa_key_lifetime_t;
9090

9191
/** Encoding of identifiers of persistent keys.
9292
*/
93+
/* Implementation-specific quirk: The Mbed Crypto library can be built as
94+
* part of a multi-client service that exposes the PSA Crypto API in each
95+
* client and encodes the client identity in the key id argument of functions
96+
* such as psa_open_key(). In this build configuration, we define
97+
* psa_key_id_t in crypto_platform.h instead of here. */
98+
#if !defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER)
9399
typedef uint32_t psa_key_id_t;
100+
#endif
94101

95102
/**@}*/
96103

scripts/config.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
MBEDTLS_NO_64BIT_MULTIPLICATION
101101
MBEDTLS_PSA_CRYPTO_SPM
102102
MBEDTLS_PSA_HAS_ITS_IO
103+
MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER
103104
MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C
104105
MBEDTLS_USE_PSA_CRYPTO
105106
_ALT\s*$

0 commit comments

Comments
 (0)