blob: 9acd33066c04654839f77a2f1448140931ca6efd [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 */
Derek Miller5b3417a2018-10-10 17:55:03 -050028#ifndef __PSA_CRYPTO_DRIVER_H__
29#define __PSA_CRYPTO_DRIVER_H__
30
31#include <stddef.h>
32#include <stdint.h>
33
Derek Miller16e72292018-10-15 16:14:24 -050034/** The following types are redefinitions from the psa/crypto.h file.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010035 * It is intended that these will be moved to a new common header file to
Derek Miller16e72292018-10-15 16:14:24 -050036 * avoid duplication. They are included here for expediency in publication.
37 */
Derek Miller5b3417a2018-10-10 17:55:03 -050038typedef uint32_t psa_status_t;
39typedef uint32_t psa_algorithm_t;
Derek Miller16e72292018-10-15 16:14:24 -050040typedef uint8_t encrypt_or_decrypt_t;
Derek Miller5b3417a2018-10-10 17:55:03 -050041typedef uint32_t psa_key_slot_t;
42typedef uint32_t psa_key_type_t;
Derek Miller81133a62018-10-23 14:55:32 -050043typedef uint32_t psa_key_usage_t;
Derek Miller5b3417a2018-10-10 17:55:03 -050044
Derek Miller6f960ab2018-10-23 15:58:06 -050045#define PSA_CRYPTO_DRIVER_ENCRYPT 1
46#define PSA_CRYPTO_DRIVER_DECRYPT 0
47
Derek Miller5b3417a2018-10-10 17:55:03 -050048/** \defgroup opaque_mac Opaque Message Authentication Code
Derek Miller765682c2018-10-22 15:27:27 -050049 * Generation and authentication of Message Authentication Codes (MACs) using
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010050 * opaque keys can be done either as a single function call (via the
Jaeden Amero1acb2c42018-10-26 10:49:58 +010051 * `psa_drv_mac_opaque_generate_t` or `psa_mac_opaque_verify_t` functions), or in
Derek Miller765682c2018-10-22 15:27:27 -050052 * parts using the following sequence:
53 * - `psa_mac_opaque_setup_t`
54 * - `psa_mac_opaque_update_t`
55 * - `psa_mac_opaque_update_t`
56 * - ...
57 * - `psa_mac_opaque_finish_t` or `psa_mac_opaque_finish_verify_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010058 *
59 * If a previously started Opaque MAC operation needs to be terminated, it
Derek Miller765682c2018-10-22 15:27:27 -050060 * should be done so by the `psa_mac_opaque_abort_t`. Failure to do so may
61 * result in allocated resources not being freed or in other undefined
62 * behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -050063 */
Derek Miller16e72292018-10-15 16:14:24 -050064/**@{*/
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010065/** \brief A function that starts a MAC operation for a PSA Crypto Driver
Derek Miller16e72292018-10-15 16:14:24 -050066 * implementation using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010067 *
68 * \param[in,out] p_context A structure that will contain the
Derek Miller16e72292018-10-15 16:14:24 -050069 * hardware-specific MAC context
70 * \param[in] key_slot The slot of the key to be used for the
71 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010072 * \param[in] algorithm The algorithm to be used to underly the MAC
Derek Miller16e72292018-10-15 16:14:24 -050073 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010074 *
Derek Miller5b3417a2018-10-10 17:55:03 -050075 * \retval PSA_SUCCESS
76 * Success.
77 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +010078typedef psa_status_t (*psa_drv_mac_opaque_setup_t)(void *p_context,
79 psa_key_slot_t key_slot,
80 psa_algorithm_t algorithm);
Derek Miller5b3417a2018-10-10 17:55:03 -050081
Derek Miller16e72292018-10-15 16:14:24 -050082/** \brief A function that continues a previously started MAC operation using
83 * an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010084 *
Derek Miller16e72292018-10-15 16:14:24 -050085 * \param[in,out] p_context A hardware-specific structure for the
86 * previously-established MAC operation to be
87 * continued
88 * \param[in] p_input A buffer containing the message to be appended
89 * to the MAC operation
90 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -050091 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +010092typedef psa_status_t (*psa_drv_mac_opaque_update_t)(void *p_context,
93 const uint8_t *p_input,
94 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -050095
Derek Miller16e72292018-10-15 16:14:24 -050096/** \brief a function that completes a previously started MAC operation by
97 * returning the resulting MAC using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010098 *
99 * \param[in,out] p_context A hardware-specific structure for the
100 * previously started MAC operation to be
Derek Miller16e72292018-10-15 16:14:24 -0500101 * finished
102 * \param[out] p_mac A buffer where the generated MAC will be
103 * placed
104 * \param[in] mac_size The size in bytes of the buffer that has been
105 * allocated for the `output` buffer
106 * \param[out] p_mac_length After completion, will contain the number of
Derek Millerf3d0a562018-10-18 16:41:08 -0500107 * bytes placed in the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100108 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500109 * \retval PSA_SUCCESS
110 * Success.
111 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100112typedef psa_status_t (*psa_drv_mac_opaque_finish_t)(void *p_context,
113 uint8_t *p_mac,
114 size_t mac_size,
115 size_t *p_mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500116
Derek Miller16e72292018-10-15 16:14:24 -0500117/** \brief A function that completes a previously started MAC operation by
118 * comparing the resulting MAC against a known value using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100119 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500120 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500121 * started MAC operation to be fiinished
122 * \param[in] p_mac The MAC value against which the resulting MAC will
123 * be compared against
124 * \param[in] mac_length The size in bytes of the value stored in `p_mac`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100125 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500126 * \retval PSA_SUCCESS
Derek Miller16e72292018-10-15 16:14:24 -0500127 * The operation completed successfully and the MACs matched each
128 * other
Derek Miller5b3417a2018-10-10 17:55:03 -0500129 * \retval PSA_ERROR_INVALID_SIGNATURE
Derek Miller16e72292018-10-15 16:14:24 -0500130 * The operation completed successfully, but the calculated MAC did
131 * not match the provided MAC
Derek Miller5b3417a2018-10-10 17:55:03 -0500132 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100133typedef psa_status_t (*psa_drv_mac_opaque_finish_verify_t)(void *p_context,
134 const uint8_t *p_mac,
135 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500136
Derek Miller16e72292018-10-15 16:14:24 -0500137/** \brief A function that aborts a previous started opaque-key MAC operation
138
Derek Millerf3d0a562018-10-18 16:41:08 -0500139 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500140 * started MAC operation to be aborted
141 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100142typedef psa_status_t (*psa_drv_mac_opaque_abort_t)(void *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500143
Derek Miller81133a62018-10-23 14:55:32 -0500144/** \brief A function that performs a MAC operation in one command and returns
Derek Miller16e72292018-10-15 16:14:24 -0500145 * the calculated MAC using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100146 *
Derek Miller16e72292018-10-15 16:14:24 -0500147 * \param[in] p_input A buffer containing the message to be MACed
Derek Millerf3d0a562018-10-18 16:41:08 -0500148 * \param[in] input_length The size in bytes of `p_input`
Derek Miller16e72292018-10-15 16:14:24 -0500149 * \param[in] key_slot The slot of the key to be used
Derek Millerf3d0a562018-10-18 16:41:08 -0500150 * \param[in] alg The algorithm to be used to underlie the MAC
Derek Miller16e72292018-10-15 16:14:24 -0500151 * operation
152 * \param[out] p_mac A buffer where the generated MAC will be
153 * placed
Derek Miller81133a62018-10-23 14:55:32 -0500154 * \param[in] mac_size The size in bytes of the `p_mac` buffer
Derek Miller16e72292018-10-15 16:14:24 -0500155 * \param[out] p_mac_length After completion, will contain the number of
156 * bytes placed in the `output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100157 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500158 * \retval PSA_SUCCESS
159 * Success.
160 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100161typedef psa_status_t (*psa_drv_mac_opaque_generate_t)(const uint8_t *p_input,
162 size_t input_length,
163 psa_key_slot_t key_slot,
164 psa_algorithm_t alg,
165 uint8_t *p_mac,
166 size_t mac_size,
167 size_t *p_mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500168
Derek Miller16e72292018-10-15 16:14:24 -0500169/** \brief A function that performs an MAC operation in one command and
170 * compare the resulting MAC against a known value using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100171 *
Derek Miller16e72292018-10-15 16:14:24 -0500172 * \param[in] p_input A buffer containing the message to be MACed
173 * \param[in] input_length The size in bytes of `input`
174 * \param[in] key_slot The slot of the key to be used
175 * \param[in] alg The algorithm to be used to underlie the MAC
176 * operation
177 * \param[in] p_mac The MAC value against which the resulting MAC will
178 * be compared against
179 * \param[in] mac_length The size in bytes of `mac`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100180 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500181 * \retval PSA_SUCCESS
Derek Miller16e72292018-10-15 16:14:24 -0500182 * The operation completed successfully and the MACs matched each
183 * other
Derek Miller5b3417a2018-10-10 17:55:03 -0500184 * \retval PSA_ERROR_INVALID_SIGNATURE
Derek Miller16e72292018-10-15 16:14:24 -0500185 * The operation completed successfully, but the calculated MAC did
186 * not match the provided MAC
Derek Miller5b3417a2018-10-10 17:55:03 -0500187 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100188typedef psa_status_t (*psa_drv_mac_opaque_verify_t)(const uint8_t *p_input,
189 size_t input_length,
190 psa_key_slot_t key_slot,
191 psa_algorithm_t alg,
192 const uint8_t *p_mac,
193 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500194
Derek Miller16e72292018-10-15 16:14:24 -0500195/** \brief A struct containing all of the function pointers needed to
196 * implement MAC operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100197 *
Derek Miller16e72292018-10-15 16:14:24 -0500198 * PSA Crypto API implementations should populate the table as appropriate
199 * upon startup.
Derek Miller5b3417a2018-10-10 17:55:03 -0500200 *
Derek Miller765682c2018-10-22 15:27:27 -0500201 * If one of the functions is not implemented (such as
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100202 * `psa_drv_mac_opaque_generate_t`), it should be set to NULL.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100203 *
Derek Miller16e72292018-10-15 16:14:24 -0500204 * Driver implementers should ensure that they implement all of the functions
205 * that make sense for their hardware, and that they provide a full solution
206 * (for example, if they support `p_setup`, they should also support
207 * `p_update` and at least one of `p_finish` or `p_finish_verify`).
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100208 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500209 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100210struct psa_drv_mac_opaque_t {
Derek Miller16e72292018-10-15 16:14:24 -0500211 /**The size in bytes of the hardware-specific Opaque-MAC Context structure
212 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100213 size_t context_size;
Derek Miller16e72292018-10-15 16:14:24 -0500214 /** Function that performs the setup operation
215 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100216 psa_drv_mac_opaque_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -0500217 /** Function that performs the update operation
218 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100219 psa_drv_mac_opaque_update_t *p_update;
Derek Miller16e72292018-10-15 16:14:24 -0500220 /** Function that completes the operation
221 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100222 psa_drv_mac_opaque_finish_t *p_finish;
Derek Miller16e72292018-10-15 16:14:24 -0500223 /** Function that completed a MAC operation with a verify check
224 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100225 psa_drv_mac_opaque_finish_verify_t *p_finish_verify;
Derek Miller16e72292018-10-15 16:14:24 -0500226 /** Function that aborts a previoustly started operation
227 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100228 psa_drv_mac_opaque_abort_t *p_abort;
Derek Miller16e72292018-10-15 16:14:24 -0500229 /** Function that performs the MAC operation in one call
230 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100231 psa_drv_mac_opaque_generate_t *p_mac;
Derek Miller16e72292018-10-15 16:14:24 -0500232 /** Function that performs the MAC and verify operation in one call
233 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100234 psa_drv_mac_opaque_verify_t *p_mac_verify;
Derek Miller5b3417a2018-10-10 17:55:03 -0500235};
Derek Miller16e72292018-10-15 16:14:24 -0500236/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500237
238/** \defgroup transparent_mac Transparent Message Authentication Code
Derek Miller765682c2018-10-22 15:27:27 -0500239 * Generation and authentication of Message Authentication Codes (MACs) using
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100240 * transparent keys can be done either as a single function call (via the
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100241 * `psa_drv_mac_transparent_generate_t` or `psa_mac_transparent_verify_t`
Derek Miller765682c2018-10-22 15:27:27 -0500242 * functions), or in parts using the following sequence:
243 * - `psa_mac_transparent_setup_t`
244 * - `psa_mac_transparent_update_t`
245 * - `psa_mac_transparent_update_t`
246 * - ...
247 * - `psa_mac_transparent_finish_t` or `psa_mac_transparent_finish_verify_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100248 *
249 * If a previously started Transparent MAC operation needs to be terminated, it
Derek Miller765682c2018-10-22 15:27:27 -0500250 * should be done so by the `psa_mac_transparent_abort_t`. Failure to do so may
251 * result in allocated resources not being freed or in other undefined
252 * behavior.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100253 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500254 */
Derek Miller16e72292018-10-15 16:14:24 -0500255/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500256
257/** \brief The hardware-specific transparent-key MAC context structure
Derek Miller765682c2018-10-22 15:27:27 -0500258 *
Derek Miller16e72292018-10-15 16:14:24 -0500259 * The contents of this structure are implementation dependent and are
260 * therefore not described here.
Derek Miller5b3417a2018-10-10 17:55:03 -0500261 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100262typedef struct psa_drv_mac_transparent_context_s psa_drv_mac_transparent_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500263
Derek Miller16e72292018-10-15 16:14:24 -0500264/** \brief The function prototype for the setup operation of a
265 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100266 *
Derek Miller16e72292018-10-15 16:14:24 -0500267 * Functions that implement the prototype should be named in the following
268 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500269 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100270 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_setup
Derek Miller5b3417a2018-10-10 17:55:03 -0500271 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500272 * Where `ALGO` is the name of the underlying primitive, and `MAC_VARIANT`
273 * is the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100274 *
275 * \param[in,out] p_context A structure that will contain the
Derek Miller16e72292018-10-15 16:14:24 -0500276 * hardware-specific MAC context
277 * \param[in] p_key A buffer containing the cleartext key material
278 * to be used in the operation
279 * \param[in] key_length The size in bytes of the key material
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100280 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500281 * \retval PSA_SUCCESS
282 * Success.
283 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100284typedef psa_status_t (*psa_drv_mac_transparent_setup_t)(psa_drv_mac_transparent_context_t *p_context,
285 const uint8_t *p_key,
286 size_t key_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500287
Derek Miller16e72292018-10-15 16:14:24 -0500288/** \brief The function prototype for the update operation of a
289 * transparent-key MAC operation
Derek Miller5b3417a2018-10-10 17:55:03 -0500290 *
Derek Miller16e72292018-10-15 16:14:24 -0500291 * Functions that implement the prototype should be named in the following
292 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500293 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100294 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_update
Derek Miller5b3417a2018-10-10 17:55:03 -0500295 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500296 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT`
297 * is the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100298 *
Derek Miller16e72292018-10-15 16:14:24 -0500299 * \param[in,out] p_context A hardware-specific structure for the
300 * previously-established MAC operation to be
301 * continued
302 * \param[in] p_input A buffer containing the message to be appended
303 * to the MAC operation
304 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -0500305 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100306typedef psa_status_t (*psa_drv_mac_transparent_update_t)(psa_drv_mac_transparent_context_t *p_context,
307 const uint8_t *p_input,
308 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500309
Derek Miller16e72292018-10-15 16:14:24 -0500310/** \brief The function prototype for the finish operation of a
311 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100312 *
Derek Miller16e72292018-10-15 16:14:24 -0500313 * Functions that implement the prototype should be named in the following
314 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500315 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100316 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish
Derek Miller5b3417a2018-10-10 17:55:03 -0500317 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500318 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
319 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100320 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500321 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500322 * previously started MAC operation to be
323 * finished
324 * \param[out] p_mac A buffer where the generated MAC will be placed
325 * \param[in] mac_length The size in bytes of the buffer that has been
326 * allocated for the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100327 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500328 * \retval PSA_SUCCESS
329 * Success.
330 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100331typedef psa_status_t (*psa_drv_mac_transparent_finish_t)(psa_drv_mac_transparent_context_t *p_context,
332 uint8_t *p_mac,
333 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500334
Derek Miller16e72292018-10-15 16:14:24 -0500335/** \brief The function prototype for the finish and verify operation of a
336 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100337 *
Derek Miller16e72292018-10-15 16:14:24 -0500338 * Functions that implement the prototype should be named in the following
339 * convention:
340 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100341 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish_verify
Derek Miller16e72292018-10-15 16:14:24 -0500342 * ~~~~~~~~~~~~~
343 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
344 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100345 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500346 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500347 * previously started MAC operation to be
Derek Millerf3d0a562018-10-18 16:41:08 -0500348 * verified and finished
Derek Miller16e72292018-10-15 16:14:24 -0500349 * \param[in] p_mac A buffer containing the MAC that will be used
350 * for verification
351 * \param[in] mac_length The size in bytes of the data in the `p_mac`
352 * buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100353 *
Derek Miller16e72292018-10-15 16:14:24 -0500354 * \retval PSA_SUCCESS
355 * The operation completed successfully and the comparison matched
Derek Miller5b3417a2018-10-10 17:55:03 -0500356 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100357typedef psa_status_t (*psa_drv_mac_transparent_finish_verify_t)(psa_drv_mac_transparent_context_t *p_context,
358 const uint8_t *p_mac,
359 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500360
361/** \brief The function prototype for the abort operation for a previously
362 * started transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100363 *
Derek Miller16e72292018-10-15 16:14:24 -0500364 * Functions that implement the prototype should be named in the following
365 * convention:
366 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100367 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_abort
Derek Miller16e72292018-10-15 16:14:24 -0500368 * ~~~~~~~~~~~~~
369 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
370 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100371 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500372 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500373 * previously started MAC operation to be
Derek Millerf3d0a562018-10-18 16:41:08 -0500374 * aborted
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100375 *
Derek Miller16e72292018-10-15 16:14:24 -0500376 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100377typedef psa_status_t (*psa_drv_mac_transparent_abort_t)(psa_drv_mac_transparent_context_t *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500378
379/** \brief The function prototype for a one-shot operation of a transparent-key
380 * MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100381 *
Derek Miller16e72292018-10-15 16:14:24 -0500382 * Functions that implement the prototype should be named in the following
383 * convention:
384 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100385 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>
Derek Miller16e72292018-10-15 16:14:24 -0500386 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100387 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
Derek Miller16e72292018-10-15 16:14:24 -0500388 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100389 *
Derek Miller16e72292018-10-15 16:14:24 -0500390 * \param[in] p_input A buffer containing the data to be MACed
391 * \param[in] input_length The length in bytes of the `p_input` data
392 * \param[in] p_key A buffer containing the key material to be used
393 * for the MAC operation
394 * \param[in] key_length The length in bytes of the `p_key` data
395 * \param[in] alg The algorithm to be performed
396 * \param[out] p_mac The buffer where the resulting MAC will be placed
397 * upon success
398 * \param[in] mac_length The length in bytes of the `p_mac` buffer
399 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100400typedef psa_status_t (*psa_drv_mac_transparent_t)(const uint8_t *p_input,
401 size_t input_length,
402 const uint8_t *p_key,
403 size_t key_length,
404 psa_algorithm_t alg,
405 uint8_t *p_mac,
406 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500407
408/** \brief The function prototype for a one-shot operation of a transparent-key
409 * MAC Verify operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100410 *
Derek Miller16e72292018-10-15 16:14:24 -0500411 * Functions that implement the prototype should be named in the following
412 * convention:
413 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100414 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_verify
Derek Miller16e72292018-10-15 16:14:24 -0500415 * ~~~~~~~~~~~~~
416 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
417 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100418 *
Derek Miller16e72292018-10-15 16:14:24 -0500419 * \param[in] p_input A buffer containing the data to be MACed
420 * \param[in] input_length The length in bytes of the `p_input` data
421 * \param[in] p_key A buffer containing the key material to be used
422 * for the MAC operation
423 * \param[in] key_length The length in bytes of the `p_key` data
424 * \param[in] alg The algorithm to be performed
425 * \param[in] p_mac The MAC data to be compared
426 * \param[in] mac_length The length in bytes of the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100427 *
Derek Miller16e72292018-10-15 16:14:24 -0500428 * \retval PSA_SUCCESS
429 * The operation completed successfully and the comparison matched
430 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100431typedef psa_status_t (*psa_drv_mac_transparent_verify_t)(const uint8_t *p_input,
432 size_t input_length,
433 const uint8_t *p_key,
434 size_t key_length,
435 psa_algorithm_t alg,
436 const uint8_t *p_mac,
437 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500438/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500439
440/** \defgroup opaque_cipher Opaque Symmetric Ciphers
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100441 *
Derek Miller765682c2018-10-22 15:27:27 -0500442 * Encryption and Decryption using opaque keys in block modes other than ECB
443 * must be done in multiple parts, using the following flow:
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100444 * - `psa_drv_cipher_opaque_setup_t`
445 * - `psa_drv_cipher_opaque_set_iv_t` (optional depending upon block mode)
446 * - `psa_drv_cipher_opaque_update_t`
Derek Miller765682c2018-10-22 15:27:27 -0500447 * - ...
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100448 * - `psa_drv_cipher_opaque_finish_t`
Derek Miller765682c2018-10-22 15:27:27 -0500449
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100450 * If a previously started Opaque Cipher operation needs to be terminated, it
Derek Miller765682c2018-10-22 15:27:27 -0500451 * should be done so by the `psa_cipher_opaque_abort_t`. Failure to do so may
452 * result in allocated resources not being freed or in other undefined
453 * behavior.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100454 *
Derek Miller765682c2018-10-22 15:27:27 -0500455 * In situations where a PSA Cryptographic API implementation is using a block
456 * mode not-supported by the underlying hardware or driver, it can construct
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100457 * the block mode itself, while calling the `psa_drv_cipher_opaque_ecb_t` function
Derek Miller765682c2018-10-22 15:27:27 -0500458 * pointer for the cipher operations.
Derek Miller5b3417a2018-10-10 17:55:03 -0500459 */
Derek Miller16e72292018-10-15 16:14:24 -0500460/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500461
Derek Miller16e72292018-10-15 16:14:24 -0500462/** \brief A function pointer that provides the cipher setup function for
463 * opaque-key operations
Derek Miller5b3417a2018-10-10 17:55:03 -0500464 *
Derek Miller16e72292018-10-15 16:14:24 -0500465 * \param[in,out] p_context A structure that will contain the
466 * hardware-specific cipher context.
467 * \param[in] key_slot The slot of the key to be used for the
468 * operation
469 * \param[in] algorithm The algorithm to be used in the cipher
470 * operation
471 * \param[in] direction Indicates whether the operation is an encrypt
472 * or decrypt
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100473 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500474 * \retval PSA_SUCCESS
475 * \retval PSA_ERROR_NOT_SUPPORTED
476 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100477typedef psa_status_t (*psa_drv_cipher_opaque_setup_t)(void *p_context,
478 psa_key_slot_t key_slot,
479 psa_algorithm_t algorithm,
480 encrypt_or_decrypt_t direction);
Derek Miller16e72292018-10-15 16:14:24 -0500481
482/** \brief A function pointer that sets the initialization vector (if
483 * necessary) for an opaque cipher operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100484 *
Derek Miller81133a62018-10-23 14:55:32 -0500485 * Rationale: The `psa_cipher_*` function in the PSA Cryptographic API has two
Derek Miller765682c2018-10-22 15:27:27 -0500486 * IV functions: one to set the IV, and one to generate it internally. The
Jaeden Ameroe095d602018-10-26 12:09:31 +0100487 * generate function is not necessary for the drivers to implement as the PSA
488 * Crypto implementation can do the generation using its RNG features.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100489 *
Derek Miller16e72292018-10-15 16:14:24 -0500490 * \param[in,out] p_context A structure that contains the previously set up
491 * hardware-specific cipher context
492 * \param[in] p_iv A buffer containing the initialization vector
493 * \param[in] iv_length The size (in bytes) of the `p_iv` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100494 *
Derek Miller16e72292018-10-15 16:14:24 -0500495 * \retval PSA_SUCCESS
496 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100497typedef psa_status_t (*psa_drv_cipher_opaque_set_iv_t)(void *p_context,
498 const uint8_t *p_iv,
499 size_t iv_length);
Derek Miller16e72292018-10-15 16:14:24 -0500500
501/** \brief A function that continues a previously started opaque-key cipher
502 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100503 *
Derek Miller16e72292018-10-15 16:14:24 -0500504 * \param[in,out] p_context A hardware-specific structure for the
505 * previously started cipher operation
506 * \param[in] p_input A buffer containing the data to be
507 * encrypted/decrypted
508 * \param[in] input_size The size in bytes of the buffer pointed to
509 * by `p_input`
510 * \param[out] p_output The caller-allocated buffer where the
511 * output will be placed
512 * \param[in] output_size The allocated size in bytes of the
513 * `p_output` buffer
514 * \param[out] p_output_length After completion, will contain the number
515 * of bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100516 *
Derek Miller16e72292018-10-15 16:14:24 -0500517 * \retval PSA_SUCCESS
518 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100519typedef psa_status_t (*psa_drv_cipher_opaque_update_t)(void *p_context,
520 const uint8_t *p_input,
521 size_t input_size,
522 uint8_t *p_output,
523 size_t output_size,
524 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -0500525
526/** \brief A function that completes a previously started opaque-key cipher
527 * operation
528 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500529 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500530 * previously started cipher operation
Derek Millerf3d0a562018-10-18 16:41:08 -0500531 * \param[out] p_output The caller-allocated buffer where the output
Derek Miller16e72292018-10-15 16:14:24 -0500532 * will be placed
533 * \param[in] output_size The allocated size in bytes of the `p_output`
534 * buffer
535 * \param[out] p_output_length After completion, will contain the number of
536 * bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100537 *
Derek Miller16e72292018-10-15 16:14:24 -0500538 * \retval PSA_SUCCESS
539 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100540typedef psa_status_t (*psa_drv_cipher_opaque_finish_t)(void *p_context,
541 uint8_t *p_output,
542 size_t output_size,
543 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -0500544
545/** \brief A function that aborts a previously started opaque-key cipher
546 * operation
547 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500548 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500549 * previously started cipher operation
550 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100551typedef psa_status_t (*psa_drv_cipher_opaque_abort_t)(void *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500552
553/** \brief A function that performs the ECB block mode for opaque-key cipher
554 * operations
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100555 *
Derek Miller16e72292018-10-15 16:14:24 -0500556 * Note: this function should only be used with implementations that do not
557 * provide a needed higher-level operation.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100558 *
Derek Miller16e72292018-10-15 16:14:24 -0500559 * \param[in] key_slot The slot of the key to be used for the operation
560 * \param[in] algorithm The algorithm to be used in the cipher operation
561 * \param[in] direction Indicates whether the operation is an encrypt or
562 * decrypt
563 * \param[in] p_input A buffer containing the data to be
564 * encrypted/decrypted
565 * \param[in] input_size The size in bytes of the buffer pointed to by
566 * `p_input`
Derek Millerf3d0a562018-10-18 16:41:08 -0500567 * \param[out] p_output The caller-allocated buffer where the output will
Derek Miller16e72292018-10-15 16:14:24 -0500568 * be placed
569 * \param[in] output_size The allocated size in bytes of the `p_output`
570 * buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100571 *
Derek Miller16e72292018-10-15 16:14:24 -0500572 * \retval PSA_SUCCESS
573 * \retval PSA_ERROR_NOT_SUPPORTED
574 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100575typedef psa_status_t (*psa_drv_cipher_opaque_ecb_t)(psa_key_slot_t key_slot,
576 psa_algorithm_t algorithm,
577 encrypt_or_decrypt_t direction,
578 const uint8_t *p_input,
579 size_t input_size,
580 uint8_t *p_output,
581 size_t output_size);
Derek Miller5b3417a2018-10-10 17:55:03 -0500582
583/**
Derek Miller16e72292018-10-15 16:14:24 -0500584 * \brief A struct containing all of the function pointers needed to implement
585 * cipher operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100586 *
Derek Miller16e72292018-10-15 16:14:24 -0500587 * PSA Crypto API implementations should populate instances of the table as
588 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100589 *
Derek Miller16e72292018-10-15 16:14:24 -0500590 * If one of the functions is not implemented (such as
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100591 * `psa_drv_cipher_opaque_ecb_t`), it should be set to NULL.
Derek Miller5b3417a2018-10-10 17:55:03 -0500592 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100593struct psa_drv_cipher_opaque_t {
Derek Miller16e72292018-10-15 16:14:24 -0500594 /** The size in bytes of the hardware-specific Opaque Cipher context
595 * structure
596 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100597 size_t size;
Derek Miller16e72292018-10-15 16:14:24 -0500598 /** Function that performs the setup operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100599 psa_drv_cipher_opaque_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -0500600 /** Function that sets the IV (if necessary) */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100601 psa_drv_cipher_opaque_set_iv_t *p_set_iv;
Derek Miller16e72292018-10-15 16:14:24 -0500602 /** Function that performs the update operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100603 psa_drv_cipher_opaque_update_t *p_update;
Derek Miller16e72292018-10-15 16:14:24 -0500604 /** Function that completes the operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100605 psa_drv_cipher_opaque_finish_t *p_finish;
Derek Miller16e72292018-10-15 16:14:24 -0500606 /** Function that aborts the operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100607 psa_drv_cipher_opaque_abort_t *p_abort;
Derek Miller16e72292018-10-15 16:14:24 -0500608 /** Function that performs ECB mode for the cipher
609 * (Danger: ECB mode should not be used directly by clients of the PSA
610 * Crypto Client API)
611 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100612 psa_drv_cipher_opaque_ecb_t *p_ecb;
Derek Miller5b3417a2018-10-10 17:55:03 -0500613};
614
Derek Miller16e72292018-10-15 16:14:24 -0500615/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500616
617/** \defgroup transparent_cipher Transparent Block Cipher
Derek Miller765682c2018-10-22 15:27:27 -0500618 * Encryption and Decryption using transparent keys in block modes other than
619 * ECB must be done in multiple parts, using the following flow:
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100620 * - `psa_drv_cipher_transparent_setup_t`
621 * - `psa_drv_cipher_transparent_set_iv_t` (optional depending upon block mode)
622 * - `psa_drv_cipher_transparent_update_t`
Derek Miller765682c2018-10-22 15:27:27 -0500623 * - ...
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100624 * - `psa_drv_cipher_transparent_finish_t`
Derek Miller765682c2018-10-22 15:27:27 -0500625
626 * If a previously started Transparent Cipher operation needs to be terminated,
627 * it should be done so by the `psa_cipher_transparent_abort_t`. Failure to do
628 * so may result in allocated resources not being freed or in other undefined
629 * behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -0500630 */
Derek Miller16e72292018-10-15 16:14:24 -0500631/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500632
633/** \brief The hardware-specific transparent-key Cipher context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100634 *
Derek Miller765682c2018-10-22 15:27:27 -0500635 * The contents of this structure are implementation dependent and are
Derek Miller16e72292018-10-15 16:14:24 -0500636 * therefore not described here.
Derek Miller5b3417a2018-10-10 17:55:03 -0500637 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100638typedef struct psa_drv_cipher_transparent_context_s psa_drv_cipher_transparent_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500639
Derek Miller16e72292018-10-15 16:14:24 -0500640/** \brief The function prototype for the setup operation of transparent-key
641 * block cipher operations.
642 * Functions that implement the prototype should be named in the following
643 * conventions:
Derek Miller5b3417a2018-10-10 17:55:03 -0500644 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100645 * psa_drv_cipher_transparent_setup_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500646 * ~~~~~~~~~~~~~
647 * Where
648 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
649 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Derek Miller16e72292018-10-15 16:14:24 -0500650 * or for stream ciphers:
651 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100652 * psa_drv_cipher_transparent_setup_<CIPHER_NAME>
Derek Miller16e72292018-10-15 16:14:24 -0500653 * ~~~~~~~~~~~~~
654 * Where `CIPHER_NAME` is the name of a stream cipher (i.e. RC4)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100655 *
Derek Miller16e72292018-10-15 16:14:24 -0500656 * \param[in,out] p_context A structure that will contain the
657 * hardware-specific cipher context
658 * \param[in] direction Indicates if the operation is an encrypt or a
659 * decrypt
660 * \param[in] p_key_data A buffer containing the cleartext key material
661 * to be used in the operation
662 * \param[in] key_data_size The size in bytes of the key material
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100663 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500664 * \retval PSA_SUCCESS
665 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100666typedef psa_status_t (*psa_drv_cipher_transparent_setup_t)(psa_drv_cipher_transparent_context_t *p_context,
667 encrypt_or_decrypt_t direction,
668 const uint8_t *p_key_data,
669 size_t key_data_size);
Derek Miller5b3417a2018-10-10 17:55:03 -0500670
Derek Miller16e72292018-10-15 16:14:24 -0500671/** \brief The function prototype for the set initialization vector operation
672 * of transparent-key block cipher operations
673 * Functions that implement the prototype should be named in the following
674 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500675 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100676 * psa_drv_cipher_transparent_set_iv_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500677 * ~~~~~~~~~~~~~
678 * Where
679 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
680 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100681 *
Derek Miller16e72292018-10-15 16:14:24 -0500682 * \param[in,out] p_context A structure that contains the previously setup
683 * hardware-specific cipher context
684 * \param[in] p_iv A buffer containing the initialization vecotr
685 * \param[in] iv_length The size in bytes of the contents of `p_iv`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100686 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500687 * \retval PSA_SUCCESS
Jaeden Amero0a09f772018-10-26 11:42:32 +0100688 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100689typedef psa_status_t (*psa_drv_cipher_transparent_set_iv_t)(psa_drv_cipher_transparent_context_t *p_context,
690 const uint8_t *p_iv,
691 size_t iv_length);
Derek Miller16e72292018-10-15 16:14:24 -0500692
693/** \brief The function prototype for the update operation of transparent-key
694 * block cipher operations.
Derek Miller5b3417a2018-10-10 17:55:03 -0500695 *
Derek Miller16e72292018-10-15 16:14:24 -0500696 * Functions that implement the prototype should be named in the following
697 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500698 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100699 * psa_drv_cipher_transparent_update_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500700 * ~~~~~~~~~~~~~
701 * Where
702 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
703 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100704 *
Derek Miller16e72292018-10-15 16:14:24 -0500705 * \param[in,out] p_context A hardware-specific structure for the
706 * previously started cipher operation
707 * \param[in] p_input A buffer containing the data to be
708 * encrypted or decrypted
709 * \param[in] input_size The size in bytes of the `p_input` buffer
710 * \param[out] p_output A caller-allocated buffer where the
711 * generated output will be placed
712 * \param[in] output_size The size in bytes of the `p_output` buffer
713 * \param[out] p_output_length After completion, will contain the number
714 * of bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100715 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500716 * \retval PSA_SUCCESS
717 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100718typedef psa_status_t (*psa_drv_cipher_transparent_update_t)(psa_drv_cipher_transparent_context_t *p_context,
719 const uint8_t *p_input,
720 size_t input_size,
721 uint8_t *p_output,
722 size_t output_size,
723 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500724
Derek Miller16e72292018-10-15 16:14:24 -0500725/** \brief The function prototype for the finish operation of transparent-key
726 * block cipher operations.
Jaeden Amero0a09f772018-10-26 11:42:32 +0100727 *
Derek Miller16e72292018-10-15 16:14:24 -0500728 * Functions that implement the prototype should be named in the following
729 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500730 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100731 * psa_drv_cipher_transparent_finish_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500732 * ~~~~~~~~~~~~~
733 * Where
734 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
735 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Derek Miller16e72292018-10-15 16:14:24 -0500736 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500737 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500738 * previously started cipher operation
739 * \param[out] p_output A caller-allocated buffer where the generated
740 * output will be placed
741 * \param[in] output_size The size in bytes of the `p_output` buffer
742 * \param[out] p_output_length After completion, will contain the number of
743 * bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100744 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500745 * \retval PSA_SUCCESS
746 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100747typedef psa_status_t (*psa_drv_cipher_transparent_finish_t)(psa_drv_cipher_transparent_context_t *p_context,
748 uint8_t *p_output,
749 size_t output_size,
750 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500751
Derek Miller16e72292018-10-15 16:14:24 -0500752/** \brief The function prototype for the abort operation of transparent-key
753 * block cipher operations.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100754 *
Derek Miller16e72292018-10-15 16:14:24 -0500755 * Functions that implement the following prototype should be named in the
756 * following convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500757 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100758 * psa_drv_cipher_transparent_abort_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500759 * ~~~~~~~~~~~~~
760 * Where
761 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
762 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100763 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500764 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500765 * previously started cipher operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100766 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500767 * \retval PSA_SUCCESS
768 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100769typedef psa_status_t (*psa_drv_cipher_transparent_abort_t)(psa_drv_cipher_transparent_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500770
Derek Miller16e72292018-10-15 16:14:24 -0500771/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500772
Derek Miller16e72292018-10-15 16:14:24 -0500773/** \defgroup driver_digest Message Digests
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100774 *
Derek Miller765682c2018-10-22 15:27:27 -0500775 * Generation and authentication of Message Digests (aka hashes) must be done
776 * in parts using the following sequence:
777 * - `psa_hash_setup_t`
778 * - `psa_hash_update_t`
779 * - ...
780 * - `psa_hash_finish_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100781 *
Derek Miller765682c2018-10-22 15:27:27 -0500782 * If a previously started Message Digest operation needs to be terminated
783 * before the `psa_hash_finish_t` operation is complete, it should be aborted
784 * by the `psa_hash_abort_t`. Failure to do so may result in allocated
785 * resources not being freed or in other undefined behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -0500786 */
Derek Miller16e72292018-10-15 16:14:24 -0500787/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500788
789/** \brief The hardware-specific hash context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100790 *
Derek Miller16e72292018-10-15 16:14:24 -0500791 * The contents of this structure are implementation dependent and are
792 * therefore not described here
Derek Miller5b3417a2018-10-10 17:55:03 -0500793 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100794typedef struct psa_drv_hash_context_s psa_drv_hash_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500795
Derek Miller16e72292018-10-15 16:14:24 -0500796/** \brief The function prototype for the start operation of a hash (message
797 * digest) operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100798 *
Derek Miller16e72292018-10-15 16:14:24 -0500799 * Functions that implement the prototype should be named in the following
800 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500801 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100802 * psa_drv_hash_<ALGO>_setup
Derek Miller5b3417a2018-10-10 17:55:03 -0500803 * ~~~~~~~~~~~~~
804 * Where `ALGO` is the name of the underlying hash function
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100805 *
Derek Miller16e72292018-10-15 16:14:24 -0500806 * \param[in,out] p_context A structure that will contain the
807 * hardware-specific hash context
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100808 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500809 * \retval PSA_SUCCESS Success.
810 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100811typedef psa_status_t (*psa_drv_hash_setup_t)(psa_drv_hash_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500812
Derek Miller16e72292018-10-15 16:14:24 -0500813/** \brief The function prototype for the update operation of a hash (message
814 * digest) operation
Derek Miller5b3417a2018-10-10 17:55:03 -0500815 *
Derek Miller16e72292018-10-15 16:14:24 -0500816 * Functions that implement the prototype should be named in the following
817 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500818 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100819 * psa_drv_hash_<ALGO>_update
Derek Miller5b3417a2018-10-10 17:55:03 -0500820 * ~~~~~~~~~~~~~
821 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100822 *
Derek Miller16e72292018-10-15 16:14:24 -0500823 * \param[in,out] p_context A hardware-specific structure for the
824 * previously-established hash operation to be
825 * continued
826 * \param[in] p_input A buffer containing the message to be appended
827 * to the hash operation
828 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -0500829 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100830typedef psa_status_t (*psa_drv_hash_update_t)(psa_drv_hash_context_t *p_context,
831 const uint8_t *p_input,
832 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500833
Derek Miller16e72292018-10-15 16:14:24 -0500834/** \brief The prototype for the finish operation of a hash (message digest)
835 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100836 *
Derek Miller16e72292018-10-15 16:14:24 -0500837 * Functions that implement the prototype should be named in the following
838 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500839 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100840 * psa_drv_hash_<ALGO>_finish
Derek Miller5b3417a2018-10-10 17:55:03 -0500841 * ~~~~~~~~~~~~~
842 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100843 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500844 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500845 * previously started hash operation to be
846 * fiinished
847 * \param[out] p_output A buffer where the generated digest will be
848 * placed
849 * \param[in] output_size The size in bytes of the buffer that has been
850 * allocated for the `p_output` buffer
Derek Millerf3d0a562018-10-18 16:41:08 -0500851 * \param[out] p_output_length The number of bytes placed in `p_output` after
852 * success
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100853 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500854 * \retval PSA_SUCCESS
855 * Success.
856 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100857typedef psa_status_t (*psa_drv_hash_finish_t)(psa_drv_hash_context_t *p_context,
858 uint8_t *p_output,
859 size_t output_size,
860 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500861
Derek Miller16e72292018-10-15 16:14:24 -0500862/** \brief The function prototype for the abort operation of a hash (message
863 * digest) operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100864 *
Derek Miller16e72292018-10-15 16:14:24 -0500865 * Functions that implement the prototype should be named in the following
866 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500867 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100868 * psa_drv_hash_<ALGO>_abort
Derek Miller5b3417a2018-10-10 17:55:03 -0500869 * ~~~~~~~~~~~~~
870 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100871 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500872 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500873 * started hash operation to be aborted
Derek Miller5b3417a2018-10-10 17:55:03 -0500874 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100875typedef void (*psa_drv_hash_abort_t)(psa_drv_hash_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500876
Derek Miller16e72292018-10-15 16:14:24 -0500877/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500878
879
880/** \defgroup opaque_asymmetric Opaque Asymmetric Cryptography
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100881 *
Derek Miller765682c2018-10-22 15:27:27 -0500882 * Since the amount of data that can (or should) be encrypted or signed using
883 * asymmetric keys is limited by the key size, asymmetric key operations using
884 * opaque keys must be done in single function calls.
Derek Miller5b3417a2018-10-10 17:55:03 -0500885 */
Derek Miller16e72292018-10-15 16:14:24 -0500886/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500887
888/**
Derek Miller16e72292018-10-15 16:14:24 -0500889 * \brief A function that signs a hash or short message with a private key
Derek Miller5b3417a2018-10-10 17:55:03 -0500890 *
Derek Miller16e72292018-10-15 16:14:24 -0500891 * \param[in] key_slot Key slot of an asymmetric key pair
892 * \param[in] alg A signature algorithm that is compatible
893 * with the type of `key`
Derek Miller765682c2018-10-22 15:27:27 -0500894 * \param[in] p_hash The hash to sign
Derek Miller16e72292018-10-15 16:14:24 -0500895 * \param[in] hash_length Size of the `p_hash` buffer in bytes
896 * \param[out] p_signature Buffer where the signature is to be written
Derek Millerf3d0a562018-10-18 16:41:08 -0500897 * \param[in] signature_size Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500898 * \param[out] p_signature_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -0500899 * that make up the returned signature value
Derek Miller5b3417a2018-10-10 17:55:03 -0500900 *
901 * \retval PSA_SUCCESS
902 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100903typedef psa_status_t (*psa_drv_asymmetric_opaque_sign_t)(psa_key_slot_t key_slot,
904 psa_algorithm_t alg,
905 const uint8_t *p_hash,
906 size_t hash_length,
907 uint8_t *p_signature,
908 size_t signature_size,
909 size_t *p_signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500910
911/**
Derek Miller16e72292018-10-15 16:14:24 -0500912 * \brief A function that verifies the signature a hash or short message using
Derek Miller765682c2018-10-22 15:27:27 -0500913 * an asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -0500914 *
Derek Miller16e72292018-10-15 16:14:24 -0500915 * \param[in] key_slot Key slot of a public key or an asymmetric key
916 * pair
917 * \param[in] alg A signature algorithm that is compatible with
918 * the type of `key`
Derek Miller765682c2018-10-22 15:27:27 -0500919 * \param[in] p_hash The hash whose signature is to be verified
Derek Miller16e72292018-10-15 16:14:24 -0500920 * \param[in] hash_length Size of the `p_hash` buffer in bytes
921 * \param[in] p_signature Buffer containing the signature to verify
922 * \param[in] signature_length Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500923 *
924 * \retval PSA_SUCCESS
925 * The signature is valid.
926 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100927typedef psa_status_t (*psa_drv_asymmetric_opaque_verify_t)(psa_key_slot_t key_slot,
928 psa_algorithm_t alg,
929 const uint8_t *p_hash,
930 size_t hash_length,
931 const uint8_t *p_signature,
932 size_t signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500933
934/**
Derek Miller765682c2018-10-22 15:27:27 -0500935 * \brief A function that encrypts a short message with an asymmetric public
936 * key
Derek Miller5b3417a2018-10-10 17:55:03 -0500937 *
Derek Miller16e72292018-10-15 16:14:24 -0500938 * \param[in] key_slot Key slot of a public key or an asymmetric key
939 * pair
940 * \param[in] alg An asymmetric encryption algorithm that is
941 * compatible with the type of `key`
942 * \param[in] p_input The message to encrypt
943 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500944 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -0500945 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -0500946 * If the algorithm does not support a
947 * salt, pass `NULL`.
948 * If the algorithm supports an optional
949 * salt and you do not want to pass a salt,
950 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -0500951 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
952 * supported.
953 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500954 * If `p_salt` is `NULL`, pass 0.
955 * \param[out] p_output Buffer where the encrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -0500956 * be written
957 * \param[in] output_size Size of the `p_output` buffer in bytes
958 * \param[out] p_output_length On success, the number of bytes that make up
959 * the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -0500960 *
961 * \retval PSA_SUCCESS
962 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100963typedef psa_status_t (*psa_drv_asymmetric_opaque_encrypt_t)(psa_key_slot_t key_slot,
964 psa_algorithm_t alg,
965 const uint8_t *p_input,
966 size_t input_length,
967 const uint8_t *p_salt,
968 size_t salt_length,
969 uint8_t *p_output,
970 size_t output_size,
971 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500972
973/**
Derek Miller765682c2018-10-22 15:27:27 -0500974 * \brief Decrypt a short message with an asymmetric private key.
Derek Miller5b3417a2018-10-10 17:55:03 -0500975 *
Derek Miller16e72292018-10-15 16:14:24 -0500976 * \param[in] key_slot Key slot of an asymmetric key pair
977 * \param[in] alg An asymmetric encryption algorithm that is
978 * compatible with the type of `key`
979 * \param[in] p_input The message to decrypt
980 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500981 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -0500982 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -0500983 * If the algorithm does not support a
984 * salt, pass `NULL`.
985 * If the algorithm supports an optional
986 * salt and you do not want to pass a salt,
987 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -0500988 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
989 * supported.
990 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500991 * If `p_salt` is `NULL`, pass 0.
992 * \param[out] p_output Buffer where the decrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -0500993 * be written
994 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500995 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -0500996 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -0500997 *
998 * \retval PSA_SUCCESS
999 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001000typedef psa_status_t (*psa_drv_asymmetric_opaque_decrypt_t)(psa_key_slot_t key_slot,
1001 psa_algorithm_t alg,
1002 const uint8_t *p_input,
1003 size_t input_length,
1004 const uint8_t *p_salt,
1005 size_t salt_length,
1006 uint8_t *p_output,
1007 size_t output_size,
1008 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001009
1010/**
Derek Miller16e72292018-10-15 16:14:24 -05001011 * \brief A struct containing all of the function pointers needed to implement
1012 * asymmetric cryptographic operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001013 *
Derek Miller16e72292018-10-15 16:14:24 -05001014 * PSA Crypto API implementations should populate instances of the table as
1015 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001016 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001017 * If one of the functions is not implemented, it should be set to NULL.
1018 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001019struct psa_drv_asymmetric_opaque_t {
Derek Miller16e72292018-10-15 16:14:24 -05001020 /** Function that performs the asymmetric sign operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001021 psa_drv_asymmetric_opaque_sign_t *p_sign;
Derek Miller16e72292018-10-15 16:14:24 -05001022 /** Function that performs the asymmetric verify operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001023 psa_drv_asymmetric_opaque_verify_t *p_verify;
Derek Miller16e72292018-10-15 16:14:24 -05001024 /** Function that performs the asymmetric encrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001025 psa_drv_asymmetric_opaque_encrypt_t *p_encrypt;
Derek Miller16e72292018-10-15 16:14:24 -05001026 /** Function that performs the asymmetric decrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001027 psa_drv_asymmetric_opaque_decrypt_t *p_decrypt;
Derek Miller5b3417a2018-10-10 17:55:03 -05001028};
1029
Derek Miller16e72292018-10-15 16:14:24 -05001030/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001031
1032/** \defgroup transparent_asymmetric Transparent Asymmetric Cryptography
Derek Miller765682c2018-10-22 15:27:27 -05001033 *
1034 * Since the amount of data that can (or should) be encrypted or signed using
1035 * asymmetric keys is limited by the key size, asymmetric key operations using
1036 * transparent keys must be done in single function calls.
Derek Miller5b3417a2018-10-10 17:55:03 -05001037 */
Derek Miller16e72292018-10-15 16:14:24 -05001038/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001039
1040
1041/**
Derek Miller16e72292018-10-15 16:14:24 -05001042 * \brief A function that signs a hash or short message with a transparent
Derek Miller765682c2018-10-22 15:27:27 -05001043 * asymmetric private key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001044 *
Derek Miller16e72292018-10-15 16:14:24 -05001045 * Functions that implement the prototype should be named in the following
1046 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001047 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001048 * psa_drv_asymmetric_<ALGO>_sign
Derek Miller5b3417a2018-10-10 17:55:03 -05001049 * ~~~~~~~~~~~~~
1050 * Where `ALGO` is the name of the signing algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001051 *
Derek Miller16e72292018-10-15 16:14:24 -05001052 * \param[in] p_key A buffer containing the private key
1053 * material
1054 * \param[in] key_size The size in bytes of the `p_key` data
1055 * \param[in] alg A signature algorithm that is compatible
1056 * with the type of `p_key`
1057 * \param[in] p_hash The hash or message to sign
1058 * \param[in] hash_length Size of the `p_hash` buffer in bytes
1059 * \param[out] p_signature Buffer where the signature is to be written
1060 * \param[in] signature_size Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001061 * \param[out] p_signature_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001062 * that make up the returned signature value
Derek Miller5b3417a2018-10-10 17:55:03 -05001063 *
1064 * \retval PSA_SUCCESS
1065 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001066typedef psa_status_t (*psa_drv_asymmetric_transparent_sign_t)(const uint8_t *p_key,
1067 size_t key_size,
1068 psa_algorithm_t alg,
1069 const uint8_t *p_hash,
1070 size_t hash_length,
1071 uint8_t *p_signature,
1072 size_t signature_size,
1073 size_t *p_signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001074
1075/**
Derek Miller16e72292018-10-15 16:14:24 -05001076 * \brief A function that verifies the signature a hash or short message using
Derek Miller765682c2018-10-22 15:27:27 -05001077 * a transparent asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -05001078 *
Derek Miller16e72292018-10-15 16:14:24 -05001079 * Functions that implement the prototype should be named in the following
1080 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001081 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001082 * psa_drv_asymmetric_<ALGO>_verify
Derek Miller5b3417a2018-10-10 17:55:03 -05001083 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001084 * Where `ALGO` is the name of the signing algorithm
1085 *
Derek Miller16e72292018-10-15 16:14:24 -05001086 * \param[in] p_key A buffer containing the public key material
1087 * \param[in] key_size The size in bytes of the `p_key` data
1088 * \param[in] alg A signature algorithm that is compatible with
1089 * the type of `key`
1090 * \param[in] p_hash The hash or message whose signature is to be
1091 * verified
1092 * \param[in] hash_length Size of the `p_hash` buffer in bytes
1093 * \param[in] p_signature Buffer containing the signature to verify
1094 * \param[in] signature_length Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001095 *
1096 * \retval PSA_SUCCESS
1097 * The signature is valid.
1098 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001099typedef psa_status_t (*psa_drv_asymmetric_transparent_verify_t)(const uint8_t *p_key,
1100 size_t key_size,
1101 psa_algorithm_t alg,
1102 const uint8_t *p_hash,
1103 size_t hash_length,
1104 const uint8_t *p_signature,
1105 size_t signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001106
1107/**
Derek Miller765682c2018-10-22 15:27:27 -05001108 * \brief A function that encrypts a short message with a transparent
1109 * asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -05001110 *
Derek Miller16e72292018-10-15 16:14:24 -05001111 * Functions that implement the prototype should be named in the following
1112 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001113 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001114 * psa_drv_asymmetric_<ALGO>_encrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001115 * ~~~~~~~~~~~~~
1116 * Where `ALGO` is the name of the encryption algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001117 *
Derek Miller16e72292018-10-15 16:14:24 -05001118 * \param[in] p_key A buffer containing the public key material
1119 * \param[in] key_size The size in bytes of the `p_key` data
1120 * \param[in] alg An asymmetric encryption algorithm that is
1121 * compatible with the type of `key`
1122 * \param[in] p_input The message to encrypt
1123 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001124 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -05001125 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -05001126 * If the algorithm does not support a
Derek Miller16e72292018-10-15 16:14:24 -05001127 * salt, pass `NULL`
Derek Miller5b3417a2018-10-10 17:55:03 -05001128 * If the algorithm supports an optional
1129 * salt and you do not want to pass a salt,
1130 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -05001131 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1132 * supported.
1133 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001134 * If `p_salt` is `NULL`, pass 0.
1135 * \param[out] p_output Buffer where the encrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -05001136 * be written
1137 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001138 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001139 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -05001140 *
1141 * \retval PSA_SUCCESS
1142 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001143typedef psa_status_t (*psa_drv_asymmetric_transparent_encrypt_t)(const uint8_t *p_key,
1144 size_t key_size,
1145 psa_algorithm_t alg,
1146 const uint8_t *p_input,
1147 size_t input_length,
1148 const uint8_t *p_salt,
1149 size_t salt_length,
1150 uint8_t *p_output,
1151 size_t output_size,
1152 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001153
1154/**
Derek Miller765682c2018-10-22 15:27:27 -05001155 * \brief Decrypt a short message with a transparent asymmetric private key
Derek Miller5b3417a2018-10-10 17:55:03 -05001156 *
Derek Miller16e72292018-10-15 16:14:24 -05001157 * Functions that implement the prototype should be named in the following
1158 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001159 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001160 * psa_drv_asymmetric_<ALGO>_decrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001161 * ~~~~~~~~~~~~~
1162 * Where `ALGO` is the name of the encryption algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001163 *
Derek Miller16e72292018-10-15 16:14:24 -05001164 * \param[in] p_key A buffer containing the private key material
1165 * \param[in] key_size The size in bytes of the `p_key` data
1166 * \param[in] alg An asymmetric encryption algorithm that is
1167 * compatible with the type of `key`
1168 * \param[in] p_input The message to decrypt
1169 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001170 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -05001171 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -05001172 * If the algorithm does not support a
1173 * salt, pass `NULL`.
1174 * If the algorithm supports an optional
1175 * salt and you do not want to pass a salt,
1176 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -05001177 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1178 * supported
1179 * \param[in] salt_length Size of the `p_salt` buffer in bytes
1180 * If `p_salt` is `NULL`, pass 0
Derek Miller5b3417a2018-10-10 17:55:03 -05001181 * \param[out] p_output Buffer where the decrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -05001182 * be written
1183 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001184 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001185 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -05001186 *
1187 * \retval PSA_SUCCESS
1188 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001189typedef psa_status_t (*psa_drv_asymmetric_transparent_decrypt_t)(const uint8_t *p_key,
1190 size_t key_size,
1191 psa_algorithm_t alg,
1192 const uint8_t *p_input,
1193 size_t input_length,
1194 const uint8_t *p_salt,
1195 size_t salt_length,
1196 uint8_t *p_output,
1197 size_t output_size,
1198 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001199
Derek Miller16e72292018-10-15 16:14:24 -05001200/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001201
1202/** \defgroup aead_opaque AEAD Opaque
Derek Miller765682c2018-10-22 15:27:27 -05001203 * Authenticated Encryption with Additional Data (AEAD) operations with opaque
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001204 * keys must be done in one function call. While this creates a burden for
Derek Miller765682c2018-10-22 15:27:27 -05001205 * implementers as there must be sufficient space in memory for the entire
1206 * message, it prevents decrypted data from being made available before the
1207 * authentication operation is complete and the data is known to be authentic.
Derek Miller5b3417a2018-10-10 17:55:03 -05001208 */
Derek Miller16e72292018-10-15 16:14:24 -05001209/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001210
Derek Miller16e72292018-10-15 16:14:24 -05001211/** \brief Process an authenticated encryption operation using an opaque key
Derek Miller5b3417a2018-10-10 17:55:03 -05001212 *
Derek Miller16e72292018-10-15 16:14:24 -05001213 * \param[in] key_slot Slot containing the key to use.
1214 * \param[in] algorithm The AEAD algorithm to compute
1215 * (\c PSA_ALG_XXX value such that
1216 * #PSA_ALG_IS_AEAD(`alg`) is true)
1217 * \param[in] p_nonce Nonce or IV to use
1218 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
1219 * \param[in] p_additional_data Additional data that will be
1220 * authenticated but not encrypted
1221 * \param[in] additional_data_length Size of `p_additional_data` in bytes
1222 * \param[in] p_plaintext Data that will be authenticated and
1223 * encrypted
1224 * \param[in] plaintext_length Size of `p_plaintext` in bytes
1225 * \param[out] p_ciphertext Output buffer for the authenticated and
1226 * encrypted data. The additional data is
1227 * not part of this output. For algorithms
1228 * where the encrypted data and the
1229 * authentication tag are defined as
1230 * separate outputs, the authentication
1231 * tag is appended to the encrypted data.
1232 * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in
1233 * bytes
1234 * \param[out] p_ciphertext_length On success, the size of the output in
1235 * the `p_ciphertext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001236 *
1237 * \retval #PSA_SUCCESS
1238 * Success.
1239 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001240typedef psa_status_t (*psa_drv_aead_opaque_encrypt_t)(psa_key_slot_t key_slot,
1241 psa_algorithm_t algorithm,
1242 const uint8_t *p_nonce,
1243 size_t nonce_length,
1244 const uint8_t *p_additional_data,
1245 size_t additional_data_length,
1246 const uint8_t *p_plaintext,
1247 size_t plaintext_length,
1248 uint8_t *p_ciphertext,
1249 size_t ciphertext_size,
1250 size_t *p_ciphertext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001251
Derek Miller16e72292018-10-15 16:14:24 -05001252/** Process an authenticated decryption operation using an opaque key
Derek Miller5b3417a2018-10-10 17:55:03 -05001253 *
Derek Miller16e72292018-10-15 16:14:24 -05001254 * \param[in] key_slot Slot containing the key to use
1255 * \param[in] algorithm The AEAD algorithm to compute
1256 * (\c PSA_ALG_XXX value such that
1257 * #PSA_ALG_IS_AEAD(`alg`) is true)
1258 * \param[in] p_nonce Nonce or IV to use
1259 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
1260 * \param[in] p_additional_data Additional data that has been
1261 * authenticated but not encrypted
1262 * \param[in] additional_data_length Size of `p_additional_data` in bytes
1263 * \param[in] p_ciphertext Data that has been authenticated and
1264 * encrypted.
1265 * For algorithms where the encrypted data
1266 * and the authentication tag are defined
1267 * as separate inputs, the buffer must
1268 * contain the encrypted data followed by
1269 * the authentication tag.
1270 * \param[in] ciphertext_length Size of `p_ciphertext` in bytes
1271 * \param[out] p_plaintext Output buffer for the decrypted data
1272 * \param[in] plaintext_size Size of the `p_plaintext` buffer in
1273 * bytes
1274 * \param[out] p_plaintext_length On success, the size of the output in
1275 * the `p_plaintext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001276 *
1277 * \retval #PSA_SUCCESS
1278 * Success.
1279 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001280typedef psa_status_t (*psa_drv_aead_opaque_decrypt_t)(psa_key_slot_t key_slot,
1281 psa_algorithm_t algorithm,
1282 const uint8_t *p_nonce,
1283 size_t nonce_length,
1284 const uint8_t *p_additional_data,
1285 size_t additional_data_length,
1286 const uint8_t *p_ciphertext,
1287 size_t ciphertext_length,
1288 uint8_t *p_plaintext,
1289 size_t plaintext_size,
1290 size_t *p_plaintext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001291
1292/**
Derek Miller16e72292018-10-15 16:14:24 -05001293 * \brief A struct containing all of the function pointers needed to implement
1294 * Authenticated Encryption with Additional Data operations using opaque keys
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001295 *
Derek Miller16e72292018-10-15 16:14:24 -05001296 * PSA Crypto API implementations should populate instances of the table as
1297 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001298 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001299 * If one of the functions is not implemented, it should be set to NULL.
1300 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001301struct psa_drv_aead_opaque_t {
Derek Miller16e72292018-10-15 16:14:24 -05001302 /** Function that performs the AEAD encrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001303 psa_drv_aead_opaque_encrypt_t *p_encrypt;
Derek Miller16e72292018-10-15 16:14:24 -05001304 /** Function that performs the AEAD decrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001305 psa_drv_aead_opaque_decrypt_t *p_decrypt;
Derek Miller5b3417a2018-10-10 17:55:03 -05001306};
Derek Miller16e72292018-10-15 16:14:24 -05001307/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001308
1309/** \defgroup aead_transparent AEAD Transparent
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001310 *
Derek Miller765682c2018-10-22 15:27:27 -05001311 * Authenticated Encryption with Additional Data (AEAD) operations with
1312 * transparent keys must be done in one function call. While this creates a
1313 * burden for implementers as there must be sufficient space in memory for the
1314 * entire message, it prevents decrypted data from being made available before
1315 * the authentication operation is complete and the data is known to be
1316 * authentic.
Derek Miller5b3417a2018-10-10 17:55:03 -05001317 */
Derek Miller16e72292018-10-15 16:14:24 -05001318/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001319
Derek Miller765682c2018-10-22 15:27:27 -05001320/** Process an authenticated encryption operation using an opaque key.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001321 *
Derek Miller16e72292018-10-15 16:14:24 -05001322 * Functions that implement the prototype should be named in the following
1323 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001324 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001325 * psa_drv_aead_<ALGO>_encrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001326 * ~~~~~~~~~~~~~
1327 * Where `ALGO` is the name of the AEAD algorithm
1328 *
Derek Miller16e72292018-10-15 16:14:24 -05001329 * \param[in] p_key A pointer to the key material
1330 * \param[in] key_length The size in bytes of the key material
1331 * \param[in] alg The AEAD algorithm to compute
1332 * (\c PSA_ALG_XXX value such that
1333 * #PSA_ALG_IS_AEAD(`alg`) is true)
1334 * \param[in] nonce Nonce or IV to use
1335 * \param[in] nonce_length Size of the `nonce` buffer in bytes
1336 * \param[in] additional_data Additional data that will be MACed
1337 * but not encrypted.
1338 * \param[in] additional_data_length Size of `additional_data` in bytes
1339 * \param[in] plaintext Data that will be MACed and
1340 * encrypted.
1341 * \param[in] plaintext_length Size of `plaintext` in bytes
1342 * \param[out] ciphertext Output buffer for the authenticated and
1343 * encrypted data. The additional data is
1344 * not part of this output. For algorithms
1345 * where the encrypted data and the
1346 * authentication tag are defined as
1347 * separate outputs, the authentication
1348 * tag is appended to the encrypted data.
1349 * \param[in] ciphertext_size Size of the `ciphertext` buffer in
1350 * bytes
1351 * This must be at least
1352 * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(`alg`,
1353 * `plaintext_length`).
1354 * \param[out] ciphertext_length On success, the size of the output in
1355 * the `ciphertext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001356 *
1357 * \retval #PSA_SUCCESS
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001358
Derek Miller5b3417a2018-10-10 17:55:03 -05001359 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001360typedef psa_status_t (*psa_drv_aead_transparent_encrypt_t)(const uint8_t *p_key,
1361 size_t key_length,
1362 psa_algorithm_t alg,
1363 const uint8_t *nonce,
1364 size_t nonce_length,
1365 const uint8_t *additional_data,
1366 size_t additional_data_length,
1367 const uint8_t *plaintext,
1368 size_t plaintext_length,
1369 uint8_t *ciphertext,
1370 size_t ciphertext_size,
1371 size_t *ciphertext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001372
Derek Miller765682c2018-10-22 15:27:27 -05001373/** Process an authenticated decryption operation using an opaque key.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001374 *
Derek Miller16e72292018-10-15 16:14:24 -05001375 * Functions that implement the prototype should be named in the following
1376 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001377 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001378 * psa_drv_aead_<ALGO>_decrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001379 * ~~~~~~~~~~~~~
1380 * Where `ALGO` is the name of the AEAD algorithm
Derek Miller16e72292018-10-15 16:14:24 -05001381 * \param[in] p_key A pointer to the key material
1382 * \param[in] key_length The size in bytes of the key material
1383 * \param[in] alg The AEAD algorithm to compute
1384 * (\c PSA_ALG_XXX value such that
1385 * #PSA_ALG_IS_AEAD(`alg`) is true)
1386 * \param[in] nonce Nonce or IV to use
1387 * \param[in] nonce_length Size of the `nonce` buffer in bytes
1388 * \param[in] additional_data Additional data that has been MACed
1389 * but not encrypted
1390 * \param[in] additional_data_length Size of `additional_data` in bytes
1391 * \param[in] ciphertext Data that has been MACed and
1392 * encrypted
1393 * For algorithms where the encrypted data
1394 * and the authentication tag are defined
1395 * as separate inputs, the buffer must
1396 * contain the encrypted data followed by
1397 * the authentication tag.
1398 * \param[in] ciphertext_length Size of `ciphertext` in bytes
1399 * \param[out] plaintext Output buffer for the decrypted data
1400 * \param[in] plaintext_size Size of the `plaintext` buffer in
1401 * bytes
1402 * This must be at least
1403 * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(`alg`,
1404 * `ciphertext_length`).
1405 * \param[out] plaintext_length On success, the size of the output
1406 * in the \b plaintext buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001407 *
1408 * \retval #PSA_SUCCESS
1409 * Success.
1410 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001411typedef psa_status_t (*psa_drv_aead_transparent_decrypt_t)(const uint8_t *p_key,
1412 size_t key_length,
1413 psa_algorithm_t alg,
1414 const uint8_t *nonce,
1415 size_t nonce_length,
1416 const uint8_t *additional_data,
1417 size_t additional_data_length,
1418 const uint8_t *ciphertext,
1419 size_t ciphertext_length,
1420 uint8_t *plaintext,
1421 size_t plaintext_size,
1422 size_t *plaintext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001423
Derek Miller16e72292018-10-15 16:14:24 -05001424/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001425
1426
Derek Miller16e72292018-10-15 16:14:24 -05001427/** \defgroup driver_rng Entropy Generation
Derek Miller5b3417a2018-10-10 17:55:03 -05001428 */
Derek Miller16e72292018-10-15 16:14:24 -05001429/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001430
1431/** \brief A hardware-specific structure for a entropy providing hardware
1432 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001433typedef struct psa_drv_entropy_context_s psa_drv_entropy_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -05001434
1435/** \brief Initialize an entropy driver
1436 *
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001437 *
Derek Miller16e72292018-10-15 16:14:24 -05001438 * \param[in,out] p_context A hardware-specific structure
1439 * containing any context information for
1440 * the implementation
Derek Miller5b3417a2018-10-10 17:55:03 -05001441 *
1442 * \retval PSA_SUCCESS
1443 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001444typedef psa_status_t (*psa_drv_entropy_init_t)(psa_drv_entropy_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -05001445
Derek Miller6f960ab2018-10-23 15:58:06 -05001446/** \brief Get a specified number of bits from the entropy source
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001447 *
Derek Miller16e72292018-10-15 16:14:24 -05001448 * It retrives `buffer_size` bytes of data from the entropy source. The entropy
1449 * source will always fill the provided buffer to its full size, however, most
1450 * entropy sources have biases, and the actual amount of entropy contained in
1451 * the buffer will be less than the number of bytes.
1452 * The driver will return the actual number of bytes of entropy placed in the
1453 * buffer in `p_received_entropy_bytes`.
1454 * A PSA Crypto API implementation will likely feed the output of this function
1455 * into a Digital Random Bit Generator (DRBG), and typically has a minimum
1456 * amount of entropy that it needs.
1457 * To accomplish this, the PSA Crypto implementation should be designed to call
1458 * this function multiple times until it has received the required amount of
1459 * entropy from the entropy source.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001460 *
Derek Miller16e72292018-10-15 16:14:24 -05001461 * \param[in,out] p_context A hardware-specific structure
1462 * containing any context information
1463 * for the implementation
1464 * \param[out] p_buffer A caller-allocated buffer for the
Derek Miller6f960ab2018-10-23 15:58:06 -05001465 * retrieved entropy to be placed in
Derek Miller16e72292018-10-15 16:14:24 -05001466 * \param[in] buffer_size The allocated size of `p_buffer`
Derek Miller6f960ab2018-10-23 15:58:06 -05001467 * \param[out] p_received_entropy_bits The amount of entropy (in bits)
Derek Miller16e72292018-10-15 16:14:24 -05001468 * actually provided in `p_buffer`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001469 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001470 * \retval PSA_SUCCESS
1471 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001472typedef psa_status_t (*psa_drv_entropy_get_bits_t)(psa_drv_entropy_context_t *p_context,
1473 uint8_t *p_buffer,
1474 uint32_t buffer_size,
1475 uint32_t *p_received_entropy_bits);
Derek Miller5b3417a2018-10-10 17:55:03 -05001476
1477/**
Derek Miller16e72292018-10-15 16:14:24 -05001478 * \brief A struct containing all of the function pointers needed to interface
1479 * to an entropy source
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001480 *
Derek Miller16e72292018-10-15 16:14:24 -05001481 * PSA Crypto API implementations should populate instances of the table as
1482 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001483 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001484 * If one of the functions is not implemented, it should be set to NULL.
1485 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001486struct psa_drv_entropy_t {
Derek Miller16e72292018-10-15 16:14:24 -05001487 /** Function that performs initialization for the entropy source */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001488 psa_drv_entropy_init_t *p_init;
Derek Miller6f960ab2018-10-23 15:58:06 -05001489 /** Function that performs the get_bits operation for the entropy source
Derek Miller16e72292018-10-15 16:14:24 -05001490 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001491 psa_drv_entropy_get_bits_t *p_get_bits;
Derek Miller5b3417a2018-10-10 17:55:03 -05001492};
Derek Miller16e72292018-10-15 16:14:24 -05001493/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001494
Derek Miller16e72292018-10-15 16:14:24 -05001495/** \defgroup driver_key_management Key Management
Derek Miller765682c2018-10-22 15:27:27 -05001496 * Currently, key management is limited to importing keys in the clear,
1497 * destroying keys, and exporting keys in the clear.
1498 * Whether a key may be exported is determined by the key policies in place
1499 * on the key slot.
Derek Miller5b3417a2018-10-10 17:55:03 -05001500 */
Derek Miller16e72292018-10-15 16:14:24 -05001501/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001502
Derek Miller16e72292018-10-15 16:14:24 -05001503/** \brief Import a key in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001504 *
1505 * This function can support any output from psa_export_key(). Refer to the
1506 * documentation of psa_export_key() for the format for each key type.
1507 *
Derek Miller81133a62018-10-23 14:55:32 -05001508 * \param[in] key_slot Slot where the key will be stored
1509 * This must be a valid slot for a key of the chosen
1510 * type. It must be unoccupied.
1511 * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value)
1512 * \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value)
1513 * \param[in] usage The allowed uses of the key
1514 * \param[in] p_data Buffer containing the key data
1515 * \param[in] data_length Size of the `data` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001516 *
1517 * \retval #PSA_SUCCESS
1518 * Success.
1519 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001520typedef psa_status_t (*psa_drv_opaque_import_key_t)(psa_key_slot_t key_slot,
1521 psa_key_type_t type,
1522 psa_algorithm_t algorithm,
1523 psa_key_usage_t usage,
1524 const uint8_t *p_data,
1525 size_t data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001526
1527/**
Derek Miller16e72292018-10-15 16:14:24 -05001528 * \brief Destroy a key and restore the slot to its default state
Derek Miller5b3417a2018-10-10 17:55:03 -05001529 *
1530 * This function destroys the content of the key slot from both volatile
1531 * memory and, if applicable, non-volatile storage. Implementations shall
1532 * make a best effort to ensure that any previous content of the slot is
1533 * unrecoverable.
1534 *
1535 * This function also erases any metadata such as policies. It returns the
1536 * specified slot to its default state.
1537 *
Derek Miller16e72292018-10-15 16:14:24 -05001538 * \param[in] key_slot The key slot to erase.
Derek Miller5b3417a2018-10-10 17:55:03 -05001539 *
1540 * \retval #PSA_SUCCESS
1541 * The slot's content, if any, has been erased.
1542 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001543typedef psa_status_t (*psa_drv_destroy_key_t)(psa_key_slot_t key);
Derek Miller5b3417a2018-10-10 17:55:03 -05001544
1545/**
Derek Miller16e72292018-10-15 16:14:24 -05001546 * \brief Export a key in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001547 *
1548 * The output of this function can be passed to psa_import_key() to
1549 * create an equivalent object.
1550 *
Derek Miller16e72292018-10-15 16:14:24 -05001551 * If a key is created with `psa_import_key()` and then exported with
Derek Miller5b3417a2018-10-10 17:55:03 -05001552 * this function, it is not guaranteed that the resulting data is
1553 * identical: the implementation may choose a different representation
1554 * of the same key if the format permits it.
1555 *
1556 * For standard key types, the output format is as follows:
1557 *
1558 * - For symmetric keys (including MAC keys), the format is the
1559 * raw bytes of the key.
1560 * - For DES, the key data consists of 8 bytes. The parity bits must be
1561 * correct.
1562 * - For Triple-DES, the format is the concatenation of the
1563 * two or three DES keys.
1564 * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format
1565 * is the non-encrypted DER representation defined by PKCS\#1 (RFC 8017)
1566 * as RSAPrivateKey.
1567 * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the format
1568 * is the DER representation defined by RFC 5280 as SubjectPublicKeyInfo.
1569 *
Derek Miller16e72292018-10-15 16:14:24 -05001570 * \param[in] key Slot whose content is to be exported. This must
Derek Miller5b3417a2018-10-10 17:55:03 -05001571 * be an occupied key slot.
1572 * \param[out] p_data Buffer where the key data is to be written.
Derek Miller16e72292018-10-15 16:14:24 -05001573 * \param[in] data_size Size of the `p_data` buffer in bytes.
Derek Miller5b3417a2018-10-10 17:55:03 -05001574 * \param[out] p_data_length On success, the number of bytes
1575 * that make up the key data.
1576 *
1577 * \retval #PSA_SUCCESS
1578 * \retval #PSA_ERROR_EMPTY_SLOT
1579 * \retval #PSA_ERROR_NOT_PERMITTED
1580 * \retval #PSA_ERROR_NOT_SUPPORTED
1581 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
1582 * \retval #PSA_ERROR_HARDWARE_FAILURE
1583 * \retval #PSA_ERROR_TAMPERING_DETECTED
1584 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001585typedef psa_status_t (*psa_drv_export_key_t)(psa_key_slot_t key,
1586 uint8_t *p_data,
1587 size_t data_size,
1588 size_t *p_data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001589
1590/**
Derek Miller16e72292018-10-15 16:14:24 -05001591 * \brief Export a public key or the public part of a key pair in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001592 *
1593 * The output of this function can be passed to psa_import_key() to
1594 * create an object that is equivalent to the public key.
1595 *
1596 * For standard key types, the output format is as follows:
1597 *
1598 * - For RSA keys (#PSA_KEY_TYPE_RSA_KEYPAIR or #PSA_KEY_TYPE_RSA_PUBLIC_KEY),
1599 * the format is the DER representation of the public key defined by RFC 5280
1600 * as SubjectPublicKeyInfo.
1601 *
Derek Miller16e72292018-10-15 16:14:24 -05001602 * \param[in] key_slot Slot whose content is to be exported. This must
Derek Miller5b3417a2018-10-10 17:55:03 -05001603 * be an occupied key slot.
1604 * \param[out] p_data Buffer where the key data is to be written.
Derek Miller16e72292018-10-15 16:14:24 -05001605 * \param[in] data_size Size of the `data` buffer in bytes.
Derek Miller5b3417a2018-10-10 17:55:03 -05001606 * \param[out] p_data_length On success, the number of bytes
1607 * that make up the key data.
1608 *
1609 * \retval #PSA_SUCCESS
1610 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001611typedef psa_status_t (*psa_drv_export_public_key_t)(psa_key_slot_t key,
1612 uint8_t *p_data,
1613 size_t data_size,
1614 size_t *p_data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001615
1616/**
Derek Miller16e72292018-10-15 16:14:24 -05001617 * \brief A struct containing all of the function pointers needed to for key
1618 * management using opaque keys
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001619 *
Derek Miller16e72292018-10-15 16:14:24 -05001620 * PSA Crypto API implementations should populate instances of the table as
1621 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001622 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001623 * If one of the functions is not implemented, it should be set to NULL.
1624 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001625struct psa_drv_key_management_t {
Derek Miller16e72292018-10-15 16:14:24 -05001626 /** Function that performs the key import operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001627 psa_drv_opaque_import_key_t *p_import;
Derek Miller16e72292018-10-15 16:14:24 -05001628 /** Function that performs the key destroy operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001629 psa_drv_destroy_key_t *p_destroy;
Derek Miller16e72292018-10-15 16:14:24 -05001630 /** Function that performs the key export operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001631 psa_drv_export_key_t *p_export;
Derek Miller16e72292018-10-15 16:14:24 -05001632 /** Function that perforsm the public key export operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001633 psa_drv_export_public_key_t *p_export_public;
Derek Miller5b3417a2018-10-10 17:55:03 -05001634};
1635
Derek Miller16e72292018-10-15 16:14:24 -05001636/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001637
Derek Miller16e72292018-10-15 16:14:24 -05001638/** \defgroup driver_derivation Key Derivation and Agreement
Derek Miller16e72292018-10-15 16:14:24 -05001639 * Key derivation is the process of generating new key material using an
1640 * existing key and additional parameters, iterating through a basic
1641 * cryptographic function, such as a hash.
1642 * Key agreement is a part of cryptographic protocols that allows two parties
1643 * to agree on the same key value, but starting from different original key
1644 * material.
Jaeden Ameroe095d602018-10-26 12:09:31 +01001645 * The flows are similar, and the PSA Crypto Driver Model uses the same functions
Derek Miller16e72292018-10-15 16:14:24 -05001646 * for both of the flows.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001647 *
Derek Miller16e72292018-10-15 16:14:24 -05001648 * There are two different final functions for the flows,
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001649 * `psa_drv_key_derivation_derive` and `psa_drv_key_derivation_export`.
1650 * `psa_drv_key_derivation_derive` is used when the key material should be placed
Derek Miller16e72292018-10-15 16:14:24 -05001651 * in a slot on the hardware and not exposed to the caller.
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001652 * `psa_drv_key_derivation_export` is used when the key material should be returned
Derek Miller16e72292018-10-15 16:14:24 -05001653 * to the PSA Cryptographic API implementation.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001654 *
Derek Miller16e72292018-10-15 16:14:24 -05001655 * Different key derivation algorithms require a different number of inputs.
1656 * Instead of having an API that takes as input variable length arrays, which
1657 * can be problemmatic to manage on embedded platforms, the inputs are passed
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001658 * to the driver via a function, `psa_drv_key_derivation_collateral`, that is
Derek Miller16e72292018-10-15 16:14:24 -05001659 * called multiple times with different `collateral_id`s. Thus, for a key
1660 * derivation algorithm that required 3 paramter inputs, the flow would look
1661 * something like:
1662 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001663 * psa_drv_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes);
1664 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_0,
1665 * p_collateral_0,
1666 * collateral_0_size);
1667 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_1,
1668 * p_collateral_1,
1669 * collateral_1_size);
1670 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_2,
1671 * p_collateral_2,
1672 * collateral_2_size);
1673 * psa_drv_key_derivation_derive();
Derek Miller16e72292018-10-15 16:14:24 -05001674 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001675 *
Derek Miller16e72292018-10-15 16:14:24 -05001676 * key agreement example:
1677 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001678 * psa_drv_key_derivation_setup(alg, source_key. dest_key_size_bytes);
1679 * psa_drv_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size);
1680 * psa_drv_key_derivation_export(p_session_key,
1681 * session_key_size,
1682 * &session_key_length);
Derek Miller16e72292018-10-15 16:14:24 -05001683 * ~~~~~~~~~~~~~
1684 */
Derek Miller765682c2018-10-22 15:27:27 -05001685/**@{*/
Derek Miller16e72292018-10-15 16:14:24 -05001686
Derek Miller765682c2018-10-22 15:27:27 -05001687/** \brief The hardware-specific key derivation context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001688 *
Derek Miller765682c2018-10-22 15:27:27 -05001689 * The contents of this structure are implementation dependent and are
1690 * therefore not described here
1691 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001692typedef struct psa_drv_key_derivation_context_s psa_drv_key_derivation_context_t;
Derek Miller16e72292018-10-15 16:14:24 -05001693
1694/** \brief Set up a key derivation operation by specifying the algorithm and
1695 * the source key sot
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001696 *
Derek Miller16e72292018-10-15 16:14:24 -05001697 * \param[in,out] p_context A hardware-specific structure containing any
1698 * context information for the implementation
1699 * \param[in] kdf_alg The algorithm to be used for the key derivation
1700 * \param[in] souce_key The key to be used as the source material for the
1701 * key derivation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001702 *
Derek Miller16e72292018-10-15 16:14:24 -05001703 * \retval PSA_SUCCESS
1704 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001705typedef psa_status_t (*psa_drv_key_derivation_setup_t)(psa_drv_key_derivation_context_t *p_context,
1706 psa_algorithm_t kdf_alg,
1707 psa_key_slot_t source_key);
Derek Miller16e72292018-10-15 16:14:24 -05001708
1709/** \brief Provide collateral (parameters) needed for a key derivation or key
1710 * agreement operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001711 *
Derek Miller16e72292018-10-15 16:14:24 -05001712 * Since many key derivation algorithms require multiple parameters, it is
1713 * expeced that this function may be called multiple times for the same
1714 * operation, each with a different algorithm-specific `collateral_id`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001715 *
Derek Miller16e72292018-10-15 16:14:24 -05001716 * \param[in,out] p_context A hardware-specific structure containing any
1717 * context information for the implementation
1718 * \param[in] collateral_id An ID for the collateral being provided
1719 * \param[in] p_collateral A buffer containing the collateral data
1720 * \param[in] collateral_size The size in bytes of the collateral
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001721 *
Derek Miller16e72292018-10-15 16:14:24 -05001722 * \retval PSA_SUCCESS
1723 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001724typedef psa_status_t (*psa_drv_key_derivation_collateral_t)(psa_drv_key_derivation_context_t *p_context,
1725 uint32_t collateral_id,
1726 const uint8_t *p_collateral,
1727 size_t collateral_size);
Derek Miller16e72292018-10-15 16:14:24 -05001728
1729/** \brief Perform the final key derivation step and place the generated key
1730 * material in a slot
1731 * \param[in,out] p_context A hardware-specific structure containing any
1732 * context information for the implementation
1733 * \param[in] dest_key The slot where the generated key material
1734 * should be placed
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001735 *
Derek Miller16e72292018-10-15 16:14:24 -05001736 * \retval PSA_SUCCESS
1737 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001738typedef psa_status_t (*psa_drv_key_derivation_derive_t)(psa_drv_key_derivation_context_t *p_context,
1739 psa_key_slot_t dest_key);
Derek Miller16e72292018-10-15 16:14:24 -05001740
1741/** \brief Perform the final step of a key agreement and place the generated
1742 * key material in a buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001743 *
Derek Miller16e72292018-10-15 16:14:24 -05001744 * \param[out] p_output Buffer in which to place the generated key
1745 * material
1746 * \param[in] output_size The size in bytes of `p_output`
1747 * \param[out] p_output_length Upon success, contains the number of bytes of
1748 * key material placed in `p_output`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001749 *
Derek Miller16e72292018-10-15 16:14:24 -05001750 * \retval PSA_SUCCESS
1751 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001752typedef psa_status_t (*psa_drv_key_derivation_export_t)(uint8_t *p_output,
1753 size_t output_size,
1754 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -05001755
1756/**
1757 * \brief A struct containing all of the function pointers needed to for key
1758 * derivation and agreement
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001759 *
Derek Miller16e72292018-10-15 16:14:24 -05001760 * PSA Crypto API implementations should populate instances of the table as
1761 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001762 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001763 * If one of the functions is not implemented, it should be set to NULL.
1764 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001765struct psa_drv_key_derivation_t {
Derek Miller16e72292018-10-15 16:14:24 -05001766 /** Function that performs the key derivation setup */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001767 psa_drv_key_derivation_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -05001768 /** Function that sets the key derivation collateral */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001769 psa_drv_key_derivation_collateral_t *p_collateral;
Derek Miller16e72292018-10-15 16:14:24 -05001770 /** Function that performs the final key derivation step */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001771 psa_drv_key_derivation_derive_t *p_derive;
Derek Miller16e72292018-10-15 16:14:24 -05001772 /** Function that perforsm the final key derivation or agreement and
1773 * exports the key */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001774 psa_drv_key_derivation_export_t *p_export;
Derek Miller5b3417a2018-10-10 17:55:03 -05001775};
1776
Derek Miller16e72292018-10-15 16:14:24 -05001777/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001778
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001779#endif // __PSA_CRYPTO_DRIVER_H__