blob: bdc038e880563b03c12ae035419b5ee66a14dfb0 [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 *
66 * The size of this buffer is given by psa_drv_se_t::persistent_data_size
67 * when the driver is registered, and this value is also recorded in the
68 * ::persistent_data_size field of this structure.
69 *
70 * Before the driver is initialized for the first time, the content of
71 * the persistent data is all-bits-zero. After a driver upgrade, if the
72 * size of the persistent data has increased, the original data is padded
73 * on the right with zeros; if the size has decreased, the original data
74 * is truncated to the new size.
75 *
76 * This pointer is to read-only data. Only a few driver functions are
77 * allowed to modify the persistent data. These functions receive a
78 * writable pointer.
79 */
80 const void *const persistent_data;
81
82 /** The size of \c persistent_data in bytes.
83 *
84 * This is always equal to the value of
85 * psa_drv_se_t::persistent_data_size when the driver is registered.
86 */
87 const size_t persistent_data_size;
88
89 /** Driver transient data.
90 *
91 * The core initializes this value to 0 and does not read or modify it
92 * afterwards. The driver may store whatever it wants in this field.
93 */
94 uintptr_t transient_data;
95} psa_drv_se_context_t;
96
97/** \brief A driver initialization function.
98 *
99 * \param[in,out] drv_context The driver context structure.
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200100 * \param[in,out] persistent_data A pointer to the persistent data
101 * that allows writing.
Gilles Peskine7a86da12019-07-12 23:25:38 +0200102 * \param lifetime The lifetime value for which this driver
103 * is registered.
104 *
105 * \retval #PSA_SUCCESS
106 * The driver is operational.
107 * The core will update the persistent data in storage.
108 * \return
109 * Any other return value prevents the driver from being used in
110 * this session.
111 * The core will NOT update the persistent data in storage.
112 */
113typedef psa_status_t (*psa_drv_se_init_t)(psa_drv_se_context_t *drv_context,
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200114 void *persistent_data,
Gilles Peskine7a86da12019-07-12 23:25:38 +0200115 psa_key_lifetime_t lifetime);
116
Gilles Peskine75976892018-12-12 15:55:09 +0100117/** An internal designation of a key slot between the core part of the
118 * PSA Crypto implementation and the driver. The meaning of this value
119 * is driver-dependent. */
Gilles Peskinef03143a2019-07-12 23:18:29 +0200120typedef uint64_t psa_key_slot_number_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100121
Gilles Peskine7a86da12019-07-12 23:25:38 +0200122/**@}*/
123
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600124/** \defgroup se_mac Secure Element Message Authentication Codes
Gilles Peskine75976892018-12-12 15:55:09 +0100125 * Generation and authentication of Message Authentication Codes (MACs) using
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600126 * a secure element can be done either as a single function call (via the
127 * `psa_drv_se_mac_generate_t` or `psa_drv_se_mac_verify_t` functions), or in
Gilles Peskine75976892018-12-12 15:55:09 +0100128 * parts using the following sequence:
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600129 * - `psa_drv_se_mac_setup_t`
130 * - `psa_drv_se_mac_update_t`
131 * - `psa_drv_se_mac_update_t`
Gilles Peskine75976892018-12-12 15:55:09 +0100132 * - ...
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600133 * - `psa_drv_se_mac_finish_t` or `psa_drv_se_mac_finish_verify_t`
Gilles Peskine75976892018-12-12 15:55:09 +0100134 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600135 * If a previously started secure element MAC operation needs to be terminated,
136 * 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 +0100137 * result in allocated resources not being freed or in other undefined
138 * behavior.
139 */
140/**@{*/
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600141/** \brief A function that starts a secure element MAC operation for a PSA
142 * Crypto Driver implementation
Gilles Peskine75976892018-12-12 15:55:09 +0100143 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200144 * \param[in,out] drv_context The driver context structure.
145 * \param[in,out] op_context A structure that will contain the
Gilles Peskine75976892018-12-12 15:55:09 +0100146 * hardware-specific MAC context
147 * \param[in] key_slot The slot of the key to be used for the
148 * operation
149 * \param[in] algorithm The algorithm to be used to underly the MAC
150 * operation
151 *
152 * \retval PSA_SUCCESS
153 * Success.
154 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200155typedef psa_status_t (*psa_drv_se_mac_setup_t)(psa_drv_se_context_t *drv_context,
156 void *op_context,
Derek Millerb2a1cce2019-02-15 17:03:42 -0600157 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600158 psa_algorithm_t algorithm);
Gilles Peskine75976892018-12-12 15:55:09 +0100159
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600160/** \brief A function that continues a previously started secure element MAC
161 * operation
Gilles Peskine75976892018-12-12 15:55:09 +0100162 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200163 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100164 * previously-established MAC operation to be
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600165 * updated
Gilles Peskine75976892018-12-12 15:55:09 +0100166 * \param[in] p_input A buffer containing the message to be appended
167 * to the MAC operation
168 * \param[in] input_length The size in bytes of the input message buffer
169 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200170typedef psa_status_t (*psa_drv_se_mac_update_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600171 const uint8_t *p_input,
172 size_t input_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100173
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600174/** \brief a function that completes a previously started secure element MAC
175 * operation by returning the resulting MAC.
Gilles Peskine75976892018-12-12 15:55:09 +0100176 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200177 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100178 * previously started MAC operation to be
179 * finished
180 * \param[out] p_mac A buffer where the generated MAC will be
181 * placed
182 * \param[in] mac_size The size in bytes of the buffer that has been
183 * allocated for the `output` buffer
184 * \param[out] p_mac_length After completion, will contain the number of
185 * bytes placed in the `p_mac` buffer
186 *
187 * \retval PSA_SUCCESS
188 * Success.
189 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200190typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600191 uint8_t *p_mac,
192 size_t mac_size,
193 size_t *p_mac_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100194
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600195/** \brief A function that completes a previously started secure element MAC
196 * operation by comparing the resulting MAC against a provided value
Gilles Peskine75976892018-12-12 15:55:09 +0100197 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200198 * \param[in,out] op_context A hardware-specific structure for the previously
Gilles Peskine75976892018-12-12 15:55:09 +0100199 * started MAC operation to be fiinished
200 * \param[in] p_mac The MAC value against which the resulting MAC will
201 * be compared against
202 * \param[in] mac_length The size in bytes of the value stored in `p_mac`
203 *
204 * \retval PSA_SUCCESS
205 * The operation completed successfully and the MACs matched each
206 * other
207 * \retval PSA_ERROR_INVALID_SIGNATURE
208 * The operation completed successfully, but the calculated MAC did
209 * not match the provided MAC
210 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200211typedef psa_status_t (*psa_drv_se_mac_finish_verify_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600212 const uint8_t *p_mac,
213 size_t mac_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100214
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600215/** \brief A function that aborts a previous started secure element MAC
216 * operation
Gilles Peskine32668ce2019-03-06 18:29:57 +0100217 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200218 * \param[in,out] op_context A hardware-specific structure for the previously
Gilles Peskine75976892018-12-12 15:55:09 +0100219 * started MAC operation to be aborted
220 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200221typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *op_context);
Gilles Peskine75976892018-12-12 15:55:09 +0100222
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600223/** \brief A function that performs a secure element MAC operation in one
224 * command and returns the calculated MAC
Gilles Peskine75976892018-12-12 15:55:09 +0100225 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200226 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100227 * \param[in] p_input A buffer containing the message to be MACed
228 * \param[in] input_length The size in bytes of `p_input`
229 * \param[in] key_slot The slot of the key to be used
230 * \param[in] alg The algorithm to be used to underlie the MAC
231 * operation
232 * \param[out] p_mac A buffer where the generated MAC will be
233 * placed
234 * \param[in] mac_size The size in bytes of the `p_mac` buffer
235 * \param[out] p_mac_length After completion, will contain the number of
236 * bytes placed in the `output` buffer
237 *
238 * \retval PSA_SUCCESS
239 * Success.
240 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200241typedef psa_status_t (*psa_drv_se_mac_generate_t)(psa_drv_se_context_t *drv_context,
242 const uint8_t *p_input,
Derek Miller83d26622019-02-15 16:41:22 -0600243 size_t input_length,
Derek Millerb2a1cce2019-02-15 17:03:42 -0600244 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600245 psa_algorithm_t alg,
246 uint8_t *p_mac,
247 size_t mac_size,
248 size_t *p_mac_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100249
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600250/** \brief A function that performs a secure element MAC operation in one
251 * command and compares the resulting MAC against a provided value
Gilles Peskine75976892018-12-12 15:55:09 +0100252 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200253 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100254 * \param[in] p_input A buffer containing the message to be MACed
255 * \param[in] input_length The size in bytes of `input`
256 * \param[in] key_slot The slot of the key to be used
257 * \param[in] alg The algorithm to be used to underlie the MAC
258 * operation
259 * \param[in] p_mac The MAC value against which the resulting MAC will
260 * be compared against
261 * \param[in] mac_length The size in bytes of `mac`
262 *
263 * \retval PSA_SUCCESS
264 * The operation completed successfully and the MACs matched each
265 * other
266 * \retval PSA_ERROR_INVALID_SIGNATURE
267 * The operation completed successfully, but the calculated MAC did
268 * not match the provided MAC
269 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200270typedef psa_status_t (*psa_drv_se_mac_verify_t)(psa_drv_se_context_t *drv_context,
271 const uint8_t *p_input,
Derek Miller83d26622019-02-15 16:41:22 -0600272 size_t input_length,
Derek Millerb2a1cce2019-02-15 17:03:42 -0600273 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600274 psa_algorithm_t alg,
275 const uint8_t *p_mac,
276 size_t mac_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100277
278/** \brief A struct containing all of the function pointers needed to
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600279 * perform secure element MAC operations
Gilles Peskine75976892018-12-12 15:55:09 +0100280 *
281 * PSA Crypto API implementations should populate the table as appropriate
282 * upon startup.
283 *
284 * If one of the functions is not implemented (such as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600285 * `psa_drv_se_mac_generate_t`), it should be set to NULL.
Gilles Peskine75976892018-12-12 15:55:09 +0100286 *
287 * Driver implementers should ensure that they implement all of the functions
288 * that make sense for their hardware, and that they provide a full solution
289 * (for example, if they support `p_setup`, they should also support
290 * `p_update` and at least one of `p_finish` or `p_finish_verify`).
291 *
292 */
293typedef struct {
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600294 /**The size in bytes of the hardware-specific secure element MAC context
295 * structure
Gilles Peskine75976892018-12-12 15:55:09 +0100296 */
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600297 size_t context_size;
298 /** Function that performs a MAC setup operation
Gilles Peskine75976892018-12-12 15:55:09 +0100299 */
Derek Millerea743cf2019-02-15 17:06:29 -0600300 psa_drv_se_mac_setup_t p_setup;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600301 /** Function that performs a MAC update operation
Gilles Peskine75976892018-12-12 15:55:09 +0100302 */
Derek Millerea743cf2019-02-15 17:06:29 -0600303 psa_drv_se_mac_update_t p_update;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600304 /** Function that completes a MAC operation
Gilles Peskine75976892018-12-12 15:55:09 +0100305 */
Derek Millerea743cf2019-02-15 17:06:29 -0600306 psa_drv_se_mac_finish_t p_finish;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600307 /** Function that completes a MAC operation with a verify check
Gilles Peskine75976892018-12-12 15:55:09 +0100308 */
Derek Millerea743cf2019-02-15 17:06:29 -0600309 psa_drv_se_mac_finish_verify_t p_finish_verify;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600310 /** Function that aborts a previoustly started MAC operation
Gilles Peskine75976892018-12-12 15:55:09 +0100311 */
Derek Millerea743cf2019-02-15 17:06:29 -0600312 psa_drv_se_mac_abort_t p_abort;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600313 /** Function that performs a MAC operation in one call
Gilles Peskine75976892018-12-12 15:55:09 +0100314 */
Derek Millerea743cf2019-02-15 17:06:29 -0600315 psa_drv_se_mac_generate_t p_mac;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600316 /** Function that performs a MAC and verify operation in one call
Gilles Peskine75976892018-12-12 15:55:09 +0100317 */
Derek Millerea743cf2019-02-15 17:06:29 -0600318 psa_drv_se_mac_verify_t p_mac_verify;
Derek Miller83d26622019-02-15 16:41:22 -0600319} psa_drv_se_mac_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100320/**@}*/
321
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600322/** \defgroup se_cipher Secure Element Symmetric Ciphers
Gilles Peskine75976892018-12-12 15:55:09 +0100323 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600324 * Encryption and Decryption using secure element keys in block modes other
325 * than ECB must be done in multiple parts, using the following flow:
326 * - `psa_drv_se_cipher_setup_t`
327 * - `psa_drv_se_cipher_set_iv_t` (optional depending upon block mode)
328 * - `psa_drv_se_cipher_update_t`
329 * - `psa_drv_se_cipher_update_t`
Gilles Peskine75976892018-12-12 15:55:09 +0100330 * - ...
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600331 * - `psa_drv_se_cipher_finish_t`
Gilles Peskine32668ce2019-03-06 18:29:57 +0100332 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600333 * If a previously started secure element Cipher operation needs to be
334 * terminated, it should be done so by the `psa_drv_se_cipher_abort_t`. Failure
335 * to do so may result in allocated resources not being freed or in other
336 * undefined behavior.
Gilles Peskine75976892018-12-12 15:55:09 +0100337 *
338 * In situations where a PSA Cryptographic API implementation is using a block
339 * mode not-supported by the underlying hardware or driver, it can construct
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600340 * the block mode itself, while calling the `psa_drv_se_cipher_ecb_t` function
341 * for the cipher operations.
Gilles Peskine75976892018-12-12 15:55:09 +0100342 */
343/**@{*/
344
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600345/** \brief A function that provides the cipher setup function for a
346 * secure element driver
Gilles Peskine75976892018-12-12 15:55:09 +0100347 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200348 * \param[in,out] drv_context The driver context structure.
349 * \param[in,out] op_context A structure that will contain the
Gilles Peskine75976892018-12-12 15:55:09 +0100350 * hardware-specific cipher context.
351 * \param[in] key_slot The slot of the key to be used for the
352 * operation
353 * \param[in] algorithm The algorithm to be used in the cipher
354 * operation
355 * \param[in] direction Indicates whether the operation is an encrypt
356 * or decrypt
357 *
358 * \retval PSA_SUCCESS
359 * \retval PSA_ERROR_NOT_SUPPORTED
360 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200361typedef psa_status_t (*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t *drv_context,
362 void *op_context,
Derek Millerb2a1cce2019-02-15 17:03:42 -0600363 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600364 psa_algorithm_t algorithm,
365 psa_encrypt_or_decrypt_t direction);
Gilles Peskine75976892018-12-12 15:55:09 +0100366
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600367/** \brief A function that sets the initialization vector (if
368 * necessary) for an secure element cipher operation
Gilles Peskine75976892018-12-12 15:55:09 +0100369 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600370 * Rationale: The `psa_se_cipher_*` operation in the PSA Cryptographic API has
371 * two IV functions: one to set the IV, and one to generate it internally. The
Gilles Peskine75976892018-12-12 15:55:09 +0100372 * generate function is not necessary for the drivers to implement as the PSA
373 * Crypto implementation can do the generation using its RNG features.
374 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200375 * \param[in,out] op_context A structure that contains the previously set up
Gilles Peskine75976892018-12-12 15:55:09 +0100376 * hardware-specific cipher context
377 * \param[in] p_iv A buffer containing the initialization vector
378 * \param[in] iv_length The size (in bytes) of the `p_iv` buffer
379 *
380 * \retval PSA_SUCCESS
381 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200382typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600383 const uint8_t *p_iv,
384 size_t iv_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100385
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600386/** \brief A function that continues a previously started secure element cipher
Gilles Peskine75976892018-12-12 15:55:09 +0100387 * operation
388 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200389 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100390 * previously started cipher operation
391 * \param[in] p_input A buffer containing the data to be
392 * encrypted/decrypted
393 * \param[in] input_size The size in bytes of the buffer pointed to
394 * by `p_input`
395 * \param[out] p_output The caller-allocated buffer where the
396 * output will be placed
397 * \param[in] output_size The allocated size in bytes of the
398 * `p_output` buffer
399 * \param[out] p_output_length After completion, will contain the number
400 * of bytes placed in the `p_output` buffer
401 *
402 * \retval PSA_SUCCESS
403 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200404typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600405 const uint8_t *p_input,
406 size_t input_size,
407 uint8_t *p_output,
408 size_t output_size,
409 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100410
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600411/** \brief A function that completes a previously started secure element cipher
Gilles Peskine75976892018-12-12 15:55:09 +0100412 * operation
413 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200414 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100415 * previously started cipher operation
416 * \param[out] p_output The caller-allocated buffer where the output
417 * will be placed
418 * \param[in] output_size The allocated size in bytes of the `p_output`
419 * buffer
420 * \param[out] p_output_length After completion, will contain the number of
421 * bytes placed in the `p_output` buffer
422 *
423 * \retval PSA_SUCCESS
424 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200425typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -0600426 uint8_t *p_output,
427 size_t output_size,
428 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100429
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600430/** \brief A function that aborts a previously started secure element cipher
Gilles Peskine75976892018-12-12 15:55:09 +0100431 * operation
432 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200433 * \param[in,out] op_context A hardware-specific structure for the
Gilles Peskine75976892018-12-12 15:55:09 +0100434 * previously started cipher operation
435 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200436typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *op_context);
Gilles Peskine75976892018-12-12 15:55:09 +0100437
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600438/** \brief A function that performs the ECB block mode for secure element
439 * cipher operations
Gilles Peskine75976892018-12-12 15:55:09 +0100440 *
441 * Note: this function should only be used with implementations that do not
442 * provide a needed higher-level operation.
443 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200444 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100445 * \param[in] key_slot The slot of the key to be used for the operation
446 * \param[in] algorithm The algorithm to be used in the cipher operation
447 * \param[in] direction Indicates whether the operation is an encrypt or
448 * decrypt
449 * \param[in] p_input A buffer containing the data to be
450 * encrypted/decrypted
451 * \param[in] input_size The size in bytes of the buffer pointed to by
452 * `p_input`
453 * \param[out] p_output The caller-allocated buffer where the output will
454 * be placed
455 * \param[in] output_size The allocated size in bytes of the `p_output`
456 * buffer
457 *
458 * \retval PSA_SUCCESS
459 * \retval PSA_ERROR_NOT_SUPPORTED
460 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200461typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_drv_se_context_t *drv_context,
462 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600463 psa_algorithm_t algorithm,
464 psa_encrypt_or_decrypt_t direction,
465 const uint8_t *p_input,
466 size_t input_size,
467 uint8_t *p_output,
468 size_t output_size);
Gilles Peskine75976892018-12-12 15:55:09 +0100469
470/**
471 * \brief A struct containing all of the function pointers needed to implement
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600472 * cipher operations using secure elements.
Gilles Peskine75976892018-12-12 15:55:09 +0100473 *
474 * PSA Crypto API implementations should populate instances of the table as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600475 * appropriate upon startup or at build time.
Gilles Peskine75976892018-12-12 15:55:09 +0100476 *
477 * If one of the functions is not implemented (such as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600478 * `psa_drv_se_cipher_ecb_t`), it should be set to NULL.
Gilles Peskine75976892018-12-12 15:55:09 +0100479 */
480typedef struct {
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600481 /** The size in bytes of the hardware-specific secure element cipher
482 * context structure
Gilles Peskine75976892018-12-12 15:55:09 +0100483 */
Derek Miller34b33f12019-02-15 17:13:54 -0600484 size_t context_size;
485 /** Function that performs a cipher setup operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600486 psa_drv_se_cipher_setup_t p_setup;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600487 /** Function that sets a cipher IV (if necessary) */
Derek Millerea743cf2019-02-15 17:06:29 -0600488 psa_drv_se_cipher_set_iv_t p_set_iv;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600489 /** Function that performs a cipher update operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600490 psa_drv_se_cipher_update_t p_update;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600491 /** Function that completes a cipher operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600492 psa_drv_se_cipher_finish_t p_finish;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600493 /** Function that aborts a cipher operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600494 psa_drv_se_cipher_abort_t p_abort;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600495 /** Function that performs ECB mode for a cipher operation
Gilles Peskine75976892018-12-12 15:55:09 +0100496 * (Danger: ECB mode should not be used directly by clients of the PSA
497 * Crypto Client API)
498 */
Derek Millerea743cf2019-02-15 17:06:29 -0600499 psa_drv_se_cipher_ecb_t p_ecb;
Derek Miller83d26622019-02-15 16:41:22 -0600500} psa_drv_se_cipher_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100501
502/**@}*/
503
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600504/** \defgroup se_asymmetric Secure Element Asymmetric Cryptography
Gilles Peskine75976892018-12-12 15:55:09 +0100505 *
506 * Since the amount of data that can (or should) be encrypted or signed using
507 * asymmetric keys is limited by the key size, asymmetric key operations using
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600508 * keys in a secure element must be done in single function calls.
Gilles Peskine75976892018-12-12 15:55:09 +0100509 */
510/**@{*/
511
512/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600513 * \brief A function that signs a hash or short message with a private key in
514 * a secure element
Gilles Peskine75976892018-12-12 15:55:09 +0100515 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200516 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100517 * \param[in] key_slot Key slot of an asymmetric key pair
518 * \param[in] alg A signature algorithm that is compatible
519 * with the type of `key`
520 * \param[in] p_hash The hash to sign
521 * \param[in] hash_length Size of the `p_hash` buffer in bytes
522 * \param[out] p_signature Buffer where the signature is to be written
523 * \param[in] signature_size Size of the `p_signature` buffer in bytes
524 * \param[out] p_signature_length On success, the number of bytes
525 * that make up the returned signature value
526 *
527 * \retval PSA_SUCCESS
528 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200529typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_drv_se_context_t *drv_context,
530 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600531 psa_algorithm_t alg,
532 const uint8_t *p_hash,
533 size_t hash_length,
534 uint8_t *p_signature,
535 size_t signature_size,
536 size_t *p_signature_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100537
538/**
539 * \brief A function that verifies the signature a hash or short message using
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600540 * an asymmetric public key in a secure element
Gilles Peskine75976892018-12-12 15:55:09 +0100541 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200542 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100543 * \param[in] key_slot Key slot of a public key or an asymmetric key
544 * pair
545 * \param[in] alg A signature algorithm that is compatible with
546 * the type of `key`
547 * \param[in] p_hash The hash whose signature is to be verified
548 * \param[in] hash_length Size of the `p_hash` buffer in bytes
549 * \param[in] p_signature Buffer containing the signature to verify
550 * \param[in] signature_length Size of the `p_signature` buffer in bytes
551 *
552 * \retval PSA_SUCCESS
553 * The signature is valid.
554 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200555typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_drv_se_context_t *drv_context,
556 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600557 psa_algorithm_t alg,
558 const uint8_t *p_hash,
559 size_t hash_length,
560 const uint8_t *p_signature,
561 size_t signature_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100562
563/**
564 * \brief A function that encrypts a short message with an asymmetric public
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600565 * key in a secure element
Gilles Peskine75976892018-12-12 15:55:09 +0100566 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200567 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100568 * \param[in] key_slot Key slot of a public key or an asymmetric key
569 * pair
570 * \param[in] alg An asymmetric encryption algorithm that is
571 * compatible with the type of `key`
572 * \param[in] p_input The message to encrypt
573 * \param[in] input_length Size of the `p_input` buffer in bytes
574 * \param[in] p_salt A salt or label, if supported by the
575 * encryption algorithm
576 * If the algorithm does not support a
577 * salt, pass `NULL`.
578 * If the algorithm supports an optional
579 * salt and you do not want to pass a salt,
580 * pass `NULL`.
581 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
582 * supported.
583 * \param[in] salt_length Size of the `p_salt` buffer in bytes
584 * If `p_salt` is `NULL`, pass 0.
585 * \param[out] p_output Buffer where the encrypted message is to
586 * be written
587 * \param[in] output_size Size of the `p_output` buffer in bytes
588 * \param[out] p_output_length On success, the number of bytes that make up
589 * the returned output
590 *
591 * \retval PSA_SUCCESS
592 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200593typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t *drv_context,
594 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600595 psa_algorithm_t alg,
596 const uint8_t *p_input,
597 size_t input_length,
598 const uint8_t *p_salt,
599 size_t salt_length,
600 uint8_t *p_output,
601 size_t output_size,
602 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100603
604/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600605 * \brief A function that decrypts a short message with an asymmetric private
606 * key in a secure element.
Gilles Peskine75976892018-12-12 15:55:09 +0100607 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200608 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100609 * \param[in] key_slot Key slot of an asymmetric key pair
610 * \param[in] alg An asymmetric encryption algorithm that is
611 * compatible with the type of `key`
612 * \param[in] p_input The message to decrypt
613 * \param[in] input_length Size of the `p_input` buffer in bytes
614 * \param[in] p_salt A salt or label, if supported by the
615 * encryption algorithm
616 * If the algorithm does not support a
617 * salt, pass `NULL`.
618 * If the algorithm supports an optional
619 * salt and you do not want to pass a salt,
620 * pass `NULL`.
621 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
622 * supported.
623 * \param[in] salt_length Size of the `p_salt` buffer in bytes
624 * If `p_salt` is `NULL`, pass 0.
625 * \param[out] p_output Buffer where the decrypted message is to
626 * be written
627 * \param[in] output_size Size of the `p_output` buffer in bytes
628 * \param[out] p_output_length On success, the number of bytes
629 * that make up the returned output
630 *
631 * \retval PSA_SUCCESS
632 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200633typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_drv_se_context_t *drv_context,
634 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600635 psa_algorithm_t alg,
636 const uint8_t *p_input,
637 size_t input_length,
638 const uint8_t *p_salt,
639 size_t salt_length,
640 uint8_t *p_output,
641 size_t output_size,
642 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100643
644/**
645 * \brief A struct containing all of the function pointers needed to implement
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600646 * asymmetric cryptographic operations using secure elements.
Gilles Peskine75976892018-12-12 15:55:09 +0100647 *
648 * PSA Crypto API implementations should populate instances of the table as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600649 * appropriate upon startup or at build time.
Gilles Peskine75976892018-12-12 15:55:09 +0100650 *
651 * If one of the functions is not implemented, it should be set to NULL.
652 */
653typedef struct {
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600654 /** Function that performs an asymmetric sign operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600655 psa_drv_se_asymmetric_sign_t p_sign;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600656 /** Function that performs an asymmetric verify operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600657 psa_drv_se_asymmetric_verify_t p_verify;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600658 /** Function that performs an asymmetric encrypt operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600659 psa_drv_se_asymmetric_encrypt_t p_encrypt;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600660 /** Function that performs an asymmetric decrypt operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600661 psa_drv_se_asymmetric_decrypt_t p_decrypt;
Derek Miller83d26622019-02-15 16:41:22 -0600662} psa_drv_se_asymmetric_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100663
664/**@}*/
665
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600666/** \defgroup se_aead Secure Element Authenticated Encryption with Additional Data
667 * Authenticated Encryption with Additional Data (AEAD) operations with secure
668 * elements must be done in one function call. While this creates a burden for
Gilles Peskine75976892018-12-12 15:55:09 +0100669 * implementers as there must be sufficient space in memory for the entire
670 * message, it prevents decrypted data from being made available before the
671 * authentication operation is complete and the data is known to be authentic.
672 */
673/**@{*/
674
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600675/** \brief A function that performs a secure element authenticated encryption
676 * operation
Gilles Peskine75976892018-12-12 15:55:09 +0100677 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200678 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100679 * \param[in] key_slot Slot containing the key to use.
680 * \param[in] algorithm The AEAD algorithm to compute
681 * (\c PSA_ALG_XXX value such that
682 * #PSA_ALG_IS_AEAD(`alg`) is true)
683 * \param[in] p_nonce Nonce or IV to use
684 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
685 * \param[in] p_additional_data Additional data that will be
686 * authenticated but not encrypted
687 * \param[in] additional_data_length Size of `p_additional_data` in bytes
688 * \param[in] p_plaintext Data that will be authenticated and
689 * encrypted
690 * \param[in] plaintext_length Size of `p_plaintext` in bytes
691 * \param[out] p_ciphertext Output buffer for the authenticated and
692 * encrypted data. The additional data is
693 * not part of this output. For algorithms
694 * where the encrypted data and the
695 * authentication tag are defined as
696 * separate outputs, the authentication
697 * tag is appended to the encrypted data.
698 * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in
699 * bytes
700 * \param[out] p_ciphertext_length On success, the size of the output in
701 * the `p_ciphertext` buffer
702 *
703 * \retval #PSA_SUCCESS
704 * Success.
705 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200706typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_drv_se_context_t *drv_context,
707 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600708 psa_algorithm_t algorithm,
709 const uint8_t *p_nonce,
710 size_t nonce_length,
711 const uint8_t *p_additional_data,
712 size_t additional_data_length,
713 const uint8_t *p_plaintext,
714 size_t plaintext_length,
715 uint8_t *p_ciphertext,
716 size_t ciphertext_size,
717 size_t *p_ciphertext_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100718
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600719/** A function that peforms a secure element authenticated decryption operation
Gilles Peskine75976892018-12-12 15:55:09 +0100720 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200721 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100722 * \param[in] key_slot Slot containing the key to use
723 * \param[in] algorithm The AEAD algorithm to compute
724 * (\c PSA_ALG_XXX value such that
725 * #PSA_ALG_IS_AEAD(`alg`) is true)
726 * \param[in] p_nonce Nonce or IV to use
727 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
728 * \param[in] p_additional_data Additional data that has been
729 * authenticated but not encrypted
730 * \param[in] additional_data_length Size of `p_additional_data` in bytes
731 * \param[in] p_ciphertext Data that has been authenticated and
732 * encrypted.
733 * For algorithms where the encrypted data
734 * and the authentication tag are defined
735 * as separate inputs, the buffer must
736 * contain the encrypted data followed by
737 * the authentication tag.
738 * \param[in] ciphertext_length Size of `p_ciphertext` in bytes
739 * \param[out] p_plaintext Output buffer for the decrypted data
740 * \param[in] plaintext_size Size of the `p_plaintext` buffer in
741 * bytes
742 * \param[out] p_plaintext_length On success, the size of the output in
743 * the `p_plaintext` buffer
744 *
745 * \retval #PSA_SUCCESS
746 * Success.
747 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200748typedef psa_status_t (*psa_drv_se_aead_decrypt_t)(psa_drv_se_context_t *drv_context,
749 psa_key_slot_number_t key_slot,
Derek Miller83d26622019-02-15 16:41:22 -0600750 psa_algorithm_t algorithm,
751 const uint8_t *p_nonce,
752 size_t nonce_length,
753 const uint8_t *p_additional_data,
754 size_t additional_data_length,
755 const uint8_t *p_ciphertext,
756 size_t ciphertext_length,
757 uint8_t *p_plaintext,
758 size_t plaintext_size,
759 size_t *p_plaintext_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100760
761/**
762 * \brief A struct containing all of the function pointers needed to implement
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600763 * secure element Authenticated Encryption with Additional Data operations
Gilles Peskine75976892018-12-12 15:55:09 +0100764 *
765 * PSA Crypto API implementations should populate instances of the table as
766 * appropriate upon startup.
767 *
768 * If one of the functions is not implemented, it should be set to NULL.
769 */
770typedef struct {
771 /** Function that performs the AEAD encrypt operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600772 psa_drv_se_aead_encrypt_t p_encrypt;
Gilles Peskine75976892018-12-12 15:55:09 +0100773 /** Function that performs the AEAD decrypt operation */
Derek Millerea743cf2019-02-15 17:06:29 -0600774 psa_drv_se_aead_decrypt_t p_decrypt;
Derek Miller83d26622019-02-15 16:41:22 -0600775} psa_drv_se_aead_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100776/**@}*/
777
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600778/** \defgroup se_key_management Secure Element Key Management
Gilles Peskine75976892018-12-12 15:55:09 +0100779 * Currently, key management is limited to importing keys in the clear,
780 * destroying keys, and exporting keys in the clear.
781 * Whether a key may be exported is determined by the key policies in place
782 * on the key slot.
783 */
784/**@{*/
785
Gilles Peskinef2223c82019-07-12 23:33:02 +0200786/* This type is documented in crypto.h. As far as drivers are concerned,
787 * this is an opaque type. */
788typedef struct psa_key_attributes_s psa_key_attributes_t;
789
790/** \brief A function that allocates a slot for a key.
791 *
792 * \param[in,out] drv_context The driver context structure.
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200793 * \param[in,out] persistent_data A pointer to the persistent data
794 * that allows writing.
Gilles Peskinef2223c82019-07-12 23:33:02 +0200795 * \param[in] attributes Attributes of the key.
796 * \param[out] key_slot Slot where the key will be stored.
797 * This must be a valid slot for a key of the
798 * chosen type. It must be unoccupied.
799 *
800 * \retval #PSA_SUCCESS
801 * Success.
802 * The core will record \c *key_slot as the key slot where the key
803 * is stored and will update the persistent data in storage.
804 * \retval #PSA_ERROR_NOT_SUPPORTED
805 * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
806 */
807typedef psa_status_t (*psa_drv_se_allocate_key_t)(
808 psa_drv_se_context_t *drv_context,
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200809 void *persistent_data,
Gilles Peskinef2223c82019-07-12 23:33:02 +0200810 const psa_key_attributes_t *attributes,
811 psa_key_slot_number_t *key_slot);
812
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600813/** \brief A function that imports a key into a secure element in binary format
Gilles Peskine75976892018-12-12 15:55:09 +0100814 *
815 * This function can support any output from psa_export_key(). Refer to the
816 * documentation of psa_export_key() for the format for each key type.
817 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200818 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100819 * \param[in] key_slot Slot where the key will be stored
820 * This must be a valid slot for a key of the chosen
821 * type. It must be unoccupied.
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600822 * \param[in] lifetime The required lifetime of the key storage
Gilles Peskine75976892018-12-12 15:55:09 +0100823 * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value)
824 * \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value)
825 * \param[in] usage The allowed uses of the key
826 * \param[in] p_data Buffer containing the key data
827 * \param[in] data_length Size of the `data` buffer in bytes
828 *
829 * \retval #PSA_SUCCESS
830 * Success.
831 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200832typedef psa_status_t (*psa_drv_se_import_key_t)(psa_drv_se_context_t *drv_context,
833 psa_key_slot_number_t key_slot,
Derek Miller0972fe52019-02-15 17:08:27 -0600834 psa_key_lifetime_t lifetime,
Derek Miller83d26622019-02-15 16:41:22 -0600835 psa_key_type_t type,
836 psa_algorithm_t algorithm,
837 psa_key_usage_t usage,
838 const uint8_t *p_data,
839 size_t data_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100840
841/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600842 * \brief A function that destroys a secure element key and restore the slot to
843 * its default state
Gilles Peskine75976892018-12-12 15:55:09 +0100844 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600845 * This function destroys the content of the key from a secure element.
846 * Implementations shall make a best effort to ensure that any previous content
847 * of the slot is unrecoverable.
Gilles Peskine75976892018-12-12 15:55:09 +0100848 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600849 * This function returns the specified slot to its default state.
Gilles Peskine75976892018-12-12 15:55:09 +0100850 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200851 * \param[in,out] drv_context The driver context structure.
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200852 * \param[in,out] persistent_data A pointer to the persistent data
853 * that allows writing.
Gilles Peskine8597bc12019-07-12 23:28:46 +0200854 * \param key_slot The key slot to erase.
Gilles Peskine75976892018-12-12 15:55:09 +0100855 *
856 * \retval #PSA_SUCCESS
857 * The slot's content, if any, has been erased.
858 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200859typedef psa_status_t (*psa_drv_se_destroy_key_t)(
860 psa_drv_se_context_t *drv_context,
Gilles Peskine94cc42c2019-07-12 23:34:20 +0200861 void *persistent_data,
Gilles Peskine8597bc12019-07-12 23:28:46 +0200862 psa_key_slot_number_t key_slot);
Gilles Peskine75976892018-12-12 15:55:09 +0100863
864/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600865 * \brief A function that exports a secure element key in binary format
Gilles Peskine75976892018-12-12 15:55:09 +0100866 *
867 * The output of this function can be passed to psa_import_key() to
868 * create an equivalent object.
869 *
870 * If a key is created with `psa_import_key()` and then exported with
871 * this function, it is not guaranteed that the resulting data is
872 * identical: the implementation may choose a different representation
873 * of the same key if the format permits it.
874 *
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600875 * This function should generate output in the same format that
876 * `psa_export_key()` does. Refer to the
877 * documentation of `psa_export_key()` for the format for each key type.
Gilles Peskine75976892018-12-12 15:55:09 +0100878 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200879 * \param[in,out] drv_context The driver context structure.
Gilles Peskine75976892018-12-12 15:55:09 +0100880 * \param[in] key Slot whose content is to be exported. This must
881 * be an occupied key slot.
882 * \param[out] p_data Buffer where the key data is to be written.
883 * \param[in] data_size Size of the `p_data` buffer in bytes.
884 * \param[out] p_data_length On success, the number of bytes
885 * that make up the key data.
886 *
887 * \retval #PSA_SUCCESS
David Saadab4ecc272019-02-14 13:48:10 +0200888 * \retval #PSA_ERROR_DOES_NOT_EXIST
Gilles Peskine75976892018-12-12 15:55:09 +0100889 * \retval #PSA_ERROR_NOT_PERMITTED
890 * \retval #PSA_ERROR_NOT_SUPPORTED
891 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
892 * \retval #PSA_ERROR_HARDWARE_FAILURE
Gilles Peskine4b3eb692019-05-16 21:35:18 +0200893 * \retval #PSA_ERROR_CORRUPTION_DETECTED
Gilles Peskine75976892018-12-12 15:55:09 +0100894 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200895typedef psa_status_t (*psa_drv_se_export_key_t)(psa_drv_se_context_t *drv_context,
896 psa_key_slot_number_t key,
Derek Miller83d26622019-02-15 16:41:22 -0600897 uint8_t *p_data,
898 size_t data_size,
899 size_t *p_data_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100900
901/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600902 * \brief A function that generates a symmetric or asymmetric key on a secure
903 * element
Gilles Peskine75976892018-12-12 15:55:09 +0100904 *
Gilles Peskinee5c025c2019-03-06 18:01:43 +0100905 * If \p type is asymmetric (`#PSA_KEY_TYPE_IS_ASYMMETRIC(\p type) == 1`),
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600906 * the public component of the generated key will be placed in `p_pubkey_out`.
907 * The format of the public key information will match the format specified for
Gilles Peskinee5c025c2019-03-06 18:01:43 +0100908 * the psa_export_key() function for the key type.
Gilles Peskine75976892018-12-12 15:55:09 +0100909 *
Gilles Peskine8597bc12019-07-12 23:28:46 +0200910 * \param[in,out] drv_context The driver context structure.
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600911 * \param[in] key_slot Slot where the generated key will be placed
912 * \param[in] type The type of the key to be generated
913 * \param[in] usage The prescribed usage of the generated key
Gilles Peskinec3044a62019-03-06 17:56:28 +0100914 * Note: Not all Secure Elements support the same
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600915 * restrictions that PSA Crypto does (and vice versa).
916 * Driver developers should endeavor to match the
917 * usages as close as possible.
918 * \param[in] bits The size in bits of the key to be generated.
919 * \param[in] extra Extra parameters for key generation. The
920 * interpretation of this parameter should match the
921 * interpretation in the `extra` parameter is the
Gilles Peskine35ef36b2019-05-16 19:42:05 +0200922 * `psa_generate_key` function
Gilles Peskinee5c025c2019-03-06 18:01:43 +0100923 * \param[in] extra_size The size in bytes of the \p extra buffer
Gilles Peskinec3044a62019-03-06 17:56:28 +0100924 * \param[out] p_pubkey_out The buffer where the public key information will
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600925 * be placed
926 * \param[in] pubkey_out_size The size in bytes of the `p_pubkey_out` buffer
927 * \param[out] p_pubkey_length Upon successful completion, will contain the
928 * size of the data placed in `p_pubkey_out`.
Gilles Peskine75976892018-12-12 15:55:09 +0100929 */
Gilles Peskine8597bc12019-07-12 23:28:46 +0200930typedef psa_status_t (*psa_drv_se_generate_key_t)(psa_drv_se_context_t *drv_context,
931 psa_key_slot_number_t key_slot,
Gilles Peskine32668ce2019-03-06 18:29:57 +0100932 psa_key_type_t type,
933 psa_key_usage_t usage,
934 size_t bits,
935 const void *extra,
936 size_t extra_size,
937 uint8_t *p_pubkey_out,
938 size_t pubkey_out_size,
939 size_t *p_pubkey_length);
Gilles Peskine75976892018-12-12 15:55:09 +0100940
941/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600942 * \brief A struct containing all of the function pointers needed to for secure
943 * element key management
Gilles Peskine75976892018-12-12 15:55:09 +0100944 *
945 * PSA Crypto API implementations should populate instances of the table as
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600946 * appropriate upon startup or at build time.
Gilles Peskine75976892018-12-12 15:55:09 +0100947 *
948 * If one of the functions is not implemented, it should be set to NULL.
949 */
950typedef struct {
Gilles Peskinef2223c82019-07-12 23:33:02 +0200951 /** Function that allocates a slot. */
952 psa_drv_se_allocate_key_t p_allocate;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600953 /** Function that performs a key import operation */
954 psa_drv_se_import_key_t p_import;
955 /** Function that performs a generation */
Derek Miller0b3098a2019-02-15 17:10:49 -0600956 psa_drv_se_generate_key_t p_generate;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600957 /** Function that performs a key destroy operation */
Derek Miller0b3098a2019-02-15 17:10:49 -0600958 psa_drv_se_destroy_key_t p_destroy;
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600959 /** Function that performs a key export operation */
Derek Miller0b3098a2019-02-15 17:10:49 -0600960 psa_drv_se_export_key_t p_export;
Gilles Peskinee62b74e2019-06-25 15:25:09 +0200961 /** Function that performs a public key export operation */
962 psa_drv_se_export_key_t p_export_public;
Derek Miller83d26622019-02-15 16:41:22 -0600963} psa_drv_se_key_management_t;
Gilles Peskine75976892018-12-12 15:55:09 +0100964
965/**@}*/
966
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600967/** \defgroup driver_derivation Secure Element Key Derivation and Agreement
Gilles Peskine75976892018-12-12 15:55:09 +0100968 * Key derivation is the process of generating new key material using an
969 * existing key and additional parameters, iterating through a basic
970 * cryptographic function, such as a hash.
971 * Key agreement is a part of cryptographic protocols that allows two parties
972 * to agree on the same key value, but starting from different original key
973 * material.
974 * The flows are similar, and the PSA Crypto Driver Model uses the same functions
975 * for both of the flows.
976 *
977 * There are two different final functions for the flows,
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600978 * `psa_drv_se_key_derivation_derive` and `psa_drv_se_key_derivation_export`.
979 * `psa_drv_se_key_derivation_derive` is used when the key material should be
980 * placed in a slot on the hardware and not exposed to the caller.
981 * `psa_drv_se_key_derivation_export` is used when the key material should be
982 * returned to the PSA Cryptographic API implementation.
Gilles Peskine75976892018-12-12 15:55:09 +0100983 *
984 * Different key derivation algorithms require a different number of inputs.
985 * Instead of having an API that takes as input variable length arrays, which
986 * can be problemmatic to manage on embedded platforms, the inputs are passed
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600987 * to the driver via a function, `psa_drv_se_key_derivation_collateral`, that
988 * is called multiple times with different `collateral_id`s. Thus, for a key
Gilles Peskine75976892018-12-12 15:55:09 +0100989 * derivation algorithm that required 3 paramter inputs, the flow would look
990 * something like:
991 * ~~~~~~~~~~~~~{.c}
Derek Millerf0c1d0d2019-02-15 17:23:42 -0600992 * psa_drv_se_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes);
993 * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_0,
994 * p_collateral_0,
995 * collateral_0_size);
996 * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_1,
997 * p_collateral_1,
998 * collateral_1_size);
999 * psa_drv_se_key_derivation_collateral(kdf_algorithm_collateral_id_2,
1000 * p_collateral_2,
1001 * collateral_2_size);
1002 * psa_drv_se_key_derivation_derive();
Gilles Peskine75976892018-12-12 15:55:09 +01001003 * ~~~~~~~~~~~~~
1004 *
1005 * key agreement example:
1006 * ~~~~~~~~~~~~~{.c}
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001007 * psa_drv_se_key_derivation_setup(alg, source_key. dest_key_size_bytes);
1008 * psa_drv_se_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size);
1009 * psa_drv_se_key_derivation_export(p_session_key,
1010 * session_key_size,
1011 * &session_key_length);
Gilles Peskine75976892018-12-12 15:55:09 +01001012 * ~~~~~~~~~~~~~
1013 */
1014/**@{*/
1015
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001016/** \brief A function that Sets up a secure element key derivation operation by
1017 * specifying the algorithm and the source key sot
Gilles Peskine75976892018-12-12 15:55:09 +01001018 *
Gilles Peskine8597bc12019-07-12 23:28:46 +02001019 * \param[in,out] drv_context The driver context structure.
1020 * \param[in,out] op_context A hardware-specific structure containing any
Gilles Peskine75976892018-12-12 15:55:09 +01001021 * context information for the implementation
1022 * \param[in] kdf_alg The algorithm to be used for the key derivation
Gilles Peskine45a8ca32019-06-24 15:08:56 +02001023 * \param[in] source_key The key to be used as the source material for the
Gilles Peskine75976892018-12-12 15:55:09 +01001024 * key derivation
1025 *
1026 * \retval PSA_SUCCESS
1027 */
Gilles Peskine8597bc12019-07-12 23:28:46 +02001028typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *drv_context,
1029 void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -06001030 psa_algorithm_t kdf_alg,
Derek Millerb2a1cce2019-02-15 17:03:42 -06001031 psa_key_slot_number_t source_key);
Gilles Peskine75976892018-12-12 15:55:09 +01001032
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001033/** \brief A function that provides collateral (parameters) needed for a secure
1034 * element key derivation or key agreement operation
Gilles Peskine75976892018-12-12 15:55:09 +01001035 *
1036 * Since many key derivation algorithms require multiple parameters, it is
1037 * expeced that this function may be called multiple times for the same
1038 * operation, each with a different algorithm-specific `collateral_id`
1039 *
Gilles Peskine8597bc12019-07-12 23:28:46 +02001040 * \param[in,out] op_context A hardware-specific structure containing any
Gilles Peskine75976892018-12-12 15:55:09 +01001041 * context information for the implementation
1042 * \param[in] collateral_id An ID for the collateral being provided
1043 * \param[in] p_collateral A buffer containing the collateral data
1044 * \param[in] collateral_size The size in bytes of the collateral
1045 *
1046 * \retval PSA_SUCCESS
1047 */
Gilles Peskine8597bc12019-07-12 23:28:46 +02001048typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *op_context,
Derek Miller83d26622019-02-15 16:41:22 -06001049 uint32_t collateral_id,
1050 const uint8_t *p_collateral,
1051 size_t collateral_size);
Gilles Peskine75976892018-12-12 15:55:09 +01001052
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001053/** \brief A function that performs the final secure element key derivation
1054 * step and place the generated key material in a slot
Gilles Peskinec3044a62019-03-06 17:56:28 +01001055 *
Gilles Peskine8597bc12019-07-12 23:28:46 +02001056 * \param[in,out] op_context A hardware-specific structure containing any
Gilles Peskine75976892018-12-12 15:55:09 +01001057 * context information for the implementation
1058 * \param[in] dest_key The slot where the generated key material
1059 * should be placed
1060 *
1061 * \retval PSA_SUCCESS
1062 */
Gilles Peskine8597bc12019-07-12 23:28:46 +02001063typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *op_context,
Derek Miller62117262019-02-15 17:12:26 -06001064 psa_key_slot_number_t dest_key);
Gilles Peskine75976892018-12-12 15:55:09 +01001065
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001066/** \brief A function that performs the final step of a secure element key
1067 * agreement and place the generated key material in a buffer
Gilles Peskine75976892018-12-12 15:55:09 +01001068 *
1069 * \param[out] p_output Buffer in which to place the generated key
1070 * material
1071 * \param[in] output_size The size in bytes of `p_output`
1072 * \param[out] p_output_length Upon success, contains the number of bytes of
1073 * key material placed in `p_output`
1074 *
1075 * \retval PSA_SUCCESS
1076 */
Gilles Peskine8597bc12019-07-12 23:28:46 +02001077typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *op_context,
Derek Miller62117262019-02-15 17:12:26 -06001078 uint8_t *p_output,
1079 size_t output_size,
1080 size_t *p_output_length);
Gilles Peskine75976892018-12-12 15:55:09 +01001081
1082/**
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001083 * \brief A struct containing all of the function pointers needed to for secure
1084 * element key derivation and agreement
Gilles Peskine75976892018-12-12 15:55:09 +01001085 *
1086 * PSA Crypto API implementations should populate instances of the table as
1087 * appropriate upon startup.
1088 *
1089 * If one of the functions is not implemented, it should be set to NULL.
1090 */
1091typedef struct {
Derek Miller62117262019-02-15 17:12:26 -06001092 /** The driver-specific size of the key derivation context */
1093 size_t context_size;
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001094 /** Function that performs a key derivation setup */
Derek Millerea743cf2019-02-15 17:06:29 -06001095 psa_drv_se_key_derivation_setup_t p_setup;
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001096 /** Function that sets key derivation collateral */
Derek Millerea743cf2019-02-15 17:06:29 -06001097 psa_drv_se_key_derivation_collateral_t p_collateral;
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001098 /** Function that performs a final key derivation step */
Derek Millerea743cf2019-02-15 17:06:29 -06001099 psa_drv_se_key_derivation_derive_t p_derive;
Derek Millerf0c1d0d2019-02-15 17:23:42 -06001100 /** Function that perforsm a final key derivation or agreement and
Gilles Peskine75976892018-12-12 15:55:09 +01001101 * exports the key */
Derek Millerea743cf2019-02-15 17:06:29 -06001102 psa_drv_se_key_derivation_export_t p_export;
Derek Miller83d26622019-02-15 16:41:22 -06001103} psa_drv_se_key_derivation_t;
Gilles Peskine75976892018-12-12 15:55:09 +01001104
1105/**@}*/
1106
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001107/** \defgroup se_registration Secure element driver registration
1108 */
1109/**@{*/
1110
1111/** A structure containing pointers to all the entry points of a
1112 * secure element driver.
1113 *
1114 * Future versions of this specification may add extra substructures at
1115 * the end of this structure.
1116 */
1117typedef struct {
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001118 /** The version of the driver HAL that this driver implements.
1119 * This is a protection against loading driver binaries built against
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001120 * a different version of this specification.
1121 * Use #PSA_DRV_SE_HAL_VERSION.
1122 */
1123 uint32_t hal_version;
Gilles Peskine7a86da12019-07-12 23:25:38 +02001124
1125 /** The size of the driver's persistent data in bytes. */
1126 size_t persistent_data_size;
1127
1128 /** The driver initialization function.
1129 *
1130 * This function is called once during the initialization of the
1131 * PSA Cryptography subsystem, before any other function of the
1132 * driver is called. If this function returns a failure status,
1133 * the driver will be unusable, at least until the next system reset.
1134 *
1135 * If this field is \c NULL, it is equivalent to a function that does
1136 * nothing and returns #PSA_SUCCESS.
1137 */
1138 psa_drv_se_init_t p_init;
1139
Gilles Peskine6e59c422019-06-26 19:06:52 +02001140 const psa_drv_se_key_management_t *key_management;
1141 const psa_drv_se_mac_t *mac;
1142 const psa_drv_se_cipher_t *cipher;
1143 const psa_drv_se_aead_t *aead;
1144 const psa_drv_se_asymmetric_t *asymmetric;
1145 const psa_drv_se_key_derivation_t *derivation;
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001146} psa_drv_se_t;
1147
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001148/** The current version of the secure element driver HAL.
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001149 */
1150/* 0.0.0 patchlevel 5 */
1151#define PSA_DRV_SE_HAL_VERSION 0x00000005
1152
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001153/** Register an external cryptoprocessor (secure element) driver.
Gilles Peskined910e922019-06-24 13:47:07 +02001154 *
1155 * This function is only intended to be used by driver code, not by
1156 * application code. In implementations with separation between the
1157 * PSA cryptography module and applications, this function should
1158 * only be available to callers that run in the same memory space as
1159 * the cryptography module, and should not be exposed to applications
1160 * running in a different memory space.
1161 *
1162 * This function may be called before psa_crypto_init(). It is
1163 * implementation-defined whether this function may be called
1164 * after psa_crypto_init().
1165 *
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001166 * \note Implementations store metadata about keys including the lifetime
1167 * value. Therefore, from one instantiation of the PSA Cryptography
1168 * library to the next one, if there is a key in storage with a certain
1169 * lifetime value, you must always register the same driver (or an
1170 * updated version that communicates with the same secure element)
1171 * with the same lifetime value.
1172 *
Gilles Peskined910e922019-06-24 13:47:07 +02001173 * \param lifetime The lifetime value through which this driver will
1174 * be exposed to applications.
1175 * The values #PSA_KEY_LIFETIME_VOLATILE and
1176 * #PSA_KEY_LIFETIME_PERSISTENT are reserved and
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001177 * may not be used for drivers. Implementations
Gilles Peskined910e922019-06-24 13:47:07 +02001178 * may reserve other values.
1179 * \param[in] methods The method table of the driver. This structure must
1180 * remain valid for as long as the cryptography
1181 * module keeps running. It is typically a global
1182 * constant.
1183 *
1184 * \return PSA_SUCCESS
1185 * The driver was successfully registered. Applications can now
1186 * use \p lifetime to access keys through the methods passed to
1187 * this function.
1188 * \return PSA_ERROR_BAD_STATE
1189 * This function was called after the initialization of the
1190 * cryptography module, and this implementation does not support
1191 * driver registration at this stage.
1192 * \return PSA_ERROR_ALREADY_EXISTS
1193 * There is already a registered driver for this value of \p lifetime.
1194 * \return PSA_ERROR_INVALID_ARGUMENT
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001195 * \p lifetime is a reserved value.
Gilles Peskined910e922019-06-24 13:47:07 +02001196 * \return PSA_ERROR_NOT_SUPPORTED
Gilles Peskinec93a43b2019-06-26 11:21:41 +02001197 * `methods->hal_version` is not supported by this implementation.
Gilles Peskined910e922019-06-24 13:47:07 +02001198 * \return PSA_ERROR_INSUFFICIENT_MEMORY
1199 * \return PSA_ERROR_NOT_PERMITTED
1200 */
1201psa_status_t psa_register_se_driver(
1202 psa_key_lifetime_t lifetime,
1203 const psa_drv_se_t *methods);
1204
Gilles Peskineb6cadea2019-06-24 13:46:37 +02001205/**@}*/
1206
Gilles Peskine75976892018-12-12 15:55:09 +01001207#ifdef __cplusplus
1208}
1209#endif
1210
1211#endif /* PSA_CRYPTO_SE_DRIVER_H */