Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa/crypto_struct.h |
| 3 | * |
| 4 | * \brief PSA cryptography module: Mbed TLS structured type implementations |
Gilles Peskine | 07c91f5 | 2018-06-28 18:02:53 +0200 | [diff] [blame] | 5 | * |
| 6 | * \note This file may not be included directly. Applications must |
| 7 | * include psa/crypto.h. |
| 8 | * |
| 9 | * This file contains the definitions of some data structures with |
| 10 | * implementation-specific definitions. |
| 11 | * |
| 12 | * In implementations with isolation between the application and the |
| 13 | * cryptography module, it is expected that the front-end and the back-end |
| 14 | * would have different versions of this file. |
Gilles Peskine | b4e73e9 | 2019-08-13 15:00:57 +0200 | [diff] [blame] | 15 | * |
| 16 | * <h3>Design notes about multipart operation structures</h3> |
| 17 | * |
Ronald Cron | 980230e | 2021-04-01 15:37:49 +0200 | [diff] [blame] | 18 | * For multipart operations without driver delegation support, each multipart |
| 19 | * operation structure contains a `psa_algorithm_t alg` field which indicates |
| 20 | * which specific algorithm the structure is for. When the structure is not in |
| 21 | * use, `alg` is 0. Most of the structure consists of a union which is |
| 22 | * discriminated by `alg`. |
Gilles Peskine | b4e73e9 | 2019-08-13 15:00:57 +0200 | [diff] [blame] | 23 | * |
Ronald Cron | 980230e | 2021-04-01 15:37:49 +0200 | [diff] [blame] | 24 | * For multipart operations with driver delegation support, each multipart |
| 25 | * operation structure contains an `unsigned int id` field indicating which |
| 26 | * driver got assigned to do the operation. When the structure is not in use, |
| 27 | * 'id' is 0. The structure contains also a driver context which is the union |
| 28 | * of the contexts of all drivers able to handle the type of multipart |
| 29 | * operation. |
| 30 | * |
| 31 | * Note that when `alg` or `id` is 0, the content of other fields is undefined. |
Gilles Peskine | b4e73e9 | 2019-08-13 15:00:57 +0200 | [diff] [blame] | 32 | * In particular, it is not guaranteed that a freshly-initialized structure |
| 33 | * is all-zero: we initialize structures to something like `{0, 0}`, which |
| 34 | * is only guaranteed to initializes the first member of the union; |
| 35 | * GCC and Clang initialize the whole structure to 0 (at the time of writing), |
| 36 | * but MSVC and CompCert don't. |
| 37 | * |
Fredrik Hesse | cc207bc | 2021-09-28 21:06:08 +0200 | [diff] [blame] | 38 | * In Mbed TLS, multipart operation structures live independently from |
| 39 | * the key. This allows Mbed TLS to free the key objects when destroying |
Gilles Peskine | b4e73e9 | 2019-08-13 15:00:57 +0200 | [diff] [blame] | 40 | * a key slot. If a multipart operation needs to remember the key after |
| 41 | * the setup function returns, the operation structure needs to contain a |
| 42 | * copy of the key. |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 43 | */ |
| 44 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 45 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 46 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 47 | */ |
| 48 | |
| 49 | #ifndef PSA_CRYPTO_STRUCT_H |
| 50 | #define PSA_CRYPTO_STRUCT_H |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 51 | #include "mbedtls/private_access.h" |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 52 | |
Jaeden Amero | 8013f44 | 2019-08-16 16:13:51 +0100 | [diff] [blame] | 53 | #ifdef __cplusplus |
| 54 | extern "C" { |
| 55 | #endif |
| 56 | |
Ronald Cron | f6d17ca | 2024-11-06 14:11:15 +0100 | [diff] [blame] | 57 | #include "tf-psa-crypto/build_info.h" |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 58 | |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 59 | /* Include the context definition for the compiled-in drivers for the primitive |
| 60 | * algorithms. */ |
Steven Cooreman | 675501d | 2021-04-26 11:54:58 +0200 | [diff] [blame] | 61 | #include "psa/crypto_driver_contexts_primitives.h" |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 62 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 63 | struct psa_hash_operation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 64 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 65 | mbedtls_psa_client_handle_t handle; |
| 66 | #else |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 67 | /** Unique ID indicating which driver got assigned to do the |
| 68 | * operation. Since driver contexts are driver-specific, swapping |
| 69 | * drivers halfway through the operation is not supported. |
Ronald Cron | 980230e | 2021-04-01 15:37:49 +0200 | [diff] [blame] | 70 | * ID values are auto-generated in psa_driver_wrappers.h. |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 71 | * ID value zero means the context is not valid or not assigned to |
Ronald Cron | 980230e | 2021-04-01 15:37:49 +0200 | [diff] [blame] | 72 | * any driver (i.e. the driver context is not active, in use). */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 73 | unsigned int MBEDTLS_PRIVATE(id); |
| 74 | psa_driver_hash_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 75 | #endif |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 76 | }; |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 77 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 78 | #define PSA_HASH_OPERATION_INIT { 0 } |
| 79 | #else |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 80 | #define PSA_HASH_OPERATION_INIT { 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 81 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 82 | static inline struct psa_hash_operation_s psa_hash_operation_init(void) |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 83 | { |
| 84 | const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 85 | return v; |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 88 | struct psa_cipher_operation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 89 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 90 | mbedtls_psa_client_handle_t handle; |
| 91 | #else |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 92 | /** Unique ID indicating which driver got assigned to do the |
| 93 | * operation. Since driver contexts are driver-specific, swapping |
| 94 | * drivers halfway through the operation is not supported. |
| 95 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 96 | * ID value zero means the context is not valid or not assigned to |
| 97 | * any driver (i.e. none of the driver contexts are active). */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 98 | unsigned int MBEDTLS_PRIVATE(id); |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 99 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 100 | unsigned int MBEDTLS_PRIVATE(iv_required) : 1; |
| 101 | unsigned int MBEDTLS_PRIVATE(iv_set) : 1; |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 102 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 103 | uint8_t MBEDTLS_PRIVATE(default_iv_length); |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 104 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 105 | psa_driver_cipher_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 106 | #endif |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 107 | }; |
| 108 | |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 109 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 110 | #define PSA_CIPHER_OPERATION_INIT { 0 } |
| 111 | #else |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 112 | #define PSA_CIPHER_OPERATION_INIT { 0, 0, 0, 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 113 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 114 | static inline struct psa_cipher_operation_s psa_cipher_operation_init(void) |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 115 | { |
| 116 | const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 117 | return v; |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Steven Cooreman | 3c8dd63 | 2021-04-26 12:16:27 +0200 | [diff] [blame] | 120 | /* Include the context definition for the compiled-in drivers for the composite |
| 121 | * algorithms. */ |
| 122 | #include "psa/crypto_driver_contexts_composites.h" |
Nir Sonnenschein | dcd636a | 2018-06-04 16:03:32 +0300 | [diff] [blame] | 123 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 124 | struct psa_mac_operation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 125 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 126 | mbedtls_psa_client_handle_t handle; |
| 127 | #else |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 128 | /** Unique ID indicating which driver got assigned to do the |
| 129 | * operation. Since driver contexts are driver-specific, swapping |
| 130 | * drivers halfway through the operation is not supported. |
| 131 | * ID values are auto-generated in psa_driver_wrappers.h |
| 132 | * ID value zero means the context is not valid or not assigned to |
| 133 | * any driver (i.e. none of the driver contexts are active). */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 134 | unsigned int MBEDTLS_PRIVATE(id); |
| 135 | uint8_t MBEDTLS_PRIVATE(mac_size); |
| 136 | unsigned int MBEDTLS_PRIVATE(is_sign) : 1; |
| 137 | psa_driver_mac_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 138 | #endif |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 139 | }; |
| 140 | |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 141 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 142 | #define PSA_MAC_OPERATION_INIT { 0 } |
| 143 | #else |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 144 | #define PSA_MAC_OPERATION_INIT { 0, 0, 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 145 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 146 | static inline struct psa_mac_operation_s psa_mac_operation_init(void) |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 147 | { |
| 148 | const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 149 | return v; |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 152 | struct psa_aead_operation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 153 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 154 | mbedtls_psa_client_handle_t handle; |
| 155 | #else |
Paul Elliott | 6504aa6 | 2021-04-20 17:09:36 +0100 | [diff] [blame] | 156 | /** Unique ID indicating which driver got assigned to do the |
| 157 | * operation. Since driver contexts are driver-specific, swapping |
| 158 | * drivers halfway through the operation is not supported. |
| 159 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 160 | * ID value zero means the context is not valid or not assigned to |
| 161 | * any driver (i.e. none of the driver contexts are active). */ |
Paul Elliott | c7e7fe5 | 2021-09-27 09:23:40 +0100 | [diff] [blame] | 162 | unsigned int MBEDTLS_PRIVATE(id); |
Paul Elliott | 6504aa6 | 2021-04-20 17:09:36 +0100 | [diff] [blame] | 163 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 164 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
Paul Elliott | 71b0567 | 2021-09-24 11:18:13 +0100 | [diff] [blame] | 165 | psa_key_type_t MBEDTLS_PRIVATE(key_type); |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 166 | |
Paul Elliott | 71b0567 | 2021-09-24 11:18:13 +0100 | [diff] [blame] | 167 | size_t MBEDTLS_PRIVATE(ad_remaining); |
| 168 | size_t MBEDTLS_PRIVATE(body_remaining); |
Paul Elliott | ee4ffe0 | 2021-05-20 17:25:06 +0100 | [diff] [blame] | 169 | |
Paul Elliott | 71b0567 | 2021-09-24 11:18:13 +0100 | [diff] [blame] | 170 | unsigned int MBEDTLS_PRIVATE(nonce_set) : 1; |
| 171 | unsigned int MBEDTLS_PRIVATE(lengths_set) : 1; |
| 172 | unsigned int MBEDTLS_PRIVATE(ad_started) : 1; |
| 173 | unsigned int MBEDTLS_PRIVATE(body_started) : 1; |
| 174 | unsigned int MBEDTLS_PRIVATE(is_encrypt) : 1; |
Paul Elliott | 07a30c4 | 2021-04-20 14:13:23 +0100 | [diff] [blame] | 175 | |
Paul Elliott | 71b0567 | 2021-09-24 11:18:13 +0100 | [diff] [blame] | 176 | psa_driver_aead_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 177 | #endif |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 180 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 181 | #define PSA_AEAD_OPERATION_INIT { 0 } |
| 182 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 183 | #define PSA_AEAD_OPERATION_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 184 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 185 | static inline struct psa_aead_operation_s psa_aead_operation_init(void) |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 186 | { |
| 187 | const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 188 | return v; |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Ronald Cron | 2f10fce | 2023-01-11 09:21:47 +0100 | [diff] [blame] | 191 | /* Include the context definition for the compiled-in drivers for the key |
| 192 | * derivation algorithms. */ |
| 193 | #include "psa/crypto_driver_contexts_key_derivation.h" |
Hanno Becker | c8a41d7 | 2018-10-09 17:33:01 +0100 | [diff] [blame] | 194 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 195 | struct psa_key_derivation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 196 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 197 | mbedtls_psa_client_handle_t handle; |
| 198 | #else |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 199 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
| 200 | unsigned int MBEDTLS_PRIVATE(can_output_key) : 1; |
| 201 | size_t MBEDTLS_PRIVATE(capacity); |
Ronald Cron | 2f10fce | 2023-01-11 09:21:47 +0100 | [diff] [blame] | 202 | psa_driver_key_derivation_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 203 | #endif |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 204 | }; |
| 205 | |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 206 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 207 | #define PSA_KEY_DERIVATION_OPERATION_INIT { 0 } |
| 208 | #else |
Janos Follath | adbec81 | 2019-06-14 11:05:39 +0100 | [diff] [blame] | 209 | /* This only zeroes out the first byte in the union, the rest is unspecified. */ |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 210 | #define PSA_KEY_DERIVATION_OPERATION_INIT { 0, 0, 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 211 | #endif |
Janos Follath | 0dcda95 | 2021-06-07 14:52:13 +0100 | [diff] [blame] | 212 | static inline struct psa_key_derivation_s psa_key_derivation_operation_init( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 213 | void) |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 214 | { |
Gilles Peskine | cbe6650 | 2019-05-16 16:59:18 +0200 | [diff] [blame] | 215 | const struct psa_key_derivation_s v = PSA_KEY_DERIVATION_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 216 | return v; |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Gilles Peskine | f940828 | 2024-06-06 21:11:44 +0200 | [diff] [blame] | 219 | struct psa_custom_key_parameters_s { |
Gilles Peskine | 6d81cbc | 2024-02-12 16:25:19 +0100 | [diff] [blame] | 220 | /* Future versions may add other fields in this structure. */ |
| 221 | uint32_t flags; |
Gilles Peskine | f940828 | 2024-06-06 21:11:44 +0200 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | /** The default production parameters for key generation or key derivation. |
| 225 | * |
| 226 | * Calling psa_generate_key_custom() or psa_key_derivation_output_key_custom() |
| 227 | * with `custom=PSA_CUSTOM_KEY_PARAMETERS_INIT` and `custom_data_length=0` is |
| 228 | * equivalent to calling psa_generate_key() or psa_key_derivation_output_key() |
| 229 | * respectively. |
| 230 | */ |
| 231 | #define PSA_CUSTOM_KEY_PARAMETERS_INIT { 0 } |
| 232 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 233 | struct psa_key_policy_s { |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 234 | psa_key_usage_t MBEDTLS_PRIVATE(usage); |
| 235 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
| 236 | psa_algorithm_t MBEDTLS_PRIVATE(alg2); |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 237 | }; |
Gilles Peskine | a3dd737 | 2019-04-19 19:42:26 +0200 | [diff] [blame] | 238 | typedef struct psa_key_policy_s psa_key_policy_t; |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 239 | |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 240 | #define PSA_KEY_POLICY_INIT { 0, 0, 0 } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 241 | static inline struct psa_key_policy_s psa_key_policy_init(void) |
Jaeden Amero | 70261c5 | 2019-01-04 11:47:20 +0000 | [diff] [blame] | 242 | { |
| 243 | const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 244 | return v; |
Jaeden Amero | 70261c5 | 2019-01-04 11:47:20 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Gilles Peskine | 68cc433b | 2019-07-30 17:42:47 +0200 | [diff] [blame] | 247 | /* The type used internally for key sizes. |
| 248 | * Public interfaces use size_t, but internally we use a smaller type. */ |
| 249 | typedef uint16_t psa_key_bits_t; |
| 250 | /* The maximum value of the type used to represent bit-sizes. |
| 251 | * This is used to mark an invalid key size. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 252 | #define PSA_KEY_BITS_TOO_LARGE ((psa_key_bits_t) -1) |
Gilles Peskine | c744d99 | 2019-07-30 17:26:54 +0200 | [diff] [blame] | 253 | /* The maximum size of a key in bits. |
Gilles Peskine | 68cc433b | 2019-07-30 17:42:47 +0200 | [diff] [blame] | 254 | * Currently defined as the maximum that can be represented, rounded down |
| 255 | * to a whole number of bytes. |
| 256 | * This is an uncast value so that it can be used in preprocessor |
| 257 | * conditionals. */ |
Gilles Peskine | c744d99 | 2019-07-30 17:26:54 +0200 | [diff] [blame] | 258 | #define PSA_MAX_KEY_BITS 0xfff8 |
| 259 | |
Gilles Peskine | 7fad3ef | 2024-02-28 01:08:27 +0100 | [diff] [blame] | 260 | struct psa_key_attributes_s { |
Gilles Peskine | 7fad3ef | 2024-02-28 01:08:27 +0100 | [diff] [blame] | 261 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 262 | psa_key_slot_number_t MBEDTLS_PRIVATE(slot_number); |
Gilles Peskine | 972539c | 2024-02-28 01:49:45 +0100 | [diff] [blame] | 263 | int MBEDTLS_PRIVATE(has_slot_number); |
Gilles Peskine | 7fad3ef | 2024-02-28 01:08:27 +0100 | [diff] [blame] | 264 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 265 | psa_key_type_t MBEDTLS_PRIVATE(type); |
| 266 | psa_key_bits_t MBEDTLS_PRIVATE(bits); |
| 267 | psa_key_lifetime_t MBEDTLS_PRIVATE(lifetime); |
| 268 | psa_key_policy_t MBEDTLS_PRIVATE(policy); |
Gilles Peskine | 7fad3ef | 2024-02-28 01:08:27 +0100 | [diff] [blame] | 269 | /* This type has a different layout in the client view wrt the |
| 270 | * service view of the key id, i.e. in service view usually is |
| 271 | * expected to have MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER defined |
| 272 | * thus adding an owner field to the standard psa_key_id_t. For |
| 273 | * implementations with client/service separation, this means the |
| 274 | * object will be marshalled through a transport channel and |
| 275 | * interpreted differently at each side of the transport. Placing |
| 276 | * it at the end of structures allows to interpret the structure |
| 277 | * at the client without reorganizing the memory layout of the |
| 278 | * struct |
| 279 | */ |
| 280 | mbedtls_svc_key_id_t MBEDTLS_PRIVATE(id); |
Gilles Peskine | 7fad3ef | 2024-02-28 01:08:27 +0100 | [diff] [blame] | 281 | }; |
| 282 | |
Gilles Peskine | 0f40a41 | 2024-02-27 23:21:15 +0100 | [diff] [blame] | 283 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
Gilles Peskine | 972539c | 2024-02-28 01:49:45 +0100 | [diff] [blame] | 284 | #define PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER 0, 0, |
Gilles Peskine | 0f40a41 | 2024-02-27 23:21:15 +0100 | [diff] [blame] | 285 | #else |
| 286 | #define PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER |
| 287 | #endif |
Gilles Peskine | 2dc2bd7 | 2024-02-28 01:32:31 +0100 | [diff] [blame] | 288 | #define PSA_KEY_ATTRIBUTES_INIT { PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER \ |
Gilles Peskine | 0eb4e7f | 2024-02-28 10:56:14 +0100 | [diff] [blame] | 289 | PSA_KEY_TYPE_NONE, 0, \ |
| 290 | PSA_KEY_LIFETIME_VOLATILE, \ |
| 291 | PSA_KEY_POLICY_INIT, \ |
| 292 | MBEDTLS_SVC_KEY_ID_INIT } |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 293 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 294 | static inline struct psa_key_attributes_s psa_key_attributes_init(void) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 295 | { |
| 296 | const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 297 | return v; |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 298 | } |
| 299 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 300 | static inline void psa_set_key_id(psa_key_attributes_t *attributes, |
| 301 | mbedtls_svc_key_id_t key) |
Gilles Peskine | dc8219a | 2019-05-15 16:11:15 +0200 | [diff] [blame] | 302 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 303 | psa_key_lifetime_t lifetime = attributes->MBEDTLS_PRIVATE(lifetime); |
Ronald Cron | d98059d | 2020-10-23 18:00:55 +0200 | [diff] [blame] | 304 | |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 305 | attributes->MBEDTLS_PRIVATE(id) = key; |
Ronald Cron | d98059d | 2020-10-23 18:00:55 +0200 | [diff] [blame] | 306 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 307 | if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 308 | attributes->MBEDTLS_PRIVATE(lifetime) = |
Ronald Cron | d98059d | 2020-10-23 18:00:55 +0200 | [diff] [blame] | 309 | PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( |
| 310 | PSA_KEY_LIFETIME_PERSISTENT, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 311 | PSA_KEY_LIFETIME_GET_LOCATION(lifetime)); |
Ronald Cron | d98059d | 2020-10-23 18:00:55 +0200 | [diff] [blame] | 312 | } |
Gilles Peskine | dc8219a | 2019-05-15 16:11:15 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 315 | static inline mbedtls_svc_key_id_t psa_get_key_id( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 316 | const psa_key_attributes_t *attributes) |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 317 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 318 | return attributes->MBEDTLS_PRIVATE(id); |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Ronald Cron | 6b5ff53 | 2020-10-16 14:38:19 +0200 | [diff] [blame] | 321 | #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 322 | static inline void mbedtls_set_key_owner_id(psa_key_attributes_t *attributes, |
| 323 | mbedtls_key_owner_id_t owner) |
Ronald Cron | 6b5ff53 | 2020-10-16 14:38:19 +0200 | [diff] [blame] | 324 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 325 | attributes->MBEDTLS_PRIVATE(id).MBEDTLS_PRIVATE(owner) = owner; |
Ronald Cron | 6b5ff53 | 2020-10-16 14:38:19 +0200 | [diff] [blame] | 326 | } |
| 327 | #endif |
| 328 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 329 | static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes, |
| 330 | psa_key_lifetime_t lifetime) |
Gilles Peskine | dc8219a | 2019-05-15 16:11:15 +0200 | [diff] [blame] | 331 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 332 | attributes->MBEDTLS_PRIVATE(lifetime) = lifetime; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 333 | if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) { |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 334 | #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 335 | attributes->MBEDTLS_PRIVATE(id).MBEDTLS_PRIVATE(key_id) = 0; |
Jaeden Amero | e3cdf28 | 2019-08-20 12:58:20 +0100 | [diff] [blame] | 336 | #else |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 337 | attributes->MBEDTLS_PRIVATE(id) = 0; |
Jaeden Amero | e3cdf28 | 2019-08-20 12:58:20 +0100 | [diff] [blame] | 338 | #endif |
| 339 | } |
Gilles Peskine | dc8219a | 2019-05-15 16:11:15 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 342 | static inline psa_key_lifetime_t psa_get_key_lifetime( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 343 | const psa_key_attributes_t *attributes) |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 344 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 345 | return attributes->MBEDTLS_PRIVATE(lifetime); |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 346 | } |
| 347 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 348 | static inline void psa_extend_key_usage_flags(psa_key_usage_t *usage_flags) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 349 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 350 | if (*usage_flags & PSA_KEY_USAGE_SIGN_HASH) { |
gabor-mezei-arm | 43110b6 | 2021-06-23 16:48:08 +0200 | [diff] [blame] | 351 | *usage_flags |= PSA_KEY_USAGE_SIGN_MESSAGE; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 352 | } |
gabor-mezei-arm | 86bf008 | 2021-04-29 15:57:57 +0200 | [diff] [blame] | 353 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 354 | if (*usage_flags & PSA_KEY_USAGE_VERIFY_HASH) { |
gabor-mezei-arm | 43110b6 | 2021-06-23 16:48:08 +0200 | [diff] [blame] | 355 | *usage_flags |= PSA_KEY_USAGE_VERIFY_MESSAGE; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 356 | } |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes, |
| 360 | psa_key_usage_t usage_flags) |
| 361 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 362 | psa_extend_key_usage_flags(&usage_flags); |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 363 | attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(usage) = usage_flags; |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static inline psa_key_usage_t psa_get_key_usage_flags( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 367 | const psa_key_attributes_t *attributes) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 368 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 369 | return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(usage); |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 370 | } |
| 371 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 372 | static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes, |
| 373 | psa_algorithm_t alg) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 374 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 375 | attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg) = alg; |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static inline psa_algorithm_t psa_get_key_algorithm( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 379 | const psa_key_attributes_t *attributes) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 380 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 381 | return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg); |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 382 | } |
| 383 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 384 | static inline void psa_set_key_type(psa_key_attributes_t *attributes, |
| 385 | psa_key_type_t type) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 386 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 387 | attributes->MBEDTLS_PRIVATE(type) = type; |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | static inline psa_key_type_t psa_get_key_type( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 391 | const psa_key_attributes_t *attributes) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 392 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 393 | return attributes->MBEDTLS_PRIVATE(type); |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 396 | static inline void psa_set_key_bits(psa_key_attributes_t *attributes, |
| 397 | size_t bits) |
Gilles Peskine | 3a4f1f8 | 2019-04-26 13:49:28 +0200 | [diff] [blame] | 398 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 399 | if (bits > PSA_MAX_KEY_BITS) { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 400 | attributes->MBEDTLS_PRIVATE(bits) = PSA_KEY_BITS_TOO_LARGE; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 401 | } else { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 402 | attributes->MBEDTLS_PRIVATE(bits) = (psa_key_bits_t) bits; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 403 | } |
Gilles Peskine | 3a4f1f8 | 2019-04-26 13:49:28 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 406 | static inline size_t psa_get_key_bits( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 407 | const psa_key_attributes_t *attributes) |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 408 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 409 | return attributes->MBEDTLS_PRIVATE(bits); |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 412 | /** |
| 413 | * \brief The context for PSA interruptible hash signing. |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 414 | */ |
| 415 | struct psa_sign_hash_interruptible_operation_s { |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 416 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 417 | mbedtls_psa_client_handle_t handle; |
| 418 | #else |
Paul Elliott | 2d24792 | 2022-11-29 14:54:44 +0000 | [diff] [blame] | 419 | /** Unique ID indicating which driver got assigned to do the |
| 420 | * operation. Since driver contexts are driver-specific, swapping |
| 421 | * drivers halfway through the operation is not supported. |
| 422 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 423 | * ID value zero means the context is not valid or not assigned to |
| 424 | * any driver (i.e. none of the driver contexts are active). */ |
| 425 | unsigned int MBEDTLS_PRIVATE(id); |
| 426 | |
Paul Elliott | 588f8ed | 2022-12-02 18:10:26 +0000 | [diff] [blame] | 427 | psa_driver_sign_hash_interruptible_context_t MBEDTLS_PRIVATE(ctx); |
| 428 | |
Paul Elliott | c977441 | 2023-02-06 15:14:07 +0000 | [diff] [blame] | 429 | unsigned int MBEDTLS_PRIVATE(error_occurred) : 1; |
| 430 | |
Paul Elliott | 296ede9 | 2022-12-15 17:00:30 +0000 | [diff] [blame] | 431 | uint32_t MBEDTLS_PRIVATE(num_ops); |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 432 | #endif |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 433 | }; |
| 434 | |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 435 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 436 | #define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 } |
| 437 | #else |
Paul Elliott | c977441 | 2023-02-06 15:14:07 +0000 | [diff] [blame] | 438 | #define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, { 0 }, 0, 0 } |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 439 | #endif |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 440 | |
| 441 | static inline struct psa_sign_hash_interruptible_operation_s |
| 442 | psa_sign_hash_interruptible_operation_init(void) |
| 443 | { |
| 444 | const struct psa_sign_hash_interruptible_operation_s v = |
| 445 | PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT; |
| 446 | |
| 447 | return v; |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * \brief The context for PSA interruptible hash verification. |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 452 | */ |
| 453 | struct psa_verify_hash_interruptible_operation_s { |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 454 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 455 | mbedtls_psa_client_handle_t handle; |
| 456 | #else |
Paul Elliott | 2d24792 | 2022-11-29 14:54:44 +0000 | [diff] [blame] | 457 | /** Unique ID indicating which driver got assigned to do the |
| 458 | * operation. Since driver contexts are driver-specific, swapping |
| 459 | * drivers halfway through the operation is not supported. |
| 460 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 461 | * ID value zero means the context is not valid or not assigned to |
| 462 | * any driver (i.e. none of the driver contexts are active). */ |
| 463 | unsigned int MBEDTLS_PRIVATE(id); |
| 464 | |
Paul Elliott | 588f8ed | 2022-12-02 18:10:26 +0000 | [diff] [blame] | 465 | psa_driver_verify_hash_interruptible_context_t MBEDTLS_PRIVATE(ctx); |
| 466 | |
Paul Elliott | c977441 | 2023-02-06 15:14:07 +0000 | [diff] [blame] | 467 | unsigned int MBEDTLS_PRIVATE(error_occurred) : 1; |
| 468 | |
Paul Elliott | 296ede9 | 2022-12-15 17:00:30 +0000 | [diff] [blame] | 469 | uint32_t MBEDTLS_PRIVATE(num_ops); |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 470 | #endif |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 471 | }; |
| 472 | |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 473 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 474 | #define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 } |
| 475 | #else |
Paul Elliott | c977441 | 2023-02-06 15:14:07 +0000 | [diff] [blame] | 476 | #define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, { 0 }, 0, 0 } |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 477 | #endif |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 478 | |
| 479 | static inline struct psa_verify_hash_interruptible_operation_s |
| 480 | psa_verify_hash_interruptible_operation_init(void) |
| 481 | { |
| 482 | const struct psa_verify_hash_interruptible_operation_s v = |
| 483 | PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT; |
| 484 | |
| 485 | return v; |
| 486 | } |
| 487 | |
Paul Elliott | 03d62b1 | 2024-07-18 19:31:57 +0100 | [diff] [blame] | 488 | /** |
| 489 | * \brief The context for PSA interruptible key agreement. |
| 490 | */ |
| 491 | struct psa_key_agreement_iop_s { |
| 492 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 493 | mbedtls_psa_client_handle_t handle; |
| 494 | #else |
| 495 | /** |
| 496 | * Unique ID indicating which driver got assigned to do the |
| 497 | * operation. Since driver contexts are driver-specific, swapping |
| 498 | * drivers halfway through the operation is not supported. |
| 499 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 500 | * ID value zero means the context is not valid or not assigned to |
| 501 | * any driver (i.e. none of the driver contexts are active). |
| 502 | */ |
| 503 | unsigned int MBEDTLS_PRIVATE(id); |
Waleed Elmelegy | 86e518b | 2024-10-30 16:38:31 +0000 | [diff] [blame] | 504 | mbedtls_psa_key_agreement_interruptible_operation_t MBEDTLS_PRIVATE(mbedtls_ctx); |
Waleed Elmelegy | a2891a9 | 2024-08-06 10:55:09 +0100 | [diff] [blame] | 505 | uint32_t MBEDTLS_PRIVATE(num_ops); |
Waleed Elmelegy | 93be7a1 | 2024-09-24 18:26:25 +0100 | [diff] [blame] | 506 | psa_key_attributes_t MBEDTLS_PRIVATE(attributes); |
Waleed Elmelegy | a98aeaf | 2024-09-24 21:04:54 +0100 | [diff] [blame] | 507 | unsigned int MBEDTLS_PRIVATE(error_occurred) : 1; |
Paul Elliott | 03d62b1 | 2024-07-18 19:31:57 +0100 | [diff] [blame] | 508 | #endif |
| 509 | }; |
| 510 | |
| 511 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 512 | #define PSA_KEY_AGREEMENT_IOP_INIT { 0 } |
| 513 | #else |
Waleed Elmelegy | e980fbe | 2024-11-01 16:19:28 +0000 | [diff] [blame] | 514 | #define PSA_KEY_AGREEMENT_IOP_INIT { 0, MBEDTLS_PSA_KEY_AGREEMENT_IOP_INIT, 0, \ |
| 515 | PSA_KEY_ATTRIBUTES_INIT, 0 } |
Paul Elliott | 03d62b1 | 2024-07-18 19:31:57 +0100 | [diff] [blame] | 516 | #endif |
| 517 | |
| 518 | static inline struct psa_key_agreement_iop_s |
| 519 | psa_key_agreement_iop_init(void) |
| 520 | { |
| 521 | const struct psa_key_agreement_iop_s v = PSA_KEY_AGREEMENT_IOP_INIT; |
| 522 | |
| 523 | return v; |
| 524 | } |
| 525 | |
Paul Elliott | 9e143a7 | 2024-07-18 19:31:57 +0100 | [diff] [blame] | 526 | /** |
Waleed Elmelegy | 5fc76a9 | 2024-11-15 17:28:29 +0000 | [diff] [blame] | 527 | * \brief The context for PSA interruptible key generation. |
Paul Elliott | 9e143a7 | 2024-07-18 19:31:57 +0100 | [diff] [blame] | 528 | */ |
| 529 | struct psa_generate_key_iop_s { |
| 530 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 531 | mbedtls_psa_client_handle_t handle; |
| 532 | #else |
| 533 | /** |
| 534 | * Unique ID indicating which driver got assigned to do the |
| 535 | * operation. Since driver contexts are driver-specific, swapping |
| 536 | * drivers halfway through the operation is not supported. |
| 537 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 538 | * ID value zero means the context is not valid or not assigned to |
| 539 | * any driver (i.e. none of the driver contexts are active). |
| 540 | */ |
| 541 | unsigned int MBEDTLS_PRIVATE(id); |
Waleed Elmelegy | cca4dbe | 2024-09-25 17:49:14 +0100 | [diff] [blame] | 542 | mbedtls_psa_generate_key_iop_t MBEDTLS_PRIVATE(ctx); |
| 543 | psa_key_attributes_t MBEDTLS_PRIVATE(attributes); |
| 544 | unsigned int MBEDTLS_PRIVATE(error_occurred) : 1; |
| 545 | uint32_t MBEDTLS_PRIVATE(num_ops); |
Paul Elliott | 9e143a7 | 2024-07-18 19:31:57 +0100 | [diff] [blame] | 546 | #endif |
| 547 | }; |
| 548 | |
| 549 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 550 | #define PSA_GENERATE_KEY_IOP_INIT { 0 } |
| 551 | #else |
Waleed Elmelegy | cca4dbe | 2024-09-25 17:49:14 +0100 | [diff] [blame] | 552 | #define PSA_GENERATE_KEY_IOP_INIT { 0, MBEDTLS_PSA_GENERATE_KEY_IOP_INIT, PSA_KEY_ATTRIBUTES_INIT, \ |
| 553 | 0, 0 } |
Paul Elliott | 9e143a7 | 2024-07-18 19:31:57 +0100 | [diff] [blame] | 554 | #endif |
| 555 | |
| 556 | static inline struct psa_generate_key_iop_s |
| 557 | psa_generate_key_iop_init(void) |
| 558 | { |
| 559 | const struct psa_generate_key_iop_s v = PSA_GENERATE_KEY_IOP_INIT; |
| 560 | |
| 561 | return v; |
| 562 | } |
| 563 | |
Waleed Elmelegy | e34a5c5 | 2024-11-15 16:31:34 +0000 | [diff] [blame] | 564 | /** |
| 565 | * \brief The context for PSA interruptible export public-key. |
| 566 | */ |
| 567 | struct psa_export_public_key_iop_s { |
| 568 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 569 | mbedtls_psa_client_handle_t handle; |
| 570 | #else |
| 571 | /** |
| 572 | * Unique ID indicating which driver got assigned to do the |
| 573 | * operation. Since driver contexts are driver-specific, swapping |
| 574 | * drivers halfway through the operation is not supported. |
| 575 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 576 | * ID value zero means the context is not valid or not assigned to |
| 577 | * any driver (i.e. none of the driver contexts are active). |
| 578 | */ |
| 579 | unsigned int MBEDTLS_PRIVATE(id); |
Waleed Elmelegy | 3c46535 | 2024-12-03 14:34:35 +0000 | [diff] [blame] | 580 | mbedtls_psa_export_public_key_iop_t MBEDTLS_PRIVATE(ctx); |
Waleed Elmelegy | 9958ff6 | 2024-11-20 11:47:13 +0000 | [diff] [blame] | 581 | unsigned int MBEDTLS_PRIVATE(error_occurred) : 1; |
| 582 | uint32_t MBEDTLS_PRIVATE(num_ops); |
Waleed Elmelegy | e34a5c5 | 2024-11-15 16:31:34 +0000 | [diff] [blame] | 583 | #endif |
| 584 | }; |
Waleed Elmelegy | 9958ff6 | 2024-11-20 11:47:13 +0000 | [diff] [blame] | 585 | |
Waleed Elmelegy | e34a5c5 | 2024-11-15 16:31:34 +0000 | [diff] [blame] | 586 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 587 | #define PSA_EXPORT_PUBLIC_KEY_IOP_INIT { 0 } |
| 588 | #else |
Waleed Elmelegy | 9958ff6 | 2024-11-20 11:47:13 +0000 | [diff] [blame] | 589 | #define PSA_EXPORT_PUBLIC_KEY_IOP_INIT { 0, MBEDTLS_PSA_EXPORT_PUBLIC_KEY_IOP_INIT, 0, 0 } |
Waleed Elmelegy | e34a5c5 | 2024-11-15 16:31:34 +0000 | [diff] [blame] | 590 | #endif |
| 591 | |
Waleed Elmelegy | 9958ff6 | 2024-11-20 11:47:13 +0000 | [diff] [blame] | 592 | static inline struct psa_export_public_key_iop_s |
| 593 | psa_export_public_key_iop_init(void) |
Waleed Elmelegy | e34a5c5 | 2024-11-15 16:31:34 +0000 | [diff] [blame] | 594 | { |
| 595 | const struct psa_export_public_key_iop_s v = PSA_EXPORT_PUBLIC_KEY_IOP_INIT; |
| 596 | |
| 597 | return v; |
| 598 | } |
| 599 | |
Jaeden Amero | 8013f44 | 2019-08-16 16:13:51 +0100 | [diff] [blame] | 600 | #ifdef __cplusplus |
| 601 | } |
| 602 | #endif |
| 603 | |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 604 | #endif /* PSA_CRYPTO_STRUCT_H */ |