blob: 3f3d7ca8dde7834fee7fee3fcb4296a059920e79 [file] [log] [blame]
Gilles Peskine75976892018-12-12 15:55:09 +01001/**
2 * \file psa/crypto_se_driver.h
3 * \brief PSA external cryptoprocessor driver module
4 *
5 * This header declares types and function signatures for cryptography
Derek Millerf0c1d0d2019-02-15 17:23:42 -06006 * drivers that access key material via opaque references.
7 * This is meant for cryptoprocessors that have a separate key storage from the
Gilles Peskine75976892018-12-12 15:55:09 +01008 * space in which the PSA Crypto implementation runs, typically secure
Derek Millerf0c1d0d2019-02-15 17:23:42 -06009 * elements (SEs).
Gilles Peskine75976892018-12-12 15:55:09 +010010 *
Gilles Peskineb6cadea2019-06-24 13:46:37 +020011 * This file is part of the PSA Crypto Driver HAL (hardware abstraction layer),
12 * containing functions for driver developers to implement to enable hardware
13 * to be called in a standardized way by a PSA Cryptography API
14 * implementation. The functions comprising the driver HAL, which driver
15 * authors implement, are not intended to be called by application developers.
Gilles Peskine75976892018-12-12 15:55:09 +010016 */
17
18/*
19 * Copyright (C) 2018, ARM Limited, All Rights Reserved
20 * SPDX-License-Identifier: Apache-2.0
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License"); you may
23 * not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
30 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 */
34#ifndef PSA_CRYPTO_SE_DRIVER_H
35#define PSA_CRYPTO_SE_DRIVER_H
36
37#include "crypto_driver_common.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
Gilles Peskine7a86da12019-07-12 23:25:38 +020043/** \defgroup se_init Secure element driver initialization
44 */
45/**@{*/
46
47/** \brief Driver context structure
48 *
49 * Driver functions receive a pointer to this structure.
50 * Each registered driver has one instance of this structure.
51 *
52 * Implementations must include the fields specified here and
53 * may include other fields.
54 */
55typedef struct {
56 /** A read-only pointer to the driver's persistent data.
57 *
58 * The PSA Cryptography core saves the persistent data from one
59 * session to the next.
60 *
61 * The core allocates a memory buffer for the persistent data.
62 * The pointer is guaranteed to be suitably alignedfor any data type,
63 * like a pointer returned by `malloc` (but the core can use any
64 * method to allocate the buffer, not necessarily `malloc`).
65 *
Gilles Peskine9dd125d2019-07-23 18:26:43 +020066 * The size of this buffer is in the \c persistent_data_size field of
67 * this structure.
Gilles Peskine7a86da12019-07-12 23:25:38 +020068 *
69 * Before the driver is initialized for the first time, the content of
70 * the persistent data is all-bits-zero. After a driver upgrade, if the
71 * size of the persistent data has increased, the original data is padded
72 * on the right with zeros; if the size has decreased, the original data
73 * is truncated to the new size.
74 *
75 * This pointer is to read-only data. Only a few driver functions are
76 * allowed to modify the persistent data. These functions receive a
77 * writable pointer.
78 */
79 const void *const persistent_data;
80
81 /** The size of \c persistent_data in bytes.
82 *
Gilles Peskine9dd125d2019-07-23 18:26:43 +020083 * This is always equal to the value of the `persistent_data_size` field
84 * of the ::psa_drv_se_t structure when the driver is registered.
Gilles Peskine7a86da12019-07-12 23:25:38 +020085 */
86 const size_t persistent_data_size;
87
88 /** Driver transient data.
89 *
90 * The core initializes this value to 0 and does not read or modify it
91 * afterwards. The driver may store whatever it wants in this field.
92 */
93 uintptr_t transient_data;
94} psa_drv_se_context_t;
95
96/** \brief A driver initialization function.
97 *
98 * \param[in,out] drv_context The driver context structure.
Gilles Peskine94cc42c2019-07-12 23:34:20 +020099 * \param[in,out] persistent_data A pointer to the persistent data
100 * that allows writing.
Gilles Peskine7a86da12019-07-12 23:25:38 +0200101 * \param lifetime The lifetime value for which this driver
102 * is registered.
103 *
104 * \retval #PSA_SUCCESS
105 * The driver is operational.
106 * The core will update the persistent data in storage.
107 * \return
108 * Any other return value prevents the driver from being used in
109 * this session.
110 * The core will NOT update the persistent data in storage.
111 */
112typedef psa_status_t (*psa_drv_se_init_t)(psa_drv_se_context_t *drv_context,
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200113 void *persistent_data,
Gilles Peskine7a86da12019-07-12 23:25:38 +0200114 psa_key_lifetime_t lifetime);
115
Gilles Peskine75976892018-12-12 15:55:09 +0100116/** An internal designation of a key slot between the core part of the
117 * PSA Crypto implementation and the driver. The meaning of this value
118 * is driver-dependent. */
Gilles Peskinef03143a2019-07-12 23:18:29 +0200119typedef uint64_t psa_key_slot_number_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100120
Gilles Peskine7a86da12019-07-12 23:25:38 +0200121/**@}*/
122
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600123/** \defgroup se_mac Secure Element Message Authentication Codes
Gilles Peskine75976892018-12-12 15:55:09 +0100124 * Generation and authentication of Message Authentication Codes (MACs) using
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600125 * a secure element can be done either as a single function call (via the
126 * `psa_drv_se_mac_generate_t` or `psa_drv_se_mac_verify_t` functions), or in
Gilles Peskine75976892018-12-12 15:55:09 +0100127 * parts using the following sequence:
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600128 * - `psa_drv_se_mac_setup_t`
129 * - `psa_drv_se_mac_update_t`
130 * - `psa_drv_se_mac_update_t`
Gilles Peskine75976892018-12-12 15:55:09 +0100131 * - ...
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600132 * - `psa_drv_se_mac_finish_t` or `psa_drv_se_mac_finish_verify_t`
Gilles Peskine75976892018-12-12 15:55:09 +0100133 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600134 * If a previously started secure element MAC operation needs to be terminated,
135 * it should be done so by the `psa_drv_se_mac_abort_t`. Failure to do so may
Gilles Peskine75976892018-12-12 15:55:09 +0100136 * result in allocated resources not being freed or in other undefined
137 * behavior.
138 */
139/**@{*/
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600140/** \brief A function that starts a secure element MAC operation for a PSA
141 * Crypto Driver implementation
Gilles Peskine75976892018-12-12 15:55:09 +0100142 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200143 * \param[in,out] drv_context The driver context structure.
144 * \param[in,out] op_context A structure that will contain the
Gilles Peskine75976892018-12-12 15:55:09 +0100145 * hardware-specific MAC context
146 * \param[in] key_slot The slot of the key to be used for the
147 * operation
148 * \param[in] algorithm The algorithm to be used to underly the MAC
149 * operation
150 *
151 * \retval PSA_SUCCESS
152 * Success.
153 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200154typedef psa_status_t (*psa_drv_se_mac_setup_t)(psa_drv_se_context_t *drv_context,
155 void *op_context,
Derek Millerb2a1cce2019-02-15 17:03:42 -0600156 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600157 psa_algorithm_t algorithm);
Gilles Peskine75976892018-12-12 15:55:09 +0100158
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600159/** \brief A function that continues a previously started secure element MAC
160 * operation
Gilles Peskine75976892018-12-12 15:55:09 +0100161 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200162 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100163 * previously-established MAC operation to be
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600164 * updated
Gilles Peskine75976892018-12-12 15:55:09 +0100165 * \param[in] p_input A buffer containing the message to be appended
166 * to the MAC operation
167 * \param[in] input_length The size in bytes of the input message buffer
168 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200169typedef psa_status_t (*psa_drv_se_mac_update_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600170 const uint8_t *p_input,
171 size_t input_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100172
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600173/** \brief a function that completes a previously started secure element MAC
174 * operation by returning the resulting MAC.
Gilles Peskine75976892018-12-12 15:55:09 +0100175 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200176 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100177 * previously started MAC operation to be
178 * finished
179 * \param[out] p_mac A buffer where the generated MAC will be
180 * placed
181 * \param[in] mac_size The size in bytes of the buffer that has been
182 * allocated for the `output` buffer
183 * \param[out] p_mac_length After completion, will contain the number of
184 * bytes placed in the `p_mac` buffer
185 *
186 * \retval PSA_SUCCESS
187 * Success.
188 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200189typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600190 uint8_t *p_mac,
191 size_t mac_size,
192 size_t *p_mac_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100193
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600194/** \brief A function that completes a previously started secure element MAC
195 * operation by comparing the resulting MAC against a provided value
Gilles Peskine75976892018-12-12 15:55:09 +0100196 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200197 * \param[in,out] op_context A hardware-specific structure for the previously
Gilles Peskine75976892018-12-12 15:55:09 +0100198 * started MAC operation to be fiinished
199 * \param[in] p_mac The MAC value against which the resulting MAC will
200 * be compared against
201 * \param[in] mac_length The size in bytes of the value stored in `p_mac`
202 *
203 * \retval PSA_SUCCESS
204 * The operation completed successfully and the MACs matched each
205 * other
206 * \retval PSA_ERROR_INVALID_SIGNATURE
207 * The operation completed successfully, but the calculated MAC did
208 * not match the provided MAC
209 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200210typedef psa_status_t (*psa_drv_se_mac_finish_verify_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600211 const uint8_t *p_mac,
212 size_t mac_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100213
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600214/** \brief A function that aborts a previous started secure element MAC
215 * operation
Gilles Peskine32668ce2019-03-06 18:29:57 +0100216 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200217 * \param[in,out] op_context A hardware-specific structure for the previously
Gilles Peskine75976892018-12-12 15:55:09 +0100218 * started MAC operation to be aborted
219 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200220typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *op_context);
Gilles Peskine75976892018-12-12 15:55:09 +0100221
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600222/** \brief A function that performs a secure element MAC operation in one
223 * command and returns the calculated MAC
Gilles Peskine75976892018-12-12 15:55:09 +0100224 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200225 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100226 * \param[in] p_input A buffer containing the message to be MACed
227 * \param[in] input_length The size in bytes of `p_input`
228 * \param[in] key_slot The slot of the key to be used
229 * \param[in] alg The algorithm to be used to underlie the MAC
230 * operation
231 * \param[out] p_mac A buffer where the generated MAC will be
232 * placed
233 * \param[in] mac_size The size in bytes of the `p_mac` buffer
234 * \param[out] p_mac_length After completion, will contain the number of
235 * bytes placed in the `output` buffer
236 *
237 * \retval PSA_SUCCESS
238 * Success.
239 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200240typedef psa_status_t (*psa_drv_se_mac_generate_t)(psa_drv_se_context_t *drv_context,
241 const uint8_t *p_input,
Derek Miller83d26622019-02-15 16:41:22 -0600242 size_t input_length,
Derek Millerb2a1cce2019-02-15 17:03:42 -0600243 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600244 psa_algorithm_t alg,
245 uint8_t *p_mac,
246 size_t mac_size,
247 size_t *p_mac_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100248
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600249/** \brief A function that performs a secure element MAC operation in one
250 * command and compares the resulting MAC against a provided value
Gilles Peskine75976892018-12-12 15:55:09 +0100251 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200252 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100253 * \param[in] p_input A buffer containing the message to be MACed
254 * \param[in] input_length The size in bytes of `input`
255 * \param[in] key_slot The slot of the key to be used
256 * \param[in] alg The algorithm to be used to underlie the MAC
257 * operation
258 * \param[in] p_mac The MAC value against which the resulting MAC will
259 * be compared against
260 * \param[in] mac_length The size in bytes of `mac`
261 *
262 * \retval PSA_SUCCESS
263 * The operation completed successfully and the MACs matched each
264 * other
265 * \retval PSA_ERROR_INVALID_SIGNATURE
266 * The operation completed successfully, but the calculated MAC did
267 * not match the provided MAC
268 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200269typedef psa_status_t (*psa_drv_se_mac_verify_t)(psa_drv_se_context_t *drv_context,
270 const uint8_t *p_input,
Derek Miller83d26622019-02-15 16:41:22 -0600271 size_t input_length,
Derek Millerb2a1cce2019-02-15 17:03:42 -0600272 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600273 psa_algorithm_t alg,
274 const uint8_t *p_mac,
275 size_t mac_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100276
277/** \brief A struct containing all of the function pointers needed to
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600278 * perform secure element MAC operations
Gilles Peskine75976892018-12-12 15:55:09 +0100279 *
280 * PSA Crypto API implementations should populate the table as appropriate
281 * upon startup.
282 *
283 * If one of the functions is not implemented (such as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600284 * `psa_drv_se_mac_generate_t`), it should be set to NULL.
Gilles Peskine75976892018-12-12 15:55:09 +0100285 *
286 * Driver implementers should ensure that they implement all of the functions
287 * that make sense for their hardware, and that they provide a full solution
288 * (for example, if they support `p_setup`, they should also support
289 * `p_update` and at least one of `p_finish` or `p_finish_verify`).
290 *
291 */
292typedef struct {
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600293 /**The size in bytes of the hardware-specific secure element MAC context
294 * structure
Gilles Peskine75976892018-12-12 15:55:09 +0100295 */
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600296 size_t context_size;
297 /** Function that performs a MAC setup operation
Gilles Peskine75976892018-12-12 15:55:09 +0100298 */
Derek Millerea743cf2019-02-15 17:06:29 -0600299 psa_drv_se_mac_setup_t p_setup;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600300 /** Function that performs a MAC update operation
Gilles Peskine75976892018-12-12 15:55:09 +0100301 */
Derek Millerea743cf2019-02-15 17:06:29 -0600302 psa_drv_se_mac_update_t p_update;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600303 /** Function that completes a MAC operation
Gilles Peskine75976892018-12-12 15:55:09 +0100304 */
Derek Millerea743cf2019-02-15 17:06:29 -0600305 psa_drv_se_mac_finish_t p_finish;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600306 /** Function that completes a MAC operation with a verify check
Gilles Peskine75976892018-12-12 15:55:09 +0100307 */
Derek Millerea743cf2019-02-15 17:06:29 -0600308 psa_drv_se_mac_finish_verify_t p_finish_verify;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600309 /** Function that aborts a previoustly started MAC operation
Gilles Peskine75976892018-12-12 15:55:09 +0100310 */
Derek Millerea743cf2019-02-15 17:06:29 -0600311 psa_drv_se_mac_abort_t p_abort;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600312 /** Function that performs a MAC operation in one call
Gilles Peskine75976892018-12-12 15:55:09 +0100313 */
Derek Millerea743cf2019-02-15 17:06:29 -0600314 psa_drv_se_mac_generate_t p_mac;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600315 /** Function that performs a MAC and verify operation in one call
Gilles Peskine75976892018-12-12 15:55:09 +0100316 */
Derek Millerea743cf2019-02-15 17:06:29 -0600317 psa_drv_se_mac_verify_t p_mac_verify;
Derek Miller83d26622019-02-15 16:41:22 -0600318} psa_drv_se_mac_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100319/**@}*/
320
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600321/** \defgroup se_cipher Secure Element Symmetric Ciphers
Gilles Peskine75976892018-12-12 15:55:09 +0100322 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600323 * Encryption and Decryption using secure element keys in block modes other
324 * than ECB must be done in multiple parts, using the following flow:
325 * - `psa_drv_se_cipher_setup_t`
326 * - `psa_drv_se_cipher_set_iv_t` (optional depending upon block mode)
327 * - `psa_drv_se_cipher_update_t`
328 * - `psa_drv_se_cipher_update_t`
Gilles Peskine75976892018-12-12 15:55:09 +0100329 * - ...
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600330 * - `psa_drv_se_cipher_finish_t`
Gilles Peskine32668ce2019-03-06 18:29:57 +0100331 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600332 * If a previously started secure element Cipher operation needs to be
333 * terminated, it should be done so by the `psa_drv_se_cipher_abort_t`. Failure
334 * to do so may result in allocated resources not being freed or in other
335 * undefined behavior.
Gilles Peskine75976892018-12-12 15:55:09 +0100336 *
337 * In situations where a PSA Cryptographic API implementation is using a block
338 * mode not-supported by the underlying hardware or driver, it can construct
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600339 * the block mode itself, while calling the `psa_drv_se_cipher_ecb_t` function
340 * for the cipher operations.
Gilles Peskine75976892018-12-12 15:55:09 +0100341 */
342/**@{*/
343
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600344/** \brief A function that provides the cipher setup function for a
345 * secure element driver
Gilles Peskine75976892018-12-12 15:55:09 +0100346 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200347 * \param[in,out] drv_context The driver context structure.
348 * \param[in,out] op_context A structure that will contain the
Gilles Peskine75976892018-12-12 15:55:09 +0100349 * hardware-specific cipher context.
350 * \param[in] key_slot The slot of the key to be used for the
351 * operation
352 * \param[in] algorithm The algorithm to be used in the cipher
353 * operation
354 * \param[in] direction Indicates whether the operation is an encrypt
355 * or decrypt
356 *
357 * \retval PSA_SUCCESS
358 * \retval PSA_ERROR_NOT_SUPPORTED
359 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200360typedef psa_status_t (*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t *drv_context,
361 void *op_context,
Derek Millerb2a1cce2019-02-15 17:03:42 -0600362 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600363 psa_algorithm_t algorithm,
364 psa_encrypt_or_decrypt_t direction);
Gilles Peskine75976892018-12-12 15:55:09 +0100365
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600366/** \brief A function that sets the initialization vector (if
367 * necessary) for an secure element cipher operation
Gilles Peskine75976892018-12-12 15:55:09 +0100368 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600369 * Rationale: The `psa_se_cipher_*` operation in the PSA Cryptographic API has
370 * two IV functions: one to set the IV, and one to generate it internally. The
Gilles Peskine75976892018-12-12 15:55:09 +0100371 * generate function is not necessary for the drivers to implement as the PSA
372 * Crypto implementation can do the generation using its RNG features.
373 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200374 * \param[in,out] op_context A structure that contains the previously set up
Gilles Peskine75976892018-12-12 15:55:09 +0100375 * hardware-specific cipher context
376 * \param[in] p_iv A buffer containing the initialization vector
377 * \param[in] iv_length The size (in bytes) of the `p_iv` buffer
378 *
379 * \retval PSA_SUCCESS
380 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200381typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600382 const uint8_t *p_iv,
383 size_t iv_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100384
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600385/** \brief A function that continues a previously started secure element cipher
Gilles Peskine75976892018-12-12 15:55:09 +0100386 * operation
387 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200388 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100389 * previously started cipher operation
390 * \param[in] p_input A buffer containing the data to be
391 * encrypted/decrypted
392 * \param[in] input_size The size in bytes of the buffer pointed to
393 * by `p_input`
394 * \param[out] p_output The caller-allocated buffer where the
395 * output will be placed
396 * \param[in] output_size The allocated size in bytes of the
397 * `p_output` buffer
398 * \param[out] p_output_length After completion, will contain the number
399 * of bytes placed in the `p_output` buffer
400 *
401 * \retval PSA_SUCCESS
402 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200403typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600404 const uint8_t *p_input,
405 size_t input_size,
406 uint8_t *p_output,
407 size_t output_size,
408 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100409
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600410/** \brief A function that completes a previously started secure element cipher
Gilles Peskine75976892018-12-12 15:55:09 +0100411 * operation
412 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200413 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100414 * previously started cipher operation
415 * \param[out] p_output The caller-allocated buffer where the output
416 * will be placed
417 * \param[in] output_size The allocated size in bytes of the `p_output`
418 * buffer
419 * \param[out] p_output_length After completion, will contain the number of
420 * bytes placed in the `p_output` buffer
421 *
422 * \retval PSA_SUCCESS
423 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200424typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600425 uint8_t *p_output,
426 size_t output_size,
427 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100428
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600429/** \brief A function that aborts a previously started secure element cipher
Gilles Peskine75976892018-12-12 15:55:09 +0100430 * operation
431 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200432 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100433 * previously started cipher operation
434 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200435typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *op_context);
Gilles Peskine75976892018-12-12 15:55:09 +0100436
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600437/** \brief A function that performs the ECB block mode for secure element
438 * cipher operations
Gilles Peskine75976892018-12-12 15:55:09 +0100439 *
440 * Note: this function should only be used with implementations that do not
441 * provide a needed higher-level operation.
442 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200443 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100444 * \param[in] key_slot The slot of the key to be used for the operation
445 * \param[in] algorithm The algorithm to be used in the cipher operation
446 * \param[in] direction Indicates whether the operation is an encrypt or
447 * decrypt
448 * \param[in] p_input A buffer containing the data to be
449 * encrypted/decrypted
450 * \param[in] input_size The size in bytes of the buffer pointed to by
451 * `p_input`
452 * \param[out] p_output The caller-allocated buffer where the output will
453 * be placed
454 * \param[in] output_size The allocated size in bytes of the `p_output`
455 * buffer
456 *
457 * \retval PSA_SUCCESS
458 * \retval PSA_ERROR_NOT_SUPPORTED
459 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200460typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_drv_se_context_t *drv_context,
461 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600462 psa_algorithm_t algorithm,
463 psa_encrypt_or_decrypt_t direction,
464 const uint8_t *p_input,
465 size_t input_size,
466 uint8_t *p_output,
467 size_t output_size);
Gilles Peskine75976892018-12-12 15:55:09 +0100468
469/**
470 * \brief A struct containing all of the function pointers needed to implement
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600471 * cipher operations using secure elements.
Gilles Peskine75976892018-12-12 15:55:09 +0100472 *
473 * PSA Crypto API implementations should populate instances of the table as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600474 * appropriate upon startup or at build time.
Gilles Peskine75976892018-12-12 15:55:09 +0100475 *
476 * If one of the functions is not implemented (such as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600477 * `psa_drv_se_cipher_ecb_t`), it should be set to NULL.
Gilles Peskine75976892018-12-12 15:55:09 +0100478 */
479typedef struct {
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600480 /** The size in bytes of the hardware-specific secure element cipher
481 * context structure
Gilles Peskine75976892018-12-12 15:55:09 +0100482 */
Derek Miller34b33f12019-02-15 17:13:54 -0600483 size_t context_size;
484 /** Function that performs a cipher setup operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600485 psa_drv_se_cipher_setup_t p_setup;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600486 /** Function that sets a cipher IV (if necessary) */
Derek Millerea743cf2019-02-15 17:06:29 -0600487 psa_drv_se_cipher_set_iv_t p_set_iv;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600488 /** Function that performs a cipher update operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600489 psa_drv_se_cipher_update_t p_update;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600490 /** Function that completes a cipher operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600491 psa_drv_se_cipher_finish_t p_finish;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600492 /** Function that aborts a cipher operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600493 psa_drv_se_cipher_abort_t p_abort;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600494 /** Function that performs ECB mode for a cipher operation
Gilles Peskine75976892018-12-12 15:55:09 +0100495 * (Danger: ECB mode should not be used directly by clients of the PSA
496 * Crypto Client API)
497 */
Derek Millerea743cf2019-02-15 17:06:29 -0600498 psa_drv_se_cipher_ecb_t p_ecb;
Derek Miller83d26622019-02-15 16:41:22 -0600499} psa_drv_se_cipher_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100500
501/**@}*/
502
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600503/** \defgroup se_asymmetric Secure Element Asymmetric Cryptography
Gilles Peskine75976892018-12-12 15:55:09 +0100504 *
505 * Since the amount of data that can (or should) be encrypted or signed using
506 * asymmetric keys is limited by the key size, asymmetric key operations using
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600507 * keys in a secure element must be done in single function calls.
Gilles Peskine75976892018-12-12 15:55:09 +0100508 */
509/**@{*/
510
511/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600512 * \brief A function that signs a hash or short message with a private key in
513 * a secure element
Gilles Peskine75976892018-12-12 15:55:09 +0100514 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200515 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100516 * \param[in] key_slot Key slot of an asymmetric key pair
517 * \param[in] alg A signature algorithm that is compatible
518 * with the type of `key`
519 * \param[in] p_hash The hash to sign
520 * \param[in] hash_length Size of the `p_hash` buffer in bytes
521 * \param[out] p_signature Buffer where the signature is to be written
522 * \param[in] signature_size Size of the `p_signature` buffer in bytes
523 * \param[out] p_signature_length On success, the number of bytes
524 * that make up the returned signature value
525 *
526 * \retval PSA_SUCCESS
527 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200528typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_drv_se_context_t *drv_context,
529 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600530 psa_algorithm_t alg,
531 const uint8_t *p_hash,
532 size_t hash_length,
533 uint8_t *p_signature,
534 size_t signature_size,
535 size_t *p_signature_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100536
537/**
538 * \brief A function that verifies the signature a hash or short message using
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600539 * an asymmetric public key in a secure element
Gilles Peskine75976892018-12-12 15:55:09 +0100540 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200541 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100542 * \param[in] key_slot Key slot of a public key or an asymmetric key
543 * pair
544 * \param[in] alg A signature algorithm that is compatible with
545 * the type of `key`
546 * \param[in] p_hash The hash whose signature is to be verified
547 * \param[in] hash_length Size of the `p_hash` buffer in bytes
548 * \param[in] p_signature Buffer containing the signature to verify
549 * \param[in] signature_length Size of the `p_signature` buffer in bytes
550 *
551 * \retval PSA_SUCCESS
552 * The signature is valid.
553 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200554typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_drv_se_context_t *drv_context,
555 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600556 psa_algorithm_t alg,
557 const uint8_t *p_hash,
558 size_t hash_length,
559 const uint8_t *p_signature,
560 size_t signature_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100561
562/**
563 * \brief A function that encrypts a short message with an asymmetric public
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600564 * key in a secure element
Gilles Peskine75976892018-12-12 15:55:09 +0100565 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200566 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100567 * \param[in] key_slot Key slot of a public key or an asymmetric key
568 * pair
569 * \param[in] alg An asymmetric encryption algorithm that is
570 * compatible with the type of `key`
571 * \param[in] p_input The message to encrypt
572 * \param[in] input_length Size of the `p_input` buffer in bytes
573 * \param[in] p_salt A salt or label, if supported by the
574 * encryption algorithm
575 * If the algorithm does not support a
576 * salt, pass `NULL`.
577 * If the algorithm supports an optional
578 * salt and you do not want to pass a salt,
579 * pass `NULL`.
580 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
581 * supported.
582 * \param[in] salt_length Size of the `p_salt` buffer in bytes
583 * If `p_salt` is `NULL`, pass 0.
584 * \param[out] p_output Buffer where the encrypted message is to
585 * be written
586 * \param[in] output_size Size of the `p_output` buffer in bytes
587 * \param[out] p_output_length On success, the number of bytes that make up
588 * the returned output
589 *
590 * \retval PSA_SUCCESS
591 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200592typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t *drv_context,
593 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600594 psa_algorithm_t alg,
595 const uint8_t *p_input,
596 size_t input_length,
597 const uint8_t *p_salt,
598 size_t salt_length,
599 uint8_t *p_output,
600 size_t output_size,
601 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100602
603/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600604 * \brief A function that decrypts a short message with an asymmetric private
605 * key in a secure element.
Gilles Peskine75976892018-12-12 15:55:09 +0100606 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200607 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100608 * \param[in] key_slot Key slot of an asymmetric key pair
609 * \param[in] alg An asymmetric encryption algorithm that is
610 * compatible with the type of `key`
611 * \param[in] p_input The message to decrypt
612 * \param[in] input_length Size of the `p_input` buffer in bytes
613 * \param[in] p_salt A salt or label, if supported by the
614 * encryption algorithm
615 * If the algorithm does not support a
616 * salt, pass `NULL`.
617 * If the algorithm supports an optional
618 * salt and you do not want to pass a salt,
619 * pass `NULL`.
620 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
621 * supported.
622 * \param[in] salt_length Size of the `p_salt` buffer in bytes
623 * If `p_salt` is `NULL`, pass 0.
624 * \param[out] p_output Buffer where the decrypted message is to
625 * be written
626 * \param[in] output_size Size of the `p_output` buffer in bytes
627 * \param[out] p_output_length On success, the number of bytes
628 * that make up the returned output
629 *
630 * \retval PSA_SUCCESS
631 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200632typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_drv_se_context_t *drv_context,
633 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600634 psa_algorithm_t alg,
635 const uint8_t *p_input,
636 size_t input_length,
637 const uint8_t *p_salt,
638 size_t salt_length,
639 uint8_t *p_output,
640 size_t output_size,
641 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100642
643/**
644 * \brief A struct containing all of the function pointers needed to implement
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600645 * asymmetric cryptographic operations using secure elements.
Gilles Peskine75976892018-12-12 15:55:09 +0100646 *
647 * PSA Crypto API implementations should populate instances of the table as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600648 * appropriate upon startup or at build time.
Gilles Peskine75976892018-12-12 15:55:09 +0100649 *
650 * If one of the functions is not implemented, it should be set to NULL.
651 */
652typedef struct {
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600653 /** Function that performs an asymmetric sign operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600654 psa_drv_se_asymmetric_sign_t p_sign;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600655 /** Function that performs an asymmetric verify operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600656 psa_drv_se_asymmetric_verify_t p_verify;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600657 /** Function that performs an asymmetric encrypt operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600658 psa_drv_se_asymmetric_encrypt_t p_encrypt;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600659 /** Function that performs an asymmetric decrypt operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600660 psa_drv_se_asymmetric_decrypt_t p_decrypt;
Derek Miller83d26622019-02-15 16:41:22 -0600661} psa_drv_se_asymmetric_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100662
663/**@}*/
664
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600665/** \defgroup se_aead Secure Element Authenticated Encryption with Additional Data
666 * Authenticated Encryption with Additional Data (AEAD) operations with secure
667 * elements must be done in one function call. While this creates a burden for
Gilles Peskine75976892018-12-12 15:55:09 +0100668 * implementers as there must be sufficient space in memory for the entire
669 * message, it prevents decrypted data from being made available before the
670 * authentication operation is complete and the data is known to be authentic.
671 */
672/**@{*/
673
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600674/** \brief A function that performs a secure element authenticated encryption
675 * operation
Gilles Peskine75976892018-12-12 15:55:09 +0100676 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200677 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100678 * \param[in] key_slot Slot containing the key to use.
679 * \param[in] algorithm The AEAD algorithm to compute
680 * (\c PSA_ALG_XXX value such that
681 * #PSA_ALG_IS_AEAD(`alg`) is true)
682 * \param[in] p_nonce Nonce or IV to use
683 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
684 * \param[in] p_additional_data Additional data that will be
685 * authenticated but not encrypted
686 * \param[in] additional_data_length Size of `p_additional_data` in bytes
687 * \param[in] p_plaintext Data that will be authenticated and
688 * encrypted
689 * \param[in] plaintext_length Size of `p_plaintext` in bytes
690 * \param[out] p_ciphertext Output buffer for the authenticated and
691 * encrypted data. The additional data is
692 * not part of this output. For algorithms
693 * where the encrypted data and the
694 * authentication tag are defined as
695 * separate outputs, the authentication
696 * tag is appended to the encrypted data.
697 * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in
698 * bytes
699 * \param[out] p_ciphertext_length On success, the size of the output in
700 * the `p_ciphertext` buffer
701 *
702 * \retval #PSA_SUCCESS
703 * Success.
704 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200705typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_drv_se_context_t *drv_context,
706 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600707 psa_algorithm_t algorithm,
708 const uint8_t *p_nonce,
709 size_t nonce_length,
710 const uint8_t *p_additional_data,
711 size_t additional_data_length,
712 const uint8_t *p_plaintext,
713 size_t plaintext_length,
714 uint8_t *p_ciphertext,
715 size_t ciphertext_size,
716 size_t *p_ciphertext_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100717
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600718/** A function that peforms a secure element authenticated decryption operation
Gilles Peskine75976892018-12-12 15:55:09 +0100719 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200720 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100721 * \param[in] key_slot Slot containing the key to use
722 * \param[in] algorithm The AEAD algorithm to compute
723 * (\c PSA_ALG_XXX value such that
724 * #PSA_ALG_IS_AEAD(`alg`) is true)
725 * \param[in] p_nonce Nonce or IV to use
726 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
727 * \param[in] p_additional_data Additional data that has been
728 * authenticated but not encrypted
729 * \param[in] additional_data_length Size of `p_additional_data` in bytes
730 * \param[in] p_ciphertext Data that has been authenticated and
731 * encrypted.
732 * For algorithms where the encrypted data
733 * and the authentication tag are defined
734 * as separate inputs, the buffer must
735 * contain the encrypted data followed by
736 * the authentication tag.
737 * \param[in] ciphertext_length Size of `p_ciphertext` in bytes
738 * \param[out] p_plaintext Output buffer for the decrypted data
739 * \param[in] plaintext_size Size of the `p_plaintext` buffer in
740 * bytes
741 * \param[out] p_plaintext_length On success, the size of the output in
742 * the `p_plaintext` buffer
743 *
744 * \retval #PSA_SUCCESS
745 * Success.
746 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200747typedef psa_status_t (*psa_drv_se_aead_decrypt_t)(psa_drv_se_context_t *drv_context,
748 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600749 psa_algorithm_t algorithm,
750 const uint8_t *p_nonce,
751 size_t nonce_length,
752 const uint8_t *p_additional_data,
753 size_t additional_data_length,
754 const uint8_t *p_ciphertext,
755 size_t ciphertext_length,
756 uint8_t *p_plaintext,
757 size_t plaintext_size,
758 size_t *p_plaintext_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100759
760/**
761 * \brief A struct containing all of the function pointers needed to implement
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600762 * secure element Authenticated Encryption with Additional Data operations
Gilles Peskine75976892018-12-12 15:55:09 +0100763 *
764 * PSA Crypto API implementations should populate instances of the table as
765 * appropriate upon startup.
766 *
767 * If one of the functions is not implemented, it should be set to NULL.
768 */
769typedef struct {
770 /** Function that performs the AEAD encrypt operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600771 psa_drv_se_aead_encrypt_t p_encrypt;
Gilles Peskine75976892018-12-12 15:55:09 +0100772 /** Function that performs the AEAD decrypt operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600773 psa_drv_se_aead_decrypt_t p_decrypt;
Derek Miller83d26622019-02-15 16:41:22 -0600774} psa_drv_se_aead_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100775/**@}*/
776
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600777/** \defgroup se_key_management Secure Element Key Management
Gilles Peskine75976892018-12-12 15:55:09 +0100778 * Currently, key management is limited to importing keys in the clear,
779 * destroying keys, and exporting keys in the clear.
780 * Whether a key may be exported is determined by the key policies in place
781 * on the key slot.
782 */
783/**@{*/
784
Gilles Peskinef2223c82019-07-12 23:33:02 +0200785/* This type is documented in crypto.h. As far as drivers are concerned,
786 * this is an opaque type. */
787typedef struct psa_key_attributes_s psa_key_attributes_t;
788
789/** \brief A function that allocates a slot for a key.
790 *
791 * \param[in,out] drv_context The driver context structure.
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200792 * \param[in,out] persistent_data A pointer to the persistent data
793 * that allows writing.
Gilles Peskinef2223c82019-07-12 23:33:02 +0200794 * \param[in] attributes Attributes of the key.
795 * \param[out] key_slot Slot where the key will be stored.
796 * This must be a valid slot for a key of the
797 * chosen type. It must be unoccupied.
798 *
799 * \retval #PSA_SUCCESS
800 * Success.
801 * The core will record \c *key_slot as the key slot where the key
802 * is stored and will update the persistent data in storage.
803 * \retval #PSA_ERROR_NOT_SUPPORTED
804 * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
805 */
806typedef psa_status_t (*psa_drv_se_allocate_key_t)(
807 psa_drv_se_context_t *drv_context,
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200808 void *persistent_data,
Gilles Peskinef2223c82019-07-12 23:33:02 +0200809 const psa_key_attributes_t *attributes,
810 psa_key_slot_number_t *key_slot);
811
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600812/** \brief A function that imports a key into a secure element in binary format
Gilles Peskine75976892018-12-12 15:55:09 +0100813 *
814 * This function can support any output from psa_export_key(). Refer to the
815 * documentation of psa_export_key() for the format for each key type.
816 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200817 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100818 * \param[in] key_slot Slot where the key will be stored
819 * This must be a valid slot for a key of the chosen
820 * type. It must be unoccupied.
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600821 * \param[in] lifetime The required lifetime of the key storage
Gilles Peskine75976892018-12-12 15:55:09 +0100822 * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value)
823 * \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value)
824 * \param[in] usage The allowed uses of the key
825 * \param[in] p_data Buffer containing the key data
826 * \param[in] data_length Size of the `data` buffer in bytes
827 *
828 * \retval #PSA_SUCCESS
829 * Success.
830 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200831typedef psa_status_t (*psa_drv_se_import_key_t)(psa_drv_se_context_t *drv_context,
832 psa_key_slot_number_t key_slot,
Derek Miller0972fe52019-02-15 17:08:27 -0600833 psa_key_lifetime_t lifetime,
Derek Miller83d26622019-02-15 16:41:22 -0600834 psa_key_type_t type,
835 psa_algorithm_t algorithm,
836 psa_key_usage_t usage,
837 const uint8_t *p_data,
838 size_t data_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100839
840/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600841 * \brief A function that destroys a secure element key and restore the slot to
842 * its default state
Gilles Peskine75976892018-12-12 15:55:09 +0100843 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600844 * This function destroys the content of the key from a secure element.
845 * Implementations shall make a best effort to ensure that any previous content
846 * of the slot is unrecoverable.
Gilles Peskine75976892018-12-12 15:55:09 +0100847 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600848 * This function returns the specified slot to its default state.
Gilles Peskine75976892018-12-12 15:55:09 +0100849 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200850 * \param[in,out] drv_context The driver context structure.
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200851 * \param[in,out] persistent_data A pointer to the persistent data
852 * that allows writing.
Gilles Peskine8597bc12019-07-12 23:28:46 +0200853 * \param key_slot The key slot to erase.
Gilles Peskine75976892018-12-12 15:55:09 +0100854 *
855 * \retval #PSA_SUCCESS
856 * The slot's content, if any, has been erased.
857 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200858typedef psa_status_t (*psa_drv_se_destroy_key_t)(
859 psa_drv_se_context_t *drv_context,
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200860 void *persistent_data,
Gilles Peskine8597bc12019-07-12 23:28:46 +0200861 psa_key_slot_number_t key_slot);
Gilles Peskine75976892018-12-12 15:55:09 +0100862
863/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600864 * \brief A function that exports a secure element key in binary format
Gilles Peskine75976892018-12-12 15:55:09 +0100865 *
866 * The output of this function can be passed to psa_import_key() to
867 * create an equivalent object.
868 *
869 * If a key is created with `psa_import_key()` and then exported with
870 * this function, it is not guaranteed that the resulting data is
871 * identical: the implementation may choose a different representation
872 * of the same key if the format permits it.
873 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600874 * This function should generate output in the same format that
875 * `psa_export_key()` does. Refer to the
876 * documentation of `psa_export_key()` for the format for each key type.
Gilles Peskine75976892018-12-12 15:55:09 +0100877 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200878 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100879 * \param[in] key Slot whose content is to be exported. This must
880 * be an occupied key slot.
881 * \param[out] p_data Buffer where the key data is to be written.
882 * \param[in] data_size Size of the `p_data` buffer in bytes.
883 * \param[out] p_data_length On success, the number of bytes
884 * that make up the key data.
885 *
886 * \retval #PSA_SUCCESS
David Saadab4ecc272019-02-14 13:48:10 +0200887 * \retval #PSA_ERROR_DOES_NOT_EXIST
Gilles Peskine75976892018-12-12 15:55:09 +0100888 * \retval #PSA_ERROR_NOT_PERMITTED
889 * \retval #PSA_ERROR_NOT_SUPPORTED
890 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
891 * \retval #PSA_ERROR_HARDWARE_FAILURE
Gilles Peskine4b3eb692019-05-16 21:35:18 +0200892 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Gilles Peskine75976892018-12-12 15:55:09 +0100893 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200894typedef psa_status_t (*psa_drv_se_export_key_t)(psa_drv_se_context_t *drv_context,
895 psa_key_slot_number_t key,
Derek Miller83d26622019-02-15 16:41:22 -0600896 uint8_t *p_data,
897 size_t data_size,
898 size_t *p_data_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100899
900/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600901 * \brief A function that generates a symmetric or asymmetric key on a secure
902 * element
Gilles Peskine75976892018-12-12 15:55:09 +0100903 *
Gilles Peskine9dd125d2019-07-23 18:26:43 +0200904 * If \p type is asymmetric (#PSA_KEY_TYPE_IS_ASYMMETRIC(\p type) = 1),
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600905 * the public component of the generated key will be placed in `p_pubkey_out`.
906 * The format of the public key information will match the format specified for
Gilles Peskinee5c025c2019-03-06 18:01:43 +0100907 * the psa_export_key() function for the key type.
Gilles Peskine75976892018-12-12 15:55:09 +0100908 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200909 * \param[in,out] drv_context The driver context structure.
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600910 * \param[in] key_slot Slot where the generated key will be placed
911 * \param[in] type The type of the key to be generated
912 * \param[in] usage The prescribed usage of the generated key
Gilles Peskinec3044a62019-03-06 17:56:28 +0100913 * Note: Not all Secure Elements support the same
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600914 * restrictions that PSA Crypto does (and vice versa).
915 * Driver developers should endeavor to match the
916 * usages as close as possible.
917 * \param[in] bits The size in bits of the key to be generated.
918 * \param[in] extra Extra parameters for key generation. The
919 * interpretation of this parameter should match the
920 * interpretation in the `extra` parameter is the
Gilles Peskine35ef36b2019-05-16 19:42:05 +0200921 * `psa_generate_key` function
Gilles Peskinee5c025c2019-03-06 18:01:43 +0100922 * \param[in] extra_size The size in bytes of the \p extra buffer
Gilles Peskinec3044a62019-03-06 17:56:28 +0100923 * \param[out] p_pubkey_out The buffer where the public key information will
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600924 * be placed
925 * \param[in] pubkey_out_size The size in bytes of the `p_pubkey_out` buffer
926 * \param[out] p_pubkey_length Upon successful completion, will contain the
927 * size of the data placed in `p_pubkey_out`.
Gilles Peskine75976892018-12-12 15:55:09 +0100928 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200929typedef psa_status_t (*psa_drv_se_generate_key_t)(psa_drv_se_context_t *drv_context,
930 psa_key_slot_number_t key_slot,
Gilles Peskine32668ce2019-03-06 18:29:57 +0100931 psa_key_type_t type,
932 psa_key_usage_t usage,
933 size_t bits,
934 const void *extra,
935 size_t extra_size,
936 uint8_t *p_pubkey_out,
937 size_t pubkey_out_size,
938 size_t *p_pubkey_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100939
940/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600941 * \brief A struct containing all of the function pointers needed to for secure
942 * element key management
Gilles Peskine75976892018-12-12 15:55:09 +0100943 *
944 * PSA Crypto API implementations should populate instances of the table as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600945 * appropriate upon startup or at build time.
Gilles Peskine75976892018-12-12 15:55:09 +0100946 *
947 * If one of the functions is not implemented, it should be set to NULL.
948 */
949typedef struct {
Gilles Peskinef2223c82019-07-12 23:33:02 +0200950 /** Function that allocates a slot. */
951 psa_drv_se_allocate_key_t p_allocate;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600952 /** Function that performs a key import operation */
953 psa_drv_se_import_key_t p_import;
954 /** Function that performs a generation */
Derek Miller0b3098a2019-02-15 17:10:49 -0600955 psa_drv_se_generate_key_t p_generate;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600956 /** Function that performs a key destroy operation */
Derek Miller0b3098a2019-02-15 17:10:49 -0600957 psa_drv_se_destroy_key_t p_destroy;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600958 /** Function that performs a key export operation */
Derek Miller0b3098a2019-02-15 17:10:49 -0600959 psa_drv_se_export_key_t p_export;
Gilles Peskinee62b74e2019-06-25 15:25:09 +0200960 /** Function that performs a public key export operation */
961 psa_drv_se_export_key_t p_export_public;
Derek Miller83d26622019-02-15 16:41:22 -0600962} psa_drv_se_key_management_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100963
964/**@}*/
965
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600966/** \defgroup driver_derivation Secure Element Key Derivation and Agreement
Gilles Peskine75976892018-12-12 15:55:09 +0100967 * Key derivation is the process of generating new key material using an
968 * existing key and additional parameters, iterating through a basic
969 * cryptographic function, such as a hash.
970 * Key agreement is a part of cryptographic protocols that allows two parties
971 * to agree on the same key value, but starting from different original key
972 * material.
973 * The flows are similar, and the PSA Crypto Driver Model uses the same functions
974 * for both of the flows.
975 *
976 * There are two different final functions for the flows,
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600977 * `psa_drv_se_key_derivation_derive` and `psa_drv_se_key_derivation_export`.
978 * `psa_drv_se_key_derivation_derive` is used when the key material should be
979 * placed in a slot on the hardware and not exposed to the caller.
980 * `psa_drv_se_key_derivation_export` is used when the key material should be
981 * returned to the PSA Cryptographic API implementation.
Gilles Peskine75976892018-12-12 15:55:09 +0100982 *
983 * Different key derivation algorithms require a different number of inputs.
984 * Instead of having an API that takes as input variable length arrays, which
985 * can be problemmatic to manage on embedded platforms, the inputs are passed
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600986 * to the driver via a function, `psa_drv_se_key_derivation_collateral`, that
987 * is called multiple times with different `collateral_id`s. Thus, for a key
Gilles Peskine75976892018-12-12 15:55:09 +0100988 * derivation algorithm that required 3 paramter inputs, the flow would look
989 * something like:
990 * ~~~~~~~~~~~~~{.c}
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600991 * psa_drv_se_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes);
992 * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_0,
993 * p_collateral_0,
994 * collateral_0_size);
995 * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_1,
996 * p_collateral_1,
997 * collateral_1_size);
998 * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_2,
999 * p_collateral_2,
1000 * collateral_2_size);
1001 * psa_drv_se_key_derivation_derive();
Gilles Peskine75976892018-12-12 15:55:09 +01001002 * ~~~~~~~~~~~~~
1003 *
1004 * key agreement example:
1005 * ~~~~~~~~~~~~~{.c}
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001006 * psa_drv_se_key_derivation_setup(alg, source_key. dest_key_size_bytes);
1007 * psa_drv_se_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size);
1008 * psa_drv_se_key_derivation_export(p_session_key,
1009 * session_key_size,
1010 * &session_key_length);
Gilles Peskine75976892018-12-12 15:55:09 +01001011 * ~~~~~~~~~~~~~
1012 */
1013/**@{*/
1014
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001015/** \brief A function that Sets up a secure element key derivation operation by
1016 * specifying the algorithm and the source key sot
Gilles Peskine75976892018-12-12 15:55:09 +01001017 *
Gilles Peskine8597bc12019-07-12 23:28:46 +02001018 * \param[in,out] drv_context The driver context structure.
1019 * \param[in,out] op_context A hardware-specific structure containing any
Gilles Peskine75976892018-12-12 15:55:09 +01001020 * context information for the implementation
1021 * \param[in] kdf_alg The algorithm to be used for the key derivation
Gilles Peskine45a8ca32019-06-24 15:08:56 +02001022 * \param[in] source_key The key to be used as the source material for the
Gilles Peskine75976892018-12-12 15:55:09 +01001023 * key derivation
1024 *
1025 * \retval PSA_SUCCESS
1026 */
Gilles Peskine8597bc12019-07-12 23:28:46 +02001027typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *drv_context,
1028 void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -06001029 psa_algorithm_t kdf_alg,
Derek Millerb2a1cce2019-02-15 17:03:42 -06001030 psa_key_slot_number_t source_key);
Gilles Peskine75976892018-12-12 15:55:09 +01001031
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001032/** \brief A function that provides collateral (parameters) needed for a secure
1033 * element key derivation or key agreement operation
Gilles Peskine75976892018-12-12 15:55:09 +01001034 *
1035 * Since many key derivation algorithms require multiple parameters, it is
1036 * expeced that this function may be called multiple times for the same
1037 * operation, each with a different algorithm-specific `collateral_id`
1038 *
Gilles Peskine8597bc12019-07-12 23:28:46 +02001039 * \param[in,out] op_context A hardware-specific structure containing any
Gilles Peskine75976892018-12-12 15:55:09 +01001040 * context information for the implementation
1041 * \param[in] collateral_id An ID for the collateral being provided
1042 * \param[in] p_collateral A buffer containing the collateral data
1043 * \param[in] collateral_size The size in bytes of the collateral
1044 *
1045 * \retval PSA_SUCCESS
1046 */
Gilles Peskine8597bc12019-07-12 23:28:46 +02001047typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -06001048 uint32_t collateral_id,
1049 const uint8_t *p_collateral,
1050 size_t collateral_size);
Gilles Peskine75976892018-12-12 15:55:09 +01001051
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001052/** \brief A function that performs the final secure element key derivation
1053 * step and place the generated key material in a slot
Gilles Peskinec3044a62019-03-06 17:56:28 +01001054 *
Gilles Peskine8597bc12019-07-12 23:28:46 +02001055 * \param[in,out] op_context A hardware-specific structure containing any
Gilles Peskine75976892018-12-12 15:55:09 +01001056 * context information for the implementation
1057 * \param[in] dest_key The slot where the generated key material
1058 * should be placed
1059 *
1060 * \retval PSA_SUCCESS
1061 */
Gilles Peskine8597bc12019-07-12 23:28:46 +02001062typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *op_context,
Derek Miller62117262019-02-15 17:12:26 -06001063 psa_key_slot_number_t dest_key);
Gilles Peskine75976892018-12-12 15:55:09 +01001064
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001065/** \brief A function that performs the final step of a secure element key
1066 * agreement and place the generated key material in a buffer
Gilles Peskine75976892018-12-12 15:55:09 +01001067 *
1068 * \param[out] p_output Buffer in which to place the generated key
1069 * material
1070 * \param[in] output_size The size in bytes of `p_output`
1071 * \param[out] p_output_length Upon success, contains the number of bytes of
1072 * key material placed in `p_output`
1073 *
1074 * \retval PSA_SUCCESS
1075 */
Gilles Peskine8597bc12019-07-12 23:28:46 +02001076typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *op_context,
Derek Miller62117262019-02-15 17:12:26 -06001077 uint8_t *p_output,
1078 size_t output_size,
1079 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +01001080
1081/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001082 * \brief A struct containing all of the function pointers needed to for secure
1083 * element key derivation and agreement
Gilles Peskine75976892018-12-12 15:55:09 +01001084 *
1085 * PSA Crypto API implementations should populate instances of the table as
1086 * appropriate upon startup.
1087 *
1088 * If one of the functions is not implemented, it should be set to NULL.
1089 */
1090typedef struct {
Derek Miller62117262019-02-15 17:12:26 -06001091 /** The driver-specific size of the key derivation context */
1092 size_t context_size;
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001093 /** Function that performs a key derivation setup */
Derek Millerea743cf2019-02-15 17:06:29 -06001094 psa_drv_se_key_derivation_setup_t p_setup;
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001095 /** Function that sets key derivation collateral */
Derek Millerea743cf2019-02-15 17:06:29 -06001096 psa_drv_se_key_derivation_collateral_t p_collateral;
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001097 /** Function that performs a final key derivation step */
Derek Millerea743cf2019-02-15 17:06:29 -06001098 psa_drv_se_key_derivation_derive_t p_derive;
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001099 /** Function that perforsm a final key derivation or agreement and
Gilles Peskine75976892018-12-12 15:55:09 +01001100 * exports the key */
Derek Millerea743cf2019-02-15 17:06:29 -06001101 psa_drv_se_key_derivation_export_t p_export;
Derek Miller83d26622019-02-15 16:41:22 -06001102} psa_drv_se_key_derivation_t;
Gilles Peskine75976892018-12-12 15:55:09 +01001103
1104/**@}*/
1105
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001106/** \defgroup se_registration Secure element driver registration
1107 */
1108/**@{*/
1109
1110/** A structure containing pointers to all the entry points of a
1111 * secure element driver.
1112 *
1113 * Future versions of this specification may add extra substructures at
1114 * the end of this structure.
1115 */
1116typedef struct {
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001117 /** The version of the driver HAL that this driver implements.
1118 * This is a protection against loading driver binaries built against
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001119 * a different version of this specification.
1120 * Use #PSA_DRV_SE_HAL_VERSION.
1121 */
1122 uint32_t hal_version;
Gilles Peskine7a86da12019-07-12 23:25:38 +02001123
1124 /** The size of the driver's persistent data in bytes. */
1125 size_t persistent_data_size;
1126
1127 /** The driver initialization function.
1128 *
1129 * This function is called once during the initialization of the
1130 * PSA Cryptography subsystem, before any other function of the
1131 * driver is called. If this function returns a failure status,
1132 * the driver will be unusable, at least until the next system reset.
1133 *
1134 * If this field is \c NULL, it is equivalent to a function that does
1135 * nothing and returns #PSA_SUCCESS.
1136 */
1137 psa_drv_se_init_t p_init;
1138
Gilles Peskine6e59c422019-06-26 19:06:52 +02001139 const psa_drv_se_key_management_t *key_management;
1140 const psa_drv_se_mac_t *mac;
1141 const psa_drv_se_cipher_t *cipher;
1142 const psa_drv_se_aead_t *aead;
1143 const psa_drv_se_asymmetric_t *asymmetric;
1144 const psa_drv_se_key_derivation_t *derivation;
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001145} psa_drv_se_t;
1146
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001147/** The current version of the secure element driver HAL.
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001148 */
1149/* 0.0.0 patchlevel 5 */
1150#define PSA_DRV_SE_HAL_VERSION 0x00000005
1151
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001152/** Register an external cryptoprocessor (secure element) driver.
Gilles Peskined910e922019-06-24 13:47:07 +02001153 *
1154 * This function is only intended to be used by driver code, not by
1155 * application code. In implementations with separation between the
1156 * PSA cryptography module and applications, this function should
1157 * only be available to callers that run in the same memory space as
1158 * the cryptography module, and should not be exposed to applications
1159 * running in a different memory space.
1160 *
1161 * This function may be called before psa_crypto_init(). It is
1162 * implementation-defined whether this function may be called
1163 * after psa_crypto_init().
1164 *
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001165 * \note Implementations store metadata about keys including the lifetime
1166 * value. Therefore, from one instantiation of the PSA Cryptography
1167 * library to the next one, if there is a key in storage with a certain
1168 * lifetime value, you must always register the same driver (or an
1169 * updated version that communicates with the same secure element)
1170 * with the same lifetime value.
1171 *
Gilles Peskined910e922019-06-24 13:47:07 +02001172 * \param lifetime The lifetime value through which this driver will
1173 * be exposed to applications.
1174 * The values #PSA_KEY_LIFETIME_VOLATILE and
1175 * #PSA_KEY_LIFETIME_PERSISTENT are reserved and
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001176 * may not be used for drivers. Implementations
Gilles Peskined910e922019-06-24 13:47:07 +02001177 * may reserve other values.
1178 * \param[in] methods The method table of the driver. This structure must
1179 * remain valid for as long as the cryptography
1180 * module keeps running. It is typically a global
1181 * constant.
1182 *
1183 * \return PSA_SUCCESS
1184 * The driver was successfully registered. Applications can now
1185 * use \p lifetime to access keys through the methods passed to
1186 * this function.
1187 * \return PSA_ERROR_BAD_STATE
1188 * This function was called after the initialization of the
1189 * cryptography module, and this implementation does not support
1190 * driver registration at this stage.
1191 * \return PSA_ERROR_ALREADY_EXISTS
1192 * There is already a registered driver for this value of \p lifetime.
1193 * \return PSA_ERROR_INVALID_ARGUMENT
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001194 * \p lifetime is a reserved value.
Gilles Peskined910e922019-06-24 13:47:07 +02001195 * \return PSA_ERROR_NOT_SUPPORTED
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001196 * `methods->hal_version` is not supported by this implementation.
Gilles Peskined910e922019-06-24 13:47:07 +02001197 * \return PSA_ERROR_INSUFFICIENT_MEMORY
1198 * \return PSA_ERROR_NOT_PERMITTED
1199 */
1200psa_status_t psa_register_se_driver(
1201 psa_key_lifetime_t lifetime,
1202 const psa_drv_se_t *methods);
1203
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001204/**@}*/
1205
Gilles Peskine75976892018-12-12 15:55:09 +01001206#ifdef __cplusplus
1207}
1208#endif
1209
1210#endif /* PSA_CRYPTO_SE_DRIVER_H */