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 | 7871cb1 | 2023-10-10 08:51:39 +0200 | [diff] [blame] | 57 | /* |
| 58 | * Include the build-time configuration information header. Here, we do not |
| 59 | * include `"mbedtls/build_info.h"` directly but `"psa/build_info.h"`, which |
| 60 | * is basically just an alias to it. This is to ease the maintenance of the |
| 61 | * TF-PSA-Crypto repository which has a different build system and |
| 62 | * configuration. |
| 63 | */ |
| 64 | #include "psa/build_info.h" |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 65 | |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 66 | /* Include the context definition for the compiled-in drivers for the primitive |
| 67 | * algorithms. */ |
Steven Cooreman | 675501d | 2021-04-26 11:54:58 +0200 | [diff] [blame] | 68 | #include "psa/crypto_driver_contexts_primitives.h" |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 69 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 70 | struct psa_hash_operation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 71 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 72 | mbedtls_psa_client_handle_t handle; |
| 73 | #else |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 74 | /** Unique ID indicating which driver got assigned to do the |
| 75 | * operation. Since driver contexts are driver-specific, swapping |
| 76 | * drivers halfway through the operation is not supported. |
Ronald Cron | 980230e | 2021-04-01 15:37:49 +0200 | [diff] [blame] | 77 | * ID values are auto-generated in psa_driver_wrappers.h. |
Steven Cooreman | dbf8ced | 2021-03-04 13:01:18 +0100 | [diff] [blame] | 78 | * 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] | 79 | * any driver (i.e. the driver context is not active, in use). */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 80 | unsigned int MBEDTLS_PRIVATE(id); |
| 81 | psa_driver_hash_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 82 | #endif |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 83 | }; |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 84 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 85 | #define PSA_HASH_OPERATION_INIT { 0 } |
| 86 | #else |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 87 | #define PSA_HASH_OPERATION_INIT { 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 88 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 89 | static inline struct psa_hash_operation_s psa_hash_operation_init(void) |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 90 | { |
| 91 | const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 92 | return v; |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 95 | struct psa_cipher_operation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 96 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 97 | mbedtls_psa_client_handle_t handle; |
| 98 | #else |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 99 | /** Unique ID indicating which driver got assigned to do the |
| 100 | * operation. Since driver contexts are driver-specific, swapping |
| 101 | * drivers halfway through the operation is not supported. |
| 102 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 103 | * ID value zero means the context is not valid or not assigned to |
| 104 | * any driver (i.e. none of the driver contexts are active). */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 105 | unsigned int MBEDTLS_PRIVATE(id); |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 106 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 107 | unsigned int MBEDTLS_PRIVATE(iv_required) : 1; |
| 108 | unsigned int MBEDTLS_PRIVATE(iv_set) : 1; |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 109 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 110 | uint8_t MBEDTLS_PRIVATE(default_iv_length); |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 111 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 112 | psa_driver_cipher_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 113 | #endif |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 114 | }; |
| 115 | |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 116 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 117 | #define PSA_CIPHER_OPERATION_INIT { 0 } |
| 118 | #else |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 119 | #define PSA_CIPHER_OPERATION_INIT { 0, 0, 0, 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 120 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 121 | static inline struct psa_cipher_operation_s psa_cipher_operation_init(void) |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 122 | { |
| 123 | const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 124 | return v; |
Steven Cooreman | 61398ec | 2021-04-26 12:04:53 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Steven Cooreman | 3c8dd63 | 2021-04-26 12:16:27 +0200 | [diff] [blame] | 127 | /* Include the context definition for the compiled-in drivers for the composite |
| 128 | * algorithms. */ |
| 129 | #include "psa/crypto_driver_contexts_composites.h" |
Nir Sonnenschein | dcd636a | 2018-06-04 16:03:32 +0300 | [diff] [blame] | 130 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 131 | struct psa_mac_operation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 132 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 133 | mbedtls_psa_client_handle_t handle; |
| 134 | #else |
Steven Cooreman | 77e2cc5 | 2021-03-19 17:05:52 +0100 | [diff] [blame] | 135 | /** Unique ID indicating which driver got assigned to do the |
| 136 | * operation. Since driver contexts are driver-specific, swapping |
| 137 | * drivers halfway through the operation is not supported. |
| 138 | * ID values are auto-generated in psa_driver_wrappers.h |
| 139 | * ID value zero means the context is not valid or not assigned to |
| 140 | * any driver (i.e. none of the driver contexts are active). */ |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 141 | unsigned int MBEDTLS_PRIVATE(id); |
| 142 | uint8_t MBEDTLS_PRIVATE(mac_size); |
| 143 | unsigned int MBEDTLS_PRIVATE(is_sign) : 1; |
| 144 | psa_driver_mac_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 145 | #endif |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 148 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 149 | #define PSA_MAC_OPERATION_INIT { 0 } |
| 150 | #else |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 151 | #define PSA_MAC_OPERATION_INIT { 0, 0, 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 152 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 153 | static inline struct psa_mac_operation_s psa_mac_operation_init(void) |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 154 | { |
| 155 | const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 156 | return v; |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 159 | struct psa_aead_operation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 160 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 161 | mbedtls_psa_client_handle_t handle; |
| 162 | #else |
Paul Elliott | 6504aa6 | 2021-04-20 17:09:36 +0100 | [diff] [blame] | 163 | /** Unique ID indicating which driver got assigned to do the |
| 164 | * operation. Since driver contexts are driver-specific, swapping |
| 165 | * drivers halfway through the operation is not supported. |
| 166 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 167 | * ID value zero means the context is not valid or not assigned to |
| 168 | * any driver (i.e. none of the driver contexts are active). */ |
Paul Elliott | c7e7fe5 | 2021-09-27 09:23:40 +0100 | [diff] [blame] | 169 | unsigned int MBEDTLS_PRIVATE(id); |
Paul Elliott | 6504aa6 | 2021-04-20 17:09:36 +0100 | [diff] [blame] | 170 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 171 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
Paul Elliott | 71b0567 | 2021-09-24 11:18:13 +0100 | [diff] [blame] | 172 | psa_key_type_t MBEDTLS_PRIVATE(key_type); |
Paul Elliott | cbbde5f | 2021-05-10 18:19:46 +0100 | [diff] [blame] | 173 | |
Paul Elliott | 71b0567 | 2021-09-24 11:18:13 +0100 | [diff] [blame] | 174 | size_t MBEDTLS_PRIVATE(ad_remaining); |
| 175 | size_t MBEDTLS_PRIVATE(body_remaining); |
Paul Elliott | ee4ffe0 | 2021-05-20 17:25:06 +0100 | [diff] [blame] | 176 | |
Paul Elliott | 71b0567 | 2021-09-24 11:18:13 +0100 | [diff] [blame] | 177 | unsigned int MBEDTLS_PRIVATE(nonce_set) : 1; |
| 178 | unsigned int MBEDTLS_PRIVATE(lengths_set) : 1; |
| 179 | unsigned int MBEDTLS_PRIVATE(ad_started) : 1; |
| 180 | unsigned int MBEDTLS_PRIVATE(body_started) : 1; |
| 181 | unsigned int MBEDTLS_PRIVATE(is_encrypt) : 1; |
Paul Elliott | 07a30c4 | 2021-04-20 14:13:23 +0100 | [diff] [blame] | 182 | |
Paul Elliott | 71b0567 | 2021-09-24 11:18:13 +0100 | [diff] [blame] | 183 | psa_driver_aead_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 184 | #endif |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 185 | }; |
| 186 | |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 187 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 188 | #define PSA_AEAD_OPERATION_INIT { 0 } |
| 189 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 190 | #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] | 191 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 192 | static inline struct psa_aead_operation_s psa_aead_operation_init(void) |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 193 | { |
| 194 | const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 195 | return v; |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Ronald Cron | 2f10fce | 2023-01-11 09:21:47 +0100 | [diff] [blame] | 198 | /* Include the context definition for the compiled-in drivers for the key |
| 199 | * derivation algorithms. */ |
| 200 | #include "psa/crypto_driver_contexts_key_derivation.h" |
Hanno Becker | c8a41d7 | 2018-10-09 17:33:01 +0100 | [diff] [blame] | 201 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 202 | struct psa_key_derivation_s { |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 203 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 204 | mbedtls_psa_client_handle_t handle; |
| 205 | #else |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 206 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
| 207 | unsigned int MBEDTLS_PRIVATE(can_output_key) : 1; |
| 208 | size_t MBEDTLS_PRIVATE(capacity); |
Ronald Cron | 2f10fce | 2023-01-11 09:21:47 +0100 | [diff] [blame] | 209 | psa_driver_key_derivation_context_t MBEDTLS_PRIVATE(ctx); |
Antonio de Angelis | 6425a18 | 2024-01-22 11:39:34 +0000 | [diff] [blame] | 210 | #endif |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 211 | }; |
| 212 | |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 213 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 214 | #define PSA_KEY_DERIVATION_OPERATION_INIT { 0 } |
| 215 | #else |
Janos Follath | adbec81 | 2019-06-14 11:05:39 +0100 | [diff] [blame] | 216 | /* 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] | 217 | #define PSA_KEY_DERIVATION_OPERATION_INIT { 0, 0, 0, { 0 } } |
Antonio de Angelis | 90d1834 | 2024-01-22 13:15:37 +0000 | [diff] [blame] | 218 | #endif |
Janos Follath | 0dcda95 | 2021-06-07 14:52:13 +0100 | [diff] [blame] | 219 | static inline struct psa_key_derivation_s psa_key_derivation_operation_init( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 220 | void) |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 221 | { |
Gilles Peskine | cbe6650 | 2019-05-16 16:59:18 +0200 | [diff] [blame] | 222 | const struct psa_key_derivation_s v = PSA_KEY_DERIVATION_OPERATION_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 223 | return v; |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Gilles Peskine | 092ce51 | 2024-02-20 12:31:24 +0100 | [diff] [blame] | 226 | struct psa_key_production_parameters_s { |
Gilles Peskine | 6d81cbc | 2024-02-12 16:25:19 +0100 | [diff] [blame] | 227 | /* Future versions may add other fields in this structure. */ |
| 228 | uint32_t flags; |
| 229 | uint8_t data[]; |
| 230 | }; |
| 231 | |
Gilles Peskine | 092ce51 | 2024-02-20 12:31:24 +0100 | [diff] [blame] | 232 | /** The default production parameters for key generation or key derivation. |
Gilles Peskine | 6d81cbc | 2024-02-12 16:25:19 +0100 | [diff] [blame] | 233 | * |
| 234 | * Calling psa_generate_key_ext() or psa_key_derivation_output_key_ext() |
Gilles Peskine | 092ce51 | 2024-02-20 12:31:24 +0100 | [diff] [blame] | 235 | * with `params=PSA_KEY_PRODUCTION_PARAMETERS_INIT` and |
| 236 | * `params_data_length == 0` is equivalent to |
Gilles Peskine | 6d81cbc | 2024-02-12 16:25:19 +0100 | [diff] [blame] | 237 | * calling psa_generate_key() or psa_key_derivation_output_key() |
| 238 | * respectively. |
| 239 | */ |
Gilles Peskine | 092ce51 | 2024-02-20 12:31:24 +0100 | [diff] [blame] | 240 | #define PSA_KEY_PRODUCTION_PARAMETERS_INIT { 0 } |
Gilles Peskine | 6d81cbc | 2024-02-12 16:25:19 +0100 | [diff] [blame] | 241 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 242 | struct psa_key_policy_s { |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 243 | psa_key_usage_t MBEDTLS_PRIVATE(usage); |
| 244 | psa_algorithm_t MBEDTLS_PRIVATE(alg); |
| 245 | psa_algorithm_t MBEDTLS_PRIVATE(alg2); |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 246 | }; |
Gilles Peskine | a3dd737 | 2019-04-19 19:42:26 +0200 | [diff] [blame] | 247 | typedef struct psa_key_policy_s psa_key_policy_t; |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 248 | |
Janos Follath | 33434a9 | 2021-05-26 09:25:33 +0100 | [diff] [blame] | 249 | #define PSA_KEY_POLICY_INIT { 0, 0, 0 } |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 250 | static inline struct psa_key_policy_s psa_key_policy_init(void) |
Jaeden Amero | 70261c5 | 2019-01-04 11:47:20 +0000 | [diff] [blame] | 251 | { |
| 252 | const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 253 | return v; |
Jaeden Amero | 70261c5 | 2019-01-04 11:47:20 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Gilles Peskine | 68cc433b | 2019-07-30 17:42:47 +0200 | [diff] [blame] | 256 | /* The type used internally for key sizes. |
| 257 | * Public interfaces use size_t, but internally we use a smaller type. */ |
| 258 | typedef uint16_t psa_key_bits_t; |
| 259 | /* The maximum value of the type used to represent bit-sizes. |
| 260 | * This is used to mark an invalid key size. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 261 | #define PSA_KEY_BITS_TOO_LARGE ((psa_key_bits_t) -1) |
Gilles Peskine | c744d99 | 2019-07-30 17:26:54 +0200 | [diff] [blame] | 262 | /* The maximum size of a key in bits. |
Gilles Peskine | 68cc433b | 2019-07-30 17:42:47 +0200 | [diff] [blame] | 263 | * Currently defined as the maximum that can be represented, rounded down |
| 264 | * to a whole number of bytes. |
| 265 | * This is an uncast value so that it can be used in preprocessor |
| 266 | * conditionals. */ |
Gilles Peskine | c744d99 | 2019-07-30 17:26:54 +0200 | [diff] [blame] | 267 | #define PSA_MAX_KEY_BITS 0xfff8 |
| 268 | |
Gilles Peskine | 91e8c33 | 2019-08-02 19:19:39 +0200 | [diff] [blame] | 269 | /** A mask of flags that can be stored in key attributes. |
| 270 | * |
| 271 | * This type is also used internally to store flags in slots. Internal |
| 272 | * flags are defined in library/psa_crypto_core.h. Internal flags may have |
| 273 | * the same value as external flags if they are properly handled during |
| 274 | * key creation and in psa_get_key_attributes. |
| 275 | */ |
| 276 | typedef uint16_t psa_key_attributes_flag_t; |
| 277 | |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 278 | #define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 279 | ((psa_key_attributes_flag_t) 0x0001) |
Gilles Peskine | 91e8c33 | 2019-08-02 19:19:39 +0200 | [diff] [blame] | 280 | |
| 281 | /* A mask of key attribute flags used externally only. |
| 282 | * Only meant for internal checks inside the library. */ |
| 283 | #define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \ |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 284 | MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 285 | 0) |
Gilles Peskine | 91e8c33 | 2019-08-02 19:19:39 +0200 | [diff] [blame] | 286 | |
| 287 | /* A mask of key attribute flags used both internally and externally. |
| 288 | * Currently there aren't any. */ |
| 289 | #define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 290 | 0) |
Gilles Peskine | 91e8c33 | 2019-08-02 19:19:39 +0200 | [diff] [blame] | 291 | |
Gilles Peskine | 7fad3ef | 2024-02-28 01:08:27 +0100 | [diff] [blame] | 292 | struct psa_key_attributes_s { |
Gilles Peskine | 7fad3ef | 2024-02-28 01:08:27 +0100 | [diff] [blame] | 293 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 294 | psa_key_slot_number_t MBEDTLS_PRIVATE(slot_number); |
| 295 | #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ |
| 296 | psa_key_type_t MBEDTLS_PRIVATE(type); |
| 297 | psa_key_bits_t MBEDTLS_PRIVATE(bits); |
| 298 | psa_key_lifetime_t MBEDTLS_PRIVATE(lifetime); |
| 299 | psa_key_policy_t MBEDTLS_PRIVATE(policy); |
| 300 | psa_key_attributes_flag_t MBEDTLS_PRIVATE(flags); |
| 301 | /* This type has a different layout in the client view wrt the |
| 302 | * service view of the key id, i.e. in service view usually is |
| 303 | * expected to have MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER defined |
| 304 | * thus adding an owner field to the standard psa_key_id_t. For |
| 305 | * implementations with client/service separation, this means the |
| 306 | * object will be marshalled through a transport channel and |
| 307 | * interpreted differently at each side of the transport. Placing |
| 308 | * it at the end of structures allows to interpret the structure |
| 309 | * at the client without reorganizing the memory layout of the |
| 310 | * struct |
| 311 | */ |
| 312 | mbedtls_svc_key_id_t MBEDTLS_PRIVATE(id); |
Gilles Peskine | 7fad3ef | 2024-02-28 01:08:27 +0100 | [diff] [blame] | 313 | }; |
| 314 | |
Gilles Peskine | 0f40a41 | 2024-02-27 23:21:15 +0100 | [diff] [blame] | 315 | #if defined(MBEDTLS_PSA_CRYPTO_SE_C) |
| 316 | #define PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER 0, |
| 317 | #else |
| 318 | #define PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER |
| 319 | #endif |
Gilles Peskine | 2dc2bd7 | 2024-02-28 01:32:31 +0100 | [diff] [blame^] | 320 | #define PSA_KEY_ATTRIBUTES_INIT { PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER \ |
| 321 | PSA_KEY_TYPE_NONE, 0, \ |
| 322 | PSA_KEY_LIFETIME_VOLATILE, \ |
| 323 | PSA_KEY_POLICY_INIT, 0, \ |
| 324 | MBEDTLS_SVC_KEY_ID_INIT } |
Gilles Peskine | c8000c0 | 2019-08-02 20:15:51 +0200 | [diff] [blame] | 325 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 326 | static inline struct psa_key_attributes_s psa_key_attributes_init(void) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 327 | { |
| 328 | const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 329 | return v; |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 330 | } |
| 331 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 332 | static inline void psa_set_key_id(psa_key_attributes_t *attributes, |
| 333 | mbedtls_svc_key_id_t key) |
Gilles Peskine | dc8219a | 2019-05-15 16:11:15 +0200 | [diff] [blame] | 334 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 335 | psa_key_lifetime_t lifetime = attributes->MBEDTLS_PRIVATE(lifetime); |
Ronald Cron | d98059d | 2020-10-23 18:00:55 +0200 | [diff] [blame] | 336 | |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 337 | attributes->MBEDTLS_PRIVATE(id) = key; |
Ronald Cron | d98059d | 2020-10-23 18:00:55 +0200 | [diff] [blame] | 338 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 339 | if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 340 | attributes->MBEDTLS_PRIVATE(lifetime) = |
Ronald Cron | d98059d | 2020-10-23 18:00:55 +0200 | [diff] [blame] | 341 | PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( |
| 342 | PSA_KEY_LIFETIME_PERSISTENT, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 343 | PSA_KEY_LIFETIME_GET_LOCATION(lifetime)); |
Ronald Cron | d98059d | 2020-10-23 18:00:55 +0200 | [diff] [blame] | 344 | } |
Gilles Peskine | dc8219a | 2019-05-15 16:11:15 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 347 | static inline mbedtls_svc_key_id_t psa_get_key_id( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 348 | const psa_key_attributes_t *attributes) |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 349 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 350 | return attributes->MBEDTLS_PRIVATE(id); |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Ronald Cron | 6b5ff53 | 2020-10-16 14:38:19 +0200 | [diff] [blame] | 353 | #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 354 | static inline void mbedtls_set_key_owner_id(psa_key_attributes_t *attributes, |
| 355 | mbedtls_key_owner_id_t owner) |
Ronald Cron | 6b5ff53 | 2020-10-16 14:38:19 +0200 | [diff] [blame] | 356 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 357 | attributes->MBEDTLS_PRIVATE(id).MBEDTLS_PRIVATE(owner) = owner; |
Ronald Cron | 6b5ff53 | 2020-10-16 14:38:19 +0200 | [diff] [blame] | 358 | } |
| 359 | #endif |
| 360 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 361 | static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes, |
| 362 | psa_key_lifetime_t lifetime) |
Gilles Peskine | dc8219a | 2019-05-15 16:11:15 +0200 | [diff] [blame] | 363 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 364 | attributes->MBEDTLS_PRIVATE(lifetime) = lifetime; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 365 | if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) { |
Ronald Cron | 71016a9 | 2020-08-28 19:01:50 +0200 | [diff] [blame] | 366 | #ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 367 | attributes->MBEDTLS_PRIVATE(id).MBEDTLS_PRIVATE(key_id) = 0; |
Jaeden Amero | e3cdf28 | 2019-08-20 12:58:20 +0100 | [diff] [blame] | 368 | #else |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 369 | attributes->MBEDTLS_PRIVATE(id) = 0; |
Jaeden Amero | e3cdf28 | 2019-08-20 12:58:20 +0100 | [diff] [blame] | 370 | #endif |
| 371 | } |
Gilles Peskine | dc8219a | 2019-05-15 16:11:15 +0200 | [diff] [blame] | 372 | } |
| 373 | |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 374 | static inline psa_key_lifetime_t psa_get_key_lifetime( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 375 | const psa_key_attributes_t *attributes) |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 376 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 377 | return attributes->MBEDTLS_PRIVATE(lifetime); |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 378 | } |
| 379 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 380 | 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] | 381 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 382 | if (*usage_flags & PSA_KEY_USAGE_SIGN_HASH) { |
gabor-mezei-arm | 43110b6 | 2021-06-23 16:48:08 +0200 | [diff] [blame] | 383 | *usage_flags |= PSA_KEY_USAGE_SIGN_MESSAGE; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 384 | } |
gabor-mezei-arm | 86bf008 | 2021-04-29 15:57:57 +0200 | [diff] [blame] | 385 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 386 | if (*usage_flags & PSA_KEY_USAGE_VERIFY_HASH) { |
gabor-mezei-arm | 43110b6 | 2021-06-23 16:48:08 +0200 | [diff] [blame] | 387 | *usage_flags |= PSA_KEY_USAGE_VERIFY_MESSAGE; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 388 | } |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes, |
| 392 | psa_key_usage_t usage_flags) |
| 393 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 394 | psa_extend_key_usage_flags(&usage_flags); |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 395 | attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(usage) = usage_flags; |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | static inline psa_key_usage_t psa_get_key_usage_flags( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 399 | const psa_key_attributes_t *attributes) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 400 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 401 | return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(usage); |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 404 | static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes, |
| 405 | psa_algorithm_t alg) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 406 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 407 | attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg) = alg; |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static inline psa_algorithm_t psa_get_key_algorithm( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 411 | const psa_key_attributes_t *attributes) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 412 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 413 | return attributes->MBEDTLS_PRIVATE(policy).MBEDTLS_PRIVATE(alg); |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 414 | } |
| 415 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 416 | static inline void psa_set_key_type(psa_key_attributes_t *attributes, |
| 417 | psa_key_type_t type) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 418 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 419 | attributes->MBEDTLS_PRIVATE(type) = type; |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static inline psa_key_type_t psa_get_key_type( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 423 | const psa_key_attributes_t *attributes) |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 424 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 425 | return attributes->MBEDTLS_PRIVATE(type); |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 426 | } |
| 427 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 428 | static inline void psa_set_key_bits(psa_key_attributes_t *attributes, |
| 429 | size_t bits) |
Gilles Peskine | 3a4f1f8 | 2019-04-26 13:49:28 +0200 | [diff] [blame] | 430 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 431 | if (bits > PSA_MAX_KEY_BITS) { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 432 | attributes->MBEDTLS_PRIVATE(bits) = PSA_KEY_BITS_TOO_LARGE; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 433 | } else { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 434 | attributes->MBEDTLS_PRIVATE(bits) = (psa_key_bits_t) bits; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 435 | } |
Gilles Peskine | 3a4f1f8 | 2019-04-26 13:49:28 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 438 | static inline size_t psa_get_key_bits( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 439 | const psa_key_attributes_t *attributes) |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 440 | { |
Gilles Peskine | 2f107ae | 2024-02-28 01:26:46 +0100 | [diff] [blame] | 441 | return attributes->MBEDTLS_PRIVATE(bits); |
Gilles Peskine | db4b3ab | 2019-04-18 12:53:01 +0200 | [diff] [blame] | 442 | } |
| 443 | |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 444 | /** |
| 445 | * \brief The context for PSA interruptible hash signing. |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 446 | */ |
| 447 | struct psa_sign_hash_interruptible_operation_s { |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 448 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 449 | mbedtls_psa_client_handle_t handle; |
| 450 | #else |
Paul Elliott | 2d24792 | 2022-11-29 14:54:44 +0000 | [diff] [blame] | 451 | /** Unique ID indicating which driver got assigned to do the |
| 452 | * operation. Since driver contexts are driver-specific, swapping |
| 453 | * drivers halfway through the operation is not supported. |
| 454 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 455 | * ID value zero means the context is not valid or not assigned to |
| 456 | * any driver (i.e. none of the driver contexts are active). */ |
| 457 | unsigned int MBEDTLS_PRIVATE(id); |
| 458 | |
Paul Elliott | 588f8ed | 2022-12-02 18:10:26 +0000 | [diff] [blame] | 459 | psa_driver_sign_hash_interruptible_context_t MBEDTLS_PRIVATE(ctx); |
| 460 | |
Paul Elliott | c977441 | 2023-02-06 15:14:07 +0000 | [diff] [blame] | 461 | unsigned int MBEDTLS_PRIVATE(error_occurred) : 1; |
| 462 | |
Paul Elliott | 296ede9 | 2022-12-15 17:00:30 +0000 | [diff] [blame] | 463 | uint32_t MBEDTLS_PRIVATE(num_ops); |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 464 | #endif |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 465 | }; |
| 466 | |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 467 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 468 | #define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 } |
| 469 | #else |
Paul Elliott | c977441 | 2023-02-06 15:14:07 +0000 | [diff] [blame] | 470 | #define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, { 0 }, 0, 0 } |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 471 | #endif |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 472 | |
| 473 | static inline struct psa_sign_hash_interruptible_operation_s |
| 474 | psa_sign_hash_interruptible_operation_init(void) |
| 475 | { |
| 476 | const struct psa_sign_hash_interruptible_operation_s v = |
| 477 | PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT; |
| 478 | |
| 479 | return v; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * \brief The context for PSA interruptible hash verification. |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 484 | */ |
| 485 | struct psa_verify_hash_interruptible_operation_s { |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 486 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 487 | mbedtls_psa_client_handle_t handle; |
| 488 | #else |
Paul Elliott | 2d24792 | 2022-11-29 14:54:44 +0000 | [diff] [blame] | 489 | /** Unique ID indicating which driver got assigned to do the |
| 490 | * operation. Since driver contexts are driver-specific, swapping |
| 491 | * drivers halfway through the operation is not supported. |
| 492 | * ID values are auto-generated in psa_crypto_driver_wrappers.h |
| 493 | * ID value zero means the context is not valid or not assigned to |
| 494 | * any driver (i.e. none of the driver contexts are active). */ |
| 495 | unsigned int MBEDTLS_PRIVATE(id); |
| 496 | |
Paul Elliott | 588f8ed | 2022-12-02 18:10:26 +0000 | [diff] [blame] | 497 | psa_driver_verify_hash_interruptible_context_t MBEDTLS_PRIVATE(ctx); |
| 498 | |
Paul Elliott | c977441 | 2023-02-06 15:14:07 +0000 | [diff] [blame] | 499 | unsigned int MBEDTLS_PRIVATE(error_occurred) : 1; |
| 500 | |
Paul Elliott | 296ede9 | 2022-12-15 17:00:30 +0000 | [diff] [blame] | 501 | uint32_t MBEDTLS_PRIVATE(num_ops); |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 502 | #endif |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 503 | }; |
| 504 | |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 505 | #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C) |
| 506 | #define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 } |
| 507 | #else |
Paul Elliott | c977441 | 2023-02-06 15:14:07 +0000 | [diff] [blame] | 508 | #define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, { 0 }, 0, 0 } |
Antonio de Angelis | 4380a33 | 2024-02-02 14:21:24 +0000 | [diff] [blame] | 509 | #endif |
Paul Elliott | 1265f00 | 2022-09-09 17:15:43 +0100 | [diff] [blame] | 510 | |
| 511 | static inline struct psa_verify_hash_interruptible_operation_s |
| 512 | psa_verify_hash_interruptible_operation_init(void) |
| 513 | { |
| 514 | const struct psa_verify_hash_interruptible_operation_s v = |
| 515 | PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT; |
| 516 | |
| 517 | return v; |
| 518 | } |
| 519 | |
Jaeden Amero | 8013f44 | 2019-08-16 16:13:51 +0100 | [diff] [blame] | 520 | #ifdef __cplusplus |
| 521 | } |
| 522 | #endif |
| 523 | |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 524 | #endif /* PSA_CRYPTO_STRUCT_H */ |