1*62c56f98SSadaf EbrahimiMbed TLS storage specification 2*62c56f98SSadaf Ebrahimi================================= 3*62c56f98SSadaf Ebrahimi 4*62c56f98SSadaf EbrahimiThis document specifies how Mbed TLS uses storage. 5*62c56f98SSadaf EbrahimiKey storage was originally introduced in a product called Mbed Crypto, which was re-distributed via Mbed TLS and has since been merged into Mbed TLS. 6*62c56f98SSadaf EbrahimiThis document contains historical information both from before and after this merge. 7*62c56f98SSadaf Ebrahimi 8*62c56f98SSadaf EbrahimiMbed Crypto may be upgraded on an existing device with the storage preserved. Therefore: 9*62c56f98SSadaf Ebrahimi 10*62c56f98SSadaf Ebrahimi1. Any change may break existing installations and may require an upgrade path. 11*62c56f98SSadaf Ebrahimi1. This document retains historical information about all past released versions. Do not remove information from this document unless it has always been incorrect or it is about a version that you are sure was never released. 12*62c56f98SSadaf Ebrahimi 13*62c56f98SSadaf EbrahimiMbed Crypto 0.1.0 14*62c56f98SSadaf Ebrahimi----------------- 15*62c56f98SSadaf Ebrahimi 16*62c56f98SSadaf EbrahimiTags: mbedcrypto-0.1.0b, mbedcrypto-0.1.0b2 17*62c56f98SSadaf Ebrahimi 18*62c56f98SSadaf EbrahimiReleased in November 2018. <br> 19*62c56f98SSadaf EbrahimiIntegrated in Mbed OS 5.11. 20*62c56f98SSadaf Ebrahimi 21*62c56f98SSadaf EbrahimiSupported backends: 22*62c56f98SSadaf Ebrahimi 23*62c56f98SSadaf Ebrahimi* [PSA ITS](#file-namespace-on-its-for-0.1.0) 24*62c56f98SSadaf Ebrahimi* [C stdio](#file-namespace-on-stdio-for-0.1.0) 25*62c56f98SSadaf Ebrahimi 26*62c56f98SSadaf EbrahimiSupported features: 27*62c56f98SSadaf Ebrahimi 28*62c56f98SSadaf Ebrahimi* [Persistent transparent keys](#key-file-format-for-0.1.0) designated by a [slot number](#key-names-for-0.1.0). 29*62c56f98SSadaf Ebrahimi* [Nonvolatile random seed](#nonvolatile-random-seed-file-format-for-0.1.0) on ITS only. 30*62c56f98SSadaf Ebrahimi 31*62c56f98SSadaf EbrahimiThis is a beta release, and we do not promise backward compatibility, with one exception: 32*62c56f98SSadaf Ebrahimi 33*62c56f98SSadaf Ebrahimi> On Mbed OS, if a device has a nonvolatile random seed file produced with Mbed OS 5.11.x and is upgraded to a later version of Mbed OS, the nonvolatile random seed file is preserved or upgraded. 34*62c56f98SSadaf Ebrahimi 35*62c56f98SSadaf EbrahimiWe do not make any promises regarding key storage, or regarding the nonvolatile random seed file on other platforms. 36*62c56f98SSadaf Ebrahimi 37*62c56f98SSadaf Ebrahimi### Key names for 0.1.0 38*62c56f98SSadaf Ebrahimi 39*62c56f98SSadaf EbrahimiInformation about each key is stored in a dedicated file whose name is constructed from the key identifier. The way in which the file name is constructed depends on the storage backend. The content of the file is described [below](#key-file-format-for-0.1.0). 40*62c56f98SSadaf Ebrahimi 41*62c56f98SSadaf EbrahimiThe valid values for a key identifier are the range from 1 to 0xfffeffff. This limitation on the range is not documented in user-facing documentation: according to the user-facing documentation, arbitrary 32-bit values are valid. 42*62c56f98SSadaf Ebrahimi 43*62c56f98SSadaf EbrahimiThe code uses the following constant in an internal header (note that despite the name, this value is actually one plus the maximum permitted value): 44*62c56f98SSadaf Ebrahimi 45*62c56f98SSadaf Ebrahimi #define PSA_MAX_PERSISTENT_KEY_IDENTIFIER 0xffff0000 46*62c56f98SSadaf Ebrahimi 47*62c56f98SSadaf EbrahimiThere is a shared namespace for all callers. 48*62c56f98SSadaf Ebrahimi 49*62c56f98SSadaf Ebrahimi### Key file format for 0.1.0 50*62c56f98SSadaf Ebrahimi 51*62c56f98SSadaf EbrahimiAll integers are encoded in little-endian order in 8-bit bytes. 52*62c56f98SSadaf Ebrahimi 53*62c56f98SSadaf EbrahimiThe layout of a key file is: 54*62c56f98SSadaf Ebrahimi 55*62c56f98SSadaf Ebrahimi* magic (8 bytes): `"PSA\0KEY\0"` 56*62c56f98SSadaf Ebrahimi* version (4 bytes): 0 57*62c56f98SSadaf Ebrahimi* type (4 bytes): `psa_key_type_t` value 58*62c56f98SSadaf Ebrahimi* policy usage flags (4 bytes): `psa_key_usage_t` value 59*62c56f98SSadaf Ebrahimi* policy usage algorithm (4 bytes): `psa_algorithm_t` value 60*62c56f98SSadaf Ebrahimi* key material length (4 bytes) 61*62c56f98SSadaf Ebrahimi* key material: output of `psa_export_key` 62*62c56f98SSadaf Ebrahimi* Any trailing data is rejected on load. 63*62c56f98SSadaf Ebrahimi 64*62c56f98SSadaf Ebrahimi### Nonvolatile random seed file format for 0.1.0 65*62c56f98SSadaf Ebrahimi 66*62c56f98SSadaf EbrahimiThe nonvolatile random seed file contains a seed for the random generator. If present, it is rewritten at each boot as part of the random generator initialization. 67*62c56f98SSadaf Ebrahimi 68*62c56f98SSadaf EbrahimiThe file format is just the seed as a byte string with no metadata or encoding of any kind. 69*62c56f98SSadaf Ebrahimi 70*62c56f98SSadaf Ebrahimi### File namespace on ITS for 0.1.0 71*62c56f98SSadaf Ebrahimi 72*62c56f98SSadaf EbrahimiAssumption: ITS provides a 32-bit file identifier namespace. The Crypto service can use arbitrary file identifiers and no other part of the system accesses the same file identifier namespace. 73*62c56f98SSadaf Ebrahimi 74*62c56f98SSadaf Ebrahimi* File 0: unused. 75*62c56f98SSadaf Ebrahimi* Files 1 through 0xfffeffff: [content](#key-file-format-for-0.1.0) of the [key whose identifier is the file identifier](#key-names-for-0.1.0). 76*62c56f98SSadaf Ebrahimi* File 0xffffff52 (`PSA_CRYPTO_ITS_RANDOM_SEED_UID`): [nonvolatile random seed](#nonvolatile-random-seed-file-format-for-0.1.0). 77*62c56f98SSadaf Ebrahimi* Files 0xffff0000 through 0xffffff51, 0xffffff53 through 0xffffffff: unused. 78*62c56f98SSadaf Ebrahimi 79*62c56f98SSadaf Ebrahimi### File namespace on stdio for 0.1.0 80*62c56f98SSadaf Ebrahimi 81*62c56f98SSadaf EbrahimiAssumption: C stdio, allowing names containing lowercase letters, digits and underscores, of length up to 23. 82*62c56f98SSadaf Ebrahimi 83*62c56f98SSadaf EbrahimiAn undocumented build-time configuration value `CRYPTO_STORAGE_FILE_LOCATION` allows storing the key files in a directory other than the current directory. This value is simply prepended to the file name (so it must end with a directory separator to put the keys in a different directory). 84*62c56f98SSadaf Ebrahimi 85*62c56f98SSadaf Ebrahimi* `CRYPTO_STORAGE_FILE_LOCATION "psa_key_slot_0"`: used as a temporary file. Must be writable. May be overwritten or deleted if present. 86*62c56f98SSadaf Ebrahimi* `sprintf(CRYPTO_STORAGE_FILE_LOCATION "psa_key_slot_%lu", key_id)` [content](#key-file-format-for-0.1.0) of the [key whose identifier](#key-names-for-0.1.0) is `key_id`. 87*62c56f98SSadaf Ebrahimi* Other files: unused. 88*62c56f98SSadaf Ebrahimi 89*62c56f98SSadaf EbrahimiMbed Crypto 1.0.0 90*62c56f98SSadaf Ebrahimi----------------- 91*62c56f98SSadaf Ebrahimi 92*62c56f98SSadaf EbrahimiTags: mbedcrypto-1.0.0d4, mbedcrypto-1.0.0 93*62c56f98SSadaf Ebrahimi 94*62c56f98SSadaf EbrahimiReleased in February 2019. <br> 95*62c56f98SSadaf EbrahimiIntegrated in Mbed OS 5.12. 96*62c56f98SSadaf Ebrahimi 97*62c56f98SSadaf EbrahimiSupported integrations: 98*62c56f98SSadaf Ebrahimi 99*62c56f98SSadaf Ebrahimi* [PSA platform](#file-namespace-on-a-psa-platform-for-1.0.0) 100*62c56f98SSadaf Ebrahimi* [library using PSA ITS](#file-namespace-on-its-as-a-library-for-1.0.0) 101*62c56f98SSadaf Ebrahimi* [library using C stdio](#file-namespace-on-stdio-for-1.0.0) 102*62c56f98SSadaf Ebrahimi 103*62c56f98SSadaf EbrahimiSupported features: 104*62c56f98SSadaf Ebrahimi 105*62c56f98SSadaf Ebrahimi* [Persistent transparent keys](#key-file-format-for-1.0.0) designated by a [key identifier and owner](#key-names-for-1.0.0). 106*62c56f98SSadaf Ebrahimi* [Nonvolatile random seed](#nonvolatile-random-seed-file-format-for-1.0.0) on ITS only. 107*62c56f98SSadaf Ebrahimi 108*62c56f98SSadaf EbrahimiBackward compatibility commitments: TBD 109*62c56f98SSadaf Ebrahimi 110*62c56f98SSadaf Ebrahimi### Key names for 1.0.0 111*62c56f98SSadaf Ebrahimi 112*62c56f98SSadaf EbrahimiInformation about each key is stored in a dedicated file designated by the key identifier. In integrations where there is no concept of key owner (in particular, in library integrations), the key identifier is exactly the key identifier as defined in the PSA Cryptography API specification (`psa_key_id_t`). In integrations where there is a concept of key owner (integration into a service for example), the key identifier is made of an owner identifier (its semantics and type are integration specific) and of the key identifier (`psa_key_id_t`) from the key owner point of view. 113*62c56f98SSadaf Ebrahimi 114*62c56f98SSadaf EbrahimiThe way in which the file name is constructed from the key identifier depends on the storage backend. The content of the file is described [below](#key-file-format-for-1.0.0). 115*62c56f98SSadaf Ebrahimi 116*62c56f98SSadaf Ebrahimi* Library integration: the key file name is just the key identifier as defined in the PSA crypto specification. This is a 32-bit value. 117*62c56f98SSadaf Ebrahimi* PSA service integration: the key file name is `(uint64_t)owner_uid << 32 | key_id` where `key_id` is the key identifier from the owner point of view and `owner_uid` (of type `int32_t`) is the calling partition identifier provided to the server by the partition manager. This is a 64-bit value. 118*62c56f98SSadaf Ebrahimi 119*62c56f98SSadaf Ebrahimi### Key file format for 1.0.0 120*62c56f98SSadaf Ebrahimi 121*62c56f98SSadaf EbrahimiThe layout is identical to [0.1.0](#key-file-format-for-0.1.0) so far. However note that the encoding of key types, algorithms and key material has changed, therefore the storage format is not compatible (despite using the same value in the version field so far). 122*62c56f98SSadaf Ebrahimi 123*62c56f98SSadaf Ebrahimi### Nonvolatile random seed file format for 1.0.0 124*62c56f98SSadaf Ebrahimi 125*62c56f98SSadaf EbrahimiThe nonvolatile random seed file contains a seed for the random generator. If present, it is rewritten at each boot as part of the random generator initialization. 126*62c56f98SSadaf Ebrahimi 127*62c56f98SSadaf EbrahimiThe file format is just the seed as a byte string with no metadata or encoding of any kind. 128*62c56f98SSadaf Ebrahimi 129*62c56f98SSadaf EbrahimiThis is unchanged since [the feature was introduced in Mbed Crypto 0.1.0](#nonvolatile-random-seed-file-format-for-0.1.0). 130*62c56f98SSadaf Ebrahimi 131*62c56f98SSadaf Ebrahimi### File namespace on a PSA platform for 1.0.0 132*62c56f98SSadaf Ebrahimi 133*62c56f98SSadaf EbrahimiAssumption: ITS provides a 64-bit file identifier namespace. The Crypto service can use arbitrary file identifiers and no other part of the system accesses the same file identifier namespace. 134*62c56f98SSadaf Ebrahimi 135*62c56f98SSadaf EbrahimiAssumption: the owner identifier is a nonzero value of type `int32_t`. 136*62c56f98SSadaf Ebrahimi 137*62c56f98SSadaf Ebrahimi* Files 0 through 0xffffff51, 0xffffff53 through 0xffffffff: unused, reserved for internal use of the crypto library or crypto service. 138*62c56f98SSadaf Ebrahimi* File 0xffffff52 (`PSA_CRYPTO_ITS_RANDOM_SEED_UID`): [nonvolatile random seed](#nonvolatile-random-seed-file-format-for-0.1.0). 139*62c56f98SSadaf Ebrahimi* Files 0x100000000 through 0xffffffffffff: [content](#key-file-format-for-1.0.0) of the [key whose identifier is the file identifier](#key-names-for-1.0.0). The upper 32 bits determine the owner. 140*62c56f98SSadaf Ebrahimi 141*62c56f98SSadaf Ebrahimi### File namespace on ITS as a library for 1.0.0 142*62c56f98SSadaf Ebrahimi 143*62c56f98SSadaf EbrahimiAssumption: ITS provides a 64-bit file identifier namespace. The entity using the crypto library can use arbitrary file identifiers and no other part of the system accesses the same file identifier namespace. 144*62c56f98SSadaf Ebrahimi 145*62c56f98SSadaf EbrahimiThis is a library integration, so there is no owner. The key file identifier is identical to the key identifier. 146*62c56f98SSadaf Ebrahimi 147*62c56f98SSadaf Ebrahimi* File 0: unused. 148*62c56f98SSadaf Ebrahimi* Files 1 through 0xfffeffff: [content](#key-file-format-for-1.0.0) of the [key whose identifier is the file identifier](#key-names-for-1.0.0). 149*62c56f98SSadaf Ebrahimi* File 0xffffff52 (`PSA_CRYPTO_ITS_RANDOM_SEED_UID`): [nonvolatile random seed](#nonvolatile-random-seed-file-format-for-1.0.0). 150*62c56f98SSadaf Ebrahimi* Files 0xffff0000 through 0xffffff51, 0xffffff53 through 0xffffffff, 0x100000000 through 0xffffffffffffffff: unused. 151*62c56f98SSadaf Ebrahimi 152*62c56f98SSadaf Ebrahimi### File namespace on stdio for 1.0.0 153*62c56f98SSadaf Ebrahimi 154*62c56f98SSadaf EbrahimiThis is a library integration, so there is no owner. The key file identifier is identical to the key identifier. 155*62c56f98SSadaf Ebrahimi 156*62c56f98SSadaf Ebrahimi[Identical to 0.1.0](#file-namespace-on-stdio-for-0.1.0). 157*62c56f98SSadaf Ebrahimi 158*62c56f98SSadaf Ebrahimi### Upgrade from 0.1.0 to 1.0.0. 159*62c56f98SSadaf Ebrahimi 160*62c56f98SSadaf Ebrahimi* Delete files 1 through 0xfffeffff, which contain keys in a format that is no longer supported. 161*62c56f98SSadaf Ebrahimi 162*62c56f98SSadaf Ebrahimi### Suggested changes to make before 1.0.0 163*62c56f98SSadaf Ebrahimi 164*62c56f98SSadaf EbrahimiThe library integration and the PSA platform integration use different sets of file names. This is annoyingly non-uniform. For example, if we want to store non-key files, we have room in different ranges (0 through 0xffffffff on a PSA platform, 0xffff0000 through 0xffffffffffffffff in a library integration). 165*62c56f98SSadaf Ebrahimi 166*62c56f98SSadaf EbrahimiIt would simplify things to always have a 32-bit owner, with a nonzero value, and thus reserve the range 0–0xffffffff for internal library use. 167*62c56f98SSadaf Ebrahimi 168*62c56f98SSadaf EbrahimiMbed Crypto 1.1.0 169*62c56f98SSadaf Ebrahimi----------------- 170*62c56f98SSadaf Ebrahimi 171*62c56f98SSadaf EbrahimiTags: mbedcrypto-1.1.0 172*62c56f98SSadaf Ebrahimi 173*62c56f98SSadaf EbrahimiReleased in early June 2019. <br> 174*62c56f98SSadaf EbrahimiIntegrated in Mbed OS 5.13. 175*62c56f98SSadaf Ebrahimi 176*62c56f98SSadaf EbrahimiChanges since [1.0.0](#mbed-crypto-1.0.0): 177*62c56f98SSadaf Ebrahimi 178*62c56f98SSadaf Ebrahimi* The stdio backend for storage has been replaced by an implementation of [PSA ITS over stdio](#file-namespace-on-stdio-for-1.1.0). 179*62c56f98SSadaf Ebrahimi* [Some changes in the key file format](#key-file-format-for-1.1.0). 180*62c56f98SSadaf Ebrahimi 181*62c56f98SSadaf Ebrahimi### File namespace on stdio for 1.1.0 182*62c56f98SSadaf Ebrahimi 183*62c56f98SSadaf EbrahimiAssumption: C stdio, allowing names containing lowercase letters, digits and underscores, of length up to 23. 184*62c56f98SSadaf Ebrahimi 185*62c56f98SSadaf EbrahimiAn undocumented build-time configuration value `PSA_ITS_STORAGE_PREFIX` allows storing the key files in a directory other than the current directory. This value is simply prepended to the file name (so it must end with a directory separator to put the keys in a different directory). 186*62c56f98SSadaf Ebrahimi 187*62c56f98SSadaf Ebrahimi* `PSA_ITS_STORAGE_PREFIX "tempfile.psa_its"`: used as a temporary file. Must be writable. May be overwritten or deleted if present. 188*62c56f98SSadaf Ebrahimi* `sprintf(PSA_ITS_STORAGE_PREFIX "%016llx.psa_its", key_id)`: a key or non-key file. The `key_id` in the name is the 64-bit file identifier, which is the [key identifier](#key-names-for-mbed-tls-2.25.0) for a key file or some reserved identifier for a non-key file (currently: only the [nonvolatile random seed](#nonvolatile-random-seed-file-format-for-1.0.0)). The contents of the file are: 189*62c56f98SSadaf Ebrahimi * Magic header (8 bytes): `"PSA\0ITS\0"` 190*62c56f98SSadaf Ebrahimi * File contents. 191*62c56f98SSadaf Ebrahimi 192*62c56f98SSadaf Ebrahimi### Key file format for 1.1.0 193*62c56f98SSadaf Ebrahimi 194*62c56f98SSadaf EbrahimiThe key file format is identical to [1.0.0](#key-file-format-for-1.0.0), except for the following changes: 195*62c56f98SSadaf Ebrahimi 196*62c56f98SSadaf Ebrahimi* A new policy field, marked as [NEW:1.1.0] below. 197*62c56f98SSadaf Ebrahimi* The encoding of key types, algorithms and key material has changed, therefore the storage format is not compatible (despite using the same value in the version field so far). 198*62c56f98SSadaf Ebrahimi 199*62c56f98SSadaf EbrahimiA self-contained description of the file layout follows. 200*62c56f98SSadaf Ebrahimi 201*62c56f98SSadaf EbrahimiAll integers are encoded in little-endian order in 8-bit bytes. 202*62c56f98SSadaf Ebrahimi 203*62c56f98SSadaf EbrahimiThe layout of a key file is: 204*62c56f98SSadaf Ebrahimi 205*62c56f98SSadaf Ebrahimi* magic (8 bytes): `"PSA\0KEY\0"` 206*62c56f98SSadaf Ebrahimi* version (4 bytes): 0 207*62c56f98SSadaf Ebrahimi* type (4 bytes): `psa_key_type_t` value 208*62c56f98SSadaf Ebrahimi* policy usage flags (4 bytes): `psa_key_usage_t` value 209*62c56f98SSadaf Ebrahimi* policy usage algorithm (4 bytes): `psa_algorithm_t` value 210*62c56f98SSadaf Ebrahimi* policy enrollment algorithm (4 bytes): `psa_algorithm_t` value [NEW:1.1.0] 211*62c56f98SSadaf Ebrahimi* key material length (4 bytes) 212*62c56f98SSadaf Ebrahimi* key material: output of `psa_export_key` 213*62c56f98SSadaf Ebrahimi* Any trailing data is rejected on load. 214*62c56f98SSadaf Ebrahimi 215*62c56f98SSadaf EbrahimiMbed Crypto TBD 216*62c56f98SSadaf Ebrahimi--------------- 217*62c56f98SSadaf Ebrahimi 218*62c56f98SSadaf EbrahimiTags: TBD 219*62c56f98SSadaf Ebrahimi 220*62c56f98SSadaf EbrahimiReleased in TBD 2019. <br> 221*62c56f98SSadaf EbrahimiIntegrated in Mbed OS TBD. 222*62c56f98SSadaf Ebrahimi 223*62c56f98SSadaf Ebrahimi### Changes introduced in TBD 224*62c56f98SSadaf Ebrahimi 225*62c56f98SSadaf Ebrahimi* The layout of a key file now has a lifetime field before the type field. 226*62c56f98SSadaf Ebrahimi* Key files can store references to keys in a secure element. In such key files, the key material contains the slot number. 227*62c56f98SSadaf Ebrahimi 228*62c56f98SSadaf Ebrahimi### File namespace on a PSA platform on TBD 229*62c56f98SSadaf Ebrahimi 230*62c56f98SSadaf EbrahimiAssumption: ITS provides a 64-bit file identifier namespace. The Crypto service can use arbitrary file identifiers and no other part of the system accesses the same file identifier namespace. 231*62c56f98SSadaf Ebrahimi 232*62c56f98SSadaf EbrahimiAssumption: the owner identifier is a nonzero value of type `int32_t`. 233*62c56f98SSadaf Ebrahimi 234*62c56f98SSadaf Ebrahimi* Files 0 through 0xfffeffff: unused. 235*62c56f98SSadaf Ebrahimi* Files 0xffff0000 through 0xffffffff: reserved for internal use of the crypto library or crypto service. See [non-key files](#non-key-files-on-tbd). 236*62c56f98SSadaf Ebrahimi* Files 0x100000000 through 0xffffffffffff: [content](#key-file-format-for-1.0.0) of the [key whose identifier is the file identifier](#key-names-for-1.0.0). The upper 32 bits determine the owner. 237*62c56f98SSadaf Ebrahimi 238*62c56f98SSadaf Ebrahimi### File namespace on ITS as a library on TBD 239*62c56f98SSadaf Ebrahimi 240*62c56f98SSadaf EbrahimiAssumption: ITS provides a 64-bit file identifier namespace. The entity using the crypto library can use arbitrary file identifiers and no other part of the system accesses the same file identifier namespace. 241*62c56f98SSadaf Ebrahimi 242*62c56f98SSadaf EbrahimiThis is a library integration, so there is no owner. The key file identifier is identical to the key identifier. 243*62c56f98SSadaf Ebrahimi 244*62c56f98SSadaf Ebrahimi* File 0: unused. 245*62c56f98SSadaf Ebrahimi* Files 1 through 0xfffeffff: [content](#key-file-format-for-1.0.0) of the [key whose identifier is the file identifier](#key-names-for-1.0.0). 246*62c56f98SSadaf Ebrahimi* Files 0xffff0000 through 0xffffffff: reserved for internal use of the crypto library or crypto service. See [non-key files](#non-key-files-on-tbd). 247*62c56f98SSadaf Ebrahimi* Files 0x100000000 through 0xffffffffffffffff: unused. 248*62c56f98SSadaf Ebrahimi 249*62c56f98SSadaf Ebrahimi### Non-key files on TBD 250*62c56f98SSadaf Ebrahimi 251*62c56f98SSadaf EbrahimiFile identifiers in the range 0xffff0000 through 0xffffffff are reserved for internal use in Mbed Crypto. 252*62c56f98SSadaf Ebrahimi 253*62c56f98SSadaf Ebrahimi* Files 0xfffffe02 through 0xfffffeff (`PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + lifetime`): secure element driver storage. The content of the file is the secure element driver's persistent data. 254*62c56f98SSadaf Ebrahimi* File 0xffffff52 (`PSA_CRYPTO_ITS_RANDOM_SEED_UID`): [nonvolatile random seed](#nonvolatile-random-seed-file-format-for-1.0.0). 255*62c56f98SSadaf Ebrahimi* File 0xffffff54 (`PSA_CRYPTO_ITS_TRANSACTION_UID`): [transaction file](#transaction-file-format-for-tbd). 256*62c56f98SSadaf Ebrahimi* Other files are unused and reserved for future use. 257*62c56f98SSadaf Ebrahimi 258*62c56f98SSadaf Ebrahimi### Key file format for TBD 259*62c56f98SSadaf Ebrahimi 260*62c56f98SSadaf EbrahimiAll integers are encoded in little-endian order in 8-bit bytes except where otherwise indicated. 261*62c56f98SSadaf Ebrahimi 262*62c56f98SSadaf EbrahimiThe layout of a key file is: 263*62c56f98SSadaf Ebrahimi 264*62c56f98SSadaf Ebrahimi* magic (8 bytes): `"PSA\0KEY\0"`. 265*62c56f98SSadaf Ebrahimi* version (4 bytes): 0. 266*62c56f98SSadaf Ebrahimi* lifetime (4 bytes): `psa_key_lifetime_t` value. 267*62c56f98SSadaf Ebrahimi* type (4 bytes): `psa_key_type_t` value. 268*62c56f98SSadaf Ebrahimi* policy usage flags (4 bytes): `psa_key_usage_t` value. 269*62c56f98SSadaf Ebrahimi* policy usage algorithm (4 bytes): `psa_algorithm_t` value. 270*62c56f98SSadaf Ebrahimi* policy enrollment algorithm (4 bytes): `psa_algorithm_t` value. 271*62c56f98SSadaf Ebrahimi* key material length (4 bytes). 272*62c56f98SSadaf Ebrahimi* key material: 273*62c56f98SSadaf Ebrahimi * For a transparent key: output of `psa_export_key`. 274*62c56f98SSadaf Ebrahimi * For an opaque key (unified driver interface): driver-specific opaque key blob. 275*62c56f98SSadaf Ebrahimi * For an opaque key (key in a secure element): slot number (8 bytes), in platform endianness. 276*62c56f98SSadaf Ebrahimi* Any trailing data is rejected on load. 277*62c56f98SSadaf Ebrahimi 278*62c56f98SSadaf Ebrahimi### Transaction file format for TBD 279*62c56f98SSadaf Ebrahimi 280*62c56f98SSadaf EbrahimiThe transaction file contains data about an ongoing action that cannot be completed atomically. It exists only if there is an ongoing transaction. 281*62c56f98SSadaf Ebrahimi 282*62c56f98SSadaf EbrahimiAll integers are encoded in platform endianness. 283*62c56f98SSadaf Ebrahimi 284*62c56f98SSadaf EbrahimiAll currently existing transactions concern a key in a secure element. 285*62c56f98SSadaf Ebrahimi 286*62c56f98SSadaf EbrahimiThe layout of a transaction file is: 287*62c56f98SSadaf Ebrahimi 288*62c56f98SSadaf Ebrahimi* type (2 bytes): the [transaction type](#transaction-types-on-tbd). 289*62c56f98SSadaf Ebrahimi* unused (2 bytes) 290*62c56f98SSadaf Ebrahimi* lifetime (4 bytes): `psa_key_lifetime_t` value that corresponds to a key in a secure element. 291*62c56f98SSadaf Ebrahimi* slot number (8 bytes): `psa_key_slot_number_t` value. This is the unique designation of the key for the secure element driver. 292*62c56f98SSadaf Ebrahimi* key identifier (4 bytes in a library integration, 8 bytes on a PSA platform): the internal representation of the key identifier. On a PSA platform, this encodes the key owner in the same way as [in file identifiers for key files](#file-namespace-on-a-psa-platform-on-tbd)). 293*62c56f98SSadaf Ebrahimi 294*62c56f98SSadaf Ebrahimi#### Transaction types on TBD 295*62c56f98SSadaf Ebrahimi 296*62c56f98SSadaf Ebrahimi* 0x0001: key creation. The following locations may or may not contain data about the key that is being created: 297*62c56f98SSadaf Ebrahimi * The slot in the secure element designated by the slot number. 298*62c56f98SSadaf Ebrahimi * The file containing the key metadata designated by the key identifier. 299*62c56f98SSadaf Ebrahimi * The driver persistent data. 300*62c56f98SSadaf Ebrahimi* 0x0002: key destruction. The following locations may or may not still contain data about the key that is being destroyed: 301*62c56f98SSadaf Ebrahimi * The slot in the secure element designated by the slot number. 302*62c56f98SSadaf Ebrahimi * The file containing the key metadata designated by the key identifier. 303*62c56f98SSadaf Ebrahimi * The driver persistent data. 304*62c56f98SSadaf Ebrahimi 305*62c56f98SSadaf EbrahimiMbed Crypto TBD 306*62c56f98SSadaf Ebrahimi--------------- 307*62c56f98SSadaf Ebrahimi 308*62c56f98SSadaf EbrahimiTags: TBD 309*62c56f98SSadaf Ebrahimi 310*62c56f98SSadaf EbrahimiReleased in TBD 2020. <br> 311*62c56f98SSadaf EbrahimiIntegrated in Mbed OS TBD. 312*62c56f98SSadaf Ebrahimi 313*62c56f98SSadaf Ebrahimi### Changes introduced in TBD 314*62c56f98SSadaf Ebrahimi 315*62c56f98SSadaf Ebrahimi* The type field has been split into a type and a bits field of 2 bytes each. 316*62c56f98SSadaf Ebrahimi 317*62c56f98SSadaf Ebrahimi### Key file format for TBD 318*62c56f98SSadaf Ebrahimi 319*62c56f98SSadaf EbrahimiAll integers are encoded in little-endian order in 8-bit bytes except where otherwise indicated. 320*62c56f98SSadaf Ebrahimi 321*62c56f98SSadaf EbrahimiThe layout of a key file is: 322*62c56f98SSadaf Ebrahimi 323*62c56f98SSadaf Ebrahimi* magic (8 bytes): `"PSA\0KEY\0"`. 324*62c56f98SSadaf Ebrahimi* version (4 bytes): 0. 325*62c56f98SSadaf Ebrahimi* lifetime (4 bytes): `psa_key_lifetime_t` value. 326*62c56f98SSadaf Ebrahimi* type (2 bytes): `psa_key_type_t` value. 327*62c56f98SSadaf Ebrahimi* bits (2 bytes): `psa_key_bits_t` value. 328*62c56f98SSadaf Ebrahimi* policy usage flags (4 bytes): `psa_key_usage_t` value. 329*62c56f98SSadaf Ebrahimi* policy usage algorithm (4 bytes): `psa_algorithm_t` value. 330*62c56f98SSadaf Ebrahimi* policy enrollment algorithm (4 bytes): `psa_algorithm_t` value. 331*62c56f98SSadaf Ebrahimi* key material length (4 bytes). 332*62c56f98SSadaf Ebrahimi* key material: 333*62c56f98SSadaf Ebrahimi * For a transparent key: output of `psa_export_key`. 334*62c56f98SSadaf Ebrahimi * For an opaque key (unified driver interface): driver-specific opaque key blob. 335*62c56f98SSadaf Ebrahimi * For an opaque key (key in a secure element): slot number (8 bytes), in platform endianness. 336*62c56f98SSadaf Ebrahimi* Any trailing data is rejected on load. 337*62c56f98SSadaf Ebrahimi 338*62c56f98SSadaf EbrahimiMbed TLS 2.25.0 339*62c56f98SSadaf Ebrahimi--------------- 340*62c56f98SSadaf Ebrahimi 341*62c56f98SSadaf EbrahimiTags: `mbedtls-2.25.0`, `mbedtls-2.26.0`, `mbedtls-2.27.0`, `mbedtls-2.28.0`, `mbedtls-3.0.0`, `mbedtls-3.1.0` 342*62c56f98SSadaf Ebrahimi 343*62c56f98SSadaf EbrahimiFirst released in December 2020. 344*62c56f98SSadaf Ebrahimi 345*62c56f98SSadaf EbrahimiNote: this is the first version that is officially supported. The version number is still 0. 346*62c56f98SSadaf Ebrahimi 347*62c56f98SSadaf EbrahimiBackward compatibility commitments: we promise backward compatibility for stored keys when Mbed TLS is upgraded from x to y if x >= 2.25 and y < 4. See [`BRANCHES.md`](../../BRANCHES.md) for more details. 348*62c56f98SSadaf Ebrahimi 349*62c56f98SSadaf EbrahimiSupported integrations: 350*62c56f98SSadaf Ebrahimi 351*62c56f98SSadaf Ebrahimi* [PSA platform](#file-namespace-on-a-psa-platform-on-mbed-tls-2.25.0) 352*62c56f98SSadaf Ebrahimi* [library using PSA ITS](#file-namespace-on-its-as-a-library-on-mbed-tls-2.25.0) 353*62c56f98SSadaf Ebrahimi* [library using C stdio](#file-namespace-on-stdio-for-mbed-tls-2.25.0) 354*62c56f98SSadaf Ebrahimi 355*62c56f98SSadaf EbrahimiSupported features: 356*62c56f98SSadaf Ebrahimi 357*62c56f98SSadaf Ebrahimi* [Persistent keys](#key-file-format-for-mbed-tls-2.25.0) designated by a [key identifier and owner](#key-names-for-mbed-tls-2.25.0). Keys can be: 358*62c56f98SSadaf Ebrahimi * Transparent, stored in the export format. 359*62c56f98SSadaf Ebrahimi * Opaque, using the PSA driver interface with statically registered drivers. The driver determines the content of the opaque key blob. 360*62c56f98SSadaf Ebrahimi * Opaque, using the deprecated secure element interface with dynamically registered drivers (`MBEDTLS_PSA_CRYPTO_SE_C`). The driver picks a slot number which is stored in the place of the key material. 361*62c56f98SSadaf Ebrahimi* [Nonvolatile random seed](#nonvolatile-random-seed-file-format-for-mbed-tls-2.25.0) on ITS only. 362*62c56f98SSadaf Ebrahimi 363*62c56f98SSadaf Ebrahimi### Changes introduced in Mbed TLS 2.25.0 364*62c56f98SSadaf Ebrahimi 365*62c56f98SSadaf Ebrahimi* The numerical encodings of `psa_key_type_t`, `psa_key_usage_t` and `psa_algorithm_t` have changed. 366*62c56f98SSadaf Ebrahimi 367*62c56f98SSadaf Ebrahimi### File namespace on a PSA platform on Mbed TLS 2.25.0 368*62c56f98SSadaf Ebrahimi 369*62c56f98SSadaf EbrahimiAssumption: ITS provides a 64-bit file identifier namespace. The Crypto service can use arbitrary file identifiers and no other part of the system accesses the same file identifier namespace. 370*62c56f98SSadaf Ebrahimi 371*62c56f98SSadaf EbrahimiAssumption: the owner identifier is a nonzero value of type `int32_t`. 372*62c56f98SSadaf Ebrahimi 373*62c56f98SSadaf Ebrahimi* Files 0 through 0xfffeffff: unused. 374*62c56f98SSadaf Ebrahimi* Files 0xffff0000 through 0xffffffff: reserved for internal use of the crypto library or crypto service. See [non-key files](#non-key-files-on-mbed-tls-2.25.0). 375*62c56f98SSadaf Ebrahimi* Files 0x100000000 through 0xffffffffffff: [content](#key-file-format-for-mbed-tls-2.25.0) of the [key whose identifier is the file identifier](#key-names-for-mbed-tls-2.25.0). The upper 32 bits determine the owner. 376*62c56f98SSadaf Ebrahimi 377*62c56f98SSadaf Ebrahimi### File namespace on ITS as a library on Mbed TLS 2.25.0 378*62c56f98SSadaf Ebrahimi 379*62c56f98SSadaf EbrahimiAssumption: ITS provides a 64-bit file identifier namespace. The entity using the crypto library can use arbitrary file identifiers and no other part of the system accesses the same file identifier namespace. 380*62c56f98SSadaf Ebrahimi 381*62c56f98SSadaf EbrahimiThis is a library integration, so there is no owner. The key file identifier is identical to the key identifier. 382*62c56f98SSadaf Ebrahimi 383*62c56f98SSadaf Ebrahimi* File 0: unused. 384*62c56f98SSadaf Ebrahimi* Files 1 through 0xfffeffff: [content](#key-file-format-for-mbed-tls-2.25.0) of the [key whose identifier is the file identifier](#key-names-for-mbed-tls-2.25.0). 385*62c56f98SSadaf Ebrahimi* Files 0xffff0000 through 0xffffffff: reserved for internal use of the crypto library or crypto service. See [non-key files](#non-key-files-on-mbed-tls-2.25.0). 386*62c56f98SSadaf Ebrahimi* Files 0x100000000 through 0xffffffffffffffff: unused. 387*62c56f98SSadaf Ebrahimi 388*62c56f98SSadaf Ebrahimi### File namespace on stdio for Mbed TLS 2.25.0 389*62c56f98SSadaf Ebrahimi 390*62c56f98SSadaf EbrahimiAssumption: C stdio, allowing names containing lowercase letters, digits and underscores, of length up to 23. 391*62c56f98SSadaf Ebrahimi 392*62c56f98SSadaf EbrahimiAn undocumented build-time configuration value `PSA_ITS_STORAGE_PREFIX` allows storing the key files in a directory other than the current directory. This value is simply prepended to the file name (so it must end with a directory separator to put the keys in a different directory). 393*62c56f98SSadaf Ebrahimi 394*62c56f98SSadaf Ebrahimi* `PSA_ITS_STORAGE_PREFIX "tempfile.psa_its"`: used as a temporary file. Must be writable. May be overwritten or deleted if present. 395*62c56f98SSadaf Ebrahimi* `sprintf(PSA_ITS_STORAGE_PREFIX "%016llx.psa_its", key_id)`: a key or non-key file. The `key_id` in the name is the 64-bit file identifier, which is the [key identifier](#key-names-for-mbed-tls-2.25.0) for a key file or some reserved identifier for a [non-key file](#non-key-files-on-mbed-tls-2.25.0). The contents of the file are: 396*62c56f98SSadaf Ebrahimi * Magic header (8 bytes): `"PSA\0ITS\0"` 397*62c56f98SSadaf Ebrahimi * File contents. 398*62c56f98SSadaf Ebrahimi 399*62c56f98SSadaf Ebrahimi### Key names for Mbed TLS 2.25.0 400*62c56f98SSadaf Ebrahimi 401*62c56f98SSadaf EbrahimiInformation about each key is stored in a dedicated file designated by the key identifier. In integrations where there is no concept of key owner (in particular, in library integrations), the key identifier is exactly the key identifier as defined in the PSA Cryptography API specification (`psa_key_id_t`). In integrations where there is a concept of key owner (integration into a service for example), the key identifier is made of an owner identifier (its semantics and type are integration specific) and of the key identifier (`psa_key_id_t`) from the key owner point of view. 402*62c56f98SSadaf Ebrahimi 403*62c56f98SSadaf EbrahimiThe way in which the file name is constructed from the key identifier depends on the storage backend. The content of the file is described [below](#key-file-format-for-mbed-tls-2.25.0). 404*62c56f98SSadaf Ebrahimi 405*62c56f98SSadaf Ebrahimi* Library integration: the key file name is just the key identifier as defined in the PSA crypto specification. This is a 32-bit value which must be in the range 0x00000001..0x3fffffff (`PSA_KEY_ID_USER_MIN`..`PSA_KEY_ID_USER_MAX`). 406*62c56f98SSadaf Ebrahimi* PSA service integration: the key file name is `(uint64_t)owner_uid << 32 | key_id` where `key_id` is the key identifier from the owner point of view and `owner_uid` (of type `int32_t`) is the calling partition identifier provided to the server by the partition manager. This is a 64-bit value. 407*62c56f98SSadaf Ebrahimi 408*62c56f98SSadaf Ebrahimi### Key file format for Mbed TLS 2.25.0 409*62c56f98SSadaf Ebrahimi 410*62c56f98SSadaf EbrahimiAll integers are encoded in little-endian order in 8-bit bytes except where otherwise indicated. 411*62c56f98SSadaf Ebrahimi 412*62c56f98SSadaf EbrahimiThe layout of a key file is: 413*62c56f98SSadaf Ebrahimi 414*62c56f98SSadaf Ebrahimi* magic (8 bytes): `"PSA\0KEY\0"`. 415*62c56f98SSadaf Ebrahimi* version (4 bytes): 0. 416*62c56f98SSadaf Ebrahimi* lifetime (4 bytes): `psa_key_lifetime_t` value. 417*62c56f98SSadaf Ebrahimi* type (2 bytes): `psa_key_type_t` value. 418*62c56f98SSadaf Ebrahimi* bits (2 bytes): `psa_key_bits_t` value. 419*62c56f98SSadaf Ebrahimi* policy usage flags (4 bytes): `psa_key_usage_t` value. 420*62c56f98SSadaf Ebrahimi* policy usage algorithm (4 bytes): `psa_algorithm_t` value. 421*62c56f98SSadaf Ebrahimi* policy enrollment algorithm (4 bytes): `psa_algorithm_t` value. 422*62c56f98SSadaf Ebrahimi* key material length (4 bytes). 423*62c56f98SSadaf Ebrahimi* key material: 424*62c56f98SSadaf Ebrahimi * For a transparent key: output of `psa_export_key`. 425*62c56f98SSadaf Ebrahimi * For an opaque key (unified driver interface): driver-specific opaque key blob. 426*62c56f98SSadaf Ebrahimi * For an opaque key (key in a dynamic secure element): slot number (8 bytes), in platform endianness. 427*62c56f98SSadaf Ebrahimi* Any trailing data is rejected on load. 428*62c56f98SSadaf Ebrahimi 429*62c56f98SSadaf Ebrahimi### Non-key files on Mbed TLS 2.25.0 430*62c56f98SSadaf Ebrahimi 431*62c56f98SSadaf EbrahimiFile identifiers that are outside the range of persistent key identifiers are reserved for internal use by the library. The only identifiers currently in use have the owner id (top 32 bits) set to 0. 432*62c56f98SSadaf Ebrahimi 433*62c56f98SSadaf Ebrahimi* Files 0xfffffe02 through 0xfffffeff (`PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + lifetime`): dynamic secure element driver storage. The content of the file is the secure element driver's persistent data. 434*62c56f98SSadaf Ebrahimi* File 0xffffff52 (`PSA_CRYPTO_ITS_RANDOM_SEED_UID`): [nonvolatile random seed](#nonvolatile-random-seed-file-format-for-mbed-tls-2.25.0). 435*62c56f98SSadaf Ebrahimi* File 0xffffff54 (`PSA_CRYPTO_ITS_TRANSACTION_UID`): [transaction file](#transaction-file-format-for-mbed-tls-2.25.0). 436*62c56f98SSadaf Ebrahimi* Other files are unused and reserved for future use. 437*62c56f98SSadaf Ebrahimi 438*62c56f98SSadaf Ebrahimi### Nonvolatile random seed file format for Mbed TLS 2.25.0 439*62c56f98SSadaf Ebrahimi 440*62c56f98SSadaf Ebrahimi[Identical to Mbed Crypto 0.1.0](#nonvolatile-random-seed-file-format-for-0.1.0). 441*62c56f98SSadaf Ebrahimi 442*62c56f98SSadaf Ebrahimi### Transaction file format for Mbed TLS 2.25.0 443*62c56f98SSadaf Ebrahimi 444*62c56f98SSadaf EbrahimiThe transaction file contains data about an ongoing action that cannot be completed atomically. It exists only if there is an ongoing transaction. 445*62c56f98SSadaf Ebrahimi 446*62c56f98SSadaf EbrahimiAll integers are encoded in platform endianness. 447*62c56f98SSadaf Ebrahimi 448*62c56f98SSadaf EbrahimiAll currently existing transactions concern a key in a dynamic secure element. 449*62c56f98SSadaf Ebrahimi 450*62c56f98SSadaf EbrahimiThe layout of a transaction file is: 451*62c56f98SSadaf Ebrahimi 452*62c56f98SSadaf Ebrahimi* type (2 bytes): the [transaction type](#transaction-types-on-mbed-tls-2.25.0). 453*62c56f98SSadaf Ebrahimi* unused (2 bytes) 454*62c56f98SSadaf Ebrahimi* lifetime (4 bytes): `psa_key_lifetime_t` value that corresponds to a key in a secure element. 455*62c56f98SSadaf Ebrahimi* slot number (8 bytes): `psa_key_slot_number_t` value. This is the unique designation of the key for the secure element driver. 456*62c56f98SSadaf Ebrahimi* key identifier (4 bytes in a library integration, 8 bytes on a PSA platform): the internal representation of the key identifier. On a PSA platform, this encodes the key owner in the same way as [in file identifiers for key files](#file-namespace-on-a-psa-platform-on-mbed-tls-2.25.0)). 457*62c56f98SSadaf Ebrahimi 458*62c56f98SSadaf Ebrahimi#### Transaction types on Mbed TLS 2.25.0 459*62c56f98SSadaf Ebrahimi 460*62c56f98SSadaf Ebrahimi* 0x0001: key creation. The following locations may or may not contain data about the key that is being created: 461*62c56f98SSadaf Ebrahimi * The slot in the secure element designated by the slot number. 462*62c56f98SSadaf Ebrahimi * The file containing the key metadata designated by the key identifier. 463*62c56f98SSadaf Ebrahimi * The driver persistent data. 464*62c56f98SSadaf Ebrahimi* 0x0002: key destruction. The following locations may or may not still contain data about the key that is being destroyed: 465*62c56f98SSadaf Ebrahimi * The slot in the secure element designated by the slot number. 466*62c56f98SSadaf Ebrahimi * The file containing the key metadata designated by the key identifier. 467*62c56f98SSadaf Ebrahimi * The driver persistent data. 468