blob: b2e3a1d5fb2f9a6004ece8c7c64f06534fe39725 [file] [log] [blame]
Derek Miller16e72292018-10-15 16:14:24 -05001/**
2 * \file psa/crypto_driver.h
3 * \brief Platform Security Architecture cryptographic driver module
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01004 *
Jaeden Ameroe095d602018-10-26 12:09:31 +01005 * This file describes the PSA Crypto Driver Model, containing functions for
6 * driver developers to implement to enable hardware to be called in a
7 * standardized way by a PSA Cryptographic API implementation. The functions
8 * comprising the driver model, which driver authors implement, are not
9 * intended to be called by application developers.
Derek Miller16e72292018-10-15 16:14:24 -050010 */
11
12/*
13 * Copyright (C) 2018, ARM Limited, All Rights Reserved
14 * SPDX-License-Identifier: Apache-2.0
15 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
Jaeden Amero41558502018-10-26 11:44:33 +010028#ifndef PSA_CRYPTO_DRIVER_H
29#define PSA_CRYPTO_DRIVER_H
Derek Miller5b3417a2018-10-10 17:55:03 -050030
31#include <stddef.h>
32#include <stdint.h>
33
Jaeden Amero9411db72018-10-26 11:59:58 +010034#ifdef __cplusplus
35extern "C" {
36#endif
37
Derek Miller16e72292018-10-15 16:14:24 -050038/** The following types are redefinitions from the psa/crypto.h file.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010039 * It is intended that these will be moved to a new common header file to
Derek Miller16e72292018-10-15 16:14:24 -050040 * avoid duplication. They are included here for expediency in publication.
41 */
Derek Miller5b3417a2018-10-10 17:55:03 -050042typedef uint32_t psa_status_t;
43typedef uint32_t psa_algorithm_t;
Jaeden Amero7632f622018-10-26 11:26:45 +010044typedef uint8_t psa_encrypt_or_decrypt_t;
Derek Miller5b3417a2018-10-10 17:55:03 -050045typedef uint32_t psa_key_slot_t;
46typedef uint32_t psa_key_type_t;
Derek Miller81133a62018-10-23 14:55:32 -050047typedef uint32_t psa_key_usage_t;
Derek Miller5b3417a2018-10-10 17:55:03 -050048
Derek Miller6f960ab2018-10-23 15:58:06 -050049#define PSA_CRYPTO_DRIVER_ENCRYPT 1
50#define PSA_CRYPTO_DRIVER_DECRYPT 0
51
Derek Miller5b3417a2018-10-10 17:55:03 -050052/** \defgroup opaque_mac Opaque Message Authentication Code
Derek Miller765682c2018-10-22 15:27:27 -050053 * Generation and authentication of Message Authentication Codes (MACs) using
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010054 * opaque keys can be done either as a single function call (via the
Jaeden Amero1acb2c42018-10-26 10:49:58 +010055 * `psa_drv_mac_opaque_generate_t` or `psa_mac_opaque_verify_t` functions), or in
Derek Miller765682c2018-10-22 15:27:27 -050056 * parts using the following sequence:
57 * - `psa_mac_opaque_setup_t`
58 * - `psa_mac_opaque_update_t`
59 * - `psa_mac_opaque_update_t`
60 * - ...
61 * - `psa_mac_opaque_finish_t` or `psa_mac_opaque_finish_verify_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010062 *
63 * If a previously started Opaque MAC operation needs to be terminated, it
Derek Miller765682c2018-10-22 15:27:27 -050064 * should be done so by the `psa_mac_opaque_abort_t`. Failure to do so may
65 * result in allocated resources not being freed or in other undefined
66 * behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -050067 */
Derek Miller16e72292018-10-15 16:14:24 -050068/**@{*/
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010069/** \brief A function that starts a MAC operation for a PSA Crypto Driver
Derek Miller16e72292018-10-15 16:14:24 -050070 * implementation using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010071 *
72 * \param[in,out] p_context A structure that will contain the
Derek Miller16e72292018-10-15 16:14:24 -050073 * hardware-specific MAC context
74 * \param[in] key_slot The slot of the key to be used for the
75 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010076 * \param[in] algorithm The algorithm to be used to underly the MAC
Derek Miller16e72292018-10-15 16:14:24 -050077 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010078 *
Derek Miller5b3417a2018-10-10 17:55:03 -050079 * \retval PSA_SUCCESS
80 * Success.
81 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +010082typedef psa_status_t (*psa_drv_mac_opaque_setup_t)(void *p_context,
83 psa_key_slot_t key_slot,
84 psa_algorithm_t algorithm);
Derek Miller5b3417a2018-10-10 17:55:03 -050085
Derek Miller16e72292018-10-15 16:14:24 -050086/** \brief A function that continues a previously started MAC operation using
87 * an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010088 *
Derek Miller16e72292018-10-15 16:14:24 -050089 * \param[in,out] p_context A hardware-specific structure for the
90 * previously-established MAC operation to be
91 * continued
92 * \param[in] p_input A buffer containing the message to be appended
93 * to the MAC operation
94 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -050095 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +010096typedef psa_status_t (*psa_drv_mac_opaque_update_t)(void *p_context,
97 const uint8_t *p_input,
98 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -050099
Derek Miller16e72292018-10-15 16:14:24 -0500100/** \brief a function that completes a previously started MAC operation by
101 * returning the resulting MAC using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100102 *
103 * \param[in,out] p_context A hardware-specific structure for the
104 * previously started MAC operation to be
Derek Miller16e72292018-10-15 16:14:24 -0500105 * finished
106 * \param[out] p_mac A buffer where the generated MAC will be
107 * placed
108 * \param[in] mac_size The size in bytes of the buffer that has been
109 * allocated for the `output` buffer
110 * \param[out] p_mac_length After completion, will contain the number of
Derek Millerf3d0a562018-10-18 16:41:08 -0500111 * bytes placed in the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100112 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500113 * \retval PSA_SUCCESS
114 * Success.
115 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100116typedef psa_status_t (*psa_drv_mac_opaque_finish_t)(void *p_context,
117 uint8_t *p_mac,
118 size_t mac_size,
119 size_t *p_mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500120
Derek Miller16e72292018-10-15 16:14:24 -0500121/** \brief A function that completes a previously started MAC operation by
122 * comparing the resulting MAC against a known value using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100123 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500124 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500125 * started MAC operation to be fiinished
126 * \param[in] p_mac The MAC value against which the resulting MAC will
127 * be compared against
128 * \param[in] mac_length The size in bytes of the value stored in `p_mac`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100129 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500130 * \retval PSA_SUCCESS
Derek Miller16e72292018-10-15 16:14:24 -0500131 * The operation completed successfully and the MACs matched each
132 * other
Derek Miller5b3417a2018-10-10 17:55:03 -0500133 * \retval PSA_ERROR_INVALID_SIGNATURE
Derek Miller16e72292018-10-15 16:14:24 -0500134 * The operation completed successfully, but the calculated MAC did
135 * not match the provided MAC
Derek Miller5b3417a2018-10-10 17:55:03 -0500136 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100137typedef psa_status_t (*psa_drv_mac_opaque_finish_verify_t)(void *p_context,
138 const uint8_t *p_mac,
139 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500140
Derek Miller16e72292018-10-15 16:14:24 -0500141/** \brief A function that aborts a previous started opaque-key MAC operation
142
Derek Millerf3d0a562018-10-18 16:41:08 -0500143 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500144 * started MAC operation to be aborted
145 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100146typedef psa_status_t (*psa_drv_mac_opaque_abort_t)(void *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500147
Derek Miller81133a62018-10-23 14:55:32 -0500148/** \brief A function that performs a MAC operation in one command and returns
Derek Miller16e72292018-10-15 16:14:24 -0500149 * the calculated MAC using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100150 *
Derek Miller16e72292018-10-15 16:14:24 -0500151 * \param[in] p_input A buffer containing the message to be MACed
Derek Millerf3d0a562018-10-18 16:41:08 -0500152 * \param[in] input_length The size in bytes of `p_input`
Derek Miller16e72292018-10-15 16:14:24 -0500153 * \param[in] key_slot The slot of the key to be used
Derek Millerf3d0a562018-10-18 16:41:08 -0500154 * \param[in] alg The algorithm to be used to underlie the MAC
Derek Miller16e72292018-10-15 16:14:24 -0500155 * operation
156 * \param[out] p_mac A buffer where the generated MAC will be
157 * placed
Derek Miller81133a62018-10-23 14:55:32 -0500158 * \param[in] mac_size The size in bytes of the `p_mac` buffer
Derek Miller16e72292018-10-15 16:14:24 -0500159 * \param[out] p_mac_length After completion, will contain the number of
160 * bytes placed in the `output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100161 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500162 * \retval PSA_SUCCESS
163 * Success.
164 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100165typedef psa_status_t (*psa_drv_mac_opaque_generate_t)(const uint8_t *p_input,
166 size_t input_length,
167 psa_key_slot_t key_slot,
168 psa_algorithm_t alg,
169 uint8_t *p_mac,
170 size_t mac_size,
171 size_t *p_mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500172
Derek Miller16e72292018-10-15 16:14:24 -0500173/** \brief A function that performs an MAC operation in one command and
174 * compare the resulting MAC against a known value using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100175 *
Derek Miller16e72292018-10-15 16:14:24 -0500176 * \param[in] p_input A buffer containing the message to be MACed
177 * \param[in] input_length The size in bytes of `input`
178 * \param[in] key_slot The slot of the key to be used
179 * \param[in] alg The algorithm to be used to underlie the MAC
180 * operation
181 * \param[in] p_mac The MAC value against which the resulting MAC will
182 * be compared against
183 * \param[in] mac_length The size in bytes of `mac`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100184 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500185 * \retval PSA_SUCCESS
Derek Miller16e72292018-10-15 16:14:24 -0500186 * The operation completed successfully and the MACs matched each
187 * other
Derek Miller5b3417a2018-10-10 17:55:03 -0500188 * \retval PSA_ERROR_INVALID_SIGNATURE
Derek Miller16e72292018-10-15 16:14:24 -0500189 * The operation completed successfully, but the calculated MAC did
190 * not match the provided MAC
Derek Miller5b3417a2018-10-10 17:55:03 -0500191 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100192typedef psa_status_t (*psa_drv_mac_opaque_verify_t)(const uint8_t *p_input,
193 size_t input_length,
194 psa_key_slot_t key_slot,
195 psa_algorithm_t alg,
196 const uint8_t *p_mac,
197 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500198
Derek Miller16e72292018-10-15 16:14:24 -0500199/** \brief A struct containing all of the function pointers needed to
200 * implement MAC operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100201 *
Derek Miller16e72292018-10-15 16:14:24 -0500202 * PSA Crypto API implementations should populate the table as appropriate
203 * upon startup.
Derek Miller5b3417a2018-10-10 17:55:03 -0500204 *
Derek Miller765682c2018-10-22 15:27:27 -0500205 * If one of the functions is not implemented (such as
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100206 * `psa_drv_mac_opaque_generate_t`), it should be set to NULL.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100207 *
Derek Miller16e72292018-10-15 16:14:24 -0500208 * Driver implementers should ensure that they implement all of the functions
209 * that make sense for their hardware, and that they provide a full solution
210 * (for example, if they support `p_setup`, they should also support
211 * `p_update` and at least one of `p_finish` or `p_finish_verify`).
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100212 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500213 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +0100214typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -0500215 /**The size in bytes of the hardware-specific Opaque-MAC Context structure
216 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100217 size_t context_size;
Derek Miller16e72292018-10-15 16:14:24 -0500218 /** Function that performs the setup operation
219 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100220 psa_drv_mac_opaque_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -0500221 /** Function that performs the update operation
222 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100223 psa_drv_mac_opaque_update_t *p_update;
Derek Miller16e72292018-10-15 16:14:24 -0500224 /** Function that completes the operation
225 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100226 psa_drv_mac_opaque_finish_t *p_finish;
Derek Miller16e72292018-10-15 16:14:24 -0500227 /** Function that completed a MAC operation with a verify check
228 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100229 psa_drv_mac_opaque_finish_verify_t *p_finish_verify;
Derek Miller16e72292018-10-15 16:14:24 -0500230 /** Function that aborts a previoustly started operation
231 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100232 psa_drv_mac_opaque_abort_t *p_abort;
Derek Miller16e72292018-10-15 16:14:24 -0500233 /** Function that performs the MAC operation in one call
234 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100235 psa_drv_mac_opaque_generate_t *p_mac;
Derek Miller16e72292018-10-15 16:14:24 -0500236 /** Function that performs the MAC and verify operation in one call
237 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100238 psa_drv_mac_opaque_verify_t *p_mac_verify;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +0100239} psa_drv_mac_opaque_t;
Derek Miller16e72292018-10-15 16:14:24 -0500240/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500241
242/** \defgroup transparent_mac Transparent Message Authentication Code
Derek Miller765682c2018-10-22 15:27:27 -0500243 * Generation and authentication of Message Authentication Codes (MACs) using
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100244 * transparent keys can be done either as a single function call (via the
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100245 * `psa_drv_mac_transparent_generate_t` or `psa_mac_transparent_verify_t`
Derek Miller765682c2018-10-22 15:27:27 -0500246 * functions), or in parts using the following sequence:
247 * - `psa_mac_transparent_setup_t`
248 * - `psa_mac_transparent_update_t`
249 * - `psa_mac_transparent_update_t`
250 * - ...
251 * - `psa_mac_transparent_finish_t` or `psa_mac_transparent_finish_verify_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100252 *
253 * If a previously started Transparent MAC operation needs to be terminated, it
Derek Miller765682c2018-10-22 15:27:27 -0500254 * should be done so by the `psa_mac_transparent_abort_t`. Failure to do so may
255 * result in allocated resources not being freed or in other undefined
256 * behavior.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100257 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500258 */
Derek Miller16e72292018-10-15 16:14:24 -0500259/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500260
261/** \brief The hardware-specific transparent-key MAC context structure
Derek Miller765682c2018-10-22 15:27:27 -0500262 *
Derek Miller16e72292018-10-15 16:14:24 -0500263 * The contents of this structure are implementation dependent and are
264 * therefore not described here.
Derek Miller5b3417a2018-10-10 17:55:03 -0500265 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100266typedef struct psa_drv_mac_transparent_context_s psa_drv_mac_transparent_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500267
Derek Miller16e72292018-10-15 16:14:24 -0500268/** \brief The function prototype for the setup operation of a
269 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100270 *
Derek Miller16e72292018-10-15 16:14:24 -0500271 * Functions that implement the prototype should be named in the following
272 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500273 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100274 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_setup
Derek Miller5b3417a2018-10-10 17:55:03 -0500275 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500276 * Where `ALGO` is the name of the underlying primitive, and `MAC_VARIANT`
277 * is the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100278 *
279 * \param[in,out] p_context A structure that will contain the
Derek Miller16e72292018-10-15 16:14:24 -0500280 * hardware-specific MAC context
281 * \param[in] p_key A buffer containing the cleartext key material
282 * to be used in the operation
283 * \param[in] key_length The size in bytes of the key material
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100284 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500285 * \retval PSA_SUCCESS
286 * Success.
287 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100288typedef psa_status_t (*psa_drv_mac_transparent_setup_t)(psa_drv_mac_transparent_context_t *p_context,
289 const uint8_t *p_key,
290 size_t key_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500291
Derek Miller16e72292018-10-15 16:14:24 -0500292/** \brief The function prototype for the update operation of a
293 * transparent-key MAC operation
Derek Miller5b3417a2018-10-10 17:55:03 -0500294 *
Derek Miller16e72292018-10-15 16:14:24 -0500295 * Functions that implement the prototype should be named in the following
296 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500297 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100298 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_update
Derek Miller5b3417a2018-10-10 17:55:03 -0500299 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500300 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT`
301 * is the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100302 *
Derek Miller16e72292018-10-15 16:14:24 -0500303 * \param[in,out] p_context A hardware-specific structure for the
304 * previously-established MAC operation to be
305 * continued
306 * \param[in] p_input A buffer containing the message to be appended
307 * to the MAC operation
308 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -0500309 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100310typedef psa_status_t (*psa_drv_mac_transparent_update_t)(psa_drv_mac_transparent_context_t *p_context,
311 const uint8_t *p_input,
312 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500313
Derek Miller16e72292018-10-15 16:14:24 -0500314/** \brief The function prototype for the finish operation of a
315 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100316 *
Derek Miller16e72292018-10-15 16:14:24 -0500317 * Functions that implement the prototype should be named in the following
318 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500319 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100320 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish
Derek Miller5b3417a2018-10-10 17:55:03 -0500321 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500322 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
323 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100324 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500325 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500326 * previously started MAC operation to be
327 * finished
328 * \param[out] p_mac A buffer where the generated MAC will be placed
329 * \param[in] mac_length The size in bytes of the buffer that has been
330 * allocated for the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100331 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500332 * \retval PSA_SUCCESS
333 * Success.
334 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100335typedef psa_status_t (*psa_drv_mac_transparent_finish_t)(psa_drv_mac_transparent_context_t *p_context,
336 uint8_t *p_mac,
337 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500338
Derek Miller16e72292018-10-15 16:14:24 -0500339/** \brief The function prototype for the finish and verify operation of a
340 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100341 *
Derek Miller16e72292018-10-15 16:14:24 -0500342 * Functions that implement the prototype should be named in the following
343 * convention:
344 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100345 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish_verify
Derek Miller16e72292018-10-15 16:14:24 -0500346 * ~~~~~~~~~~~~~
347 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
348 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100349 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500350 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500351 * previously started MAC operation to be
Derek Millerf3d0a562018-10-18 16:41:08 -0500352 * verified and finished
Derek Miller16e72292018-10-15 16:14:24 -0500353 * \param[in] p_mac A buffer containing the MAC that will be used
354 * for verification
355 * \param[in] mac_length The size in bytes of the data in the `p_mac`
356 * buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100357 *
Derek Miller16e72292018-10-15 16:14:24 -0500358 * \retval PSA_SUCCESS
359 * The operation completed successfully and the comparison matched
Derek Miller5b3417a2018-10-10 17:55:03 -0500360 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100361typedef psa_status_t (*psa_drv_mac_transparent_finish_verify_t)(psa_drv_mac_transparent_context_t *p_context,
362 const uint8_t *p_mac,
363 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500364
365/** \brief The function prototype for the abort operation for a previously
366 * started transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100367 *
Derek Miller16e72292018-10-15 16:14:24 -0500368 * Functions that implement the prototype should be named in the following
369 * convention:
370 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100371 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_abort
Derek Miller16e72292018-10-15 16:14:24 -0500372 * ~~~~~~~~~~~~~
373 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
374 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100375 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500376 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500377 * previously started MAC operation to be
Derek Millerf3d0a562018-10-18 16:41:08 -0500378 * aborted
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100379 *
Derek Miller16e72292018-10-15 16:14:24 -0500380 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100381typedef psa_status_t (*psa_drv_mac_transparent_abort_t)(psa_drv_mac_transparent_context_t *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500382
383/** \brief The function prototype for a one-shot operation of a transparent-key
384 * MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100385 *
Derek Miller16e72292018-10-15 16:14:24 -0500386 * Functions that implement the prototype should be named in the following
387 * convention:
388 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100389 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>
Derek Miller16e72292018-10-15 16:14:24 -0500390 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100391 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
Derek Miller16e72292018-10-15 16:14:24 -0500392 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100393 *
Derek Miller16e72292018-10-15 16:14:24 -0500394 * \param[in] p_input A buffer containing the data to be MACed
395 * \param[in] input_length The length in bytes of the `p_input` data
396 * \param[in] p_key A buffer containing the key material to be used
397 * for the MAC operation
398 * \param[in] key_length The length in bytes of the `p_key` data
399 * \param[in] alg The algorithm to be performed
400 * \param[out] p_mac The buffer where the resulting MAC will be placed
401 * upon success
402 * \param[in] mac_length The length in bytes of the `p_mac` buffer
403 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100404typedef psa_status_t (*psa_drv_mac_transparent_t)(const uint8_t *p_input,
405 size_t input_length,
406 const uint8_t *p_key,
407 size_t key_length,
408 psa_algorithm_t alg,
409 uint8_t *p_mac,
410 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500411
412/** \brief The function prototype for a one-shot operation of a transparent-key
413 * MAC Verify operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100414 *
Derek Miller16e72292018-10-15 16:14:24 -0500415 * Functions that implement the prototype should be named in the following
416 * convention:
417 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100418 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_verify
Derek Miller16e72292018-10-15 16:14:24 -0500419 * ~~~~~~~~~~~~~
420 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
421 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100422 *
Derek Miller16e72292018-10-15 16:14:24 -0500423 * \param[in] p_input A buffer containing the data to be MACed
424 * \param[in] input_length The length in bytes of the `p_input` data
425 * \param[in] p_key A buffer containing the key material to be used
426 * for the MAC operation
427 * \param[in] key_length The length in bytes of the `p_key` data
428 * \param[in] alg The algorithm to be performed
429 * \param[in] p_mac The MAC data to be compared
430 * \param[in] mac_length The length in bytes of the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100431 *
Derek Miller16e72292018-10-15 16:14:24 -0500432 * \retval PSA_SUCCESS
433 * The operation completed successfully and the comparison matched
434 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100435typedef psa_status_t (*psa_drv_mac_transparent_verify_t)(const uint8_t *p_input,
436 size_t input_length,
437 const uint8_t *p_key,
438 size_t key_length,
439 psa_algorithm_t alg,
440 const uint8_t *p_mac,
441 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500442/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500443
444/** \defgroup opaque_cipher Opaque Symmetric Ciphers
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100445 *
Derek Miller765682c2018-10-22 15:27:27 -0500446 * Encryption and Decryption using opaque keys in block modes other than ECB
447 * must be done in multiple parts, using the following flow:
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100448 * - `psa_drv_cipher_opaque_setup_t`
449 * - `psa_drv_cipher_opaque_set_iv_t` (optional depending upon block mode)
450 * - `psa_drv_cipher_opaque_update_t`
Derek Miller765682c2018-10-22 15:27:27 -0500451 * - ...
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100452 * - `psa_drv_cipher_opaque_finish_t`
Derek Miller765682c2018-10-22 15:27:27 -0500453
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100454 * If a previously started Opaque Cipher operation needs to be terminated, it
Derek Miller765682c2018-10-22 15:27:27 -0500455 * should be done so by the `psa_cipher_opaque_abort_t`. Failure to do so may
456 * result in allocated resources not being freed or in other undefined
457 * behavior.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100458 *
Derek Miller765682c2018-10-22 15:27:27 -0500459 * In situations where a PSA Cryptographic API implementation is using a block
460 * mode not-supported by the underlying hardware or driver, it can construct
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100461 * the block mode itself, while calling the `psa_drv_cipher_opaque_ecb_t` function
Derek Miller765682c2018-10-22 15:27:27 -0500462 * pointer for the cipher operations.
Derek Miller5b3417a2018-10-10 17:55:03 -0500463 */
Derek Miller16e72292018-10-15 16:14:24 -0500464/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500465
Derek Miller16e72292018-10-15 16:14:24 -0500466/** \brief A function pointer that provides the cipher setup function for
467 * opaque-key operations
Derek Miller5b3417a2018-10-10 17:55:03 -0500468 *
Derek Miller16e72292018-10-15 16:14:24 -0500469 * \param[in,out] p_context A structure that will contain the
470 * hardware-specific cipher context.
471 * \param[in] key_slot The slot of the key to be used for the
472 * operation
473 * \param[in] algorithm The algorithm to be used in the cipher
474 * operation
475 * \param[in] direction Indicates whether the operation is an encrypt
476 * or decrypt
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100477 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500478 * \retval PSA_SUCCESS
479 * \retval PSA_ERROR_NOT_SUPPORTED
480 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100481typedef psa_status_t (*psa_drv_cipher_opaque_setup_t)(void *p_context,
482 psa_key_slot_t key_slot,
483 psa_algorithm_t algorithm,
Jaeden Amero7632f622018-10-26 11:26:45 +0100484 psa_encrypt_or_decrypt_t direction);
Derek Miller16e72292018-10-15 16:14:24 -0500485
486/** \brief A function pointer that sets the initialization vector (if
487 * necessary) for an opaque cipher operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100488 *
Derek Miller81133a62018-10-23 14:55:32 -0500489 * Rationale: The `psa_cipher_*` function in the PSA Cryptographic API has two
Derek Miller765682c2018-10-22 15:27:27 -0500490 * IV functions: one to set the IV, and one to generate it internally. The
Jaeden Ameroe095d602018-10-26 12:09:31 +0100491 * generate function is not necessary for the drivers to implement as the PSA
492 * Crypto implementation can do the generation using its RNG features.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100493 *
Derek Miller16e72292018-10-15 16:14:24 -0500494 * \param[in,out] p_context A structure that contains the previously set up
495 * hardware-specific cipher context
496 * \param[in] p_iv A buffer containing the initialization vector
497 * \param[in] iv_length The size (in bytes) of the `p_iv` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100498 *
Derek Miller16e72292018-10-15 16:14:24 -0500499 * \retval PSA_SUCCESS
500 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100501typedef psa_status_t (*psa_drv_cipher_opaque_set_iv_t)(void *p_context,
502 const uint8_t *p_iv,
503 size_t iv_length);
Derek Miller16e72292018-10-15 16:14:24 -0500504
505/** \brief A function that continues a previously started opaque-key cipher
506 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100507 *
Derek Miller16e72292018-10-15 16:14:24 -0500508 * \param[in,out] p_context A hardware-specific structure for the
509 * previously started cipher operation
510 * \param[in] p_input A buffer containing the data to be
511 * encrypted/decrypted
512 * \param[in] input_size The size in bytes of the buffer pointed to
513 * by `p_input`
514 * \param[out] p_output The caller-allocated buffer where the
515 * output will be placed
516 * \param[in] output_size The allocated size in bytes of the
517 * `p_output` buffer
518 * \param[out] p_output_length After completion, will contain the number
519 * of bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100520 *
Derek Miller16e72292018-10-15 16:14:24 -0500521 * \retval PSA_SUCCESS
522 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100523typedef psa_status_t (*psa_drv_cipher_opaque_update_t)(void *p_context,
524 const uint8_t *p_input,
525 size_t input_size,
526 uint8_t *p_output,
527 size_t output_size,
528 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -0500529
530/** \brief A function that completes a previously started opaque-key cipher
531 * operation
532 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500533 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500534 * previously started cipher operation
Derek Millerf3d0a562018-10-18 16:41:08 -0500535 * \param[out] p_output The caller-allocated buffer where the output
Derek Miller16e72292018-10-15 16:14:24 -0500536 * will be placed
537 * \param[in] output_size The allocated size in bytes of the `p_output`
538 * buffer
539 * \param[out] p_output_length After completion, will contain the number of
540 * bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100541 *
Derek Miller16e72292018-10-15 16:14:24 -0500542 * \retval PSA_SUCCESS
543 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100544typedef psa_status_t (*psa_drv_cipher_opaque_finish_t)(void *p_context,
545 uint8_t *p_output,
546 size_t output_size,
547 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -0500548
549/** \brief A function that aborts a previously started opaque-key cipher
550 * operation
551 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500552 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500553 * previously started cipher operation
554 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100555typedef psa_status_t (*psa_drv_cipher_opaque_abort_t)(void *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500556
557/** \brief A function that performs the ECB block mode for opaque-key cipher
558 * operations
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100559 *
Derek Miller16e72292018-10-15 16:14:24 -0500560 * Note: this function should only be used with implementations that do not
561 * provide a needed higher-level operation.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100562 *
Derek Miller16e72292018-10-15 16:14:24 -0500563 * \param[in] key_slot The slot of the key to be used for the operation
564 * \param[in] algorithm The algorithm to be used in the cipher operation
565 * \param[in] direction Indicates whether the operation is an encrypt or
566 * decrypt
567 * \param[in] p_input A buffer containing the data to be
568 * encrypted/decrypted
569 * \param[in] input_size The size in bytes of the buffer pointed to by
570 * `p_input`
Derek Millerf3d0a562018-10-18 16:41:08 -0500571 * \param[out] p_output The caller-allocated buffer where the output will
Derek Miller16e72292018-10-15 16:14:24 -0500572 * be placed
573 * \param[in] output_size The allocated size in bytes of the `p_output`
574 * buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100575 *
Derek Miller16e72292018-10-15 16:14:24 -0500576 * \retval PSA_SUCCESS
577 * \retval PSA_ERROR_NOT_SUPPORTED
578 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100579typedef psa_status_t (*psa_drv_cipher_opaque_ecb_t)(psa_key_slot_t key_slot,
580 psa_algorithm_t algorithm,
Jaeden Amero7632f622018-10-26 11:26:45 +0100581 psa_encrypt_or_decrypt_t direction,
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100582 const uint8_t *p_input,
583 size_t input_size,
584 uint8_t *p_output,
585 size_t output_size);
Derek Miller5b3417a2018-10-10 17:55:03 -0500586
587/**
Derek Miller16e72292018-10-15 16:14:24 -0500588 * \brief A struct containing all of the function pointers needed to implement
589 * cipher operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100590 *
Derek Miller16e72292018-10-15 16:14:24 -0500591 * PSA Crypto API implementations should populate instances of the table as
592 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100593 *
Derek Miller16e72292018-10-15 16:14:24 -0500594 * If one of the functions is not implemented (such as
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100595 * `psa_drv_cipher_opaque_ecb_t`), it should be set to NULL.
Derek Miller5b3417a2018-10-10 17:55:03 -0500596 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +0100597typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -0500598 /** The size in bytes of the hardware-specific Opaque Cipher context
599 * structure
600 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100601 size_t size;
Derek Miller16e72292018-10-15 16:14:24 -0500602 /** Function that performs the setup operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100603 psa_drv_cipher_opaque_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -0500604 /** Function that sets the IV (if necessary) */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100605 psa_drv_cipher_opaque_set_iv_t *p_set_iv;
Derek Miller16e72292018-10-15 16:14:24 -0500606 /** Function that performs the update operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100607 psa_drv_cipher_opaque_update_t *p_update;
Derek Miller16e72292018-10-15 16:14:24 -0500608 /** Function that completes the operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100609 psa_drv_cipher_opaque_finish_t *p_finish;
Derek Miller16e72292018-10-15 16:14:24 -0500610 /** Function that aborts the operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100611 psa_drv_cipher_opaque_abort_t *p_abort;
Derek Miller16e72292018-10-15 16:14:24 -0500612 /** Function that performs ECB mode for the cipher
613 * (Danger: ECB mode should not be used directly by clients of the PSA
614 * Crypto Client API)
615 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100616 psa_drv_cipher_opaque_ecb_t *p_ecb;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +0100617} psa_drv_cipher_opaque_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500618
Derek Miller16e72292018-10-15 16:14:24 -0500619/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500620
621/** \defgroup transparent_cipher Transparent Block Cipher
Derek Miller765682c2018-10-22 15:27:27 -0500622 * Encryption and Decryption using transparent keys in block modes other than
623 * ECB must be done in multiple parts, using the following flow:
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100624 * - `psa_drv_cipher_transparent_setup_t`
625 * - `psa_drv_cipher_transparent_set_iv_t` (optional depending upon block mode)
626 * - `psa_drv_cipher_transparent_update_t`
Derek Miller765682c2018-10-22 15:27:27 -0500627 * - ...
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100628 * - `psa_drv_cipher_transparent_finish_t`
Derek Miller765682c2018-10-22 15:27:27 -0500629
630 * If a previously started Transparent Cipher operation needs to be terminated,
631 * it should be done so by the `psa_cipher_transparent_abort_t`. Failure to do
632 * so may result in allocated resources not being freed or in other undefined
633 * behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -0500634 */
Derek Miller16e72292018-10-15 16:14:24 -0500635/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500636
637/** \brief The hardware-specific transparent-key Cipher context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100638 *
Derek Miller765682c2018-10-22 15:27:27 -0500639 * The contents of this structure are implementation dependent and are
Derek Miller16e72292018-10-15 16:14:24 -0500640 * therefore not described here.
Derek Miller5b3417a2018-10-10 17:55:03 -0500641 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100642typedef struct psa_drv_cipher_transparent_context_s psa_drv_cipher_transparent_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500643
Derek Miller16e72292018-10-15 16:14:24 -0500644/** \brief The function prototype for the setup operation of transparent-key
645 * block cipher operations.
646 * Functions that implement the prototype should be named in the following
647 * conventions:
Derek Miller5b3417a2018-10-10 17:55:03 -0500648 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100649 * psa_drv_cipher_transparent_setup_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500650 * ~~~~~~~~~~~~~
651 * Where
652 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
653 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Derek Miller16e72292018-10-15 16:14:24 -0500654 * or for stream ciphers:
655 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100656 * psa_drv_cipher_transparent_setup_<CIPHER_NAME>
Derek Miller16e72292018-10-15 16:14:24 -0500657 * ~~~~~~~~~~~~~
658 * Where `CIPHER_NAME` is the name of a stream cipher (i.e. RC4)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100659 *
Derek Miller16e72292018-10-15 16:14:24 -0500660 * \param[in,out] p_context A structure that will contain the
661 * hardware-specific cipher context
662 * \param[in] direction Indicates if the operation is an encrypt or a
663 * decrypt
664 * \param[in] p_key_data A buffer containing the cleartext key material
665 * to be used in the operation
666 * \param[in] key_data_size The size in bytes of the key material
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100667 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500668 * \retval PSA_SUCCESS
669 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100670typedef psa_status_t (*psa_drv_cipher_transparent_setup_t)(psa_drv_cipher_transparent_context_t *p_context,
Jaeden Amero7632f622018-10-26 11:26:45 +0100671 psa_encrypt_or_decrypt_t direction,
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100672 const uint8_t *p_key_data,
673 size_t key_data_size);
Derek Miller5b3417a2018-10-10 17:55:03 -0500674
Derek Miller16e72292018-10-15 16:14:24 -0500675/** \brief The function prototype for the set initialization vector operation
676 * of transparent-key block cipher operations
677 * Functions that implement the prototype should be named in the following
678 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500679 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100680 * psa_drv_cipher_transparent_set_iv_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500681 * ~~~~~~~~~~~~~
682 * Where
683 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
684 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100685 *
Derek Miller16e72292018-10-15 16:14:24 -0500686 * \param[in,out] p_context A structure that contains the previously setup
687 * hardware-specific cipher context
688 * \param[in] p_iv A buffer containing the initialization vecotr
689 * \param[in] iv_length The size in bytes of the contents of `p_iv`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100690 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500691 * \retval PSA_SUCCESS
Jaeden Amero0a09f772018-10-26 11:42:32 +0100692 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100693typedef psa_status_t (*psa_drv_cipher_transparent_set_iv_t)(psa_drv_cipher_transparent_context_t *p_context,
694 const uint8_t *p_iv,
695 size_t iv_length);
Derek Miller16e72292018-10-15 16:14:24 -0500696
697/** \brief The function prototype for the update operation of transparent-key
698 * block cipher operations.
Derek Miller5b3417a2018-10-10 17:55:03 -0500699 *
Derek Miller16e72292018-10-15 16:14:24 -0500700 * Functions that implement the prototype should be named in the following
701 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500702 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100703 * psa_drv_cipher_transparent_update_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500704 * ~~~~~~~~~~~~~
705 * Where
706 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
707 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100708 *
Derek Miller16e72292018-10-15 16:14:24 -0500709 * \param[in,out] p_context A hardware-specific structure for the
710 * previously started cipher operation
711 * \param[in] p_input A buffer containing the data to be
712 * encrypted or decrypted
713 * \param[in] input_size The size in bytes of the `p_input` buffer
714 * \param[out] p_output A caller-allocated buffer where the
715 * generated output will be placed
716 * \param[in] output_size The size in bytes of the `p_output` buffer
717 * \param[out] p_output_length After completion, will contain the number
718 * of bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100719 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500720 * \retval PSA_SUCCESS
721 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100722typedef psa_status_t (*psa_drv_cipher_transparent_update_t)(psa_drv_cipher_transparent_context_t *p_context,
723 const uint8_t *p_input,
724 size_t input_size,
725 uint8_t *p_output,
726 size_t output_size,
727 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500728
Derek Miller16e72292018-10-15 16:14:24 -0500729/** \brief The function prototype for the finish operation of transparent-key
730 * block cipher operations.
Jaeden Amero0a09f772018-10-26 11:42:32 +0100731 *
Derek Miller16e72292018-10-15 16:14:24 -0500732 * Functions that implement the prototype should be named in the following
733 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500734 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100735 * psa_drv_cipher_transparent_finish_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500736 * ~~~~~~~~~~~~~
737 * Where
738 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
739 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Derek Miller16e72292018-10-15 16:14:24 -0500740 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500741 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500742 * previously started cipher operation
743 * \param[out] p_output A caller-allocated buffer where the generated
744 * output will be placed
745 * \param[in] output_size The size in bytes of the `p_output` buffer
746 * \param[out] p_output_length After completion, will contain the number of
747 * bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100748 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500749 * \retval PSA_SUCCESS
750 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100751typedef psa_status_t (*psa_drv_cipher_transparent_finish_t)(psa_drv_cipher_transparent_context_t *p_context,
752 uint8_t *p_output,
753 size_t output_size,
754 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500755
Derek Miller16e72292018-10-15 16:14:24 -0500756/** \brief The function prototype for the abort operation of transparent-key
757 * block cipher operations.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100758 *
Derek Miller16e72292018-10-15 16:14:24 -0500759 * Functions that implement the following prototype should be named in the
760 * following convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500761 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100762 * psa_drv_cipher_transparent_abort_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500763 * ~~~~~~~~~~~~~
764 * Where
765 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
766 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100767 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500768 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500769 * previously started cipher operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100770 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500771 * \retval PSA_SUCCESS
772 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100773typedef psa_status_t (*psa_drv_cipher_transparent_abort_t)(psa_drv_cipher_transparent_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500774
Derek Miller16e72292018-10-15 16:14:24 -0500775/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500776
Derek Miller16e72292018-10-15 16:14:24 -0500777/** \defgroup driver_digest Message Digests
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100778 *
Derek Miller765682c2018-10-22 15:27:27 -0500779 * Generation and authentication of Message Digests (aka hashes) must be done
780 * in parts using the following sequence:
781 * - `psa_hash_setup_t`
782 * - `psa_hash_update_t`
783 * - ...
784 * - `psa_hash_finish_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100785 *
Derek Miller765682c2018-10-22 15:27:27 -0500786 * If a previously started Message Digest operation needs to be terminated
787 * before the `psa_hash_finish_t` operation is complete, it should be aborted
788 * by the `psa_hash_abort_t`. Failure to do so may result in allocated
789 * resources not being freed or in other undefined behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -0500790 */
Derek Miller16e72292018-10-15 16:14:24 -0500791/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500792
793/** \brief The hardware-specific hash context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100794 *
Derek Miller16e72292018-10-15 16:14:24 -0500795 * The contents of this structure are implementation dependent and are
796 * therefore not described here
Derek Miller5b3417a2018-10-10 17:55:03 -0500797 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100798typedef struct psa_drv_hash_context_s psa_drv_hash_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500799
Derek Miller16e72292018-10-15 16:14:24 -0500800/** \brief The function prototype for the start operation of a hash (message
801 * digest) operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100802 *
Derek Miller16e72292018-10-15 16:14:24 -0500803 * Functions that implement the prototype should be named in the following
804 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500805 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100806 * psa_drv_hash_<ALGO>_setup
Derek Miller5b3417a2018-10-10 17:55:03 -0500807 * ~~~~~~~~~~~~~
808 * Where `ALGO` is the name of the underlying hash function
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100809 *
Derek Miller16e72292018-10-15 16:14:24 -0500810 * \param[in,out] p_context A structure that will contain the
811 * hardware-specific hash context
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100812 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500813 * \retval PSA_SUCCESS Success.
814 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100815typedef psa_status_t (*psa_drv_hash_setup_t)(psa_drv_hash_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500816
Derek Miller16e72292018-10-15 16:14:24 -0500817/** \brief The function prototype for the update operation of a hash (message
818 * digest) operation
Derek Miller5b3417a2018-10-10 17:55:03 -0500819 *
Derek Miller16e72292018-10-15 16:14:24 -0500820 * Functions that implement the prototype should be named in the following
821 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500822 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100823 * psa_drv_hash_<ALGO>_update
Derek Miller5b3417a2018-10-10 17:55:03 -0500824 * ~~~~~~~~~~~~~
825 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100826 *
Derek Miller16e72292018-10-15 16:14:24 -0500827 * \param[in,out] p_context A hardware-specific structure for the
828 * previously-established hash operation to be
829 * continued
830 * \param[in] p_input A buffer containing the message to be appended
831 * to the hash operation
832 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -0500833 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100834typedef psa_status_t (*psa_drv_hash_update_t)(psa_drv_hash_context_t *p_context,
835 const uint8_t *p_input,
836 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500837
Derek Miller16e72292018-10-15 16:14:24 -0500838/** \brief The prototype for the finish operation of a hash (message digest)
839 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100840 *
Derek Miller16e72292018-10-15 16:14:24 -0500841 * Functions that implement the prototype should be named in the following
842 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500843 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100844 * psa_drv_hash_<ALGO>_finish
Derek Miller5b3417a2018-10-10 17:55:03 -0500845 * ~~~~~~~~~~~~~
846 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100847 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500848 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500849 * previously started hash operation to be
850 * fiinished
851 * \param[out] p_output A buffer where the generated digest will be
852 * placed
853 * \param[in] output_size The size in bytes of the buffer that has been
854 * allocated for the `p_output` buffer
Derek Millerf3d0a562018-10-18 16:41:08 -0500855 * \param[out] p_output_length The number of bytes placed in `p_output` after
856 * success
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100857 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500858 * \retval PSA_SUCCESS
859 * Success.
860 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100861typedef psa_status_t (*psa_drv_hash_finish_t)(psa_drv_hash_context_t *p_context,
862 uint8_t *p_output,
863 size_t output_size,
864 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500865
Derek Miller16e72292018-10-15 16:14:24 -0500866/** \brief The function prototype for the abort operation of a hash (message
867 * digest) operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100868 *
Derek Miller16e72292018-10-15 16:14:24 -0500869 * Functions that implement the prototype should be named in the following
870 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500871 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100872 * psa_drv_hash_<ALGO>_abort
Derek Miller5b3417a2018-10-10 17:55:03 -0500873 * ~~~~~~~~~~~~~
874 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100875 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500876 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500877 * started hash operation to be aborted
Derek Miller5b3417a2018-10-10 17:55:03 -0500878 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100879typedef void (*psa_drv_hash_abort_t)(psa_drv_hash_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500880
Derek Miller16e72292018-10-15 16:14:24 -0500881/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500882
883
884/** \defgroup opaque_asymmetric Opaque Asymmetric Cryptography
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100885 *
Derek Miller765682c2018-10-22 15:27:27 -0500886 * Since the amount of data that can (or should) be encrypted or signed using
887 * asymmetric keys is limited by the key size, asymmetric key operations using
888 * opaque keys must be done in single function calls.
Derek Miller5b3417a2018-10-10 17:55:03 -0500889 */
Derek Miller16e72292018-10-15 16:14:24 -0500890/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500891
892/**
Derek Miller16e72292018-10-15 16:14:24 -0500893 * \brief A function that signs a hash or short message with a private key
Derek Miller5b3417a2018-10-10 17:55:03 -0500894 *
Derek Miller16e72292018-10-15 16:14:24 -0500895 * \param[in] key_slot Key slot of an asymmetric key pair
896 * \param[in] alg A signature algorithm that is compatible
897 * with the type of `key`
Derek Miller765682c2018-10-22 15:27:27 -0500898 * \param[in] p_hash The hash to sign
Derek Miller16e72292018-10-15 16:14:24 -0500899 * \param[in] hash_length Size of the `p_hash` buffer in bytes
900 * \param[out] p_signature Buffer where the signature is to be written
Derek Millerf3d0a562018-10-18 16:41:08 -0500901 * \param[in] signature_size Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500902 * \param[out] p_signature_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -0500903 * that make up the returned signature value
Derek Miller5b3417a2018-10-10 17:55:03 -0500904 *
905 * \retval PSA_SUCCESS
906 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100907typedef psa_status_t (*psa_drv_asymmetric_opaque_sign_t)(psa_key_slot_t key_slot,
908 psa_algorithm_t alg,
909 const uint8_t *p_hash,
910 size_t hash_length,
911 uint8_t *p_signature,
912 size_t signature_size,
913 size_t *p_signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500914
915/**
Derek Miller16e72292018-10-15 16:14:24 -0500916 * \brief A function that verifies the signature a hash or short message using
Derek Miller765682c2018-10-22 15:27:27 -0500917 * an asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -0500918 *
Derek Miller16e72292018-10-15 16:14:24 -0500919 * \param[in] key_slot Key slot of a public key or an asymmetric key
920 * pair
921 * \param[in] alg A signature algorithm that is compatible with
922 * the type of `key`
Derek Miller765682c2018-10-22 15:27:27 -0500923 * \param[in] p_hash The hash whose signature is to be verified
Derek Miller16e72292018-10-15 16:14:24 -0500924 * \param[in] hash_length Size of the `p_hash` buffer in bytes
925 * \param[in] p_signature Buffer containing the signature to verify
926 * \param[in] signature_length Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500927 *
928 * \retval PSA_SUCCESS
929 * The signature is valid.
930 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100931typedef psa_status_t (*psa_drv_asymmetric_opaque_verify_t)(psa_key_slot_t key_slot,
932 psa_algorithm_t alg,
933 const uint8_t *p_hash,
934 size_t hash_length,
935 const uint8_t *p_signature,
936 size_t signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500937
938/**
Derek Miller765682c2018-10-22 15:27:27 -0500939 * \brief A function that encrypts a short message with an asymmetric public
940 * key
Derek Miller5b3417a2018-10-10 17:55:03 -0500941 *
Derek Miller16e72292018-10-15 16:14:24 -0500942 * \param[in] key_slot Key slot of a public key or an asymmetric key
943 * pair
944 * \param[in] alg An asymmetric encryption algorithm that is
945 * compatible with the type of `key`
946 * \param[in] p_input The message to encrypt
947 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500948 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -0500949 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -0500950 * If the algorithm does not support a
951 * salt, pass `NULL`.
952 * If the algorithm supports an optional
953 * salt and you do not want to pass a salt,
954 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -0500955 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
956 * supported.
957 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500958 * If `p_salt` is `NULL`, pass 0.
959 * \param[out] p_output Buffer where the encrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -0500960 * be written
961 * \param[in] output_size Size of the `p_output` buffer in bytes
962 * \param[out] p_output_length On success, the number of bytes that make up
963 * the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -0500964 *
965 * \retval PSA_SUCCESS
966 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100967typedef psa_status_t (*psa_drv_asymmetric_opaque_encrypt_t)(psa_key_slot_t key_slot,
968 psa_algorithm_t alg,
969 const uint8_t *p_input,
970 size_t input_length,
971 const uint8_t *p_salt,
972 size_t salt_length,
973 uint8_t *p_output,
974 size_t output_size,
975 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500976
977/**
Derek Miller765682c2018-10-22 15:27:27 -0500978 * \brief Decrypt a short message with an asymmetric private key.
Derek Miller5b3417a2018-10-10 17:55:03 -0500979 *
Derek Miller16e72292018-10-15 16:14:24 -0500980 * \param[in] key_slot Key slot of an asymmetric key pair
981 * \param[in] alg An asymmetric encryption algorithm that is
982 * compatible with the type of `key`
983 * \param[in] p_input The message to decrypt
984 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500985 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -0500986 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -0500987 * If the algorithm does not support a
988 * salt, pass `NULL`.
989 * If the algorithm supports an optional
990 * salt and you do not want to pass a salt,
991 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -0500992 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
993 * supported.
994 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500995 * If `p_salt` is `NULL`, pass 0.
996 * \param[out] p_output Buffer where the decrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -0500997 * be written
998 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500999 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001000 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -05001001 *
1002 * \retval PSA_SUCCESS
1003 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001004typedef psa_status_t (*psa_drv_asymmetric_opaque_decrypt_t)(psa_key_slot_t key_slot,
1005 psa_algorithm_t alg,
1006 const uint8_t *p_input,
1007 size_t input_length,
1008 const uint8_t *p_salt,
1009 size_t salt_length,
1010 uint8_t *p_output,
1011 size_t output_size,
1012 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001013
1014/**
Derek Miller16e72292018-10-15 16:14:24 -05001015 * \brief A struct containing all of the function pointers needed to implement
1016 * asymmetric cryptographic operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001017 *
Derek Miller16e72292018-10-15 16:14:24 -05001018 * PSA Crypto API implementations should populate instances of the table as
1019 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001020 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001021 * If one of the functions is not implemented, it should be set to NULL.
1022 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001023typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001024 /** Function that performs the asymmetric sign operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001025 psa_drv_asymmetric_opaque_sign_t *p_sign;
Derek Miller16e72292018-10-15 16:14:24 -05001026 /** Function that performs the asymmetric verify operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001027 psa_drv_asymmetric_opaque_verify_t *p_verify;
Derek Miller16e72292018-10-15 16:14:24 -05001028 /** Function that performs the asymmetric encrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001029 psa_drv_asymmetric_opaque_encrypt_t *p_encrypt;
Derek Miller16e72292018-10-15 16:14:24 -05001030 /** Function that performs the asymmetric decrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001031 psa_drv_asymmetric_opaque_decrypt_t *p_decrypt;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001032} psa_drv_asymmetric_opaque_t;
Derek Miller5b3417a2018-10-10 17:55:03 -05001033
Derek Miller16e72292018-10-15 16:14:24 -05001034/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001035
1036/** \defgroup transparent_asymmetric Transparent Asymmetric Cryptography
Derek Miller765682c2018-10-22 15:27:27 -05001037 *
1038 * Since the amount of data that can (or should) be encrypted or signed using
1039 * asymmetric keys is limited by the key size, asymmetric key operations using
1040 * transparent keys must be done in single function calls.
Derek Miller5b3417a2018-10-10 17:55:03 -05001041 */
Derek Miller16e72292018-10-15 16:14:24 -05001042/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001043
1044
1045/**
Derek Miller16e72292018-10-15 16:14:24 -05001046 * \brief A function that signs a hash or short message with a transparent
Derek Miller765682c2018-10-22 15:27:27 -05001047 * asymmetric private key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001048 *
Derek Miller16e72292018-10-15 16:14:24 -05001049 * Functions that implement the prototype should be named in the following
1050 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001051 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001052 * psa_drv_asymmetric_<ALGO>_sign
Derek Miller5b3417a2018-10-10 17:55:03 -05001053 * ~~~~~~~~~~~~~
1054 * Where `ALGO` is the name of the signing algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001055 *
Derek Miller16e72292018-10-15 16:14:24 -05001056 * \param[in] p_key A buffer containing the private key
1057 * material
1058 * \param[in] key_size The size in bytes of the `p_key` data
1059 * \param[in] alg A signature algorithm that is compatible
1060 * with the type of `p_key`
1061 * \param[in] p_hash The hash or message to sign
1062 * \param[in] hash_length Size of the `p_hash` buffer in bytes
1063 * \param[out] p_signature Buffer where the signature is to be written
1064 * \param[in] signature_size Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001065 * \param[out] p_signature_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001066 * that make up the returned signature value
Derek Miller5b3417a2018-10-10 17:55:03 -05001067 *
1068 * \retval PSA_SUCCESS
1069 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001070typedef psa_status_t (*psa_drv_asymmetric_transparent_sign_t)(const uint8_t *p_key,
1071 size_t key_size,
1072 psa_algorithm_t alg,
1073 const uint8_t *p_hash,
1074 size_t hash_length,
1075 uint8_t *p_signature,
1076 size_t signature_size,
1077 size_t *p_signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001078
1079/**
Derek Miller16e72292018-10-15 16:14:24 -05001080 * \brief A function that verifies the signature a hash or short message using
Derek Miller765682c2018-10-22 15:27:27 -05001081 * a transparent asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -05001082 *
Derek Miller16e72292018-10-15 16:14:24 -05001083 * Functions that implement the prototype should be named in the following
1084 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001085 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001086 * psa_drv_asymmetric_<ALGO>_verify
Derek Miller5b3417a2018-10-10 17:55:03 -05001087 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001088 * Where `ALGO` is the name of the signing algorithm
1089 *
Derek Miller16e72292018-10-15 16:14:24 -05001090 * \param[in] p_key A buffer containing the public key material
1091 * \param[in] key_size The size in bytes of the `p_key` data
1092 * \param[in] alg A signature algorithm that is compatible with
1093 * the type of `key`
1094 * \param[in] p_hash The hash or message whose signature is to be
1095 * verified
1096 * \param[in] hash_length Size of the `p_hash` buffer in bytes
1097 * \param[in] p_signature Buffer containing the signature to verify
1098 * \param[in] signature_length Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001099 *
1100 * \retval PSA_SUCCESS
1101 * The signature is valid.
1102 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001103typedef psa_status_t (*psa_drv_asymmetric_transparent_verify_t)(const uint8_t *p_key,
1104 size_t key_size,
1105 psa_algorithm_t alg,
1106 const uint8_t *p_hash,
1107 size_t hash_length,
1108 const uint8_t *p_signature,
1109 size_t signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001110
1111/**
Derek Miller765682c2018-10-22 15:27:27 -05001112 * \brief A function that encrypts a short message with a transparent
1113 * asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -05001114 *
Derek Miller16e72292018-10-15 16:14:24 -05001115 * Functions that implement the prototype should be named in the following
1116 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001117 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001118 * psa_drv_asymmetric_<ALGO>_encrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001119 * ~~~~~~~~~~~~~
1120 * Where `ALGO` is the name of the encryption algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001121 *
Derek Miller16e72292018-10-15 16:14:24 -05001122 * \param[in] p_key A buffer containing the public key material
1123 * \param[in] key_size The size in bytes of the `p_key` data
1124 * \param[in] alg An asymmetric encryption algorithm that is
1125 * compatible with the type of `key`
1126 * \param[in] p_input The message to encrypt
1127 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001128 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -05001129 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -05001130 * If the algorithm does not support a
Derek Miller16e72292018-10-15 16:14:24 -05001131 * salt, pass `NULL`
Derek Miller5b3417a2018-10-10 17:55:03 -05001132 * If the algorithm supports an optional
1133 * salt and you do not want to pass a salt,
1134 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -05001135 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1136 * supported.
1137 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001138 * If `p_salt` is `NULL`, pass 0.
1139 * \param[out] p_output Buffer where the encrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -05001140 * be written
1141 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001142 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001143 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -05001144 *
1145 * \retval PSA_SUCCESS
1146 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001147typedef psa_status_t (*psa_drv_asymmetric_transparent_encrypt_t)(const uint8_t *p_key,
1148 size_t key_size,
1149 psa_algorithm_t alg,
1150 const uint8_t *p_input,
1151 size_t input_length,
1152 const uint8_t *p_salt,
1153 size_t salt_length,
1154 uint8_t *p_output,
1155 size_t output_size,
1156 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001157
1158/**
Derek Miller765682c2018-10-22 15:27:27 -05001159 * \brief Decrypt a short message with a transparent asymmetric private key
Derek Miller5b3417a2018-10-10 17:55:03 -05001160 *
Derek Miller16e72292018-10-15 16:14:24 -05001161 * Functions that implement the prototype should be named in the following
1162 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001163 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001164 * psa_drv_asymmetric_<ALGO>_decrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001165 * ~~~~~~~~~~~~~
1166 * Where `ALGO` is the name of the encryption algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001167 *
Derek Miller16e72292018-10-15 16:14:24 -05001168 * \param[in] p_key A buffer containing the private key material
1169 * \param[in] key_size The size in bytes of the `p_key` data
1170 * \param[in] alg An asymmetric encryption algorithm that is
1171 * compatible with the type of `key`
1172 * \param[in] p_input The message to decrypt
1173 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001174 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -05001175 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -05001176 * If the algorithm does not support a
1177 * salt, pass `NULL`.
1178 * If the algorithm supports an optional
1179 * salt and you do not want to pass a salt,
1180 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -05001181 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1182 * supported
1183 * \param[in] salt_length Size of the `p_salt` buffer in bytes
1184 * If `p_salt` is `NULL`, pass 0
Derek Miller5b3417a2018-10-10 17:55:03 -05001185 * \param[out] p_output Buffer where the decrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -05001186 * be written
1187 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001188 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001189 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -05001190 *
1191 * \retval PSA_SUCCESS
1192 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001193typedef psa_status_t (*psa_drv_asymmetric_transparent_decrypt_t)(const uint8_t *p_key,
1194 size_t key_size,
1195 psa_algorithm_t alg,
1196 const uint8_t *p_input,
1197 size_t input_length,
1198 const uint8_t *p_salt,
1199 size_t salt_length,
1200 uint8_t *p_output,
1201 size_t output_size,
1202 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001203
Derek Miller16e72292018-10-15 16:14:24 -05001204/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001205
1206/** \defgroup aead_opaque AEAD Opaque
Derek Miller765682c2018-10-22 15:27:27 -05001207 * Authenticated Encryption with Additional Data (AEAD) operations with opaque
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001208 * keys must be done in one function call. While this creates a burden for
Derek Miller765682c2018-10-22 15:27:27 -05001209 * implementers as there must be sufficient space in memory for the entire
1210 * message, it prevents decrypted data from being made available before the
1211 * authentication operation is complete and the data is known to be authentic.
Derek Miller5b3417a2018-10-10 17:55:03 -05001212 */
Derek Miller16e72292018-10-15 16:14:24 -05001213/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001214
Derek Miller16e72292018-10-15 16:14:24 -05001215/** \brief Process an authenticated encryption operation using an opaque key
Derek Miller5b3417a2018-10-10 17:55:03 -05001216 *
Derek Miller16e72292018-10-15 16:14:24 -05001217 * \param[in] key_slot Slot containing the key to use.
1218 * \param[in] algorithm The AEAD algorithm to compute
1219 * (\c PSA_ALG_XXX value such that
1220 * #PSA_ALG_IS_AEAD(`alg`) is true)
1221 * \param[in] p_nonce Nonce or IV to use
1222 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
1223 * \param[in] p_additional_data Additional data that will be
1224 * authenticated but not encrypted
1225 * \param[in] additional_data_length Size of `p_additional_data` in bytes
1226 * \param[in] p_plaintext Data that will be authenticated and
1227 * encrypted
1228 * \param[in] plaintext_length Size of `p_plaintext` in bytes
1229 * \param[out] p_ciphertext Output buffer for the authenticated and
1230 * encrypted data. The additional data is
1231 * not part of this output. For algorithms
1232 * where the encrypted data and the
1233 * authentication tag are defined as
1234 * separate outputs, the authentication
1235 * tag is appended to the encrypted data.
1236 * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in
1237 * bytes
1238 * \param[out] p_ciphertext_length On success, the size of the output in
1239 * the `p_ciphertext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001240 *
1241 * \retval #PSA_SUCCESS
1242 * Success.
1243 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001244typedef psa_status_t (*psa_drv_aead_opaque_encrypt_t)(psa_key_slot_t key_slot,
1245 psa_algorithm_t algorithm,
1246 const uint8_t *p_nonce,
1247 size_t nonce_length,
1248 const uint8_t *p_additional_data,
1249 size_t additional_data_length,
1250 const uint8_t *p_plaintext,
1251 size_t plaintext_length,
1252 uint8_t *p_ciphertext,
1253 size_t ciphertext_size,
1254 size_t *p_ciphertext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001255
Derek Miller16e72292018-10-15 16:14:24 -05001256/** Process an authenticated decryption operation using an opaque key
Derek Miller5b3417a2018-10-10 17:55:03 -05001257 *
Derek Miller16e72292018-10-15 16:14:24 -05001258 * \param[in] key_slot Slot containing the key to use
1259 * \param[in] algorithm The AEAD algorithm to compute
1260 * (\c PSA_ALG_XXX value such that
1261 * #PSA_ALG_IS_AEAD(`alg`) is true)
1262 * \param[in] p_nonce Nonce or IV to use
1263 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
1264 * \param[in] p_additional_data Additional data that has been
1265 * authenticated but not encrypted
1266 * \param[in] additional_data_length Size of `p_additional_data` in bytes
1267 * \param[in] p_ciphertext Data that has been authenticated and
1268 * encrypted.
1269 * For algorithms where the encrypted data
1270 * and the authentication tag are defined
1271 * as separate inputs, the buffer must
1272 * contain the encrypted data followed by
1273 * the authentication tag.
1274 * \param[in] ciphertext_length Size of `p_ciphertext` in bytes
1275 * \param[out] p_plaintext Output buffer for the decrypted data
1276 * \param[in] plaintext_size Size of the `p_plaintext` buffer in
1277 * bytes
1278 * \param[out] p_plaintext_length On success, the size of the output in
1279 * the `p_plaintext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001280 *
1281 * \retval #PSA_SUCCESS
1282 * Success.
1283 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001284typedef psa_status_t (*psa_drv_aead_opaque_decrypt_t)(psa_key_slot_t key_slot,
1285 psa_algorithm_t algorithm,
1286 const uint8_t *p_nonce,
1287 size_t nonce_length,
1288 const uint8_t *p_additional_data,
1289 size_t additional_data_length,
1290 const uint8_t *p_ciphertext,
1291 size_t ciphertext_length,
1292 uint8_t *p_plaintext,
1293 size_t plaintext_size,
1294 size_t *p_plaintext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001295
1296/**
Derek Miller16e72292018-10-15 16:14:24 -05001297 * \brief A struct containing all of the function pointers needed to implement
1298 * Authenticated Encryption with Additional Data operations using opaque keys
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001299 *
Derek Miller16e72292018-10-15 16:14:24 -05001300 * PSA Crypto API implementations should populate instances of the table as
1301 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001302 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001303 * If one of the functions is not implemented, it should be set to NULL.
1304 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001305typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001306 /** Function that performs the AEAD encrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001307 psa_drv_aead_opaque_encrypt_t *p_encrypt;
Derek Miller16e72292018-10-15 16:14:24 -05001308 /** Function that performs the AEAD decrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001309 psa_drv_aead_opaque_decrypt_t *p_decrypt;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001310} psa_drv_aead_opaque_t;
Derek Miller16e72292018-10-15 16:14:24 -05001311/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001312
1313/** \defgroup aead_transparent AEAD Transparent
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001314 *
Derek Miller765682c2018-10-22 15:27:27 -05001315 * Authenticated Encryption with Additional Data (AEAD) operations with
1316 * transparent keys must be done in one function call. While this creates a
1317 * burden for implementers as there must be sufficient space in memory for the
1318 * entire message, it prevents decrypted data from being made available before
1319 * the authentication operation is complete and the data is known to be
1320 * authentic.
Derek Miller5b3417a2018-10-10 17:55:03 -05001321 */
Derek Miller16e72292018-10-15 16:14:24 -05001322/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001323
Derek Miller765682c2018-10-22 15:27:27 -05001324/** Process an authenticated encryption operation using an opaque key.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001325 *
Derek Miller16e72292018-10-15 16:14:24 -05001326 * Functions that implement the prototype should be named in the following
1327 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001328 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001329 * psa_drv_aead_<ALGO>_encrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001330 * ~~~~~~~~~~~~~
1331 * Where `ALGO` is the name of the AEAD algorithm
1332 *
Derek Miller16e72292018-10-15 16:14:24 -05001333 * \param[in] p_key A pointer to the key material
1334 * \param[in] key_length The size in bytes of the key material
1335 * \param[in] alg The AEAD algorithm to compute
1336 * (\c PSA_ALG_XXX value such that
1337 * #PSA_ALG_IS_AEAD(`alg`) is true)
1338 * \param[in] nonce Nonce or IV to use
1339 * \param[in] nonce_length Size of the `nonce` buffer in bytes
1340 * \param[in] additional_data Additional data that will be MACed
1341 * but not encrypted.
1342 * \param[in] additional_data_length Size of `additional_data` in bytes
1343 * \param[in] plaintext Data that will be MACed and
1344 * encrypted.
1345 * \param[in] plaintext_length Size of `plaintext` in bytes
1346 * \param[out] ciphertext Output buffer for the authenticated and
1347 * encrypted data. The additional data is
1348 * not part of this output. For algorithms
1349 * where the encrypted data and the
1350 * authentication tag are defined as
1351 * separate outputs, the authentication
1352 * tag is appended to the encrypted data.
1353 * \param[in] ciphertext_size Size of the `ciphertext` buffer in
1354 * bytes
1355 * This must be at least
1356 * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(`alg`,
1357 * `plaintext_length`).
1358 * \param[out] ciphertext_length On success, the size of the output in
1359 * the `ciphertext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001360 *
1361 * \retval #PSA_SUCCESS
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001362
Derek Miller5b3417a2018-10-10 17:55:03 -05001363 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001364typedef psa_status_t (*psa_drv_aead_transparent_encrypt_t)(const uint8_t *p_key,
1365 size_t key_length,
1366 psa_algorithm_t alg,
1367 const uint8_t *nonce,
1368 size_t nonce_length,
1369 const uint8_t *additional_data,
1370 size_t additional_data_length,
1371 const uint8_t *plaintext,
1372 size_t plaintext_length,
1373 uint8_t *ciphertext,
1374 size_t ciphertext_size,
1375 size_t *ciphertext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001376
Derek Miller765682c2018-10-22 15:27:27 -05001377/** Process an authenticated decryption operation using an opaque key.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001378 *
Derek Miller16e72292018-10-15 16:14:24 -05001379 * Functions that implement the prototype should be named in the following
1380 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001381 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001382 * psa_drv_aead_<ALGO>_decrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001383 * ~~~~~~~~~~~~~
1384 * Where `ALGO` is the name of the AEAD algorithm
Derek Miller16e72292018-10-15 16:14:24 -05001385 * \param[in] p_key A pointer to the key material
1386 * \param[in] key_length The size in bytes of the key material
1387 * \param[in] alg The AEAD algorithm to compute
1388 * (\c PSA_ALG_XXX value such that
1389 * #PSA_ALG_IS_AEAD(`alg`) is true)
1390 * \param[in] nonce Nonce or IV to use
1391 * \param[in] nonce_length Size of the `nonce` buffer in bytes
1392 * \param[in] additional_data Additional data that has been MACed
1393 * but not encrypted
1394 * \param[in] additional_data_length Size of `additional_data` in bytes
1395 * \param[in] ciphertext Data that has been MACed and
1396 * encrypted
1397 * For algorithms where the encrypted data
1398 * and the authentication tag are defined
1399 * as separate inputs, the buffer must
1400 * contain the encrypted data followed by
1401 * the authentication tag.
1402 * \param[in] ciphertext_length Size of `ciphertext` in bytes
1403 * \param[out] plaintext Output buffer for the decrypted data
1404 * \param[in] plaintext_size Size of the `plaintext` buffer in
1405 * bytes
1406 * This must be at least
1407 * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(`alg`,
1408 * `ciphertext_length`).
1409 * \param[out] plaintext_length On success, the size of the output
1410 * in the \b plaintext buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001411 *
1412 * \retval #PSA_SUCCESS
1413 * Success.
1414 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001415typedef psa_status_t (*psa_drv_aead_transparent_decrypt_t)(const uint8_t *p_key,
1416 size_t key_length,
1417 psa_algorithm_t alg,
1418 const uint8_t *nonce,
1419 size_t nonce_length,
1420 const uint8_t *additional_data,
1421 size_t additional_data_length,
1422 const uint8_t *ciphertext,
1423 size_t ciphertext_length,
1424 uint8_t *plaintext,
1425 size_t plaintext_size,
1426 size_t *plaintext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001427
Derek Miller16e72292018-10-15 16:14:24 -05001428/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001429
1430
Derek Miller16e72292018-10-15 16:14:24 -05001431/** \defgroup driver_rng Entropy Generation
Derek Miller5b3417a2018-10-10 17:55:03 -05001432 */
Derek Miller16e72292018-10-15 16:14:24 -05001433/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001434
1435/** \brief A hardware-specific structure for a entropy providing hardware
1436 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001437typedef struct psa_drv_entropy_context_s psa_drv_entropy_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -05001438
1439/** \brief Initialize an entropy driver
1440 *
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001441 *
Derek Miller16e72292018-10-15 16:14:24 -05001442 * \param[in,out] p_context A hardware-specific structure
1443 * containing any context information for
1444 * the implementation
Derek Miller5b3417a2018-10-10 17:55:03 -05001445 *
1446 * \retval PSA_SUCCESS
1447 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001448typedef psa_status_t (*psa_drv_entropy_init_t)(psa_drv_entropy_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -05001449
Derek Miller6f960ab2018-10-23 15:58:06 -05001450/** \brief Get a specified number of bits from the entropy source
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001451 *
Derek Miller16e72292018-10-15 16:14:24 -05001452 * It retrives `buffer_size` bytes of data from the entropy source. The entropy
1453 * source will always fill the provided buffer to its full size, however, most
1454 * entropy sources have biases, and the actual amount of entropy contained in
1455 * the buffer will be less than the number of bytes.
1456 * The driver will return the actual number of bytes of entropy placed in the
1457 * buffer in `p_received_entropy_bytes`.
1458 * A PSA Crypto API implementation will likely feed the output of this function
1459 * into a Digital Random Bit Generator (DRBG), and typically has a minimum
1460 * amount of entropy that it needs.
1461 * To accomplish this, the PSA Crypto implementation should be designed to call
1462 * this function multiple times until it has received the required amount of
1463 * entropy from the entropy source.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001464 *
Derek Miller16e72292018-10-15 16:14:24 -05001465 * \param[in,out] p_context A hardware-specific structure
1466 * containing any context information
1467 * for the implementation
1468 * \param[out] p_buffer A caller-allocated buffer for the
Derek Miller6f960ab2018-10-23 15:58:06 -05001469 * retrieved entropy to be placed in
Derek Miller16e72292018-10-15 16:14:24 -05001470 * \param[in] buffer_size The allocated size of `p_buffer`
Derek Miller6f960ab2018-10-23 15:58:06 -05001471 * \param[out] p_received_entropy_bits The amount of entropy (in bits)
Derek Miller16e72292018-10-15 16:14:24 -05001472 * actually provided in `p_buffer`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001473 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001474 * \retval PSA_SUCCESS
1475 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001476typedef psa_status_t (*psa_drv_entropy_get_bits_t)(psa_drv_entropy_context_t *p_context,
1477 uint8_t *p_buffer,
1478 uint32_t buffer_size,
1479 uint32_t *p_received_entropy_bits);
Derek Miller5b3417a2018-10-10 17:55:03 -05001480
1481/**
Derek Miller16e72292018-10-15 16:14:24 -05001482 * \brief A struct containing all of the function pointers needed to interface
1483 * to an entropy source
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001484 *
Derek Miller16e72292018-10-15 16:14:24 -05001485 * PSA Crypto API implementations should populate instances of the table as
1486 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001487 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001488 * If one of the functions is not implemented, it should be set to NULL.
1489 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001490typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001491 /** Function that performs initialization for the entropy source */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001492 psa_drv_entropy_init_t *p_init;
Derek Miller6f960ab2018-10-23 15:58:06 -05001493 /** Function that performs the get_bits operation for the entropy source
Derek Miller16e72292018-10-15 16:14:24 -05001494 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001495 psa_drv_entropy_get_bits_t *p_get_bits;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001496} psa_drv_entropy_t;
Derek Miller16e72292018-10-15 16:14:24 -05001497/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001498
Derek Miller16e72292018-10-15 16:14:24 -05001499/** \defgroup driver_key_management Key Management
Derek Miller765682c2018-10-22 15:27:27 -05001500 * Currently, key management is limited to importing keys in the clear,
1501 * destroying keys, and exporting keys in the clear.
1502 * Whether a key may be exported is determined by the key policies in place
1503 * on the key slot.
Derek Miller5b3417a2018-10-10 17:55:03 -05001504 */
Derek Miller16e72292018-10-15 16:14:24 -05001505/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001506
Derek Miller16e72292018-10-15 16:14:24 -05001507/** \brief Import a key in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001508 *
1509 * This function can support any output from psa_export_key(). Refer to the
1510 * documentation of psa_export_key() for the format for each key type.
1511 *
Derek Miller81133a62018-10-23 14:55:32 -05001512 * \param[in] key_slot Slot where the key will be stored
1513 * This must be a valid slot for a key of the chosen
1514 * type. It must be unoccupied.
1515 * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value)
1516 * \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value)
1517 * \param[in] usage The allowed uses of the key
1518 * \param[in] p_data Buffer containing the key data
1519 * \param[in] data_length Size of the `data` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001520 *
1521 * \retval #PSA_SUCCESS
1522 * Success.
1523 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001524typedef psa_status_t (*psa_drv_opaque_import_key_t)(psa_key_slot_t key_slot,
1525 psa_key_type_t type,
1526 psa_algorithm_t algorithm,
1527 psa_key_usage_t usage,
1528 const uint8_t *p_data,
1529 size_t data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001530
1531/**
Derek Miller16e72292018-10-15 16:14:24 -05001532 * \brief Destroy a key and restore the slot to its default state
Derek Miller5b3417a2018-10-10 17:55:03 -05001533 *
1534 * This function destroys the content of the key slot from both volatile
1535 * memory and, if applicable, non-volatile storage. Implementations shall
1536 * make a best effort to ensure that any previous content of the slot is
1537 * unrecoverable.
1538 *
1539 * This function also erases any metadata such as policies. It returns the
1540 * specified slot to its default state.
1541 *
Derek Miller16e72292018-10-15 16:14:24 -05001542 * \param[in] key_slot The key slot to erase.
Derek Miller5b3417a2018-10-10 17:55:03 -05001543 *
1544 * \retval #PSA_SUCCESS
1545 * The slot's content, if any, has been erased.
1546 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001547typedef psa_status_t (*psa_drv_destroy_key_t)(psa_key_slot_t key);
Derek Miller5b3417a2018-10-10 17:55:03 -05001548
1549/**
Derek Miller16e72292018-10-15 16:14:24 -05001550 * \brief Export a key in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001551 *
1552 * The output of this function can be passed to psa_import_key() to
1553 * create an equivalent object.
1554 *
Derek Miller16e72292018-10-15 16:14:24 -05001555 * If a key is created with `psa_import_key()` and then exported with
Derek Miller5b3417a2018-10-10 17:55:03 -05001556 * this function, it is not guaranteed that the resulting data is
1557 * identical: the implementation may choose a different representation
1558 * of the same key if the format permits it.
1559 *
1560 * For standard key types, the output format is as follows:
1561 *
1562 * - For symmetric keys (including MAC keys), the format is the
1563 * raw bytes of the key.
1564 * - For DES, the key data consists of 8 bytes. The parity bits must be
1565 * correct.
1566 * - For Triple-DES, the format is the concatenation of the
1567 * two or three DES keys.
1568 * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format
1569 * is the non-encrypted DER representation defined by PKCS\#1 (RFC 8017)
1570 * as RSAPrivateKey.
1571 * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the format
1572 * is the DER representation defined by RFC 5280 as SubjectPublicKeyInfo.
1573 *
Derek Miller16e72292018-10-15 16:14:24 -05001574 * \param[in] key Slot whose content is to be exported. This must
Derek Miller5b3417a2018-10-10 17:55:03 -05001575 * be an occupied key slot.
1576 * \param[out] p_data Buffer where the key data is to be written.
Derek Miller16e72292018-10-15 16:14:24 -05001577 * \param[in] data_size Size of the `p_data` buffer in bytes.
Derek Miller5b3417a2018-10-10 17:55:03 -05001578 * \param[out] p_data_length On success, the number of bytes
1579 * that make up the key data.
1580 *
1581 * \retval #PSA_SUCCESS
1582 * \retval #PSA_ERROR_EMPTY_SLOT
1583 * \retval #PSA_ERROR_NOT_PERMITTED
1584 * \retval #PSA_ERROR_NOT_SUPPORTED
1585 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
1586 * \retval #PSA_ERROR_HARDWARE_FAILURE
1587 * \retval #PSA_ERROR_TAMPERING_DETECTED
1588 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001589typedef psa_status_t (*psa_drv_export_key_t)(psa_key_slot_t key,
1590 uint8_t *p_data,
1591 size_t data_size,
1592 size_t *p_data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001593
1594/**
Derek Miller16e72292018-10-15 16:14:24 -05001595 * \brief Export a public key or the public part of a key pair in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001596 *
1597 * The output of this function can be passed to psa_import_key() to
1598 * create an object that is equivalent to the public key.
1599 *
1600 * For standard key types, the output format is as follows:
1601 *
1602 * - For RSA keys (#PSA_KEY_TYPE_RSA_KEYPAIR or #PSA_KEY_TYPE_RSA_PUBLIC_KEY),
1603 * the format is the DER representation of the public key defined by RFC 5280
1604 * as SubjectPublicKeyInfo.
1605 *
Derek Miller16e72292018-10-15 16:14:24 -05001606 * \param[in] key_slot Slot whose content is to be exported. This must
Derek Miller5b3417a2018-10-10 17:55:03 -05001607 * be an occupied key slot.
1608 * \param[out] p_data Buffer where the key data is to be written.
Derek Miller16e72292018-10-15 16:14:24 -05001609 * \param[in] data_size Size of the `data` buffer in bytes.
Derek Miller5b3417a2018-10-10 17:55:03 -05001610 * \param[out] p_data_length On success, the number of bytes
1611 * that make up the key data.
1612 *
1613 * \retval #PSA_SUCCESS
1614 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001615typedef psa_status_t (*psa_drv_export_public_key_t)(psa_key_slot_t key,
1616 uint8_t *p_data,
1617 size_t data_size,
1618 size_t *p_data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001619
1620/**
Derek Miller16e72292018-10-15 16:14:24 -05001621 * \brief A struct containing all of the function pointers needed to for key
1622 * management using opaque keys
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001623 *
Derek Miller16e72292018-10-15 16:14:24 -05001624 * PSA Crypto API implementations should populate instances of the table as
1625 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001626 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001627 * If one of the functions is not implemented, it should be set to NULL.
1628 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001629typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001630 /** Function that performs the key import operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001631 psa_drv_opaque_import_key_t *p_import;
Derek Miller16e72292018-10-15 16:14:24 -05001632 /** Function that performs the key destroy operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001633 psa_drv_destroy_key_t *p_destroy;
Derek Miller16e72292018-10-15 16:14:24 -05001634 /** Function that performs the key export operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001635 psa_drv_export_key_t *p_export;
Derek Miller16e72292018-10-15 16:14:24 -05001636 /** Function that perforsm the public key export operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001637 psa_drv_export_public_key_t *p_export_public;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001638} psa_drv_key_management_t;
Derek Miller5b3417a2018-10-10 17:55:03 -05001639
Derek Miller16e72292018-10-15 16:14:24 -05001640/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001641
Derek Miller16e72292018-10-15 16:14:24 -05001642/** \defgroup driver_derivation Key Derivation and Agreement
Derek Miller16e72292018-10-15 16:14:24 -05001643 * Key derivation is the process of generating new key material using an
1644 * existing key and additional parameters, iterating through a basic
1645 * cryptographic function, such as a hash.
1646 * Key agreement is a part of cryptographic protocols that allows two parties
1647 * to agree on the same key value, but starting from different original key
1648 * material.
Jaeden Ameroe095d602018-10-26 12:09:31 +01001649 * The flows are similar, and the PSA Crypto Driver Model uses the same functions
Derek Miller16e72292018-10-15 16:14:24 -05001650 * for both of the flows.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001651 *
Derek Miller16e72292018-10-15 16:14:24 -05001652 * There are two different final functions for the flows,
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001653 * `psa_drv_key_derivation_derive` and `psa_drv_key_derivation_export`.
1654 * `psa_drv_key_derivation_derive` is used when the key material should be placed
Derek Miller16e72292018-10-15 16:14:24 -05001655 * in a slot on the hardware and not exposed to the caller.
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001656 * `psa_drv_key_derivation_export` is used when the key material should be returned
Derek Miller16e72292018-10-15 16:14:24 -05001657 * to the PSA Cryptographic API implementation.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001658 *
Derek Miller16e72292018-10-15 16:14:24 -05001659 * Different key derivation algorithms require a different number of inputs.
1660 * Instead of having an API that takes as input variable length arrays, which
1661 * can be problemmatic to manage on embedded platforms, the inputs are passed
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001662 * to the driver via a function, `psa_drv_key_derivation_collateral`, that is
Derek Miller16e72292018-10-15 16:14:24 -05001663 * called multiple times with different `collateral_id`s. Thus, for a key
1664 * derivation algorithm that required 3 paramter inputs, the flow would look
1665 * something like:
1666 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001667 * psa_drv_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes);
1668 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_0,
1669 * p_collateral_0,
1670 * collateral_0_size);
1671 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_1,
1672 * p_collateral_1,
1673 * collateral_1_size);
1674 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_2,
1675 * p_collateral_2,
1676 * collateral_2_size);
1677 * psa_drv_key_derivation_derive();
Derek Miller16e72292018-10-15 16:14:24 -05001678 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001679 *
Derek Miller16e72292018-10-15 16:14:24 -05001680 * key agreement example:
1681 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001682 * psa_drv_key_derivation_setup(alg, source_key. dest_key_size_bytes);
1683 * psa_drv_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size);
1684 * psa_drv_key_derivation_export(p_session_key,
1685 * session_key_size,
1686 * &session_key_length);
Derek Miller16e72292018-10-15 16:14:24 -05001687 * ~~~~~~~~~~~~~
1688 */
Derek Miller765682c2018-10-22 15:27:27 -05001689/**@{*/
Derek Miller16e72292018-10-15 16:14:24 -05001690
Derek Miller765682c2018-10-22 15:27:27 -05001691/** \brief The hardware-specific key derivation context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001692 *
Derek Miller765682c2018-10-22 15:27:27 -05001693 * The contents of this structure are implementation dependent and are
1694 * therefore not described here
1695 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001696typedef struct psa_drv_key_derivation_context_s psa_drv_key_derivation_context_t;
Derek Miller16e72292018-10-15 16:14:24 -05001697
1698/** \brief Set up a key derivation operation by specifying the algorithm and
1699 * the source key sot
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001700 *
Derek Miller16e72292018-10-15 16:14:24 -05001701 * \param[in,out] p_context A hardware-specific structure containing any
1702 * context information for the implementation
1703 * \param[in] kdf_alg The algorithm to be used for the key derivation
1704 * \param[in] souce_key The key to be used as the source material for the
1705 * key derivation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001706 *
Derek Miller16e72292018-10-15 16:14:24 -05001707 * \retval PSA_SUCCESS
1708 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001709typedef psa_status_t (*psa_drv_key_derivation_setup_t)(psa_drv_key_derivation_context_t *p_context,
1710 psa_algorithm_t kdf_alg,
1711 psa_key_slot_t source_key);
Derek Miller16e72292018-10-15 16:14:24 -05001712
1713/** \brief Provide collateral (parameters) needed for a key derivation or key
1714 * agreement operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001715 *
Derek Miller16e72292018-10-15 16:14:24 -05001716 * Since many key derivation algorithms require multiple parameters, it is
1717 * expeced that this function may be called multiple times for the same
1718 * operation, each with a different algorithm-specific `collateral_id`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001719 *
Derek Miller16e72292018-10-15 16:14:24 -05001720 * \param[in,out] p_context A hardware-specific structure containing any
1721 * context information for the implementation
1722 * \param[in] collateral_id An ID for the collateral being provided
1723 * \param[in] p_collateral A buffer containing the collateral data
1724 * \param[in] collateral_size The size in bytes of the collateral
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001725 *
Derek Miller16e72292018-10-15 16:14:24 -05001726 * \retval PSA_SUCCESS
1727 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001728typedef psa_status_t (*psa_drv_key_derivation_collateral_t)(psa_drv_key_derivation_context_t *p_context,
1729 uint32_t collateral_id,
1730 const uint8_t *p_collateral,
1731 size_t collateral_size);
Derek Miller16e72292018-10-15 16:14:24 -05001732
1733/** \brief Perform the final key derivation step and place the generated key
1734 * material in a slot
1735 * \param[in,out] p_context A hardware-specific structure containing any
1736 * context information for the implementation
1737 * \param[in] dest_key The slot where the generated key material
1738 * should be placed
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001739 *
Derek Miller16e72292018-10-15 16:14:24 -05001740 * \retval PSA_SUCCESS
1741 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001742typedef psa_status_t (*psa_drv_key_derivation_derive_t)(psa_drv_key_derivation_context_t *p_context,
1743 psa_key_slot_t dest_key);
Derek Miller16e72292018-10-15 16:14:24 -05001744
1745/** \brief Perform the final step of a key agreement and place the generated
1746 * key material in a buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001747 *
Derek Miller16e72292018-10-15 16:14:24 -05001748 * \param[out] p_output Buffer in which to place the generated key
1749 * material
1750 * \param[in] output_size The size in bytes of `p_output`
1751 * \param[out] p_output_length Upon success, contains the number of bytes of
1752 * key material placed in `p_output`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001753 *
Derek Miller16e72292018-10-15 16:14:24 -05001754 * \retval PSA_SUCCESS
1755 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001756typedef psa_status_t (*psa_drv_key_derivation_export_t)(uint8_t *p_output,
1757 size_t output_size,
1758 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -05001759
1760/**
1761 * \brief A struct containing all of the function pointers needed to for key
1762 * derivation and agreement
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001763 *
Derek Miller16e72292018-10-15 16:14:24 -05001764 * PSA Crypto API implementations should populate instances of the table as
1765 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001766 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001767 * If one of the functions is not implemented, it should be set to NULL.
1768 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001769typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001770 /** Function that performs the key derivation setup */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001771 psa_drv_key_derivation_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -05001772 /** Function that sets the key derivation collateral */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001773 psa_drv_key_derivation_collateral_t *p_collateral;
Derek Miller16e72292018-10-15 16:14:24 -05001774 /** Function that performs the final key derivation step */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001775 psa_drv_key_derivation_derive_t *p_derive;
Derek Miller16e72292018-10-15 16:14:24 -05001776 /** Function that perforsm the final key derivation or agreement and
1777 * exports the key */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001778 psa_drv_key_derivation_export_t *p_export;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001779} psa_drv_key_derivation_t;
Derek Miller5b3417a2018-10-10 17:55:03 -05001780
Derek Miller16e72292018-10-15 16:14:24 -05001781/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001782
Jaeden Amero9411db72018-10-26 11:59:58 +01001783#ifdef __cplusplus
1784}
1785#endif
1786
Jaeden Amero41558502018-10-26 11:44:33 +01001787#endif /* PSA_CRYPTO_DRIVER_H */