Skip to content

Commit adb1c52

Browse files
Merge pull request #157 from gilles-peskine-arm/psa-se_driver-create_key
Secure element key creation foundation
2 parents f61bf9c + 66be51c commit adb1c52

20 files changed

+2194
-360
lines changed

docs/architecture/mbed-crypto-storage-specification.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,92 @@ The layout of a key file is:
193193
* key material length (4 bytes)
194194
* key material: output of `psa_export_key`
195195
* Any trailing data is rejected on load.
196+
197+
Mbed Crypto TBD
198+
---------------
199+
200+
Tags: TBD
201+
202+
Released in TBD 2019. <br>
203+
Integrated in Mbed OS TBD.
204+
205+
### Changes introduced in TBD
206+
207+
* The layout of a key file now has a lifetime field before the type field.
208+
* Key files can store references to keys in a secure element. In such key files, the key material contains the slot number.
209+
210+
### File namespace on a PSA platform on TBD
211+
212+
Assumption: 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.
213+
214+
Assumption: the owner identifier is a nonzero value of type `int32_t`.
215+
216+
* Files 0 through 0xfffeffff: unused.
217+
* Files 0xffff0000 through 0xffffffff: reserved for internal use of the crypto library or crypto service. See [non-key files](#non-key-files-on-tbd).
218+
* 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.
219+
220+
### File namespace on ITS as a library on TBD
221+
222+
Assumption: 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.
223+
224+
This is a library integration, so there is no owner. The key file identifier is identical to the key identifier.
225+
226+
* File 0: unused.
227+
* 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).
228+
* Files 0xffff0000 through 0xffffffff: reserved for internal use of the crypto library or crypto service. See [non-key files](#non-key-files-on-tbd).
229+
* Files 0x100000000 through 0xffffffffffffffff: unused.
230+
231+
### Non-key files on TBD
232+
233+
File identifiers in the range 0xffff0000 through 0xffffffff are reserved for internal use in Mbed Crypto.
234+
235+
* 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.
236+
* File 0xffffff52 (`PSA_CRYPTO_ITS_RANDOM_SEED_UID`): [nonvolatile random seed](#nonvolatile-random-seed-file-format-for-1.0.0).
237+
* File 0xffffff54 (`PSA_CRYPTO_ITS_TRANSACTION_UID`): [transaction file](#transaction-file-format-for-tbd).
238+
* Other files are unused and reserved for future use.
239+
240+
### Key file format for TBD
241+
242+
All integers are encoded in little-endian order in 8-bit bytes except where otherwise indicated.
243+
244+
The layout of a key file is:
245+
246+
* magic (8 bytes): `"PSA\0KEY\0"`.
247+
* version (4 bytes): 0.
248+
* lifetime (4 bytes): `psa_key_lifetime_t` value.
249+
* type (4 bytes): `psa_key_type_t` value.
250+
* policy usage flags (4 bytes): `psa_key_usage_t` value.
251+
* policy usage algorithm (4 bytes): `psa_algorithm_t` value.
252+
* policy enrollment algorithm (4 bytes): `psa_algorithm_t` value.
253+
* key material length (4 bytes).
254+
* key material:
255+
* For a transparent key: output of `psa_export_key`.
256+
* For an opaque key (key in a secure element): slot number (8 bytes), in platform endianness.
257+
* Any trailing data is rejected on load.
258+
259+
### Transaction file format for TBD
260+
261+
The transaction file contains data about an ongoing action that cannot be completed atomically. It exists only if there is an ongoing transaction.
262+
263+
All integers are encoded in platform endianness.
264+
265+
All currently existing transactions concern a key in a secure element.
266+
267+
The layout of a transaction file is:
268+
269+
* type (2 bytes): the [transaction type](#transaction-types-on-tbd).
270+
* unused (2 bytes)
271+
* lifetime (4 bytes): `psa_key_lifetime_t` value that corresponds to a key in a secure element.
272+
* slot number (8 bytes): `psa_key_slot_number_t` value. This is the unique designation of the key for the secure element driver.
273+
* 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)).
274+
275+
#### Transaction types on TBD
276+
277+
* 0x0001: key creation. The following locations may or may not contain data about the key that is being created:
278+
* The slot in the secure element designated by the slot number.
279+
* The file containing the key metadata designated by the key identifier.
280+
* The driver persistent data.
281+
* 0x0002: key destruction. The following locations may or may not still contain data about the key that is being destroyed:
282+
* The slot in the secure element designated by the slot number.
283+
* The file containing the key metadata designated by the key identifier.
284+
* The driver persistent data.

include/mbedtls/config.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,12 +1715,15 @@
17151715
* Enable secure element support in the Platform Security Architecture
17161716
* cryptography API.
17171717
*
1718+
* \warning This feature is not yet suitable for production. It is provided
1719+
* for API evaluation and testing purposes only.
1720+
*
17181721
* Module: library/psa_crypto_se.c
17191722
*
17201723
* Requires: MBEDTLS_PSA_CRYPTO_C, MBEDTLS_PSA_CRYPTO_STORAGE_C
17211724
*
17221725
*/
1723-
#define MBEDTLS_PSA_CRYPTO_SE_C
1726+
//#define MBEDTLS_PSA_CRYPTO_SE_C
17241727

17251728
/**
17261729
* \def MBEDTLS_PSA_CRYPTO_STORAGE_C

include/psa/crypto.h

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -93,117 +93,10 @@ psa_status_t psa_crypto_init(void);
9393

9494
/**@}*/
9595

96-
/** \defgroup attributes Key attributes
96+
/** \addtogroup attributes
9797
* @{
9898
*/
9999

100-
/** The type of a structure containing key attributes.
101-
*
102-
* This is an opaque structure that can represent the metadata of a key
103-
* object. Metadata that can be stored in attributes includes:
104-
* - The location of the key in storage, indicated by its key identifier
105-
* and its lifetime.
106-
* - The key's policy, comprising usage flags and a specification of
107-
* the permitted algorithm(s).
108-
* - Information about the key itself: the key type and its size.
109-
* - Implementations may define additional attributes.
110-
*
111-
* The actual key material is not considered an attribute of a key.
112-
* Key attributes do not contain information that is generally considered
113-
* highly confidential.
114-
*
115-
* An attribute structure can be a simple data structure where each function
116-
* `psa_set_key_xxx` sets a field and the corresponding function
117-
* `psa_get_key_xxx` retrieves the value of the corresponding field.
118-
* However, implementations may report values that are equivalent to the
119-
* original one, but have a different encoding. For example, an
120-
* implementation may use a more compact representation for types where
121-
* many bit-patterns are invalid or not supported, and store all values
122-
* that it does not support as a special marker value. In such an
123-
* implementation, after setting an invalid value, the corresponding
124-
* get function returns an invalid value which may not be the one that
125-
* was originally stored.
126-
*
127-
* An attribute structure may contain references to auxiliary resources,
128-
* for example pointers to allocated memory or indirect references to
129-
* pre-calculated values. In order to free such resources, the application
130-
* must call psa_reset_key_attributes(). As an exception, calling
131-
* psa_reset_key_attributes() on an attribute structure is optional if
132-
* the structure has only been modified by the following functions
133-
* since it was initialized or last reset with psa_reset_key_attributes():
134-
* - psa_set_key_id()
135-
* - psa_set_key_lifetime()
136-
* - psa_set_key_type()
137-
* - psa_set_key_bits()
138-
* - psa_set_key_usage_flags()
139-
* - psa_set_key_algorithm()
140-
*
141-
* Before calling any function on a key attribute structure, the application
142-
* must initialize it by any of the following means:
143-
* - Set the structure to all-bits-zero, for example:
144-
* \code
145-
* psa_key_attributes_t attributes;
146-
* memset(&attributes, 0, sizeof(attributes));
147-
* \endcode
148-
* - Initialize the structure to logical zero values, for example:
149-
* \code
150-
* psa_key_attributes_t attributes = {0};
151-
* \endcode
152-
* - Initialize the structure to the initializer #PSA_KEY_ATTRIBUTES_INIT,
153-
* for example:
154-
* \code
155-
* psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
156-
* \endcode
157-
* - Assign the result of the function psa_key_attributes_init()
158-
* to the structure, for example:
159-
* \code
160-
* psa_key_attributes_t attributes;
161-
* attributes = psa_key_attributes_init();
162-
* \endcode
163-
*
164-
* A freshly initialized attribute structure contains the following
165-
* values:
166-
*
167-
* - lifetime: #PSA_KEY_LIFETIME_VOLATILE.
168-
* - key identifier: unspecified.
169-
* - type: \c 0.
170-
* - key size: \c 0.
171-
* - usage flags: \c 0.
172-
* - algorithm: \c 0.
173-
*
174-
* A typical sequence to create a key is as follows:
175-
* -# Create and initialize an attribute structure.
176-
* -# If the key is persistent, call psa_set_key_id().
177-
* Also call psa_set_key_lifetime() to place the key in a non-default
178-
* location.
179-
* -# Set the key policy with psa_set_key_usage_flags() and
180-
* psa_set_key_algorithm().
181-
* -# Set the key type with psa_set_key_type().
182-
* Skip this step if copying an existing key with psa_copy_key().
183-
* -# When generating a random key with psa_generate_key() or deriving a key
184-
* with psa_key_derivation_output_key(), set the desired key size with
185-
* psa_set_key_bits().
186-
* -# Call a key creation function: psa_import_key(), psa_generate_key(),
187-
* psa_key_derivation_output_key() or psa_copy_key(). This function reads
188-
* the attribute structure, creates a key with these attributes, and
189-
* outputs a handle to the newly created key.
190-
* -# The attribute structure is now no longer necessary.
191-
* You may call psa_reset_key_attributes(), although this is optional
192-
* with the workflow presented here because the attributes currently
193-
* defined in this specification do not require any additional resources
194-
* beyond the structure itself.
195-
*
196-
* A typical sequence to query a key's attributes is as follows:
197-
* -# Call psa_get_key_attributes().
198-
* -# Call `psa_get_key_xxx` functions to retrieve the attribute(s) that
199-
* you are interested in.
200-
* -# Call psa_reset_key_attributes() to free any resources that may be
201-
* used by the attribute structure.
202-
*
203-
* Once a key has been created, it is impossible to change its attributes.
204-
*/
205-
typedef struct psa_key_attributes_s psa_key_attributes_t;
206-
207100
/** \def PSA_KEY_ATTRIBUTES_INIT
208101
*
209102
* This macro returns a suitable initializer for a key attribute structure

0 commit comments

Comments
 (0)