Skip to content

Commit 0c3ae1f

Browse files
Improve documentation of SE driver persistent state
Explain what it can be used for and when it is saved to storage.
1 parent 2e0f388 commit 0c3ae1f

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

include/psa/crypto_se_driver.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ extern "C" {
5555
typedef struct {
5656
/** A read-only pointer to the driver's persistent data.
5757
*
58-
* The PSA Cryptography core saves the persistent data from one
59-
* session to the next.
58+
* Drivers typically use this persistent data to keep track of
59+
* which slot numbers are available. This is only a guideline:
60+
* drivers may use the persistent data for any purpose, keeping
61+
* in mind the restrictions on when the persistent data is saved
62+
* to storage: the persistent data is only saved after calling
63+
* certain functions that receive a writable pointer to the
64+
* persistent data.
6065
*
6166
* The core allocates a memory buffer for the persistent data.
6267
* The pointer is guaranteed to be suitably aligned for any data type,
@@ -74,7 +79,23 @@ typedef struct {
7479
*
7580
* This pointer is to read-only data. Only a few driver functions are
7681
* allowed to modify the persistent data. These functions receive a
77-
* writable pointer.
82+
* writable pointer. These functions are:
83+
* - psa_drv_se_t::p_init
84+
* - psa_drv_se_key_management_t::p_allocate
85+
* - psa_drv_se_key_management_t::p_destroy
86+
*
87+
* The PSA Cryptography core saves the persistent data from one
88+
* session to the next. It does this before returning from API functions
89+
* that call a driver method that is allowed to modify the persistent
90+
* data, specifically:
91+
* - psa_crypto_init() causes a call to psa_drv_se_t::p_init, and may call
92+
* psa_drv_se_key_management_t::p_destroy to complete an action
93+
* that was interrupted by a power failure.
94+
* - Key creation functions cause a call to
95+
* psa_drv_se_key_management_t::p_allocate, and may cause a call to
96+
* psa_drv_se_key_management_t::p_destroy in case an error occurs.
97+
* - psa_destroy_key() causes a call to
98+
* psa_drv_se_key_management_t::p_destroy.
7899
*/
79100
const void *const persistent_data;
80101

@@ -1118,7 +1139,14 @@ typedef struct {
11181139
*/
11191140
uint32_t hal_version;
11201141

1121-
/** The size of the driver's persistent data in bytes. */
1142+
/** The size of the driver's persistent data in bytes.
1143+
*
1144+
* This can be 0 if the driver does not need persistent data.
1145+
*
1146+
* See the documentation of psa_drv_se_context_t::persistent_data
1147+
* for more information about why and how a driver can use
1148+
* persistent data.
1149+
*/
11221150
size_t persistent_data_size;
11231151

11241152
/** The driver initialization function.

0 commit comments

Comments
 (0)