@@ -104,6 +104,117 @@ static inline psa_algorithm_t psa_get_key_enrollment_algorithm(
104
104
return ( attributes -> core .policy .alg2 );
105
105
}
106
106
107
+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
108
+
109
+ /** Retrieve the slot number where a key is stored.
110
+ *
111
+ * A slot number is only defined for keys that are stored in a secure
112
+ * element.
113
+ *
114
+ * This information is only useful if the secure element is not entirely
115
+ * managed through the PSA Cryptography API. It is up to the secure
116
+ * element driver to decide how PSA slot numbers map to any other interface
117
+ * that the secure element may have.
118
+ *
119
+ * \param[in] attributes The key attribute structure to query.
120
+ * \param[out] slot_number On success, the slot number containing the key.
121
+ *
122
+ * \retval #PSA_SUCCESS
123
+ * The key is located in a secure element, and \p *slot_number
124
+ * indicates the slot number that contains it.
125
+ * \retval #PSA_ERROR_NOT_PERMITTED
126
+ * The caller is not permitted to query the slot number.
127
+ * Mbed Crypto currently does not return this error.
128
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
129
+ * The key is not located in a secure element.
130
+ */
131
+ psa_status_t psa_get_key_slot_number (
132
+ const psa_key_attributes_t * attributes ,
133
+ psa_key_slot_number_t * slot_number );
134
+
135
+ /** Choose the slot number where a key is stored.
136
+ *
137
+ * This function declares a slot number in the specified attribute
138
+ * structure.
139
+ *
140
+ * A slot number is only meaningful for keys that are stored in a secure
141
+ * element. It is up to the secure element driver to decide how PSA slot
142
+ * numbers map to any other interface that the secure element may have.
143
+ *
144
+ * \note Setting a slot number in key attributes for a key creation can
145
+ * cause the following errors when creating the key:
146
+ * - #PSA_ERROR_NOT_SUPPORTED if the selected secure element does
147
+ * not support choosing a specific slot number.
148
+ * - #PSA_ERROR_NOT_PERMITTED if the caller is not permitted to
149
+ * choose slot numbers in general or to choose this specific slot.
150
+ * - #PSA_ERROR_INVALID_ARGUMENT if the chosen slot number is not
151
+ * valid in general or not valid for this specific key.
152
+ * - #PSA_ERROR_ALREADY_EXISTS if there is already a key in the
153
+ * selected slot.
154
+ *
155
+ * \param[out] attributes The attribute structure to write to.
156
+ * \param slot_number The slot number to set.
157
+ */
158
+ static inline void psa_set_key_slot_number (
159
+ psa_key_attributes_t * attributes ,
160
+ psa_key_slot_number_t slot_number )
161
+ {
162
+ attributes -> core .flags |= MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER ;
163
+ attributes -> slot_number = slot_number ;
164
+ }
165
+
166
+ /** Remove the slot number attribute from a key attribute structure.
167
+ *
168
+ * This function undoes the action of psa_set_key_slot_number().
169
+ *
170
+ * \param[out] attributes The attribute structure to write to.
171
+ */
172
+ static inline void psa_clear_key_slot_number (
173
+ psa_key_attributes_t * attributes )
174
+ {
175
+ attributes -> core .flags &= ~MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER ;
176
+ }
177
+
178
+ /** Register a key that is already present in a secure element.
179
+ *
180
+ * The key must be located in a secure element designated by the
181
+ * lifetime field in \p attributes, in the slot set with
182
+ * psa_set_key_slot_number() in the attribute structure.
183
+ * This function makes the key available through the key identifier
184
+ * specified in \p attributes.
185
+ *
186
+ * \param[in] attributes The attributes of the existing key.
187
+ *
188
+ * \retval #PSA_SUCCESS
189
+ * The key was successfully registered.
190
+ * Note that depending on the design of the driver, this may or may
191
+ * not guarantee that a key actually exists in the designated slot
192
+ * and is compatible with the specified attributes.
193
+ * \retval #PSA_ERROR_ALREADY_EXISTS
194
+ * There is already a key with the identifier specified in
195
+ * \p attributes.
196
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
197
+ * \p attributes specifies a lifetime which is not located
198
+ * in a secure element.
199
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
200
+ * No slot number is specified in \p attributes,
201
+ * or the specified slot number is not valid.
202
+ * \retval #PSA_ERROR_NOT_PERMITTED
203
+ * The caller is not authorized to register the specified key slot.
204
+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
205
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
206
+ * \retval #PSA_ERROR_HARDWARE_FAILURE
207
+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
208
+ * \retval #PSA_ERROR_BAD_STATE
209
+ * The library has not been previously initialized by psa_crypto_init().
210
+ * It is implementation-dependent whether a failure to initialize
211
+ * results in this error code.
212
+ */
213
+ psa_status_t mbedtls_psa_register_se_key (
214
+ const psa_key_attributes_t * attributes );
215
+
216
+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
217
+
107
218
/**@}*/
108
219
109
220
/**
0 commit comments