Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 1 | /* |
Antonio de Angelis | c26af63 | 2021-10-07 15:04:12 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2022, Arm Limited. All rights reserved. |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __TFM_CRYPTO_API_H__ |
| 9 | #define __TFM_CRYPTO_API_H__ |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | #include <stdint.h> |
| 16 | #include "tfm_crypto_defs.h" |
Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame^] | 17 | #include "tfm_crypto_key.h" |
Soby Mathew | d7b79f2 | 2020-05-21 15:06:54 +0100 | [diff] [blame] | 18 | #include "psa/crypto_client_struct.h" |
| 19 | |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 20 | /** |
| 21 | * \brief List of possible operation types supported by the TFM based |
| 22 | * implementation. This type is needed by the operation allocation, |
| 23 | * lookup and release functions. |
| 24 | * |
| 25 | */ |
| 26 | enum tfm_crypto_operation_type { |
| 27 | TFM_CRYPTO_OPERATION_NONE = 0, |
| 28 | TFM_CRYPTO_CIPHER_OPERATION = 1, |
| 29 | TFM_CRYPTO_MAC_OPERATION = 2, |
| 30 | TFM_CRYPTO_HASH_OPERATION = 3, |
Antonio de Angelis | 04debbd | 2019-10-14 12:12:52 +0100 | [diff] [blame] | 31 | TFM_CRYPTO_KEY_DERIVATION_OPERATION = 4, |
Antonio de Angelis | c26af63 | 2021-10-07 15:04:12 +0100 | [diff] [blame] | 32 | TFM_CRYPTO_AEAD_OPERATION = 5, |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 33 | |
| 34 | /* Used to force the enum size */ |
| 35 | TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX |
| 36 | }; |
| 37 | |
David Hu | c9679cc | 2022-06-21 13:09:34 +0800 | [diff] [blame] | 38 | /* |
| 39 | * Macro to determine the group_id corresponding to a function_id by |
| 40 | * accessing the tfm_crypto_func_sid table |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 41 | */ |
David Hu | c9679cc | 2022-06-21 13:09:34 +0800 | [diff] [blame] | 42 | #define TFM_CRYPTO_GET_GROUP_ID(_function_id) \ |
| 43 | ((enum tfm_crypto_group_id)((_function_id) & 0xFF)) |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 44 | |
| 45 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 46 | * \brief Initialise the service |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 47 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 48 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 49 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 50 | psa_status_t tfm_crypto_init(void); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 51 | |
| 52 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 53 | * \brief Initialise the Alloc module |
| 54 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 55 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 56 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 57 | psa_status_t tfm_crypto_init_alloc(void); |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 58 | |
| 59 | /** |
Antonio de Angelis | 60a6fe6 | 2019-06-18 15:27:34 +0100 | [diff] [blame] | 60 | * \brief Returns the ID of the caller |
| 61 | * |
| 62 | * \param[out] id Pointer to hold the ID of the caller |
| 63 | * |
| 64 | * \return Return values as described in \ref psa_status_t |
| 65 | */ |
| 66 | psa_status_t tfm_crypto_get_caller_id(int32_t *id); |
| 67 | |
| 68 | /** |
Jamie Fox | 98ab441 | 2020-01-17 17:12:30 +0000 | [diff] [blame] | 69 | * \brief Gets key attributes from client key attributes. |
| 70 | * |
| 71 | * \param[in] client_key_attr Client key attributes |
| 72 | * \param[in] client_id Partition ID of the calling client |
| 73 | * \param[out] key_attributes Key attributes |
| 74 | * |
| 75 | * \return Return values as described in \ref psa_status_t |
| 76 | */ |
| 77 | psa_status_t tfm_crypto_key_attributes_from_client( |
Maulik Patel | 28659c4 | 2021-01-06 14:09:22 +0000 | [diff] [blame] | 78 | const struct psa_client_key_attributes_s *client_key_attr, |
| 79 | int32_t client_id, |
| 80 | psa_key_attributes_t *key_attributes); |
Jamie Fox | 98ab441 | 2020-01-17 17:12:30 +0000 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * \brief Converts key attributes to client key attributes. |
| 84 | * |
| 85 | * \param[in] key_attributes Key attributes |
| 86 | * \param[out] client_key_attr Client key attributes |
| 87 | * |
| 88 | * \return Return values as described in \ref psa_status_t |
| 89 | */ |
| 90 | psa_status_t tfm_crypto_key_attributes_to_client( |
Maulik Patel | 28659c4 | 2021-01-06 14:09:22 +0000 | [diff] [blame] | 91 | const psa_key_attributes_t *key_attributes, |
| 92 | struct psa_client_key_attributes_s *client_key_attr); |
Jamie Fox | 98ab441 | 2020-01-17 17:12:30 +0000 | [diff] [blame] | 93 | |
| 94 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 95 | * \brief Allocate an operation context in the backend |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 96 | * |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 97 | * \param[in] type Type of the operation context to allocate |
Antonio de Angelis | 60a6fe6 | 2019-06-18 15:27:34 +0100 | [diff] [blame] | 98 | * \param[out] handle Pointer to hold the allocated handle |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 99 | * \param[out ctx Double pointer to the corresponding context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 100 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 101 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 102 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 103 | psa_status_t tfm_crypto_operation_alloc(enum tfm_crypto_operation_type type, |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 104 | uint32_t *handle, |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 105 | void **ctx); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 106 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 107 | * \brief Release an operation context in the backend |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 108 | * |
David Hu | c9679cc | 2022-06-21 13:09:34 +0800 | [diff] [blame] | 109 | * \param[in/out] handle Pointer to the handle of the context to release |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 110 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 111 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 112 | */ |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 113 | psa_status_t tfm_crypto_operation_release(uint32_t *handle); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 114 | /** |
Antonio de Angelis | 819c2f3 | 2019-02-06 14:32:02 +0000 | [diff] [blame] | 115 | * \brief Look up an operation context in the backend for the corresponding |
| 116 | * frontend operation |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 117 | * |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 118 | * \param[in] type Type of the operation context to look up |
| 119 | * \param[in] handle Handle of the context to lookup |
| 120 | * \param[out] ctx Double pointer to the corresponding context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 121 | * |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 122 | * \return Return values as described in \ref psa_status_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 123 | */ |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 124 | psa_status_t tfm_crypto_operation_lookup(enum tfm_crypto_operation_type type, |
Antonio de Angelis | 4743e67 | 2019-04-11 11:38:48 +0100 | [diff] [blame] | 125 | uint32_t handle, |
Antonio de Angelis | ab85ccd | 2019-03-25 15:14:29 +0000 | [diff] [blame] | 126 | void **ctx); |
David Hu | c9679cc | 2022-06-21 13:09:34 +0800 | [diff] [blame] | 127 | |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 128 | /** |
| 129 | * \brief This function acts as interface from the framework dispatching |
| 130 | * calls to the set of functions that implement the PSA Crypto APIs. |
| 131 | * It is based on the Uniform Signatures prototype. |
| 132 | * |
| 133 | * \param[in] in_vec Array of invec parameters |
| 134 | * \param[in] in_len Length of the valid entries in in_vec |
| 135 | * \param[out] out_vec Array of outvec parameters |
| 136 | * \param[in] out_len Length of the valid entries in out_vec |
| 137 | * |
| 138 | * \return Return values as described in \ref psa_status_t |
| 139 | */ |
| 140 | psa_status_t tfm_crypto_api_dispatcher(psa_invec in_vec[], |
| 141 | size_t in_len, |
| 142 | psa_outvec out_vec[], |
| 143 | size_t out_len); |
| 144 | /** |
| 145 | * \brief This function acts as interface for the Key management module |
| 146 | * |
| 147 | * \param[in] in_vec Array of invec parameters |
| 148 | * \param[out] out_vec Array of outvec parameters |
| 149 | * \param[in] encoded_key Key encoded with partition_id and key_id |
| 150 | * |
| 151 | * \return Return values as described in \ref psa_status_t |
| 152 | */ |
| 153 | psa_status_t tfm_crypto_key_management_interface(psa_invec in_vec[], |
| 154 | psa_outvec out_vec[], |
Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame^] | 155 | struct tfm_crypto_key_id_s *encoded_key); |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 156 | /** |
| 157 | * \brief This function acts as interface for the MAC module |
| 158 | * |
| 159 | * \param[in] in_vec Array of invec parameters |
| 160 | * \param[out] out_vec Array of outvec parameters |
| 161 | * \param[in] encoded_key Key encoded with partition_id and key_id |
| 162 | * |
| 163 | * \return Return values as described in \ref psa_status_t |
| 164 | */ |
| 165 | psa_status_t tfm_crypto_mac_interface(psa_invec in_vec[], |
| 166 | psa_outvec out_vec[], |
Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame^] | 167 | struct tfm_crypto_key_id_s *encoded_key); |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 168 | /** |
| 169 | * \brief This function acts as interface for the Cipher module |
| 170 | * |
| 171 | * \param[in] in_vec Array of invec parameters |
| 172 | * \param[out] out_vec Array of outvec parameters |
| 173 | * \param[in] encoded_key Key encoded with partition_id and key_id |
| 174 | * |
| 175 | * \return Return values as described in \ref psa_status_t |
| 176 | */ |
| 177 | psa_status_t tfm_crypto_cipher_interface(psa_invec in_vec[], |
| 178 | psa_outvec out_vec[], |
Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame^] | 179 | struct tfm_crypto_key_id_s *encoded_key); |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 180 | /** |
| 181 | * \brief This function acts as interface for the AEAD module |
| 182 | * |
| 183 | * \param[in] in_vec Array of invec parameters |
| 184 | * \param[out] out_vec Array of outvec parameters |
| 185 | * \param[in] encoded_key Key encoded with partition_id and key_id |
| 186 | * |
| 187 | * \return Return values as described in \ref psa_status_t |
| 188 | */ |
| 189 | psa_status_t tfm_crypto_aead_interface(psa_invec in_vec[], |
| 190 | psa_outvec out_vec[], |
Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame^] | 191 | struct tfm_crypto_key_id_s *encoded_key); |
David Hu | 1eb1194 | 2022-07-05 11:36:34 +0800 | [diff] [blame] | 192 | |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 193 | /** |
David Hu | 1eb1194 | 2022-07-05 11:36:34 +0800 | [diff] [blame] | 194 | * \brief This function acts as interface for the Asymmetric signing module |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 195 | * |
| 196 | * \param[in] in_vec Array of invec parameters |
| 197 | * \param[out] out_vec Array of outvec parameters |
| 198 | * \param[in] encoded_key Key encoded with partition_id and key_id |
| 199 | * |
| 200 | * \return Return values as described in \ref psa_status_t |
| 201 | */ |
David Hu | 1eb1194 | 2022-07-05 11:36:34 +0800 | [diff] [blame] | 202 | psa_status_t tfm_crypto_asymmetric_sign_interface(psa_invec in_vec[], |
| 203 | psa_outvec out_vec[], |
Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame^] | 204 | struct tfm_crypto_key_id_s *encoded_key); |
David Hu | 1eb1194 | 2022-07-05 11:36:34 +0800 | [diff] [blame] | 205 | |
| 206 | /** |
| 207 | * \brief This function acts as interface for the Asymmetric encryption module |
| 208 | * |
| 209 | * \param[in] in_vec Array of invec parameters |
| 210 | * \param[out] out_vec Array of outvec parameters |
| 211 | * \param[in] encoded_key Key encoded with partition_id and key_id |
| 212 | * |
| 213 | * \return Return values as described in \ref psa_status_t |
| 214 | */ |
| 215 | psa_status_t tfm_crypto_asymmetric_encrypt_interface(psa_invec in_vec[], |
| 216 | psa_outvec out_vec[], |
Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame^] | 217 | struct tfm_crypto_key_id_s *encoded_key); |
David Hu | 1eb1194 | 2022-07-05 11:36:34 +0800 | [diff] [blame] | 218 | |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 219 | /** |
| 220 | * \brief This function acts as interface for the Key derivation module |
| 221 | * |
| 222 | * \param[in] in_vec Array of invec parameters |
| 223 | * \param[out] out_vec Array of outvec parameters |
| 224 | * \param[in] encoded_key Key encoded with partition_id and key_id |
| 225 | * |
| 226 | * \return Return values as described in \ref psa_status_t |
| 227 | */ |
| 228 | psa_status_t tfm_crypto_key_derivation_interface(psa_invec in_vec[], |
Antonio de Angelis | 7557e68 | 2022-11-30 15:37:51 +0000 | [diff] [blame^] | 229 | psa_outvec out_vec[], |
| 230 | struct tfm_crypto_key_id_s *encoded_key); |
Antonio de Angelis | 202425a | 2022-04-06 11:13:15 +0100 | [diff] [blame] | 231 | /** |
| 232 | * \brief This function acts as interface for the Random module |
| 233 | * |
| 234 | * \param[in] in_vec Array of invec parameters |
| 235 | * \param[out] out_vec Array of outvec parameters |
| 236 | * |
| 237 | * \return Return values as described in \ref psa_status_t |
| 238 | */ |
| 239 | psa_status_t tfm_crypto_random_interface(psa_invec in_vec[], |
| 240 | psa_outvec out_vec[]); |
| 241 | /** |
| 242 | * \brief This function acts as interface for the Hash module |
| 243 | * |
| 244 | * \param[in] in_vec Array of invec parameters |
| 245 | * \param[out] out_vec Array of outvec parameters |
| 246 | * |
| 247 | * \return Return values as described in \ref psa_status_t |
| 248 | */ |
| 249 | psa_status_t tfm_crypto_hash_interface(psa_invec in_vec[], |
| 250 | psa_outvec out_vec[]); |
Jamie Fox | efd8273 | 2018-11-26 10:34:32 +0000 | [diff] [blame] | 251 | |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 252 | #ifdef __cplusplus |
| 253 | } |
| 254 | #endif |
| 255 | |
| 256 | #endif /* __TFM_CRYPTO_API_H__ */ |