Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa/crypto_accel_driver.h |
| 3 | * \brief PSA cryptography accelerator driver module |
| 4 | * |
| 5 | * This header declares types and function signatures for cryptography |
| 6 | * drivers that access key material directly. This is meant for |
| 7 | * on-chip cryptography accelerators. |
| 8 | * |
| 9 | * This file is part of the PSA Crypto Driver Model, containing functions for |
| 10 | * driver developers to implement to enable hardware to be called in a |
| 11 | * standardized way by a PSA Cryptographic API implementation. The functions |
| 12 | * comprising the driver model, which driver authors implement, are not |
| 13 | * intended to be called by application developers. |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * Copyright (C) 2018, ARM Limited, All Rights Reserved |
| 18 | * SPDX-License-Identifier: Apache-2.0 |
| 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | * not use this file except in compliance with the License. |
| 22 | * You may obtain a copy of the License at |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | * |
| 26 | * Unless required by applicable law or agreed to in writing, software |
| 27 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | * See the License for the specific language governing permissions and |
| 30 | * limitations under the License. |
| 31 | */ |
| 32 | #ifndef PSA_CRYPTO_ACCEL_DRIVER_H |
| 33 | #define PSA_CRYPTO_ACCEL_DRIVER_H |
| 34 | |
| 35 | #include "crypto_driver_common.h" |
| 36 | |
| 37 | #ifdef __cplusplus |
| 38 | extern "C" { |
| 39 | #endif |
| 40 | |
| 41 | /** \defgroup driver_digest Message Digests |
| 42 | * |
| 43 | * Generation and authentication of Message Digests (aka hashes) must be done |
| 44 | * in parts using the following sequence: |
| 45 | * - `psa_drv_hash_setup_t` |
| 46 | * - `psa_drv_hash_update_t` |
| 47 | * - ... |
| 48 | * - `psa_drv_hash_finish_t` |
| 49 | * |
| 50 | * If a previously started Message Digest operation needs to be terminated |
| 51 | * before the `psa_drv_hash_finish_t` operation is complete, it should be aborted |
| 52 | * by the `psa_drv_hash_abort_t`. Failure to do so may result in allocated |
| 53 | * resources not being freed or in other undefined behavior. |
| 54 | */ |
| 55 | /**@{*/ |
| 56 | |
| 57 | /** \brief The hardware-specific hash context structure |
| 58 | * |
| 59 | * The contents of this structure are implementation dependent and are |
| 60 | * therefore not described here |
| 61 | */ |
| 62 | typedef struct psa_drv_hash_context_s psa_drv_hash_context_t; |
| 63 | |
| 64 | /** \brief The function prototype for the start operation of a hash (message |
| 65 | * digest) operation |
| 66 | * |
| 67 | * Functions that implement the prototype should be named in the following |
| 68 | * convention: |
| 69 | * ~~~~~~~~~~~~~{.c} |
| 70 | * psa_drv_hash_<ALGO>_setup |
| 71 | * ~~~~~~~~~~~~~ |
| 72 | * Where `ALGO` is the name of the underlying hash function |
| 73 | * |
| 74 | * \param[in,out] p_context A structure that will contain the |
| 75 | * hardware-specific hash context |
| 76 | * |
| 77 | * \retval PSA_SUCCESS Success. |
| 78 | */ |
| 79 | typedef psa_status_t (*psa_drv_hash_setup_t)(psa_drv_hash_context_t *p_context); |
| 80 | |
| 81 | /** \brief The function prototype for the update operation of a hash (message |
| 82 | * digest) operation |
| 83 | * |
| 84 | * Functions that implement the prototype should be named in the following |
| 85 | * convention: |
| 86 | * ~~~~~~~~~~~~~{.c} |
| 87 | * psa_drv_hash_<ALGO>_update |
| 88 | * ~~~~~~~~~~~~~ |
| 89 | * Where `ALGO` is the name of the underlying algorithm |
| 90 | * |
| 91 | * \param[in,out] p_context A hardware-specific structure for the |
| 92 | * previously-established hash operation to be |
| 93 | * continued |
| 94 | * \param[in] p_input A buffer containing the message to be appended |
| 95 | * to the hash operation |
| 96 | * \param[in] input_length The size in bytes of the input message buffer |
| 97 | */ |
| 98 | typedef psa_status_t (*psa_drv_hash_update_t)(psa_drv_hash_context_t *p_context, |
| 99 | const uint8_t *p_input, |
| 100 | size_t input_length); |
| 101 | |
| 102 | /** \brief The prototype for the finish operation of a hash (message digest) |
| 103 | * operation |
| 104 | * |
| 105 | * Functions that implement the prototype should be named in the following |
| 106 | * convention: |
| 107 | * ~~~~~~~~~~~~~{.c} |
| 108 | * psa_drv_hash_<ALGO>_finish |
| 109 | * ~~~~~~~~~~~~~ |
| 110 | * Where `ALGO` is the name of the underlying algorithm |
| 111 | * |
| 112 | * \param[in,out] p_context A hardware-specific structure for the |
| 113 | * previously started hash operation to be |
| 114 | * fiinished |
| 115 | * \param[out] p_output A buffer where the generated digest will be |
| 116 | * placed |
| 117 | * \param[in] output_size The size in bytes of the buffer that has been |
| 118 | * allocated for the `p_output` buffer |
| 119 | * \param[out] p_output_length The number of bytes placed in `p_output` after |
| 120 | * success |
| 121 | * |
| 122 | * \retval PSA_SUCCESS |
| 123 | * Success. |
| 124 | */ |
| 125 | typedef psa_status_t (*psa_drv_hash_finish_t)(psa_drv_hash_context_t *p_context, |
| 126 | uint8_t *p_output, |
| 127 | size_t output_size, |
| 128 | size_t *p_output_length); |
| 129 | |
| 130 | /** \brief The function prototype for the abort operation of a hash (message |
| 131 | * digest) operation |
| 132 | * |
| 133 | * Functions that implement the prototype should be named in the following |
| 134 | * convention: |
| 135 | * ~~~~~~~~~~~~~{.c} |
| 136 | * psa_drv_hash_<ALGO>_abort |
| 137 | * ~~~~~~~~~~~~~ |
| 138 | * Where `ALGO` is the name of the underlying algorithm |
| 139 | * |
| 140 | * \param[in,out] p_context A hardware-specific structure for the previously |
| 141 | * started hash operation to be aborted |
| 142 | */ |
| 143 | typedef void (*psa_drv_hash_abort_t)(psa_drv_hash_context_t *p_context); |
| 144 | |
| 145 | /**@}*/ |
| 146 | |
| 147 | /** \defgroup transparent_mac Transparent Message Authentication Code |
| 148 | * Generation and authentication of Message Authentication Codes (MACs) using |
| 149 | * transparent keys can be done either as a single function call (via the |
| 150 | * `psa_drv_mac_transparent_generate_t` or `psa_drv_mac_transparent_verify_t` |
| 151 | * functions), or in parts using the following sequence: |
| 152 | * - `psa_drv_mac_transparent_setup_t` |
| 153 | * - `psa_drv_mac_transparent_update_t` |
| 154 | * - `psa_drv_mac_transparent_update_t` |
| 155 | * - ... |
| 156 | * - `psa_drv_mac_transparent_finish_t` or `psa_drv_mac_transparent_finish_verify_t` |
| 157 | * |
| 158 | * If a previously started Transparent MAC operation needs to be terminated, it |
| 159 | * should be done so by the `psa_drv_mac_transparent_abort_t`. Failure to do so may |
| 160 | * result in allocated resources not being freed or in other undefined |
| 161 | * behavior. |
| 162 | * |
| 163 | */ |
| 164 | /**@{*/ |
| 165 | |
| 166 | /** \brief The hardware-specific transparent-key MAC context structure |
| 167 | * |
| 168 | * The contents of this structure are implementation dependent and are |
| 169 | * therefore not described here. |
| 170 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 171 | typedef struct psa_drv_accel_mac_context_s psa_drv_accel_mac_context_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 172 | |
| 173 | /** \brief The function prototype for the setup operation of a |
| 174 | * transparent-key MAC operation |
| 175 | * |
| 176 | * Functions that implement the prototype should be named in the following |
| 177 | * convention: |
| 178 | * ~~~~~~~~~~~~~{.c} |
| 179 | * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_setup |
| 180 | * ~~~~~~~~~~~~~ |
| 181 | * Where `ALGO` is the name of the underlying primitive, and `MAC_VARIANT` |
| 182 | * is the specific variant of a MAC operation (such as HMAC or CMAC) |
| 183 | * |
| 184 | * \param[in,out] p_context A structure that will contain the |
| 185 | * hardware-specific MAC context |
| 186 | * \param[in] p_key A buffer containing the cleartext key material |
| 187 | * to be used in the operation |
| 188 | * \param[in] key_length The size in bytes of the key material |
| 189 | * |
| 190 | * \retval PSA_SUCCESS |
| 191 | * Success. |
| 192 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 193 | typedef psa_status_t (*psa_drv_accel_mac_setup_t)(psa_drv_accel_mac_context_t *p_context, |
| 194 | const uint8_t *p_key, |
| 195 | size_t key_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 196 | |
| 197 | /** \brief The function prototype for the update operation of a |
| 198 | * transparent-key MAC operation |
| 199 | * |
| 200 | * Functions that implement the prototype should be named in the following |
| 201 | * convention: |
| 202 | * ~~~~~~~~~~~~~{.c} |
| 203 | * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_update |
| 204 | * ~~~~~~~~~~~~~ |
| 205 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` |
| 206 | * is the specific variant of a MAC operation (such as HMAC or CMAC) |
| 207 | * |
| 208 | * \param[in,out] p_context A hardware-specific structure for the |
| 209 | * previously-established MAC operation to be |
| 210 | * continued |
| 211 | * \param[in] p_input A buffer containing the message to be appended |
| 212 | * to the MAC operation |
| 213 | * \param[in] input_length The size in bytes of the input message buffer |
| 214 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 215 | typedef psa_status_t (*psa_drv_accel_mac_update_t)(psa_drv_accel_mac_context_t *p_context, |
| 216 | const uint8_t *p_input, |
| 217 | size_t input_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 218 | |
| 219 | /** \brief The function prototype for the finish operation of a |
| 220 | * transparent-key MAC operation |
| 221 | * |
| 222 | * Functions that implement the prototype should be named in the following |
| 223 | * convention: |
| 224 | * ~~~~~~~~~~~~~{.c} |
| 225 | * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish |
| 226 | * ~~~~~~~~~~~~~ |
| 227 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 228 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 229 | * |
| 230 | * \param[in,out] p_context A hardware-specific structure for the |
| 231 | * previously started MAC operation to be |
| 232 | * finished |
| 233 | * \param[out] p_mac A buffer where the generated MAC will be placed |
| 234 | * \param[in] mac_length The size in bytes of the buffer that has been |
| 235 | * allocated for the `p_mac` buffer |
| 236 | * |
| 237 | * \retval PSA_SUCCESS |
| 238 | * Success. |
| 239 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 240 | typedef psa_status_t (*psa_drv_accel_mac_finish_t)(psa_drv_accel_mac_context_t *p_context, |
| 241 | uint8_t *p_mac, |
| 242 | size_t mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 243 | |
| 244 | /** \brief The function prototype for the finish and verify operation of a |
| 245 | * transparent-key MAC operation |
| 246 | * |
| 247 | * Functions that implement the prototype should be named in the following |
| 248 | * convention: |
| 249 | * ~~~~~~~~~~~~~{.c} |
| 250 | * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_finish_verify |
| 251 | * ~~~~~~~~~~~~~ |
| 252 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 253 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 254 | * |
| 255 | * \param[in,out] p_context A hardware-specific structure for the |
| 256 | * previously started MAC operation to be |
| 257 | * verified and finished |
| 258 | * \param[in] p_mac A buffer containing the MAC that will be used |
| 259 | * for verification |
| 260 | * \param[in] mac_length The size in bytes of the data in the `p_mac` |
| 261 | * buffer |
| 262 | * |
| 263 | * \retval PSA_SUCCESS |
| 264 | * The operation completed successfully and the comparison matched |
| 265 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 266 | typedef psa_status_t (*psa_drv_accel_mac_finish_verify_t)(psa_drv_accel_mac_context_t *p_context, |
| 267 | const uint8_t *p_mac, |
| 268 | size_t mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 269 | |
| 270 | /** \brief The function prototype for the abort operation for a previously |
| 271 | * started transparent-key MAC operation |
| 272 | * |
| 273 | * Functions that implement the prototype should be named in the following |
| 274 | * convention: |
| 275 | * ~~~~~~~~~~~~~{.c} |
| 276 | * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_abort |
| 277 | * ~~~~~~~~~~~~~ |
| 278 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 279 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 280 | * |
| 281 | * \param[in,out] p_context A hardware-specific structure for the |
| 282 | * previously started MAC operation to be |
| 283 | * aborted |
| 284 | * |
| 285 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 286 | typedef psa_status_t (*psa_drv_accel_mac_abort_t)(psa_drv_accel_mac_context_t *p_context); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 287 | |
| 288 | /** \brief The function prototype for a one-shot operation of a transparent-key |
| 289 | * MAC operation |
| 290 | * |
| 291 | * Functions that implement the prototype should be named in the following |
| 292 | * convention: |
| 293 | * ~~~~~~~~~~~~~{.c} |
| 294 | * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT> |
| 295 | * ~~~~~~~~~~~~~ |
| 296 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 297 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 298 | * |
| 299 | * \param[in] p_input A buffer containing the data to be MACed |
| 300 | * \param[in] input_length The length in bytes of the `p_input` data |
| 301 | * \param[in] p_key A buffer containing the key material to be used |
| 302 | * for the MAC operation |
| 303 | * \param[in] key_length The length in bytes of the `p_key` data |
| 304 | * \param[in] alg The algorithm to be performed |
| 305 | * \param[out] p_mac The buffer where the resulting MAC will be placed |
| 306 | * upon success |
| 307 | * \param[in] mac_length The length in bytes of the `p_mac` buffer |
| 308 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 309 | typedef psa_status_t (*psa_drv_accel_mac_t)(const uint8_t *p_input, |
| 310 | size_t input_length, |
| 311 | const uint8_t *p_key, |
| 312 | size_t key_length, |
| 313 | psa_algorithm_t alg, |
| 314 | uint8_t *p_mac, |
| 315 | size_t mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 316 | |
| 317 | /** \brief The function prototype for a one-shot operation of a transparent-key |
| 318 | * MAC Verify operation |
| 319 | * |
| 320 | * Functions that implement the prototype should be named in the following |
| 321 | * convention: |
| 322 | * ~~~~~~~~~~~~~{.c} |
| 323 | * psa_drv_mac_transparent_<ALGO>_<MAC_VARIANT>_verify |
| 324 | * ~~~~~~~~~~~~~ |
| 325 | * Where `ALGO` is the name of the underlying algorithm, and `MAC_VARIANT` is |
| 326 | * the specific variant of a MAC operation (such as HMAC or CMAC) |
| 327 | * |
| 328 | * \param[in] p_input A buffer containing the data to be MACed |
| 329 | * \param[in] input_length The length in bytes of the `p_input` data |
| 330 | * \param[in] p_key A buffer containing the key material to be used |
| 331 | * for the MAC operation |
| 332 | * \param[in] key_length The length in bytes of the `p_key` data |
| 333 | * \param[in] alg The algorithm to be performed |
| 334 | * \param[in] p_mac The MAC data to be compared |
| 335 | * \param[in] mac_length The length in bytes of the `p_mac` buffer |
| 336 | * |
| 337 | * \retval PSA_SUCCESS |
| 338 | * The operation completed successfully and the comparison matched |
| 339 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 340 | typedef psa_status_t (*psa_drv_accel_mac_verify_t)(const uint8_t *p_input, |
| 341 | size_t input_length, |
| 342 | const uint8_t *p_key, |
| 343 | size_t key_length, |
| 344 | psa_algorithm_t alg, |
| 345 | const uint8_t *p_mac, |
| 346 | size_t mac_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 347 | /**@}*/ |
| 348 | |
| 349 | /** \defgroup transparent_cipher Transparent Block Cipher |
| 350 | * Encryption and Decryption using transparent keys in block modes other than |
| 351 | * ECB must be done in multiple parts, using the following flow: |
| 352 | * - `psa_drv_cipher_transparent_setup_t` |
| 353 | * - `psa_drv_cipher_transparent_set_iv_t` (optional depending upon block mode) |
| 354 | * - `psa_drv_cipher_transparent_update_t` |
| 355 | * - ... |
| 356 | * - `psa_drv_cipher_transparent_finish_t` |
| 357 | |
| 358 | * If a previously started Transparent Cipher operation needs to be terminated, |
| 359 | * it should be done so by the `psa_drv_cipher_transparent_abort_t`. Failure to do |
| 360 | * so may result in allocated resources not being freed or in other undefined |
| 361 | * behavior. |
| 362 | */ |
| 363 | /**@{*/ |
| 364 | |
| 365 | /** \brief The hardware-specific transparent-key Cipher context structure |
| 366 | * |
| 367 | * The contents of this structure are implementation dependent and are |
| 368 | * therefore not described here. |
| 369 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 370 | typedef struct psa_drv_accel_cipher_context_s psa_drv_accel_cipher_context_t; |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 371 | |
| 372 | /** \brief The function prototype for the setup operation of transparent-key |
| 373 | * block cipher operations. |
| 374 | * Functions that implement the prototype should be named in the following |
| 375 | * conventions: |
| 376 | * ~~~~~~~~~~~~~{.c} |
| 377 | * psa_drv_cipher_transparent_setup_<CIPHER_NAME>_<MODE> |
| 378 | * ~~~~~~~~~~~~~ |
| 379 | * Where |
| 380 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 381 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
| 382 | * or for stream ciphers: |
| 383 | * ~~~~~~~~~~~~~{.c} |
| 384 | * psa_drv_cipher_transparent_setup_<CIPHER_NAME> |
| 385 | * ~~~~~~~~~~~~~ |
| 386 | * Where `CIPHER_NAME` is the name of a stream cipher (i.e. RC4) |
| 387 | * |
| 388 | * \param[in,out] p_context A structure that will contain the |
| 389 | * hardware-specific cipher context |
| 390 | * \param[in] direction Indicates if the operation is an encrypt or a |
| 391 | * decrypt |
| 392 | * \param[in] p_key_data A buffer containing the cleartext key material |
| 393 | * to be used in the operation |
| 394 | * \param[in] key_data_size The size in bytes of the key material |
| 395 | * |
| 396 | * \retval PSA_SUCCESS |
| 397 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 398 | typedef psa_status_t (*psa_drv_accel_cipher_setup_t)(psa_drv_accel_cipher_context_t *p_context, |
| 399 | psa_encrypt_or_decrypt_t direction, |
| 400 | const uint8_t *p_key_data, |
| 401 | size_t key_data_size); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 402 | |
| 403 | /** \brief The function prototype for the set initialization vector operation |
| 404 | * of transparent-key block cipher operations |
| 405 | * Functions that implement the prototype should be named in the following |
| 406 | * convention: |
| 407 | * ~~~~~~~~~~~~~{.c} |
| 408 | * psa_drv_cipher_transparent_set_iv_<CIPHER_NAME>_<MODE> |
| 409 | * ~~~~~~~~~~~~~ |
| 410 | * Where |
| 411 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 412 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
| 413 | * |
| 414 | * \param[in,out] p_context A structure that contains the previously setup |
| 415 | * hardware-specific cipher context |
| 416 | * \param[in] p_iv A buffer containing the initialization vecotr |
| 417 | * \param[in] iv_length The size in bytes of the contents of `p_iv` |
| 418 | * |
| 419 | * \retval PSA_SUCCESS |
| 420 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 421 | typedef psa_status_t (*psa_drv_accel_cipher_set_iv_t)(psa_drv_accel_cipher_context_t *p_context, |
| 422 | const uint8_t *p_iv, |
| 423 | size_t iv_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 424 | |
| 425 | /** \brief The function prototype for the update operation of transparent-key |
| 426 | * block cipher operations. |
| 427 | * |
| 428 | * Functions that implement the prototype should be named in the following |
| 429 | * convention: |
| 430 | * ~~~~~~~~~~~~~{.c} |
| 431 | * psa_drv_cipher_transparent_update_<CIPHER_NAME>_<MODE> |
| 432 | * ~~~~~~~~~~~~~ |
| 433 | * Where |
| 434 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 435 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
| 436 | * |
| 437 | * \param[in,out] p_context A hardware-specific structure for the |
| 438 | * previously started cipher operation |
| 439 | * \param[in] p_input A buffer containing the data to be |
| 440 | * encrypted or decrypted |
| 441 | * \param[in] input_size The size in bytes of the `p_input` buffer |
| 442 | * \param[out] p_output A caller-allocated buffer where the |
| 443 | * generated output will be placed |
| 444 | * \param[in] output_size The size in bytes of the `p_output` buffer |
| 445 | * \param[out] p_output_length After completion, will contain the number |
| 446 | * of bytes placed in the `p_output` buffer |
| 447 | * |
| 448 | * \retval PSA_SUCCESS |
| 449 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 450 | typedef psa_status_t (*psa_drv_accel_cipher_update_t)(psa_drv_accel_cipher_context_t *p_context, |
| 451 | const uint8_t *p_input, |
| 452 | size_t input_size, |
| 453 | uint8_t *p_output, |
| 454 | size_t output_size, |
| 455 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 456 | |
| 457 | /** \brief The function prototype for the finish operation of transparent-key |
| 458 | * block cipher operations. |
| 459 | * |
| 460 | * Functions that implement the prototype should be named in the following |
| 461 | * convention: |
| 462 | * ~~~~~~~~~~~~~{.c} |
| 463 | * psa_drv_cipher_transparent_finish_<CIPHER_NAME>_<MODE> |
| 464 | * ~~~~~~~~~~~~~ |
| 465 | * Where |
| 466 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 467 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
| 468 | * |
| 469 | * \param[in,out] p_context A hardware-specific structure for the |
| 470 | * previously started cipher operation |
| 471 | * \param[out] p_output A caller-allocated buffer where the generated |
| 472 | * output will be placed |
| 473 | * \param[in] output_size The size in bytes of the `p_output` buffer |
| 474 | * \param[out] p_output_length After completion, will contain the number of |
| 475 | * bytes placed in the `p_output` buffer |
| 476 | * |
| 477 | * \retval PSA_SUCCESS |
| 478 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 479 | typedef psa_status_t (*psa_drv_accel_cipher_finish_t)(psa_drv_accel_cipher_context_t *p_context, |
| 480 | uint8_t *p_output, |
| 481 | size_t output_size, |
| 482 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 483 | |
| 484 | /** \brief The function prototype for the abort operation of transparent-key |
| 485 | * block cipher operations. |
| 486 | * |
| 487 | * Functions that implement the following prototype should be named in the |
| 488 | * following convention: |
| 489 | * ~~~~~~~~~~~~~{.c} |
| 490 | * psa_drv_cipher_transparent_abort_<CIPHER_NAME>_<MODE> |
| 491 | * ~~~~~~~~~~~~~ |
| 492 | * Where |
| 493 | * - `CIPHER_NAME` is the name of the underlying block cipher (i.e. AES or DES) |
| 494 | * - `MODE` is the block mode of the cipher operation (i.e. CBC or CTR) |
| 495 | * |
| 496 | * \param[in,out] p_context A hardware-specific structure for the |
| 497 | * previously started cipher operation |
| 498 | * |
| 499 | * \retval PSA_SUCCESS |
| 500 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 501 | typedef psa_status_t (*psa_drv_accel_cipher_abort_t)(psa_drv_accel_cipher_context_t *p_context); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 502 | |
| 503 | /**@}*/ |
| 504 | |
| 505 | /** \defgroup aead_transparent AEAD Transparent |
| 506 | * |
| 507 | * Authenticated Encryption with Additional Data (AEAD) operations with |
| 508 | * transparent keys must be done in one function call. While this creates a |
| 509 | * burden for implementers as there must be sufficient space in memory for the |
| 510 | * entire message, it prevents decrypted data from being made available before |
| 511 | * the authentication operation is complete and the data is known to be |
| 512 | * authentic. |
| 513 | */ |
| 514 | /**@{*/ |
| 515 | |
| 516 | /** Process an authenticated encryption operation using an opaque key. |
| 517 | * |
| 518 | * Functions that implement the prototype should be named in the following |
| 519 | * convention: |
| 520 | * ~~~~~~~~~~~~~{.c} |
| 521 | * psa_drv_aead_<ALGO>_encrypt |
| 522 | * ~~~~~~~~~~~~~ |
| 523 | * Where `ALGO` is the name of the AEAD algorithm |
| 524 | * |
| 525 | * \param[in] p_key A pointer to the key material |
| 526 | * \param[in] key_length The size in bytes of the key material |
| 527 | * \param[in] alg The AEAD algorithm to compute |
| 528 | * (\c PSA_ALG_XXX value such that |
| 529 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 530 | * \param[in] nonce Nonce or IV to use |
| 531 | * \param[in] nonce_length Size of the `nonce` buffer in bytes |
| 532 | * \param[in] additional_data Additional data that will be MACed |
| 533 | * but not encrypted. |
| 534 | * \param[in] additional_data_length Size of `additional_data` in bytes |
| 535 | * \param[in] plaintext Data that will be MACed and |
| 536 | * encrypted. |
| 537 | * \param[in] plaintext_length Size of `plaintext` in bytes |
| 538 | * \param[out] ciphertext Output buffer for the authenticated and |
| 539 | * encrypted data. The additional data is |
| 540 | * not part of this output. For algorithms |
| 541 | * where the encrypted data and the |
| 542 | * authentication tag are defined as |
| 543 | * separate outputs, the authentication |
| 544 | * tag is appended to the encrypted data. |
| 545 | * \param[in] ciphertext_size Size of the `ciphertext` buffer in |
| 546 | * bytes |
| 547 | * This must be at least |
| 548 | * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(`alg`, |
| 549 | * `plaintext_length`). |
| 550 | * \param[out] ciphertext_length On success, the size of the output in |
| 551 | * the `ciphertext` buffer |
| 552 | * |
| 553 | * \retval #PSA_SUCCESS |
| 554 | |
| 555 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 556 | typedef psa_status_t (*psa_drv_accel_aead_encrypt_t)(const uint8_t *p_key, |
| 557 | size_t key_length, |
| 558 | psa_algorithm_t alg, |
| 559 | const uint8_t *nonce, |
| 560 | size_t nonce_length, |
| 561 | const uint8_t *additional_data, |
| 562 | size_t additional_data_length, |
| 563 | const uint8_t *plaintext, |
| 564 | size_t plaintext_length, |
| 565 | uint8_t *ciphertext, |
| 566 | size_t ciphertext_size, |
| 567 | size_t *ciphertext_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 568 | |
| 569 | /** Process an authenticated decryption operation using an opaque key. |
| 570 | * |
| 571 | * Functions that implement the prototype should be named in the following |
| 572 | * convention: |
| 573 | * ~~~~~~~~~~~~~{.c} |
| 574 | * psa_drv_aead_<ALGO>_decrypt |
| 575 | * ~~~~~~~~~~~~~ |
| 576 | * Where `ALGO` is the name of the AEAD algorithm |
| 577 | * \param[in] p_key A pointer to the key material |
| 578 | * \param[in] key_length The size in bytes of the key material |
| 579 | * \param[in] alg The AEAD algorithm to compute |
| 580 | * (\c PSA_ALG_XXX value such that |
| 581 | * #PSA_ALG_IS_AEAD(`alg`) is true) |
| 582 | * \param[in] nonce Nonce or IV to use |
| 583 | * \param[in] nonce_length Size of the `nonce` buffer in bytes |
| 584 | * \param[in] additional_data Additional data that has been MACed |
| 585 | * but not encrypted |
| 586 | * \param[in] additional_data_length Size of `additional_data` in bytes |
| 587 | * \param[in] ciphertext Data that has been MACed and |
| 588 | * encrypted |
| 589 | * For algorithms where the encrypted data |
| 590 | * and the authentication tag are defined |
| 591 | * as separate inputs, the buffer must |
| 592 | * contain the encrypted data followed by |
| 593 | * the authentication tag. |
| 594 | * \param[in] ciphertext_length Size of `ciphertext` in bytes |
| 595 | * \param[out] plaintext Output buffer for the decrypted data |
| 596 | * \param[in] plaintext_size Size of the `plaintext` buffer in |
| 597 | * bytes |
| 598 | * This must be at least |
| 599 | * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(`alg`, |
| 600 | * `ciphertext_length`). |
| 601 | * \param[out] plaintext_length On success, the size of the output |
| 602 | * in the \b plaintext buffer |
| 603 | * |
| 604 | * \retval #PSA_SUCCESS |
| 605 | * Success. |
| 606 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 607 | typedef psa_status_t (*psa_drv_accel_aead_decrypt_t)(const uint8_t *p_key, |
| 608 | size_t key_length, |
| 609 | psa_algorithm_t alg, |
| 610 | const uint8_t *nonce, |
| 611 | size_t nonce_length, |
| 612 | const uint8_t *additional_data, |
| 613 | size_t additional_data_length, |
| 614 | const uint8_t *ciphertext, |
| 615 | size_t ciphertext_length, |
| 616 | uint8_t *plaintext, |
| 617 | size_t plaintext_size, |
| 618 | size_t *plaintext_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 619 | |
| 620 | /**@}*/ |
| 621 | |
| 622 | /** \defgroup transparent_asymmetric Transparent Asymmetric Cryptography |
| 623 | * |
| 624 | * Since the amount of data that can (or should) be encrypted or signed using |
| 625 | * asymmetric keys is limited by the key size, asymmetric key operations using |
| 626 | * transparent keys must be done in single function calls. |
| 627 | */ |
| 628 | /**@{*/ |
| 629 | |
| 630 | |
| 631 | /** |
| 632 | * \brief A function that signs a hash or short message with a transparent |
| 633 | * asymmetric private key |
| 634 | * |
| 635 | * Functions that implement the prototype should be named in the following |
| 636 | * convention: |
| 637 | * ~~~~~~~~~~~~~{.c} |
| 638 | * psa_drv_asymmetric_<ALGO>_sign |
| 639 | * ~~~~~~~~~~~~~ |
| 640 | * Where `ALGO` is the name of the signing algorithm |
| 641 | * |
| 642 | * \param[in] p_key A buffer containing the private key |
| 643 | * material |
| 644 | * \param[in] key_size The size in bytes of the `p_key` data |
| 645 | * \param[in] alg A signature algorithm that is compatible |
| 646 | * with the type of `p_key` |
| 647 | * \param[in] p_hash The hash or message to sign |
| 648 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 649 | * \param[out] p_signature Buffer where the signature is to be written |
| 650 | * \param[in] signature_size Size of the `p_signature` buffer in bytes |
| 651 | * \param[out] p_signature_length On success, the number of bytes |
| 652 | * that make up the returned signature value |
| 653 | * |
| 654 | * \retval PSA_SUCCESS |
| 655 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 656 | typedef psa_status_t (*psa_drv_accel_asymmetric_sign_t)(const uint8_t *p_key, |
| 657 | size_t key_size, |
| 658 | psa_algorithm_t alg, |
| 659 | const uint8_t *p_hash, |
| 660 | size_t hash_length, |
| 661 | uint8_t *p_signature, |
| 662 | size_t signature_size, |
| 663 | size_t *p_signature_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 664 | |
| 665 | /** |
| 666 | * \brief A function that verifies the signature a hash or short message using |
| 667 | * a transparent asymmetric public key |
| 668 | * |
| 669 | * Functions that implement the prototype should be named in the following |
| 670 | * convention: |
| 671 | * ~~~~~~~~~~~~~{.c} |
| 672 | * psa_drv_asymmetric_<ALGO>_verify |
| 673 | * ~~~~~~~~~~~~~ |
| 674 | * Where `ALGO` is the name of the signing algorithm |
| 675 | * |
| 676 | * \param[in] p_key A buffer containing the public key material |
| 677 | * \param[in] key_size The size in bytes of the `p_key` data |
| 678 | * \param[in] alg A signature algorithm that is compatible with |
| 679 | * the type of `key` |
| 680 | * \param[in] p_hash The hash or message whose signature is to be |
| 681 | * verified |
| 682 | * \param[in] hash_length Size of the `p_hash` buffer in bytes |
| 683 | * \param[in] p_signature Buffer containing the signature to verify |
| 684 | * \param[in] signature_length Size of the `p_signature` buffer in bytes |
| 685 | * |
| 686 | * \retval PSA_SUCCESS |
| 687 | * The signature is valid. |
| 688 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 689 | typedef psa_status_t (*psa_drv_accel_asymmetric_verify_t)(const uint8_t *p_key, |
| 690 | size_t key_size, |
| 691 | psa_algorithm_t alg, |
| 692 | const uint8_t *p_hash, |
| 693 | size_t hash_length, |
| 694 | const uint8_t *p_signature, |
| 695 | size_t signature_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 696 | |
| 697 | /** |
| 698 | * \brief A function that encrypts a short message with a transparent |
| 699 | * asymmetric public key |
| 700 | * |
| 701 | * Functions that implement the prototype should be named in the following |
| 702 | * convention: |
| 703 | * ~~~~~~~~~~~~~{.c} |
| 704 | * psa_drv_asymmetric_<ALGO>_encrypt |
| 705 | * ~~~~~~~~~~~~~ |
| 706 | * Where `ALGO` is the name of the encryption algorithm |
| 707 | * |
| 708 | * \param[in] p_key A buffer containing the public key material |
| 709 | * \param[in] key_size The size in bytes of the `p_key` data |
| 710 | * \param[in] alg An asymmetric encryption algorithm that is |
| 711 | * compatible with the type of `key` |
| 712 | * \param[in] p_input The message to encrypt |
| 713 | * \param[in] input_length Size of the `p_input` buffer in bytes |
| 714 | * \param[in] p_salt A salt or label, if supported by the |
| 715 | * encryption algorithm |
| 716 | * If the algorithm does not support a |
| 717 | * salt, pass `NULL` |
| 718 | * If the algorithm supports an optional |
| 719 | * salt and you do not want to pass a salt, |
| 720 | * pass `NULL`. |
| 721 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 722 | * supported. |
| 723 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
| 724 | * If `p_salt` is `NULL`, pass 0. |
| 725 | * \param[out] p_output Buffer where the encrypted message is to |
| 726 | * be written |
| 727 | * \param[in] output_size Size of the `p_output` buffer in bytes |
| 728 | * \param[out] p_output_length On success, the number of bytes |
| 729 | * that make up the returned output |
| 730 | * |
| 731 | * \retval PSA_SUCCESS |
| 732 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 733 | typedef psa_status_t (*psa_drv_accel_asymmetric_encrypt_t)(const uint8_t *p_key, |
| 734 | size_t key_size, |
| 735 | psa_algorithm_t alg, |
| 736 | const uint8_t *p_input, |
| 737 | size_t input_length, |
| 738 | const uint8_t *p_salt, |
| 739 | size_t salt_length, |
| 740 | uint8_t *p_output, |
| 741 | size_t output_size, |
| 742 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 743 | |
| 744 | /** |
| 745 | * \brief Decrypt a short message with a transparent asymmetric private key |
| 746 | * |
| 747 | * Functions that implement the prototype should be named in the following |
| 748 | * convention: |
| 749 | * ~~~~~~~~~~~~~{.c} |
| 750 | * psa_drv_asymmetric_<ALGO>_decrypt |
| 751 | * ~~~~~~~~~~~~~ |
| 752 | * Where `ALGO` is the name of the encryption algorithm |
| 753 | * |
| 754 | * \param[in] p_key A buffer containing the private key material |
| 755 | * \param[in] key_size The size in bytes of the `p_key` data |
| 756 | * \param[in] alg An asymmetric encryption algorithm that is |
| 757 | * compatible with the type of `key` |
| 758 | * \param[in] p_input The message to decrypt |
| 759 | * \param[in] input_length Size of the `p_input` buffer in bytes |
| 760 | * \param[in] p_salt A salt or label, if supported by the |
| 761 | * encryption algorithm |
| 762 | * If the algorithm does not support a |
| 763 | * salt, pass `NULL`. |
| 764 | * If the algorithm supports an optional |
| 765 | * salt and you do not want to pass a salt, |
| 766 | * pass `NULL`. |
| 767 | * For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 768 | * supported |
| 769 | * \param[in] salt_length Size of the `p_salt` buffer in bytes |
| 770 | * If `p_salt` is `NULL`, pass 0 |
| 771 | * \param[out] p_output Buffer where the decrypted message is to |
| 772 | * be written |
| 773 | * \param[in] output_size Size of the `p_output` buffer in bytes |
| 774 | * \param[out] p_output_length On success, the number of bytes |
| 775 | * that make up the returned output |
| 776 | * |
| 777 | * \retval PSA_SUCCESS |
| 778 | */ |
Derek Miller | 83d2662 | 2019-02-15 16:41:22 -0600 | [diff] [blame] | 779 | typedef psa_status_t (*psa_drv_accel_asymmetric_decrypt_t)(const uint8_t *p_key, |
| 780 | size_t key_size, |
| 781 | psa_algorithm_t alg, |
| 782 | const uint8_t *p_input, |
| 783 | size_t input_length, |
| 784 | const uint8_t *p_salt, |
| 785 | size_t salt_length, |
| 786 | uint8_t *p_output, |
| 787 | size_t output_size, |
| 788 | size_t *p_output_length); |
Gilles Peskine | 7597689 | 2018-12-12 15:55:09 +0100 | [diff] [blame] | 789 | |
| 790 | /**@}*/ |
| 791 | |
| 792 | #ifdef __cplusplus |
| 793 | } |
| 794 | #endif |
| 795 | |
| 796 | #endif /* PSA_CRYPTO_ACCEL_DRIVER_H */ |