blob: 43b3cf760bc501ab2b9004975b247423dd1dc38d [file] [log] [blame]
Derek Miller16e72292018-10-15 16:14:24 -05001/**
2 * \file psa/crypto_driver.h
3 * \brief Platform Security Architecture cryptographic driver module
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01004 *
Jaeden Ameroe095d602018-10-26 12:09:31 +01005 * This file describes the PSA Crypto Driver Model, containing functions for
6 * driver developers to implement to enable hardware to be called in a
7 * standardized way by a PSA Cryptographic API implementation. The functions
8 * comprising the driver model, which driver authors implement, are not
9 * intended to be called by application developers.
Derek Miller16e72292018-10-15 16:14:24 -050010 */
11
12/*
13 * Copyright (C) 2018, ARM Limited, All Rights Reserved
14 * SPDX-License-Identifier: Apache-2.0
15 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
Jaeden Amero41558502018-10-26 11:44:33 +010028#ifndef PSA_CRYPTO_DRIVER_H
29#define PSA_CRYPTO_DRIVER_H
Derek Miller5b3417a2018-10-10 17:55:03 -050030
31#include <stddef.h>
32#include <stdint.h>
33
Jaeden Amero9411db72018-10-26 11:59:58 +010034#ifdef __cplusplus
35extern "C" {
36#endif
37
Gilles Peskine2d59b2c2018-12-12 13:51:19 +010038/* Include type definitions (psa_status_t, psa_algorithm_t,
39 * psa_key_type_t, etc.) and macros to build and analyze values
40 * of these types. */
41#include "crypto_types.h"
42#include "crypto_values.h"
Derek Miller5b3417a2018-10-10 17:55:03 -050043
Gilles Peskine2d59b2c2018-12-12 13:51:19 +010044/** An internal designation of a key slot between the core part of the
45 * PSA Crypto implementation and the driver. The meaning of this value
46 * is driver-dependent. */
47typedef uint32_t psa_key_slot_t;
48
49/** For encrypt-decrypt functions, whether the operation is an encryption
50 * or a decryption. */
51typedef enum {
52 PSA_CRYPTO_DRIVER_DECRYPT,
53 PSA_CRYPTO_DRIVER_ENCRYPT
54} psa_encrypt_or_decrypt_t;
Derek Miller6f960ab2018-10-23 15:58:06 -050055
Derek Miller5b3417a2018-10-10 17:55:03 -050056/** \defgroup opaque_mac Opaque Message Authentication Code
Derek Miller765682c2018-10-22 15:27:27 -050057 * Generation and authentication of Message Authentication Codes (MACs) using
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010058 * opaque keys can be done either as a single function call (via the
Derek D. Millerf015fec2018-10-26 10:56:11 -050059 * `psa_drv_mac_opaque_generate_t` or `psa_drv_mac_opaque_verify_t` functions), or in
Derek Miller765682c2018-10-22 15:27:27 -050060 * parts using the following sequence:
Derek D. Millerf015fec2018-10-26 10:56:11 -050061 * - `psa_drv_mac_opaque_setup_t`
62 * - `psa_drv_mac_opaque_update_t`
63 * - `psa_drv_mac_opaque_update_t`
Derek Miller765682c2018-10-22 15:27:27 -050064 * - ...
Derek D. Millerf015fec2018-10-26 10:56:11 -050065 * - `psa_drv_mac_opaque_finish_t` or `psa_drv_mac_opaque_finish_verify_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010066 *
67 * If a previously started Opaque MAC operation needs to be terminated, it
Derek D. Millerf015fec2018-10-26 10:56:11 -050068 * should be done so by the `psa_drv_mac_opaque_abort_t`. Failure to do so may
Derek Miller765682c2018-10-22 15:27:27 -050069 * result in allocated resources not being freed or in other undefined
70 * behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -050071 */
Derek Miller16e72292018-10-15 16:14:24 -050072/**@{*/
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010073/** \brief A function that starts a MAC operation for a PSA Crypto Driver
Derek Miller16e72292018-10-15 16:14:24 -050074 * implementation using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010075 *
76 * \param[in,out] p_context A structure that will contain the
Derek Miller16e72292018-10-15 16:14:24 -050077 * hardware-specific MAC context
78 * \param[in] key_slot The slot of the key to be used for the
79 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010080 * \param[in] algorithm The algorithm to be used to underly the MAC
Derek Miller16e72292018-10-15 16:14:24 -050081 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010082 *
Derek Miller5b3417a2018-10-10 17:55:03 -050083 * \retval PSA_SUCCESS
84 * Success.
85 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +010086typedef psa_status_t (*psa_drv_mac_opaque_setup_t)(void *p_context,
87 psa_key_slot_t key_slot,
88 psa_algorithm_t algorithm);
Derek Miller5b3417a2018-10-10 17:55:03 -050089
Derek Miller16e72292018-10-15 16:14:24 -050090/** \brief A function that continues a previously started MAC operation using
91 * an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +010092 *
Derek Miller16e72292018-10-15 16:14:24 -050093 * \param[in,out] p_context A hardware-specific structure for the
94 * previously-established MAC operation to be
95 * continued
96 * \param[in] p_input A buffer containing the message to be appended
97 * to the MAC operation
98 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -050099 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100100typedef psa_status_t (*psa_drv_mac_opaque_update_t)(void *p_context,
101 const uint8_t *p_input,
102 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500103
Derek Miller16e72292018-10-15 16:14:24 -0500104/** \brief a function that completes a previously started MAC operation by
105 * returning the resulting MAC using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100106 *
107 * \param[in,out] p_context A hardware-specific structure for the
108 * previously started MAC operation to be
Derek Miller16e72292018-10-15 16:14:24 -0500109 * finished
110 * \param[out] p_mac A buffer where the generated MAC will be
111 * placed
112 * \param[in] mac_size The size in bytes of the buffer that has been
113 * allocated for the `output` buffer
114 * \param[out] p_mac_length After completion, will contain the number of
Derek Millerf3d0a562018-10-18 16:41:08 -0500115 * bytes placed in the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100116 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500117 * \retval PSA_SUCCESS
118 * Success.
119 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100120typedef psa_status_t (*psa_drv_mac_opaque_finish_t)(void *p_context,
121 uint8_t *p_mac,
122 size_t mac_size,
123 size_t *p_mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500124
Derek Miller16e72292018-10-15 16:14:24 -0500125/** \brief A function that completes a previously started MAC operation by
126 * comparing the resulting MAC against a known value using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100127 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500128 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500129 * started MAC operation to be fiinished
130 * \param[in] p_mac The MAC value against which the resulting MAC will
131 * be compared against
132 * \param[in] mac_length The size in bytes of the value stored in `p_mac`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100133 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500134 * \retval PSA_SUCCESS
Derek Miller16e72292018-10-15 16:14:24 -0500135 * The operation completed successfully and the MACs matched each
136 * other
Derek Miller5b3417a2018-10-10 17:55:03 -0500137 * \retval PSA_ERROR_INVALID_SIGNATURE
Derek Miller16e72292018-10-15 16:14:24 -0500138 * The operation completed successfully, but the calculated MAC did
139 * not match the provided MAC
Derek Miller5b3417a2018-10-10 17:55:03 -0500140 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100141typedef psa_status_t (*psa_drv_mac_opaque_finish_verify_t)(void *p_context,
142 const uint8_t *p_mac,
143 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500144
Derek Miller16e72292018-10-15 16:14:24 -0500145/** \brief A function that aborts a previous started opaque-key MAC operation
146
Derek Millerf3d0a562018-10-18 16:41:08 -0500147 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500148 * started MAC operation to be aborted
149 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100150typedef psa_status_t (*psa_drv_mac_opaque_abort_t)(void *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500151
Derek Miller81133a62018-10-23 14:55:32 -0500152/** \brief A function that performs a MAC operation in one command and returns
Derek Miller16e72292018-10-15 16:14:24 -0500153 * the calculated MAC using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100154 *
Derek Miller16e72292018-10-15 16:14:24 -0500155 * \param[in] p_input A buffer containing the message to be MACed
Derek Millerf3d0a562018-10-18 16:41:08 -0500156 * \param[in] input_length The size in bytes of `p_input`
Derek Miller16e72292018-10-15 16:14:24 -0500157 * \param[in] key_slot The slot of the key to be used
Derek Millerf3d0a562018-10-18 16:41:08 -0500158 * \param[in] alg The algorithm to be used to underlie the MAC
Derek Miller16e72292018-10-15 16:14:24 -0500159 * operation
160 * \param[out] p_mac A buffer where the generated MAC will be
161 * placed
Derek Miller81133a62018-10-23 14:55:32 -0500162 * \param[in] mac_size The size in bytes of the `p_mac` buffer
Derek Miller16e72292018-10-15 16:14:24 -0500163 * \param[out] p_mac_length After completion, will contain the number of
164 * bytes placed in the `output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100165 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500166 * \retval PSA_SUCCESS
167 * Success.
168 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100169typedef psa_status_t (*psa_drv_mac_opaque_generate_t)(const uint8_t *p_input,
170 size_t input_length,
171 psa_key_slot_t key_slot,
172 psa_algorithm_t alg,
173 uint8_t *p_mac,
174 size_t mac_size,
175 size_t *p_mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500176
Derek Miller16e72292018-10-15 16:14:24 -0500177/** \brief A function that performs an MAC operation in one command and
178 * compare the resulting MAC against a known value using an opaque key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100179 *
Derek Miller16e72292018-10-15 16:14:24 -0500180 * \param[in] p_input A buffer containing the message to be MACed
181 * \param[in] input_length The size in bytes of `input`
182 * \param[in] key_slot The slot of the key to be used
183 * \param[in] alg The algorithm to be used to underlie the MAC
184 * operation
185 * \param[in] p_mac The MAC value against which the resulting MAC will
186 * be compared against
187 * \param[in] mac_length The size in bytes of `mac`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100188 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500189 * \retval PSA_SUCCESS
Derek Miller16e72292018-10-15 16:14:24 -0500190 * The operation completed successfully and the MACs matched each
191 * other
Derek Miller5b3417a2018-10-10 17:55:03 -0500192 * \retval PSA_ERROR_INVALID_SIGNATURE
Derek Miller16e72292018-10-15 16:14:24 -0500193 * The operation completed successfully, but the calculated MAC did
194 * not match the provided MAC
Derek Miller5b3417a2018-10-10 17:55:03 -0500195 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100196typedef psa_status_t (*psa_drv_mac_opaque_verify_t)(const uint8_t *p_input,
197 size_t input_length,
198 psa_key_slot_t key_slot,
199 psa_algorithm_t alg,
200 const uint8_t *p_mac,
201 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500202
Derek Miller16e72292018-10-15 16:14:24 -0500203/** \brief A struct containing all of the function pointers needed to
204 * implement MAC operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100205 *
Derek Miller16e72292018-10-15 16:14:24 -0500206 * PSA Crypto API implementations should populate the table as appropriate
207 * upon startup.
Derek Miller5b3417a2018-10-10 17:55:03 -0500208 *
Derek Miller765682c2018-10-22 15:27:27 -0500209 * If one of the functions is not implemented (such as
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100210 * `psa_drv_mac_opaque_generate_t`), it should be set to NULL.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100211 *
Derek Miller16e72292018-10-15 16:14:24 -0500212 * Driver implementers should ensure that they implement all of the functions
213 * that make sense for their hardware, and that they provide a full solution
214 * (for example, if they support `p_setup`, they should also support
215 * `p_update` and at least one of `p_finish` or `p_finish_verify`).
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100216 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500217 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +0100218typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -0500219 /**The size in bytes of the hardware-specific Opaque-MAC Context structure
220 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100221 size_t context_size;
Derek Miller16e72292018-10-15 16:14:24 -0500222 /** Function that performs the setup operation
223 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100224 psa_drv_mac_opaque_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -0500225 /** Function that performs the update operation
226 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100227 psa_drv_mac_opaque_update_t *p_update;
Derek Miller16e72292018-10-15 16:14:24 -0500228 /** Function that completes the operation
229 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100230 psa_drv_mac_opaque_finish_t *p_finish;
Derek Miller16e72292018-10-15 16:14:24 -0500231 /** Function that completed a MAC operation with a verify check
232 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100233 psa_drv_mac_opaque_finish_verify_t *p_finish_verify;
Derek Miller16e72292018-10-15 16:14:24 -0500234 /** Function that aborts a previoustly started operation
235 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100236 psa_drv_mac_opaque_abort_t *p_abort;
Derek Miller16e72292018-10-15 16:14:24 -0500237 /** Function that performs the MAC operation in one call
238 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100239 psa_drv_mac_opaque_generate_t *p_mac;
Derek Miller16e72292018-10-15 16:14:24 -0500240 /** Function that performs the MAC and verify operation in one call
241 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100242 psa_drv_mac_opaque_verify_t *p_mac_verify;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +0100243} psa_drv_mac_opaque_t;
Derek Miller16e72292018-10-15 16:14:24 -0500244/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500245
246/** \defgroup transparent_mac Transparent Message Authentication Code
Derek Miller765682c2018-10-22 15:27:27 -0500247 * Generation and authentication of Message Authentication Codes (MACs) using
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100248 * transparent keys can be done either as a single function call (via the
Derek D. Millerf015fec2018-10-26 10:56:11 -0500249 * `psa_drv_mac_transparent_generate_t` or `psa_drv_mac_transparent_verify_t`
Derek Miller765682c2018-10-22 15:27:27 -0500250 * functions), or in parts using the following sequence:
Derek D. Millerf015fec2018-10-26 10:56:11 -0500251 * - `psa_drv_mac_transparent_setup_t`
252 * - `psa_drv_mac_transparent_update_t`
253 * - `psa_drv_mac_transparent_update_t`
Derek Miller765682c2018-10-22 15:27:27 -0500254 * - ...
Derek D. Millerf015fec2018-10-26 10:56:11 -0500255 * - `psa_drv_mac_transparent_finish_t` or `psa_drv_mac_transparent_finish_verify_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100256 *
257 * If a previously started Transparent MAC operation needs to be terminated, it
Derek D. Millerf015fec2018-10-26 10:56:11 -0500258 * should be done so by the `psa_drv_mac_transparent_abort_t`. Failure to do so may
Derek Miller765682c2018-10-22 15:27:27 -0500259 * result in allocated resources not being freed or in other undefined
260 * behavior.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100261 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500262 */
Derek Miller16e72292018-10-15 16:14:24 -0500263/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500264
265/** \brief The hardware-specific transparent-key MAC context structure
Derek Miller765682c2018-10-22 15:27:27 -0500266 *
Derek Miller16e72292018-10-15 16:14:24 -0500267 * The contents of this structure are implementation dependent and are
268 * therefore not described here.
Derek Miller5b3417a2018-10-10 17:55:03 -0500269 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100270typedef struct psa_drv_mac_transparent_context_s psa_drv_mac_transparent_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500271
Derek Miller16e72292018-10-15 16:14:24 -0500272/** \brief The function prototype for the setup operation of a
273 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100274 *
Derek Miller16e72292018-10-15 16:14:24 -0500275 * Functions that implement the prototype should be named in the following
276 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500277 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100278 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_setup
Derek Miller5b3417a2018-10-10 17:55:03 -0500279 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500280 * Where `ALGO` is the name of the underlying primitive, and `MAC_VARIANT`
281 * is the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100282 *
283 * \param[in,out] p_context A structure that will contain the
Derek Miller16e72292018-10-15 16:14:24 -0500284 * hardware-specific MAC context
285 * \param[in] p_key A buffer containing the cleartext key material
286 * to be used in the operation
287 * \param[in] key_length The size in bytes of the key material
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100288 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500289 * \retval PSA_SUCCESS
290 * Success.
291 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100292typedef psa_status_t (*psa_drv_mac_transparent_setup_t)(psa_drv_mac_transparent_context_t *p_context,
293 const uint8_t *p_key,
294 size_t key_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500295
Derek Miller16e72292018-10-15 16:14:24 -0500296/** \brief The function prototype for the update operation of a
297 * transparent-key MAC operation
Derek Miller5b3417a2018-10-10 17:55:03 -0500298 *
Derek Miller16e72292018-10-15 16:14:24 -0500299 * Functions that implement the prototype should be named in the following
300 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500301 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100302 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_update
Derek Miller5b3417a2018-10-10 17:55:03 -0500303 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500304 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT`
305 * is the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100306 *
Derek Miller16e72292018-10-15 16:14:24 -0500307 * \param[in,out] p_context A hardware-specific structure for the
308 * previously-established MAC operation to be
309 * continued
310 * \param[in] p_input A buffer containing the message to be appended
311 * to the MAC operation
312 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -0500313 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100314typedef psa_status_t (*psa_drv_mac_transparent_update_t)(psa_drv_mac_transparent_context_t *p_context,
315 const uint8_t *p_input,
316 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500317
Derek Miller16e72292018-10-15 16:14:24 -0500318/** \brief The function prototype for the finish operation of a
319 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100320 *
Derek Miller16e72292018-10-15 16:14:24 -0500321 * Functions that implement the prototype should be named in the following
322 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500323 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100324 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish
Derek Miller5b3417a2018-10-10 17:55:03 -0500325 * ~~~~~~~~~~~~~
Derek Miller16e72292018-10-15 16:14:24 -0500326 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
327 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100328 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500329 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500330 * previously started MAC operation to be
331 * finished
332 * \param[out] p_mac A buffer where the generated MAC will be placed
333 * \param[in] mac_length The size in bytes of the buffer that has been
334 * allocated for the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100335 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500336 * \retval PSA_SUCCESS
337 * Success.
338 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100339typedef psa_status_t (*psa_drv_mac_transparent_finish_t)(psa_drv_mac_transparent_context_t *p_context,
340 uint8_t *p_mac,
341 size_t mac_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500342
Derek Miller16e72292018-10-15 16:14:24 -0500343/** \brief The function prototype for the finish and verify operation of a
344 * transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100345 *
Derek Miller16e72292018-10-15 16:14:24 -0500346 * Functions that implement the prototype should be named in the following
347 * convention:
348 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100349 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish_verify
Derek Miller16e72292018-10-15 16:14:24 -0500350 * ~~~~~~~~~~~~~
351 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
352 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100353 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500354 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500355 * previously started MAC operation to be
Derek Millerf3d0a562018-10-18 16:41:08 -0500356 * verified and finished
Derek Miller16e72292018-10-15 16:14:24 -0500357 * \param[in] p_mac A buffer containing the MAC that will be used
358 * for verification
359 * \param[in] mac_length The size in bytes of the data in the `p_mac`
360 * buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100361 *
Derek Miller16e72292018-10-15 16:14:24 -0500362 * \retval PSA_SUCCESS
363 * The operation completed successfully and the comparison matched
Derek Miller5b3417a2018-10-10 17:55:03 -0500364 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100365typedef psa_status_t (*psa_drv_mac_transparent_finish_verify_t)(psa_drv_mac_transparent_context_t *p_context,
366 const uint8_t *p_mac,
367 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500368
369/** \brief The function prototype for the abort operation for a previously
370 * started transparent-key MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100371 *
Derek Miller16e72292018-10-15 16:14:24 -0500372 * Functions that implement the prototype should be named in the following
373 * convention:
374 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100375 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_abort
Derek Miller16e72292018-10-15 16:14:24 -0500376 * ~~~~~~~~~~~~~
377 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
378 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100379 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500380 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500381 * previously started MAC operation to be
Derek Millerf3d0a562018-10-18 16:41:08 -0500382 * aborted
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100383 *
Derek Miller16e72292018-10-15 16:14:24 -0500384 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100385typedef psa_status_t (*psa_drv_mac_transparent_abort_t)(psa_drv_mac_transparent_context_t *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500386
387/** \brief The function prototype for a one-shot operation of a transparent-key
388 * MAC operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100389 *
Derek Miller16e72292018-10-15 16:14:24 -0500390 * Functions that implement the prototype should be named in the following
391 * convention:
392 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100393 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>
Derek Miller16e72292018-10-15 16:14:24 -0500394 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100395 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
Derek Miller16e72292018-10-15 16:14:24 -0500396 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100397 *
Derek Miller16e72292018-10-15 16:14:24 -0500398 * \param[in] p_input A buffer containing the data to be MACed
399 * \param[in] input_length The length in bytes of the `p_input` data
400 * \param[in] p_key A buffer containing the key material to be used
401 * for the MAC operation
402 * \param[in] key_length The length in bytes of the `p_key` data
403 * \param[in] alg The algorithm to be performed
404 * \param[out] p_mac The buffer where the resulting MAC will be placed
405 * upon success
406 * \param[in] mac_length The length in bytes of the `p_mac` buffer
407 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100408typedef psa_status_t (*psa_drv_mac_transparent_t)(const uint8_t *p_input,
409 size_t input_length,
410 const uint8_t *p_key,
411 size_t key_length,
412 psa_algorithm_t alg,
413 uint8_t *p_mac,
414 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500415
416/** \brief The function prototype for a one-shot operation of a transparent-key
417 * MAC Verify operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100418 *
Derek Miller16e72292018-10-15 16:14:24 -0500419 * Functions that implement the prototype should be named in the following
420 * convention:
421 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100422 * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_verify
Derek Miller16e72292018-10-15 16:14:24 -0500423 * ~~~~~~~~~~~~~
424 * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is
425 * the specific variant of a MAC operation (such as HMAC or CMAC)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100426 *
Derek Miller16e72292018-10-15 16:14:24 -0500427 * \param[in] p_input A buffer containing the data to be MACed
428 * \param[in] input_length The length in bytes of the `p_input` data
429 * \param[in] p_key A buffer containing the key material to be used
430 * for the MAC operation
431 * \param[in] key_length The length in bytes of the `p_key` data
432 * \param[in] alg The algorithm to be performed
433 * \param[in] p_mac The MAC data to be compared
434 * \param[in] mac_length The length in bytes of the `p_mac` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100435 *
Derek Miller16e72292018-10-15 16:14:24 -0500436 * \retval PSA_SUCCESS
437 * The operation completed successfully and the comparison matched
438 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100439typedef psa_status_t (*psa_drv_mac_transparent_verify_t)(const uint8_t *p_input,
440 size_t input_length,
441 const uint8_t *p_key,
442 size_t key_length,
443 psa_algorithm_t alg,
444 const uint8_t *p_mac,
445 size_t mac_length);
Derek Miller16e72292018-10-15 16:14:24 -0500446/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500447
448/** \defgroup opaque_cipher Opaque Symmetric Ciphers
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100449 *
Derek Miller765682c2018-10-22 15:27:27 -0500450 * Encryption and Decryption using opaque keys in block modes other than ECB
451 * must be done in multiple parts, using the following flow:
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100452 * - `psa_drv_cipher_opaque_setup_t`
453 * - `psa_drv_cipher_opaque_set_iv_t` (optional depending upon block mode)
454 * - `psa_drv_cipher_opaque_update_t`
Derek Miller765682c2018-10-22 15:27:27 -0500455 * - ...
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100456 * - `psa_drv_cipher_opaque_finish_t`
Derek Miller765682c2018-10-22 15:27:27 -0500457
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100458 * If a previously started Opaque Cipher operation needs to be terminated, it
Derek D. Millerf015fec2018-10-26 10:56:11 -0500459 * should be done so by the `psa_drv_cipher_opaque_abort_t`. Failure to do so may
Derek Miller765682c2018-10-22 15:27:27 -0500460 * result in allocated resources not being freed or in other undefined
461 * behavior.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100462 *
Derek Miller765682c2018-10-22 15:27:27 -0500463 * In situations where a PSA Cryptographic API implementation is using a block
464 * mode not-supported by the underlying hardware or driver, it can construct
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100465 * the block mode itself, while calling the `psa_drv_cipher_opaque_ecb_t` function
Derek Miller765682c2018-10-22 15:27:27 -0500466 * pointer for the cipher operations.
Derek Miller5b3417a2018-10-10 17:55:03 -0500467 */
Derek Miller16e72292018-10-15 16:14:24 -0500468/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500469
Derek Miller16e72292018-10-15 16:14:24 -0500470/** \brief A function pointer that provides the cipher setup function for
471 * opaque-key operations
Derek Miller5b3417a2018-10-10 17:55:03 -0500472 *
Derek Miller16e72292018-10-15 16:14:24 -0500473 * \param[in,out] p_context A structure that will contain the
474 * hardware-specific cipher context.
475 * \param[in] key_slot The slot of the key to be used for the
476 * operation
477 * \param[in] algorithm The algorithm to be used in the cipher
478 * operation
479 * \param[in] direction Indicates whether the operation is an encrypt
480 * or decrypt
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100481 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500482 * \retval PSA_SUCCESS
483 * \retval PSA_ERROR_NOT_SUPPORTED
484 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100485typedef psa_status_t (*psa_drv_cipher_opaque_setup_t)(void *p_context,
486 psa_key_slot_t key_slot,
487 psa_algorithm_t algorithm,
Jaeden Amero7632f622018-10-26 11:26:45 +0100488 psa_encrypt_or_decrypt_t direction);
Derek Miller16e72292018-10-15 16:14:24 -0500489
490/** \brief A function pointer that sets the initialization vector (if
491 * necessary) for an opaque cipher operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100492 *
Derek Miller81133a62018-10-23 14:55:32 -0500493 * Rationale: The `psa_cipher_*` function in the PSA Cryptographic API has two
Derek Miller765682c2018-10-22 15:27:27 -0500494 * IV functions: one to set the IV, and one to generate it internally. The
Jaeden Ameroe095d602018-10-26 12:09:31 +0100495 * generate function is not necessary for the drivers to implement as the PSA
496 * Crypto implementation can do the generation using its RNG features.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100497 *
Derek Miller16e72292018-10-15 16:14:24 -0500498 * \param[in,out] p_context A structure that contains the previously set up
499 * hardware-specific cipher context
500 * \param[in] p_iv A buffer containing the initialization vector
501 * \param[in] iv_length The size (in bytes) of the `p_iv` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100502 *
Derek Miller16e72292018-10-15 16:14:24 -0500503 * \retval PSA_SUCCESS
504 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100505typedef psa_status_t (*psa_drv_cipher_opaque_set_iv_t)(void *p_context,
506 const uint8_t *p_iv,
507 size_t iv_length);
Derek Miller16e72292018-10-15 16:14:24 -0500508
509/** \brief A function that continues a previously started opaque-key cipher
510 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100511 *
Derek Miller16e72292018-10-15 16:14:24 -0500512 * \param[in,out] p_context A hardware-specific structure for the
513 * previously started cipher operation
514 * \param[in] p_input A buffer containing the data to be
515 * encrypted/decrypted
516 * \param[in] input_size The size in bytes of the buffer pointed to
517 * by `p_input`
518 * \param[out] p_output The caller-allocated buffer where the
519 * output will be placed
520 * \param[in] output_size The allocated size in bytes of the
521 * `p_output` buffer
522 * \param[out] p_output_length After completion, will contain the number
523 * of bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100524 *
Derek Miller16e72292018-10-15 16:14:24 -0500525 * \retval PSA_SUCCESS
526 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100527typedef psa_status_t (*psa_drv_cipher_opaque_update_t)(void *p_context,
528 const uint8_t *p_input,
529 size_t input_size,
530 uint8_t *p_output,
531 size_t output_size,
532 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -0500533
534/** \brief A function that completes a previously started opaque-key cipher
535 * operation
536 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500537 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500538 * previously started cipher operation
Derek Millerf3d0a562018-10-18 16:41:08 -0500539 * \param[out] p_output The caller-allocated buffer where the output
Derek Miller16e72292018-10-15 16:14:24 -0500540 * will be placed
541 * \param[in] output_size The allocated size in bytes of the `p_output`
542 * buffer
543 * \param[out] p_output_length After completion, will contain the number of
544 * bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100545 *
Derek Miller16e72292018-10-15 16:14:24 -0500546 * \retval PSA_SUCCESS
547 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100548typedef psa_status_t (*psa_drv_cipher_opaque_finish_t)(void *p_context,
549 uint8_t *p_output,
550 size_t output_size,
551 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -0500552
553/** \brief A function that aborts a previously started opaque-key cipher
554 * operation
555 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500556 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500557 * previously started cipher operation
558 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100559typedef psa_status_t (*psa_drv_cipher_opaque_abort_t)(void *p_context);
Derek Miller16e72292018-10-15 16:14:24 -0500560
561/** \brief A function that performs the ECB block mode for opaque-key cipher
562 * operations
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100563 *
Derek Miller16e72292018-10-15 16:14:24 -0500564 * Note: this function should only be used with implementations that do not
565 * provide a needed higher-level operation.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100566 *
Derek Miller16e72292018-10-15 16:14:24 -0500567 * \param[in] key_slot The slot of the key to be used for the operation
568 * \param[in] algorithm The algorithm to be used in the cipher operation
569 * \param[in] direction Indicates whether the operation is an encrypt or
570 * decrypt
571 * \param[in] p_input A buffer containing the data to be
572 * encrypted/decrypted
573 * \param[in] input_size The size in bytes of the buffer pointed to by
574 * `p_input`
Derek Millerf3d0a562018-10-18 16:41:08 -0500575 * \param[out] p_output The caller-allocated buffer where the output will
Derek Miller16e72292018-10-15 16:14:24 -0500576 * be placed
577 * \param[in] output_size The allocated size in bytes of the `p_output`
578 * buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100579 *
Derek Miller16e72292018-10-15 16:14:24 -0500580 * \retval PSA_SUCCESS
581 * \retval PSA_ERROR_NOT_SUPPORTED
582 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100583typedef psa_status_t (*psa_drv_cipher_opaque_ecb_t)(psa_key_slot_t key_slot,
584 psa_algorithm_t algorithm,
Jaeden Amero7632f622018-10-26 11:26:45 +0100585 psa_encrypt_or_decrypt_t direction,
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100586 const uint8_t *p_input,
587 size_t input_size,
588 uint8_t *p_output,
589 size_t output_size);
Derek Miller5b3417a2018-10-10 17:55:03 -0500590
591/**
Derek Miller16e72292018-10-15 16:14:24 -0500592 * \brief A struct containing all of the function pointers needed to implement
593 * cipher operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100594 *
Derek Miller16e72292018-10-15 16:14:24 -0500595 * PSA Crypto API implementations should populate instances of the table as
596 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100597 *
Derek Miller16e72292018-10-15 16:14:24 -0500598 * If one of the functions is not implemented (such as
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100599 * `psa_drv_cipher_opaque_ecb_t`), it should be set to NULL.
Derek Miller5b3417a2018-10-10 17:55:03 -0500600 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +0100601typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -0500602 /** The size in bytes of the hardware-specific Opaque Cipher context
603 * structure
604 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100605 size_t size;
Derek Miller16e72292018-10-15 16:14:24 -0500606 /** Function that performs the setup operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100607 psa_drv_cipher_opaque_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -0500608 /** Function that sets the IV (if necessary) */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100609 psa_drv_cipher_opaque_set_iv_t *p_set_iv;
Derek Miller16e72292018-10-15 16:14:24 -0500610 /** Function that performs the update operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100611 psa_drv_cipher_opaque_update_t *p_update;
Derek Miller16e72292018-10-15 16:14:24 -0500612 /** Function that completes the operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100613 psa_drv_cipher_opaque_finish_t *p_finish;
Derek Miller16e72292018-10-15 16:14:24 -0500614 /** Function that aborts the operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100615 psa_drv_cipher_opaque_abort_t *p_abort;
Derek Miller16e72292018-10-15 16:14:24 -0500616 /** Function that performs ECB mode for the cipher
617 * (Danger: ECB mode should not be used directly by clients of the PSA
618 * Crypto Client API)
619 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100620 psa_drv_cipher_opaque_ecb_t *p_ecb;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +0100621} psa_drv_cipher_opaque_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500622
Derek Miller16e72292018-10-15 16:14:24 -0500623/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500624
625/** \defgroup transparent_cipher Transparent Block Cipher
Derek Miller765682c2018-10-22 15:27:27 -0500626 * Encryption and Decryption using transparent keys in block modes other than
627 * ECB must be done in multiple parts, using the following flow:
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100628 * - `psa_drv_cipher_transparent_setup_t`
629 * - `psa_drv_cipher_transparent_set_iv_t` (optional depending upon block mode)
630 * - `psa_drv_cipher_transparent_update_t`
Derek Miller765682c2018-10-22 15:27:27 -0500631 * - ...
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100632 * - `psa_drv_cipher_transparent_finish_t`
Derek Miller765682c2018-10-22 15:27:27 -0500633
634 * If a previously started Transparent Cipher operation needs to be terminated,
Derek D. Millerf015fec2018-10-26 10:56:11 -0500635 * it should be done so by the `psa_drv_cipher_transparent_abort_t`. Failure to do
Derek Miller765682c2018-10-22 15:27:27 -0500636 * so may result in allocated resources not being freed or in other undefined
637 * behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -0500638 */
Derek Miller16e72292018-10-15 16:14:24 -0500639/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500640
641/** \brief The hardware-specific transparent-key Cipher context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100642 *
Derek Miller765682c2018-10-22 15:27:27 -0500643 * The contents of this structure are implementation dependent and are
Derek Miller16e72292018-10-15 16:14:24 -0500644 * therefore not described here.
Derek Miller5b3417a2018-10-10 17:55:03 -0500645 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100646typedef struct psa_drv_cipher_transparent_context_s psa_drv_cipher_transparent_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500647
Derek Miller16e72292018-10-15 16:14:24 -0500648/** \brief The function prototype for the setup operation of transparent-key
649 * block cipher operations.
650 * Functions that implement the prototype should be named in the following
651 * conventions:
Derek Miller5b3417a2018-10-10 17:55:03 -0500652 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100653 * psa_drv_cipher_transparent_setup_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500654 * ~~~~~~~~~~~~~
655 * Where
656 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
657 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Derek Miller16e72292018-10-15 16:14:24 -0500658 * or for stream ciphers:
659 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100660 * psa_drv_cipher_transparent_setup_<CIPHER_NAME>
Derek Miller16e72292018-10-15 16:14:24 -0500661 * ~~~~~~~~~~~~~
662 * Where `CIPHER_NAME` is the name of a stream cipher (i.e. RC4)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100663 *
Derek Miller16e72292018-10-15 16:14:24 -0500664 * \param[in,out] p_context A structure that will contain the
665 * hardware-specific cipher context
666 * \param[in] direction Indicates if the operation is an encrypt or a
667 * decrypt
668 * \param[in] p_key_data A buffer containing the cleartext key material
669 * to be used in the operation
670 * \param[in] key_data_size The size in bytes of the key material
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100671 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500672 * \retval PSA_SUCCESS
673 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100674typedef psa_status_t (*psa_drv_cipher_transparent_setup_t)(psa_drv_cipher_transparent_context_t *p_context,
Jaeden Amero7632f622018-10-26 11:26:45 +0100675 psa_encrypt_or_decrypt_t direction,
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100676 const uint8_t *p_key_data,
677 size_t key_data_size);
Derek Miller5b3417a2018-10-10 17:55:03 -0500678
Derek Miller16e72292018-10-15 16:14:24 -0500679/** \brief The function prototype for the set initialization vector operation
680 * of transparent-key block cipher operations
681 * Functions that implement the prototype should be named in the following
682 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500683 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100684 * psa_drv_cipher_transparent_set_iv_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500685 * ~~~~~~~~~~~~~
686 * Where
687 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
688 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100689 *
Derek Miller16e72292018-10-15 16:14:24 -0500690 * \param[in,out] p_context A structure that contains the previously setup
691 * hardware-specific cipher context
692 * \param[in] p_iv A buffer containing the initialization vecotr
693 * \param[in] iv_length The size in bytes of the contents of `p_iv`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100694 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500695 * \retval PSA_SUCCESS
Jaeden Amero0a09f772018-10-26 11:42:32 +0100696 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100697typedef psa_status_t (*psa_drv_cipher_transparent_set_iv_t)(psa_drv_cipher_transparent_context_t *p_context,
698 const uint8_t *p_iv,
699 size_t iv_length);
Derek Miller16e72292018-10-15 16:14:24 -0500700
701/** \brief The function prototype for the update operation of transparent-key
702 * block cipher operations.
Derek Miller5b3417a2018-10-10 17:55:03 -0500703 *
Derek Miller16e72292018-10-15 16:14:24 -0500704 * Functions that implement the prototype should be named in the following
705 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500706 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100707 * psa_drv_cipher_transparent_update_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500708 * ~~~~~~~~~~~~~
709 * Where
710 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
711 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100712 *
Derek Miller16e72292018-10-15 16:14:24 -0500713 * \param[in,out] p_context A hardware-specific structure for the
714 * previously started cipher operation
715 * \param[in] p_input A buffer containing the data to be
716 * encrypted or decrypted
717 * \param[in] input_size The size in bytes of the `p_input` buffer
718 * \param[out] p_output A caller-allocated buffer where the
719 * generated output will be placed
720 * \param[in] output_size The size in bytes of the `p_output` buffer
721 * \param[out] p_output_length After completion, will contain the number
722 * of bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100723 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500724 * \retval PSA_SUCCESS
725 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100726typedef psa_status_t (*psa_drv_cipher_transparent_update_t)(psa_drv_cipher_transparent_context_t *p_context,
727 const uint8_t *p_input,
728 size_t input_size,
729 uint8_t *p_output,
730 size_t output_size,
731 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500732
Derek Miller16e72292018-10-15 16:14:24 -0500733/** \brief The function prototype for the finish operation of transparent-key
734 * block cipher operations.
Jaeden Amero0a09f772018-10-26 11:42:32 +0100735 *
Derek Miller16e72292018-10-15 16:14:24 -0500736 * Functions that implement the prototype should be named in the following
737 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500738 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100739 * psa_drv_cipher_transparent_finish_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500740 * ~~~~~~~~~~~~~
741 * Where
742 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
743 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Derek Miller16e72292018-10-15 16:14:24 -0500744 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500745 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500746 * previously started cipher operation
747 * \param[out] p_output A caller-allocated buffer where the generated
748 * output will be placed
749 * \param[in] output_size The size in bytes of the `p_output` buffer
750 * \param[out] p_output_length After completion, will contain the number of
751 * bytes placed in the `p_output` buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100752 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500753 * \retval PSA_SUCCESS
754 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100755typedef psa_status_t (*psa_drv_cipher_transparent_finish_t)(psa_drv_cipher_transparent_context_t *p_context,
756 uint8_t *p_output,
757 size_t output_size,
758 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500759
Derek Miller16e72292018-10-15 16:14:24 -0500760/** \brief The function prototype for the abort operation of transparent-key
761 * block cipher operations.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100762 *
Derek Miller16e72292018-10-15 16:14:24 -0500763 * Functions that implement the following prototype should be named in the
764 * following convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500765 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100766 * psa_drv_cipher_transparent_abort_<CIPHER_NAME>_<MODE>
Derek Miller5b3417a2018-10-10 17:55:03 -0500767 * ~~~~~~~~~~~~~
768 * Where
769 * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES)
770 * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR)
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100771 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500772 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500773 * previously started cipher operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100774 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500775 * \retval PSA_SUCCESS
776 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100777typedef psa_status_t (*psa_drv_cipher_transparent_abort_t)(psa_drv_cipher_transparent_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500778
Derek Miller16e72292018-10-15 16:14:24 -0500779/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500780
Derek Miller16e72292018-10-15 16:14:24 -0500781/** \defgroup driver_digest Message Digests
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100782 *
Derek Miller765682c2018-10-22 15:27:27 -0500783 * Generation and authentication of Message Digests (aka hashes) must be done
784 * in parts using the following sequence:
Derek D. Millerf015fec2018-10-26 10:56:11 -0500785 * - `psa_drv_hash_setup_t`
786 * - `psa_drv_hash_update_t`
Derek Miller765682c2018-10-22 15:27:27 -0500787 * - ...
Derek D. Millerf015fec2018-10-26 10:56:11 -0500788 * - `psa_drv_hash_finish_t`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100789 *
Derek Miller765682c2018-10-22 15:27:27 -0500790 * If a previously started Message Digest operation needs to be terminated
Derek D. Millerf015fec2018-10-26 10:56:11 -0500791 * before the `psa_drv_hash_finish_t` operation is complete, it should be aborted
792 * by the `psa_drv_hash_abort_t`. Failure to do so may result in allocated
Derek Miller765682c2018-10-22 15:27:27 -0500793 * resources not being freed or in other undefined behavior.
Derek Miller5b3417a2018-10-10 17:55:03 -0500794 */
Derek Miller16e72292018-10-15 16:14:24 -0500795/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500796
797/** \brief The hardware-specific hash context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100798 *
Derek Miller16e72292018-10-15 16:14:24 -0500799 * The contents of this structure are implementation dependent and are
800 * therefore not described here
Derek Miller5b3417a2018-10-10 17:55:03 -0500801 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100802typedef struct psa_drv_hash_context_s psa_drv_hash_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -0500803
Derek Miller16e72292018-10-15 16:14:24 -0500804/** \brief The function prototype for the start operation of a hash (message
805 * digest) operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100806 *
Derek Miller16e72292018-10-15 16:14:24 -0500807 * Functions that implement the prototype should be named in the following
808 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500809 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100810 * psa_drv_hash_<ALGO>_setup
Derek Miller5b3417a2018-10-10 17:55:03 -0500811 * ~~~~~~~~~~~~~
812 * Where `ALGO` is the name of the underlying hash function
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100813 *
Derek Miller16e72292018-10-15 16:14:24 -0500814 * \param[in,out] p_context A structure that will contain the
815 * hardware-specific hash context
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100816 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500817 * \retval PSA_SUCCESS Success.
818 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100819typedef psa_status_t (*psa_drv_hash_setup_t)(psa_drv_hash_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500820
Derek Miller16e72292018-10-15 16:14:24 -0500821/** \brief The function prototype for the update operation of a hash (message
822 * digest) operation
Derek Miller5b3417a2018-10-10 17:55:03 -0500823 *
Derek Miller16e72292018-10-15 16:14:24 -0500824 * Functions that implement the prototype should be named in the following
825 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500826 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100827 * psa_drv_hash_<ALGO>_update
Derek Miller5b3417a2018-10-10 17:55:03 -0500828 * ~~~~~~~~~~~~~
829 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100830 *
Derek Miller16e72292018-10-15 16:14:24 -0500831 * \param[in,out] p_context A hardware-specific structure for the
832 * previously-established hash operation to be
833 * continued
834 * \param[in] p_input A buffer containing the message to be appended
835 * to the hash operation
836 * \param[in] input_length The size in bytes of the input message buffer
Derek Miller5b3417a2018-10-10 17:55:03 -0500837 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100838typedef psa_status_t (*psa_drv_hash_update_t)(psa_drv_hash_context_t *p_context,
839 const uint8_t *p_input,
840 size_t input_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500841
Derek Miller16e72292018-10-15 16:14:24 -0500842/** \brief The prototype for the finish operation of a hash (message digest)
843 * operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100844 *
Derek Miller16e72292018-10-15 16:14:24 -0500845 * Functions that implement the prototype should be named in the following
846 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500847 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100848 * psa_drv_hash_<ALGO>_finish
Derek Miller5b3417a2018-10-10 17:55:03 -0500849 * ~~~~~~~~~~~~~
850 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100851 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500852 * \param[in,out] p_context A hardware-specific structure for the
Derek Miller16e72292018-10-15 16:14:24 -0500853 * previously started hash operation to be
854 * fiinished
855 * \param[out] p_output A buffer where the generated digest will be
856 * placed
857 * \param[in] output_size The size in bytes of the buffer that has been
858 * allocated for the `p_output` buffer
Derek Millerf3d0a562018-10-18 16:41:08 -0500859 * \param[out] p_output_length The number of bytes placed in `p_output` after
860 * success
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100861 *
Derek Miller5b3417a2018-10-10 17:55:03 -0500862 * \retval PSA_SUCCESS
863 * Success.
864 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100865typedef psa_status_t (*psa_drv_hash_finish_t)(psa_drv_hash_context_t *p_context,
866 uint8_t *p_output,
867 size_t output_size,
868 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500869
Derek Miller16e72292018-10-15 16:14:24 -0500870/** \brief The function prototype for the abort operation of a hash (message
871 * digest) operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100872 *
Derek Miller16e72292018-10-15 16:14:24 -0500873 * Functions that implement the prototype should be named in the following
874 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -0500875 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100876 * psa_drv_hash_<ALGO>_abort
Derek Miller5b3417a2018-10-10 17:55:03 -0500877 * ~~~~~~~~~~~~~
878 * Where `ALGO` is the name of the underlying algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100879 *
Derek Millerf3d0a562018-10-18 16:41:08 -0500880 * \param[in,out] p_context A hardware-specific structure for the previously
Derek Miller16e72292018-10-15 16:14:24 -0500881 * started hash operation to be aborted
Derek Miller5b3417a2018-10-10 17:55:03 -0500882 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100883typedef void (*psa_drv_hash_abort_t)(psa_drv_hash_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -0500884
Derek Miller16e72292018-10-15 16:14:24 -0500885/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500886
887
888/** \defgroup opaque_asymmetric Opaque Asymmetric Cryptography
Jaeden Amerod3d26aa2018-10-26 10:07:32 +0100889 *
Derek Miller765682c2018-10-22 15:27:27 -0500890 * Since the amount of data that can (or should) be encrypted or signed using
891 * asymmetric keys is limited by the key size, asymmetric key operations using
892 * opaque keys must be done in single function calls.
Derek Miller5b3417a2018-10-10 17:55:03 -0500893 */
Derek Miller16e72292018-10-15 16:14:24 -0500894/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -0500895
896/**
Derek Miller16e72292018-10-15 16:14:24 -0500897 * \brief A function that signs a hash or short message with a private key
Derek Miller5b3417a2018-10-10 17:55:03 -0500898 *
Derek Miller16e72292018-10-15 16:14:24 -0500899 * \param[in] key_slot Key slot of an asymmetric key pair
900 * \param[in] alg A signature algorithm that is compatible
901 * with the type of `key`
Derek Miller765682c2018-10-22 15:27:27 -0500902 * \param[in] p_hash The hash to sign
Derek Miller16e72292018-10-15 16:14:24 -0500903 * \param[in] hash_length Size of the `p_hash` buffer in bytes
904 * \param[out] p_signature Buffer where the signature is to be written
Derek Millerf3d0a562018-10-18 16:41:08 -0500905 * \param[in] signature_size Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500906 * \param[out] p_signature_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -0500907 * that make up the returned signature value
Derek Miller5b3417a2018-10-10 17:55:03 -0500908 *
909 * \retval PSA_SUCCESS
910 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100911typedef psa_status_t (*psa_drv_asymmetric_opaque_sign_t)(psa_key_slot_t key_slot,
912 psa_algorithm_t alg,
913 const uint8_t *p_hash,
914 size_t hash_length,
915 uint8_t *p_signature,
916 size_t signature_size,
917 size_t *p_signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500918
919/**
Derek Miller16e72292018-10-15 16:14:24 -0500920 * \brief A function that verifies the signature a hash or short message using
Derek Miller765682c2018-10-22 15:27:27 -0500921 * an asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -0500922 *
Derek Miller16e72292018-10-15 16:14:24 -0500923 * \param[in] key_slot Key slot of a public key or an asymmetric key
924 * pair
925 * \param[in] alg A signature algorithm that is compatible with
926 * the type of `key`
Derek Miller765682c2018-10-22 15:27:27 -0500927 * \param[in] p_hash The hash whose signature is to be verified
Derek Miller16e72292018-10-15 16:14:24 -0500928 * \param[in] hash_length Size of the `p_hash` buffer in bytes
929 * \param[in] p_signature Buffer containing the signature to verify
930 * \param[in] signature_length Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500931 *
932 * \retval PSA_SUCCESS
933 * The signature is valid.
934 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100935typedef psa_status_t (*psa_drv_asymmetric_opaque_verify_t)(psa_key_slot_t key_slot,
936 psa_algorithm_t alg,
937 const uint8_t *p_hash,
938 size_t hash_length,
939 const uint8_t *p_signature,
940 size_t signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500941
942/**
Derek Miller765682c2018-10-22 15:27:27 -0500943 * \brief A function that encrypts a short message with an asymmetric public
944 * key
Derek Miller5b3417a2018-10-10 17:55:03 -0500945 *
Derek Miller16e72292018-10-15 16:14:24 -0500946 * \param[in] key_slot Key slot of a public key or an asymmetric key
947 * pair
948 * \param[in] alg An asymmetric encryption algorithm that is
949 * compatible with the type of `key`
950 * \param[in] p_input The message to encrypt
951 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500952 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -0500953 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -0500954 * If the algorithm does not support a
955 * salt, pass `NULL`.
956 * If the algorithm supports an optional
957 * salt and you do not want to pass a salt,
958 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -0500959 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
960 * supported.
961 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500962 * If `p_salt` is `NULL`, pass 0.
963 * \param[out] p_output Buffer where the encrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -0500964 * be written
965 * \param[in] output_size Size of the `p_output` buffer in bytes
966 * \param[out] p_output_length On success, the number of bytes that make up
967 * the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -0500968 *
969 * \retval PSA_SUCCESS
970 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +0100971typedef psa_status_t (*psa_drv_asymmetric_opaque_encrypt_t)(psa_key_slot_t key_slot,
972 psa_algorithm_t alg,
973 const uint8_t *p_input,
974 size_t input_length,
975 const uint8_t *p_salt,
976 size_t salt_length,
977 uint8_t *p_output,
978 size_t output_size,
979 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -0500980
981/**
Derek Miller765682c2018-10-22 15:27:27 -0500982 * \brief Decrypt a short message with an asymmetric private key.
Derek Miller5b3417a2018-10-10 17:55:03 -0500983 *
Derek Miller16e72292018-10-15 16:14:24 -0500984 * \param[in] key_slot Key slot of an asymmetric key pair
985 * \param[in] alg An asymmetric encryption algorithm that is
986 * compatible with the type of `key`
987 * \param[in] p_input The message to decrypt
988 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500989 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -0500990 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -0500991 * If the algorithm does not support a
992 * salt, pass `NULL`.
993 * If the algorithm supports an optional
994 * salt and you do not want to pass a salt,
995 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -0500996 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
997 * supported.
998 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -0500999 * If `p_salt` is `NULL`, pass 0.
1000 * \param[out] p_output Buffer where the decrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -05001001 * be written
1002 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001003 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001004 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -05001005 *
1006 * \retval PSA_SUCCESS
1007 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001008typedef psa_status_t (*psa_drv_asymmetric_opaque_decrypt_t)(psa_key_slot_t key_slot,
1009 psa_algorithm_t alg,
1010 const uint8_t *p_input,
1011 size_t input_length,
1012 const uint8_t *p_salt,
1013 size_t salt_length,
1014 uint8_t *p_output,
1015 size_t output_size,
1016 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001017
1018/**
Derek Miller16e72292018-10-15 16:14:24 -05001019 * \brief A struct containing all of the function pointers needed to implement
1020 * asymmetric cryptographic operations using opaque keys.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001021 *
Derek Miller16e72292018-10-15 16:14:24 -05001022 * PSA Crypto API implementations should populate instances of the table as
1023 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001024 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001025 * If one of the functions is not implemented, it should be set to NULL.
1026 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001027typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001028 /** Function that performs the asymmetric sign operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001029 psa_drv_asymmetric_opaque_sign_t *p_sign;
Derek Miller16e72292018-10-15 16:14:24 -05001030 /** Function that performs the asymmetric verify operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001031 psa_drv_asymmetric_opaque_verify_t *p_verify;
Derek Miller16e72292018-10-15 16:14:24 -05001032 /** Function that performs the asymmetric encrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001033 psa_drv_asymmetric_opaque_encrypt_t *p_encrypt;
Derek Miller16e72292018-10-15 16:14:24 -05001034 /** Function that performs the asymmetric decrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001035 psa_drv_asymmetric_opaque_decrypt_t *p_decrypt;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001036} psa_drv_asymmetric_opaque_t;
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/** \defgroup transparent_asymmetric Transparent Asymmetric Cryptography
Derek Miller765682c2018-10-22 15:27:27 -05001041 *
1042 * Since the amount of data that can (or should) be encrypted or signed using
1043 * asymmetric keys is limited by the key size, asymmetric key operations using
1044 * transparent keys must be done in single function calls.
Derek Miller5b3417a2018-10-10 17:55:03 -05001045 */
Derek Miller16e72292018-10-15 16:14:24 -05001046/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001047
1048
1049/**
Derek Miller16e72292018-10-15 16:14:24 -05001050 * \brief A function that signs a hash or short message with a transparent
Derek Miller765682c2018-10-22 15:27:27 -05001051 * asymmetric private key
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001052 *
Derek Miller16e72292018-10-15 16:14:24 -05001053 * Functions that implement the prototype should be named in the following
1054 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001055 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001056 * psa_drv_asymmetric_<ALGO>_sign
Derek Miller5b3417a2018-10-10 17:55:03 -05001057 * ~~~~~~~~~~~~~
1058 * Where `ALGO` is the name of the signing algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001059 *
Derek Miller16e72292018-10-15 16:14:24 -05001060 * \param[in] p_key A buffer containing the private key
1061 * material
1062 * \param[in] key_size The size in bytes of the `p_key` data
1063 * \param[in] alg A signature algorithm that is compatible
1064 * with the type of `p_key`
1065 * \param[in] p_hash The hash or message to sign
1066 * \param[in] hash_length Size of the `p_hash` buffer in bytes
1067 * \param[out] p_signature Buffer where the signature is to be written
1068 * \param[in] signature_size Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001069 * \param[out] p_signature_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001070 * that make up the returned signature value
Derek Miller5b3417a2018-10-10 17:55:03 -05001071 *
1072 * \retval PSA_SUCCESS
1073 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001074typedef psa_status_t (*psa_drv_asymmetric_transparent_sign_t)(const uint8_t *p_key,
1075 size_t key_size,
1076 psa_algorithm_t alg,
1077 const uint8_t *p_hash,
1078 size_t hash_length,
1079 uint8_t *p_signature,
1080 size_t signature_size,
1081 size_t *p_signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001082
1083/**
Derek Miller16e72292018-10-15 16:14:24 -05001084 * \brief A function that verifies the signature a hash or short message using
Derek Miller765682c2018-10-22 15:27:27 -05001085 * a transparent asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -05001086 *
Derek Miller16e72292018-10-15 16:14:24 -05001087 * Functions that implement the prototype should be named in the following
1088 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001089 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001090 * psa_drv_asymmetric_<ALGO>_verify
Derek Miller5b3417a2018-10-10 17:55:03 -05001091 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001092 * Where `ALGO` is the name of the signing algorithm
1093 *
Derek Miller16e72292018-10-15 16:14:24 -05001094 * \param[in] p_key A buffer containing the public key material
1095 * \param[in] key_size The size in bytes of the `p_key` data
1096 * \param[in] alg A signature algorithm that is compatible with
1097 * the type of `key`
1098 * \param[in] p_hash The hash or message whose signature is to be
1099 * verified
1100 * \param[in] hash_length Size of the `p_hash` buffer in bytes
1101 * \param[in] p_signature Buffer containing the signature to verify
1102 * \param[in] signature_length Size of the `p_signature` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001103 *
1104 * \retval PSA_SUCCESS
1105 * The signature is valid.
1106 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001107typedef psa_status_t (*psa_drv_asymmetric_transparent_verify_t)(const uint8_t *p_key,
1108 size_t key_size,
1109 psa_algorithm_t alg,
1110 const uint8_t *p_hash,
1111 size_t hash_length,
1112 const uint8_t *p_signature,
1113 size_t signature_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001114
1115/**
Derek Miller765682c2018-10-22 15:27:27 -05001116 * \brief A function that encrypts a short message with a transparent
1117 * asymmetric public key
Derek Miller5b3417a2018-10-10 17:55:03 -05001118 *
Derek Miller16e72292018-10-15 16:14:24 -05001119 * Functions that implement the prototype should be named in the following
1120 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001121 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001122 * psa_drv_asymmetric_<ALGO>_encrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001123 * ~~~~~~~~~~~~~
1124 * Where `ALGO` is the name of the encryption algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001125 *
Derek Miller16e72292018-10-15 16:14:24 -05001126 * \param[in] p_key A buffer containing the public key material
1127 * \param[in] key_size The size in bytes of the `p_key` data
1128 * \param[in] alg An asymmetric encryption algorithm that is
1129 * compatible with the type of `key`
1130 * \param[in] p_input The message to encrypt
1131 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001132 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -05001133 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -05001134 * If the algorithm does not support a
Derek Miller16e72292018-10-15 16:14:24 -05001135 * salt, pass `NULL`
Derek Miller5b3417a2018-10-10 17:55:03 -05001136 * If the algorithm supports an optional
1137 * salt and you do not want to pass a salt,
1138 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -05001139 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1140 * supported.
1141 * \param[in] salt_length Size of the `p_salt` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001142 * If `p_salt` is `NULL`, pass 0.
1143 * \param[out] p_output Buffer where the encrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -05001144 * be written
1145 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001146 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001147 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -05001148 *
1149 * \retval PSA_SUCCESS
1150 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001151typedef psa_status_t (*psa_drv_asymmetric_transparent_encrypt_t)(const uint8_t *p_key,
1152 size_t key_size,
1153 psa_algorithm_t alg,
1154 const uint8_t *p_input,
1155 size_t input_length,
1156 const uint8_t *p_salt,
1157 size_t salt_length,
1158 uint8_t *p_output,
1159 size_t output_size,
1160 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001161
1162/**
Derek Miller765682c2018-10-22 15:27:27 -05001163 * \brief Decrypt a short message with a transparent asymmetric private key
Derek Miller5b3417a2018-10-10 17:55:03 -05001164 *
Derek Miller16e72292018-10-15 16:14:24 -05001165 * Functions that implement the prototype should be named in the following
1166 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001167 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001168 * psa_drv_asymmetric_<ALGO>_decrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001169 * ~~~~~~~~~~~~~
1170 * Where `ALGO` is the name of the encryption algorithm
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001171 *
Derek Miller16e72292018-10-15 16:14:24 -05001172 * \param[in] p_key A buffer containing the private key material
1173 * \param[in] key_size The size in bytes of the `p_key` data
1174 * \param[in] alg An asymmetric encryption algorithm that is
1175 * compatible with the type of `key`
1176 * \param[in] p_input The message to decrypt
1177 * \param[in] input_length Size of the `p_input` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001178 * \param[in] p_salt A salt or label, if supported by the
Derek Miller16e72292018-10-15 16:14:24 -05001179 * encryption algorithm
Derek Miller5b3417a2018-10-10 17:55:03 -05001180 * If the algorithm does not support a
1181 * salt, pass `NULL`.
1182 * If the algorithm supports an optional
1183 * salt and you do not want to pass a salt,
1184 * pass `NULL`.
Derek Miller16e72292018-10-15 16:14:24 -05001185 * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1186 * supported
1187 * \param[in] salt_length Size of the `p_salt` buffer in bytes
1188 * If `p_salt` is `NULL`, pass 0
Derek Miller5b3417a2018-10-10 17:55:03 -05001189 * \param[out] p_output Buffer where the decrypted message is to
Derek Miller16e72292018-10-15 16:14:24 -05001190 * be written
1191 * \param[in] output_size Size of the `p_output` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001192 * \param[out] p_output_length On success, the number of bytes
Derek Miller16e72292018-10-15 16:14:24 -05001193 * that make up the returned output
Derek Miller5b3417a2018-10-10 17:55:03 -05001194 *
1195 * \retval PSA_SUCCESS
1196 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001197typedef psa_status_t (*psa_drv_asymmetric_transparent_decrypt_t)(const uint8_t *p_key,
1198 size_t key_size,
1199 psa_algorithm_t alg,
1200 const uint8_t *p_input,
1201 size_t input_length,
1202 const uint8_t *p_salt,
1203 size_t salt_length,
1204 uint8_t *p_output,
1205 size_t output_size,
1206 size_t *p_output_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001207
Derek Miller16e72292018-10-15 16:14:24 -05001208/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001209
1210/** \defgroup aead_opaque AEAD Opaque
Derek Miller765682c2018-10-22 15:27:27 -05001211 * Authenticated Encryption with Additional Data (AEAD) operations with opaque
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001212 * keys must be done in one function call. While this creates a burden for
Derek Miller765682c2018-10-22 15:27:27 -05001213 * implementers as there must be sufficient space in memory for the entire
1214 * message, it prevents decrypted data from being made available before the
1215 * authentication operation is complete and the data is known to be authentic.
Derek Miller5b3417a2018-10-10 17:55:03 -05001216 */
Derek Miller16e72292018-10-15 16:14:24 -05001217/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001218
Derek Miller16e72292018-10-15 16:14:24 -05001219/** \brief Process an authenticated encryption operation using an opaque key
Derek Miller5b3417a2018-10-10 17:55:03 -05001220 *
Derek Miller16e72292018-10-15 16:14:24 -05001221 * \param[in] key_slot Slot containing the key to use.
1222 * \param[in] algorithm The AEAD algorithm to compute
1223 * (\c PSA_ALG_XXX value such that
1224 * #PSA_ALG_IS_AEAD(`alg`) is true)
1225 * \param[in] p_nonce Nonce or IV to use
1226 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
1227 * \param[in] p_additional_data Additional data that will be
1228 * authenticated but not encrypted
1229 * \param[in] additional_data_length Size of `p_additional_data` in bytes
1230 * \param[in] p_plaintext Data that will be authenticated and
1231 * encrypted
1232 * \param[in] plaintext_length Size of `p_plaintext` in bytes
1233 * \param[out] p_ciphertext Output buffer for the authenticated and
1234 * encrypted data. The additional data is
1235 * not part of this output. For algorithms
1236 * where the encrypted data and the
1237 * authentication tag are defined as
1238 * separate outputs, the authentication
1239 * tag is appended to the encrypted data.
1240 * \param[in] ciphertext_size Size of the `p_ciphertext` buffer in
1241 * bytes
1242 * \param[out] p_ciphertext_length On success, the size of the output in
1243 * the `p_ciphertext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001244 *
1245 * \retval #PSA_SUCCESS
1246 * Success.
1247 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001248typedef psa_status_t (*psa_drv_aead_opaque_encrypt_t)(psa_key_slot_t key_slot,
1249 psa_algorithm_t algorithm,
1250 const uint8_t *p_nonce,
1251 size_t nonce_length,
1252 const uint8_t *p_additional_data,
1253 size_t additional_data_length,
1254 const uint8_t *p_plaintext,
1255 size_t plaintext_length,
1256 uint8_t *p_ciphertext,
1257 size_t ciphertext_size,
1258 size_t *p_ciphertext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001259
Derek Miller16e72292018-10-15 16:14:24 -05001260/** Process an authenticated decryption operation using an opaque key
Derek Miller5b3417a2018-10-10 17:55:03 -05001261 *
Derek Miller16e72292018-10-15 16:14:24 -05001262 * \param[in] key_slot Slot containing the key to use
1263 * \param[in] algorithm The AEAD algorithm to compute
1264 * (\c PSA_ALG_XXX value such that
1265 * #PSA_ALG_IS_AEAD(`alg`) is true)
1266 * \param[in] p_nonce Nonce or IV to use
1267 * \param[in] nonce_length Size of the `p_nonce` buffer in bytes
1268 * \param[in] p_additional_data Additional data that has been
1269 * authenticated but not encrypted
1270 * \param[in] additional_data_length Size of `p_additional_data` in bytes
1271 * \param[in] p_ciphertext Data that has been authenticated and
1272 * encrypted.
1273 * For algorithms where the encrypted data
1274 * and the authentication tag are defined
1275 * as separate inputs, the buffer must
1276 * contain the encrypted data followed by
1277 * the authentication tag.
1278 * \param[in] ciphertext_length Size of `p_ciphertext` in bytes
1279 * \param[out] p_plaintext Output buffer for the decrypted data
1280 * \param[in] plaintext_size Size of the `p_plaintext` buffer in
1281 * bytes
1282 * \param[out] p_plaintext_length On success, the size of the output in
1283 * the `p_plaintext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001284 *
1285 * \retval #PSA_SUCCESS
1286 * Success.
1287 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001288typedef psa_status_t (*psa_drv_aead_opaque_decrypt_t)(psa_key_slot_t key_slot,
1289 psa_algorithm_t algorithm,
1290 const uint8_t *p_nonce,
1291 size_t nonce_length,
1292 const uint8_t *p_additional_data,
1293 size_t additional_data_length,
1294 const uint8_t *p_ciphertext,
1295 size_t ciphertext_length,
1296 uint8_t *p_plaintext,
1297 size_t plaintext_size,
1298 size_t *p_plaintext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001299
1300/**
Derek Miller16e72292018-10-15 16:14:24 -05001301 * \brief A struct containing all of the function pointers needed to implement
1302 * Authenticated Encryption with Additional Data operations using opaque keys
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001303 *
Derek Miller16e72292018-10-15 16:14:24 -05001304 * PSA Crypto API implementations should populate instances of the table as
1305 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001306 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001307 * If one of the functions is not implemented, it should be set to NULL.
1308 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001309typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001310 /** Function that performs the AEAD encrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001311 psa_drv_aead_opaque_encrypt_t *p_encrypt;
Derek Miller16e72292018-10-15 16:14:24 -05001312 /** Function that performs the AEAD decrypt operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001313 psa_drv_aead_opaque_decrypt_t *p_decrypt;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001314} psa_drv_aead_opaque_t;
Derek Miller16e72292018-10-15 16:14:24 -05001315/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001316
1317/** \defgroup aead_transparent AEAD Transparent
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001318 *
Derek Miller765682c2018-10-22 15:27:27 -05001319 * Authenticated Encryption with Additional Data (AEAD) operations with
1320 * transparent keys must be done in one function call. While this creates a
1321 * burden for implementers as there must be sufficient space in memory for the
1322 * entire message, it prevents decrypted data from being made available before
1323 * the authentication operation is complete and the data is known to be
1324 * authentic.
Derek Miller5b3417a2018-10-10 17:55:03 -05001325 */
Derek Miller16e72292018-10-15 16:14:24 -05001326/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001327
Derek Miller765682c2018-10-22 15:27:27 -05001328/** Process an authenticated encryption operation using an opaque key.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001329 *
Derek Miller16e72292018-10-15 16:14:24 -05001330 * Functions that implement the prototype should be named in the following
1331 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001332 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001333 * psa_drv_aead_<ALGO>_encrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001334 * ~~~~~~~~~~~~~
1335 * Where `ALGO` is the name of the AEAD algorithm
1336 *
Derek Miller16e72292018-10-15 16:14:24 -05001337 * \param[in] p_key A pointer to the key material
1338 * \param[in] key_length The size in bytes of the key material
1339 * \param[in] alg The AEAD algorithm to compute
1340 * (\c PSA_ALG_XXX value such that
1341 * #PSA_ALG_IS_AEAD(`alg`) is true)
1342 * \param[in] nonce Nonce or IV to use
1343 * \param[in] nonce_length Size of the `nonce` buffer in bytes
1344 * \param[in] additional_data Additional data that will be MACed
1345 * but not encrypted.
1346 * \param[in] additional_data_length Size of `additional_data` in bytes
1347 * \param[in] plaintext Data that will be MACed and
1348 * encrypted.
1349 * \param[in] plaintext_length Size of `plaintext` in bytes
1350 * \param[out] ciphertext Output buffer for the authenticated and
1351 * encrypted data. The additional data is
1352 * not part of this output. For algorithms
1353 * where the encrypted data and the
1354 * authentication tag are defined as
1355 * separate outputs, the authentication
1356 * tag is appended to the encrypted data.
1357 * \param[in] ciphertext_size Size of the `ciphertext` buffer in
1358 * bytes
1359 * This must be at least
1360 * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(`alg`,
1361 * `plaintext_length`).
1362 * \param[out] ciphertext_length On success, the size of the output in
1363 * the `ciphertext` buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001364 *
1365 * \retval #PSA_SUCCESS
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001366
Derek Miller5b3417a2018-10-10 17:55:03 -05001367 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001368typedef psa_status_t (*psa_drv_aead_transparent_encrypt_t)(const uint8_t *p_key,
1369 size_t key_length,
1370 psa_algorithm_t alg,
1371 const uint8_t *nonce,
1372 size_t nonce_length,
1373 const uint8_t *additional_data,
1374 size_t additional_data_length,
1375 const uint8_t *plaintext,
1376 size_t plaintext_length,
1377 uint8_t *ciphertext,
1378 size_t ciphertext_size,
1379 size_t *ciphertext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001380
Derek Miller765682c2018-10-22 15:27:27 -05001381/** Process an authenticated decryption operation using an opaque key.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001382 *
Derek Miller16e72292018-10-15 16:14:24 -05001383 * Functions that implement the prototype should be named in the following
1384 * convention:
Derek Miller5b3417a2018-10-10 17:55:03 -05001385 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001386 * psa_drv_aead_<ALGO>_decrypt
Derek Miller5b3417a2018-10-10 17:55:03 -05001387 * ~~~~~~~~~~~~~
1388 * Where `ALGO` is the name of the AEAD algorithm
Derek Miller16e72292018-10-15 16:14:24 -05001389 * \param[in] p_key A pointer to the key material
1390 * \param[in] key_length The size in bytes of the key material
1391 * \param[in] alg The AEAD algorithm to compute
1392 * (\c PSA_ALG_XXX value such that
1393 * #PSA_ALG_IS_AEAD(`alg`) is true)
1394 * \param[in] nonce Nonce or IV to use
1395 * \param[in] nonce_length Size of the `nonce` buffer in bytes
1396 * \param[in] additional_data Additional data that has been MACed
1397 * but not encrypted
1398 * \param[in] additional_data_length Size of `additional_data` in bytes
1399 * \param[in] ciphertext Data that has been MACed and
1400 * encrypted
1401 * For algorithms where the encrypted data
1402 * and the authentication tag are defined
1403 * as separate inputs, the buffer must
1404 * contain the encrypted data followed by
1405 * the authentication tag.
1406 * \param[in] ciphertext_length Size of `ciphertext` in bytes
1407 * \param[out] plaintext Output buffer for the decrypted data
1408 * \param[in] plaintext_size Size of the `plaintext` buffer in
1409 * bytes
1410 * This must be at least
1411 * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(`alg`,
1412 * `ciphertext_length`).
1413 * \param[out] plaintext_length On success, the size of the output
1414 * in the \b plaintext buffer
Derek Miller5b3417a2018-10-10 17:55:03 -05001415 *
1416 * \retval #PSA_SUCCESS
1417 * Success.
1418 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001419typedef psa_status_t (*psa_drv_aead_transparent_decrypt_t)(const uint8_t *p_key,
1420 size_t key_length,
1421 psa_algorithm_t alg,
1422 const uint8_t *nonce,
1423 size_t nonce_length,
1424 const uint8_t *additional_data,
1425 size_t additional_data_length,
1426 const uint8_t *ciphertext,
1427 size_t ciphertext_length,
1428 uint8_t *plaintext,
1429 size_t plaintext_size,
1430 size_t *plaintext_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001431
Derek Miller16e72292018-10-15 16:14:24 -05001432/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001433
1434
Derek Miller16e72292018-10-15 16:14:24 -05001435/** \defgroup driver_rng Entropy Generation
Derek Miller5b3417a2018-10-10 17:55:03 -05001436 */
Derek Miller16e72292018-10-15 16:14:24 -05001437/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001438
1439/** \brief A hardware-specific structure for a entropy providing hardware
1440 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001441typedef struct psa_drv_entropy_context_s psa_drv_entropy_context_t;
Derek Miller5b3417a2018-10-10 17:55:03 -05001442
1443/** \brief Initialize an entropy driver
1444 *
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001445 *
Derek Miller16e72292018-10-15 16:14:24 -05001446 * \param[in,out] p_context A hardware-specific structure
1447 * containing any context information for
1448 * the implementation
Derek Miller5b3417a2018-10-10 17:55:03 -05001449 *
1450 * \retval PSA_SUCCESS
1451 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001452typedef psa_status_t (*psa_drv_entropy_init_t)(psa_drv_entropy_context_t *p_context);
Derek Miller5b3417a2018-10-10 17:55:03 -05001453
Derek Miller6f960ab2018-10-23 15:58:06 -05001454/** \brief Get a specified number of bits from the entropy source
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001455 *
Derek Miller16e72292018-10-15 16:14:24 -05001456 * It retrives `buffer_size` bytes of data from the entropy source. The entropy
1457 * source will always fill the provided buffer to its full size, however, most
1458 * entropy sources have biases, and the actual amount of entropy contained in
1459 * the buffer will be less than the number of bytes.
1460 * The driver will return the actual number of bytes of entropy placed in the
1461 * buffer in `p_received_entropy_bytes`.
1462 * A PSA Crypto API implementation will likely feed the output of this function
1463 * into a Digital Random Bit Generator (DRBG), and typically has a minimum
1464 * amount of entropy that it needs.
1465 * To accomplish this, the PSA Crypto implementation should be designed to call
1466 * this function multiple times until it has received the required amount of
1467 * entropy from the entropy source.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001468 *
Derek Miller16e72292018-10-15 16:14:24 -05001469 * \param[in,out] p_context A hardware-specific structure
1470 * containing any context information
1471 * for the implementation
1472 * \param[out] p_buffer A caller-allocated buffer for the
Derek Miller6f960ab2018-10-23 15:58:06 -05001473 * retrieved entropy to be placed in
Derek Miller16e72292018-10-15 16:14:24 -05001474 * \param[in] buffer_size The allocated size of `p_buffer`
Derek Miller6f960ab2018-10-23 15:58:06 -05001475 * \param[out] p_received_entropy_bits The amount of entropy (in bits)
Derek Miller16e72292018-10-15 16:14:24 -05001476 * actually provided in `p_buffer`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001477 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001478 * \retval PSA_SUCCESS
1479 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001480typedef psa_status_t (*psa_drv_entropy_get_bits_t)(psa_drv_entropy_context_t *p_context,
1481 uint8_t *p_buffer,
1482 uint32_t buffer_size,
1483 uint32_t *p_received_entropy_bits);
Derek Miller5b3417a2018-10-10 17:55:03 -05001484
1485/**
Derek Miller16e72292018-10-15 16:14:24 -05001486 * \brief A struct containing all of the function pointers needed to interface
1487 * to an entropy source
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001488 *
Derek Miller16e72292018-10-15 16:14:24 -05001489 * PSA Crypto API implementations should populate instances of the table as
1490 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001491 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001492 * If one of the functions is not implemented, it should be set to NULL.
1493 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001494typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001495 /** Function that performs initialization for the entropy source */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001496 psa_drv_entropy_init_t *p_init;
Derek Miller6f960ab2018-10-23 15:58:06 -05001497 /** Function that performs the get_bits operation for the entropy source
Derek Miller16e72292018-10-15 16:14:24 -05001498 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001499 psa_drv_entropy_get_bits_t *p_get_bits;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001500} psa_drv_entropy_t;
Derek Miller16e72292018-10-15 16:14:24 -05001501/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001502
Derek Miller16e72292018-10-15 16:14:24 -05001503/** \defgroup driver_key_management Key Management
Derek Miller765682c2018-10-22 15:27:27 -05001504 * Currently, key management is limited to importing keys in the clear,
1505 * destroying keys, and exporting keys in the clear.
1506 * Whether a key may be exported is determined by the key policies in place
1507 * on the key slot.
Derek Miller5b3417a2018-10-10 17:55:03 -05001508 */
Derek Miller16e72292018-10-15 16:14:24 -05001509/**@{*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001510
Derek Miller16e72292018-10-15 16:14:24 -05001511/** \brief Import a key in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001512 *
1513 * This function can support any output from psa_export_key(). Refer to the
1514 * documentation of psa_export_key() for the format for each key type.
1515 *
Derek Miller81133a62018-10-23 14:55:32 -05001516 * \param[in] key_slot Slot where the key will be stored
1517 * This must be a valid slot for a key of the chosen
1518 * type. It must be unoccupied.
1519 * \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value)
1520 * \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value)
1521 * \param[in] usage The allowed uses of the key
1522 * \param[in] p_data Buffer containing the key data
1523 * \param[in] data_length Size of the `data` buffer in bytes
Derek Miller5b3417a2018-10-10 17:55:03 -05001524 *
1525 * \retval #PSA_SUCCESS
1526 * Success.
1527 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001528typedef psa_status_t (*psa_drv_opaque_import_key_t)(psa_key_slot_t key_slot,
1529 psa_key_type_t type,
1530 psa_algorithm_t algorithm,
1531 psa_key_usage_t usage,
1532 const uint8_t *p_data,
1533 size_t data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001534
1535/**
Derek Miller16e72292018-10-15 16:14:24 -05001536 * \brief Destroy a key and restore the slot to its default state
Derek Miller5b3417a2018-10-10 17:55:03 -05001537 *
1538 * This function destroys the content of the key slot from both volatile
1539 * memory and, if applicable, non-volatile storage. Implementations shall
1540 * make a best effort to ensure that any previous content of the slot is
1541 * unrecoverable.
1542 *
1543 * This function also erases any metadata such as policies. It returns the
1544 * specified slot to its default state.
1545 *
Derek Miller16e72292018-10-15 16:14:24 -05001546 * \param[in] key_slot The key slot to erase.
Derek Miller5b3417a2018-10-10 17:55:03 -05001547 *
1548 * \retval #PSA_SUCCESS
1549 * The slot's content, if any, has been erased.
1550 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001551typedef psa_status_t (*psa_drv_destroy_key_t)(psa_key_slot_t key);
Derek Miller5b3417a2018-10-10 17:55:03 -05001552
1553/**
Derek Miller16e72292018-10-15 16:14:24 -05001554 * \brief Export a key in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001555 *
1556 * The output of this function can be passed to psa_import_key() to
1557 * create an equivalent object.
1558 *
Derek Miller16e72292018-10-15 16:14:24 -05001559 * If a key is created with `psa_import_key()` and then exported with
Derek Miller5b3417a2018-10-10 17:55:03 -05001560 * this function, it is not guaranteed that the resulting data is
1561 * identical: the implementation may choose a different representation
1562 * of the same key if the format permits it.
1563 *
1564 * For standard key types, the output format is as follows:
1565 *
1566 * - For symmetric keys (including MAC keys), the format is the
1567 * raw bytes of the key.
1568 * - For DES, the key data consists of 8 bytes. The parity bits must be
1569 * correct.
1570 * - For Triple-DES, the format is the concatenation of the
1571 * two or three DES keys.
1572 * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format
1573 * is the non-encrypted DER representation defined by PKCS\#1 (RFC 8017)
1574 * as RSAPrivateKey.
1575 * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the format
1576 * is the DER representation defined by RFC 5280 as SubjectPublicKeyInfo.
1577 *
Derek Miller16e72292018-10-15 16:14:24 -05001578 * \param[in] key Slot whose content is to be exported. This must
Derek Miller5b3417a2018-10-10 17:55:03 -05001579 * be an occupied key slot.
1580 * \param[out] p_data Buffer where the key data is to be written.
Derek Miller16e72292018-10-15 16:14:24 -05001581 * \param[in] data_size Size of the `p_data` buffer in bytes.
Derek Miller5b3417a2018-10-10 17:55:03 -05001582 * \param[out] p_data_length On success, the number of bytes
1583 * that make up the key data.
1584 *
1585 * \retval #PSA_SUCCESS
1586 * \retval #PSA_ERROR_EMPTY_SLOT
1587 * \retval #PSA_ERROR_NOT_PERMITTED
1588 * \retval #PSA_ERROR_NOT_SUPPORTED
1589 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
1590 * \retval #PSA_ERROR_HARDWARE_FAILURE
1591 * \retval #PSA_ERROR_TAMPERING_DETECTED
1592 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001593typedef psa_status_t (*psa_drv_export_key_t)(psa_key_slot_t key,
1594 uint8_t *p_data,
1595 size_t data_size,
1596 size_t *p_data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001597
1598/**
Derek Miller16e72292018-10-15 16:14:24 -05001599 * \brief Export a public key or the public part of a key pair in binary format
Derek Miller5b3417a2018-10-10 17:55:03 -05001600 *
1601 * The output of this function can be passed to psa_import_key() to
1602 * create an object that is equivalent to the public key.
1603 *
1604 * For standard key types, the output format is as follows:
1605 *
1606 * - For RSA keys (#PSA_KEY_TYPE_RSA_KEYPAIR or #PSA_KEY_TYPE_RSA_PUBLIC_KEY),
1607 * the format is the DER representation of the public key defined by RFC 5280
1608 * as SubjectPublicKeyInfo.
1609 *
Derek Miller16e72292018-10-15 16:14:24 -05001610 * \param[in] key_slot Slot whose content is to be exported. This must
Derek Miller5b3417a2018-10-10 17:55:03 -05001611 * be an occupied key slot.
1612 * \param[out] p_data Buffer where the key data is to be written.
Derek Miller16e72292018-10-15 16:14:24 -05001613 * \param[in] data_size Size of the `data` buffer in bytes.
Derek Miller5b3417a2018-10-10 17:55:03 -05001614 * \param[out] p_data_length On success, the number of bytes
1615 * that make up the key data.
1616 *
1617 * \retval #PSA_SUCCESS
1618 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001619typedef psa_status_t (*psa_drv_export_public_key_t)(psa_key_slot_t key,
1620 uint8_t *p_data,
1621 size_t data_size,
1622 size_t *p_data_length);
Derek Miller5b3417a2018-10-10 17:55:03 -05001623
1624/**
Derek Miller16e72292018-10-15 16:14:24 -05001625 * \brief A struct containing all of the function pointers needed to for key
1626 * management using opaque keys
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001627 *
Derek Miller16e72292018-10-15 16:14:24 -05001628 * PSA Crypto API implementations should populate instances of the table as
1629 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001630 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001631 * If one of the functions is not implemented, it should be set to NULL.
1632 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001633typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001634 /** Function that performs the key import operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001635 psa_drv_opaque_import_key_t *p_import;
Derek Miller16e72292018-10-15 16:14:24 -05001636 /** Function that performs the key destroy operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001637 psa_drv_destroy_key_t *p_destroy;
Derek Miller16e72292018-10-15 16:14:24 -05001638 /** Function that performs the key export operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001639 psa_drv_export_key_t *p_export;
Derek Miller16e72292018-10-15 16:14:24 -05001640 /** Function that perforsm the public key export operation */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001641 psa_drv_export_public_key_t *p_export_public;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001642} psa_drv_key_management_t;
Derek Miller5b3417a2018-10-10 17:55:03 -05001643
Derek Miller16e72292018-10-15 16:14:24 -05001644/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001645
Derek Miller16e72292018-10-15 16:14:24 -05001646/** \defgroup driver_derivation Key Derivation and Agreement
Derek Miller16e72292018-10-15 16:14:24 -05001647 * Key derivation is the process of generating new key material using an
1648 * existing key and additional parameters, iterating through a basic
1649 * cryptographic function, such as a hash.
1650 * Key agreement is a part of cryptographic protocols that allows two parties
1651 * to agree on the same key value, but starting from different original key
1652 * material.
Jaeden Ameroe095d602018-10-26 12:09:31 +01001653 * The flows are similar, and the PSA Crypto Driver Model uses the same functions
Derek Miller16e72292018-10-15 16:14:24 -05001654 * for both of the flows.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001655 *
Derek Miller16e72292018-10-15 16:14:24 -05001656 * There are two different final functions for the flows,
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001657 * `psa_drv_key_derivation_derive` and `psa_drv_key_derivation_export`.
1658 * `psa_drv_key_derivation_derive` is used when the key material should be placed
Derek Miller16e72292018-10-15 16:14:24 -05001659 * in a slot on the hardware and not exposed to the caller.
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001660 * `psa_drv_key_derivation_export` is used when the key material should be returned
Derek Miller16e72292018-10-15 16:14:24 -05001661 * to the PSA Cryptographic API implementation.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001662 *
Derek Miller16e72292018-10-15 16:14:24 -05001663 * Different key derivation algorithms require a different number of inputs.
1664 * Instead of having an API that takes as input variable length arrays, which
1665 * can be problemmatic to manage on embedded platforms, the inputs are passed
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001666 * to the driver via a function, `psa_drv_key_derivation_collateral`, that is
Derek Miller16e72292018-10-15 16:14:24 -05001667 * called multiple times with different `collateral_id`s. Thus, for a key
1668 * derivation algorithm that required 3 paramter inputs, the flow would look
1669 * something like:
1670 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001671 * psa_drv_key_derivation_setup(kdf_algorithm, source_key, dest_key_size_bytes);
1672 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_0,
1673 * p_collateral_0,
1674 * collateral_0_size);
1675 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_1,
1676 * p_collateral_1,
1677 * collateral_1_size);
1678 * psa_drv_key_derivation_collateral(kdf_algorithm_collateral_id_2,
1679 * p_collateral_2,
1680 * collateral_2_size);
1681 * psa_drv_key_derivation_derive();
Derek Miller16e72292018-10-15 16:14:24 -05001682 * ~~~~~~~~~~~~~
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001683 *
Derek Miller16e72292018-10-15 16:14:24 -05001684 * key agreement example:
1685 * ~~~~~~~~~~~~~{.c}
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001686 * psa_drv_key_derivation_setup(alg, source_key. dest_key_size_bytes);
1687 * psa_drv_key_derivation_collateral(DHE_PUBKEY, p_pubkey, pubkey_size);
1688 * psa_drv_key_derivation_export(p_session_key,
1689 * session_key_size,
1690 * &session_key_length);
Derek Miller16e72292018-10-15 16:14:24 -05001691 * ~~~~~~~~~~~~~
1692 */
Derek Miller765682c2018-10-22 15:27:27 -05001693/**@{*/
Derek Miller16e72292018-10-15 16:14:24 -05001694
Derek Miller765682c2018-10-22 15:27:27 -05001695/** \brief The hardware-specific key derivation context structure
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001696 *
Derek Miller765682c2018-10-22 15:27:27 -05001697 * The contents of this structure are implementation dependent and are
1698 * therefore not described here
1699 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001700typedef struct psa_drv_key_derivation_context_s psa_drv_key_derivation_context_t;
Derek Miller16e72292018-10-15 16:14:24 -05001701
1702/** \brief Set up a key derivation operation by specifying the algorithm and
1703 * the source key sot
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001704 *
Derek Miller16e72292018-10-15 16:14:24 -05001705 * \param[in,out] p_context A hardware-specific structure containing any
1706 * context information for the implementation
1707 * \param[in] kdf_alg The algorithm to be used for the key derivation
1708 * \param[in] souce_key The key to be used as the source material for the
1709 * key derivation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001710 *
Derek Miller16e72292018-10-15 16:14:24 -05001711 * \retval PSA_SUCCESS
1712 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001713typedef psa_status_t (*psa_drv_key_derivation_setup_t)(psa_drv_key_derivation_context_t *p_context,
1714 psa_algorithm_t kdf_alg,
1715 psa_key_slot_t source_key);
Derek Miller16e72292018-10-15 16:14:24 -05001716
1717/** \brief Provide collateral (parameters) needed for a key derivation or key
1718 * agreement operation
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001719 *
Derek Miller16e72292018-10-15 16:14:24 -05001720 * Since many key derivation algorithms require multiple parameters, it is
1721 * expeced that this function may be called multiple times for the same
1722 * operation, each with a different algorithm-specific `collateral_id`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001723 *
Derek Miller16e72292018-10-15 16:14:24 -05001724 * \param[in,out] p_context A hardware-specific structure containing any
1725 * context information for the implementation
1726 * \param[in] collateral_id An ID for the collateral being provided
1727 * \param[in] p_collateral A buffer containing the collateral data
1728 * \param[in] collateral_size The size in bytes of the collateral
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001729 *
Derek Miller16e72292018-10-15 16:14:24 -05001730 * \retval PSA_SUCCESS
1731 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001732typedef psa_status_t (*psa_drv_key_derivation_collateral_t)(psa_drv_key_derivation_context_t *p_context,
1733 uint32_t collateral_id,
1734 const uint8_t *p_collateral,
1735 size_t collateral_size);
Derek Miller16e72292018-10-15 16:14:24 -05001736
1737/** \brief Perform the final key derivation step and place the generated key
1738 * material in a slot
1739 * \param[in,out] p_context A hardware-specific structure containing any
1740 * context information for the implementation
1741 * \param[in] dest_key The slot where the generated key material
1742 * should be placed
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001743 *
Derek Miller16e72292018-10-15 16:14:24 -05001744 * \retval PSA_SUCCESS
1745 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001746typedef psa_status_t (*psa_drv_key_derivation_derive_t)(psa_drv_key_derivation_context_t *p_context,
1747 psa_key_slot_t dest_key);
Derek Miller16e72292018-10-15 16:14:24 -05001748
1749/** \brief Perform the final step of a key agreement and place the generated
1750 * key material in a buffer
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001751 *
Derek Miller16e72292018-10-15 16:14:24 -05001752 * \param[out] p_output Buffer in which to place the generated key
1753 * material
1754 * \param[in] output_size The size in bytes of `p_output`
1755 * \param[out] p_output_length Upon success, contains the number of bytes of
1756 * key material placed in `p_output`
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001757 *
Derek Miller16e72292018-10-15 16:14:24 -05001758 * \retval PSA_SUCCESS
1759 */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001760typedef psa_status_t (*psa_drv_key_derivation_export_t)(uint8_t *p_output,
1761 size_t output_size,
1762 size_t *p_output_length);
Derek Miller16e72292018-10-15 16:14:24 -05001763
1764/**
1765 * \brief A struct containing all of the function pointers needed to for key
1766 * derivation and agreement
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001767 *
Derek Miller16e72292018-10-15 16:14:24 -05001768 * PSA Crypto API implementations should populate instances of the table as
1769 * appropriate upon startup.
Jaeden Amerod3d26aa2018-10-26 10:07:32 +01001770 *
Derek Miller5b3417a2018-10-10 17:55:03 -05001771 * If one of the functions is not implemented, it should be set to NULL.
1772 */
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001773typedef struct {
Derek Miller16e72292018-10-15 16:14:24 -05001774 /** Function that performs the key derivation setup */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001775 psa_drv_key_derivation_setup_t *p_setup;
Derek Miller16e72292018-10-15 16:14:24 -05001776 /** Function that sets the key derivation collateral */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001777 psa_drv_key_derivation_collateral_t *p_collateral;
Derek Miller16e72292018-10-15 16:14:24 -05001778 /** Function that performs the final key derivation step */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001779 psa_drv_key_derivation_derive_t *p_derive;
Derek Miller16e72292018-10-15 16:14:24 -05001780 /** Function that perforsm the final key derivation or agreement and
1781 * exports the key */
Jaeden Amero1acb2c42018-10-26 10:49:58 +01001782 psa_drv_key_derivation_export_t *p_export;
Jaeden Amero20b8a4f2018-10-26 11:57:26 +01001783} psa_drv_key_derivation_t;
Derek Miller5b3417a2018-10-10 17:55:03 -05001784
Derek Miller16e72292018-10-15 16:14:24 -05001785/**@}*/
Derek Miller5b3417a2018-10-10 17:55:03 -05001786
Jaeden Amero9411db72018-10-26 11:59:58 +01001787#ifdef __cplusplus
1788}
1789#endif
1790
Jaeden Amero41558502018-10-26 11:44:33 +01001791#endif /* PSA_CRYPTO_DRIVER_H */