Skip to content

Commit eda4ffd

Browse files
PSA crypto service: encode the key owner (ITS backend only)
When building for the PSA crypto service (defined(PSA_CRYPTO_SECURE)), define psa_key_owner_id_t as int32_t, which is how a PSA platform encodes partition identity. Note that this only takes effect when the build option MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER is active. Support this configuration in the ITS backend.
1 parent b61309a commit eda4ffd

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

include/psa/crypto_platform.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ typedef uint32_t psa_app_key_id_t;
7070

7171
#if defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER)
7272

73+
#if defined(PSA_CRYPTO_SECURE)
74+
/* Building for the PSA Crypto service on a PSA platform. */
75+
/* A key owner is a PSA partition identifier. */
76+
typedef int32_t psa_key_owner_id_t;
77+
#endif
78+
7379
typedef struct
7480
{
7581
uint32_t key_id;

library/psa_crypto_storage_its.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,28 @@
3636
#include "mbedtls/platform.h"
3737
#endif
3838

39-
static psa_storage_uid_t psa_its_identifier_of_slot( psa_key_file_id_t key )
39+
/* Determine a file name (ITS file identifier) for the given key file
40+
* identifier. The file name must be distinct from any file that is used
41+
* for a purpose other than storing a key. Currently, the only such file
42+
* is the random seed file whose name is PSA_CRYPTO_ITS_RANDOM_SEED_UID
43+
* and whose value is 0xFFFFFF52. */
44+
static psa_storage_uid_t psa_its_identifier_of_slot( psa_key_file_id_t file_id )
4045
{
41-
return( key );
46+
#if defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER) && \
47+
defined(PSA_CRYPTO_SECURE)
48+
/* Encode the owner in the upper 32 bits. This means that if
49+
* owner values are nonzero (as they are on a PSA platform),
50+
* no key file will ever have a value less than 0x100000000, so
51+
* the whole range 0..0xffffffff is available for non-key files. */
52+
uint32_t unsigned_owner = (uint32_t) file_id.owner;
53+
return( (uint64_t) unsigned_owner << 32 | file_id.key_id );
54+
#else
55+
/* Use the key id directly as a file name.
56+
* psa_is_key_file_id_valid() in psa_crypto_slot_management.c
57+
* is responsible for ensuring that key identifiers do not have a
58+
* value that is reserved for non-key files. */
59+
return( file_id );
60+
#endif
4261
}
4362

4463
psa_status_t psa_crypto_storage_load( const psa_key_file_id_t key, uint8_t *data,

0 commit comments

Comments
 (0)