Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 1 | /* |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, 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" |
| 17 | #include "psa_crypto.h" |
| 18 | |
| 19 | /** |
| 20 | * \brief List of possible operation types supported by the TFM based |
| 21 | * implementation. This type is needed by the operation allocation, |
| 22 | * lookup and release functions. |
| 23 | * |
| 24 | */ |
| 25 | enum tfm_crypto_operation_type { |
| 26 | TFM_CRYPTO_OPERATION_NONE = 0, |
| 27 | TFM_CRYPTO_CIPHER_OPERATION = 1, |
| 28 | TFM_CRYPTO_MAC_OPERATION = 2, |
| 29 | TFM_CRYPTO_HASH_OPERATION = 3, |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 30 | |
| 31 | /* Used to force the enum size */ |
| 32 | TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX |
| 33 | }; |
| 34 | |
| 35 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 36 | * \brief Initialise the service |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 37 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 38 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 39 | */ |
| 40 | enum tfm_crypto_err_t tfm_crypto_init(void); |
| 41 | |
| 42 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 43 | * \brief Initialise the Key module |
| 44 | * |
| 45 | * \return Return values as described in \ref tfm_crypto_err_t |
| 46 | */ |
| 47 | enum tfm_crypto_err_t tfm_crypto_init_key(void); |
| 48 | |
| 49 | /** |
| 50 | * \brief Initialise the Alloc module |
| 51 | * |
| 52 | * \return Return values as described in \ref tfm_crypto_err_t |
| 53 | */ |
| 54 | enum tfm_crypto_err_t tfm_crypto_init_alloc(void); |
| 55 | |
| 56 | /** |
| 57 | * \brief Allocate an operation object |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 58 | * |
| 59 | * \param[in] type Type of the operation object to allocate |
| 60 | * \param[out] handle Pointer to the corresponding handle assigned |
| 61 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 62 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 63 | */ |
| 64 | enum tfm_crypto_err_t tfm_crypto_operation_alloc( |
| 65 | enum tfm_crypto_operation_type type, |
| 66 | uint32_t *handle); |
| 67 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 68 | * \brief Release an operation object |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 69 | * |
| 70 | * \param[in] handle Pointer to the handle for the release of the |
| 71 | * corresponding object |
| 72 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 73 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 74 | */ |
| 75 | enum tfm_crypto_err_t tfm_crypto_operation_release(uint32_t *handle); |
| 76 | |
| 77 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 78 | * \brief Look up an operation object pointer from the corresponding handle |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 79 | * |
| 80 | * \param[in] type Type of the operation object to look up |
| 81 | * \param[in] handle Handle to the operation object to look up |
| 82 | * \param[out] oper Double pointer to the corresponding object |
| 83 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 84 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 85 | */ |
| 86 | enum tfm_crypto_err_t tfm_crypto_operation_lookup( |
| 87 | enum tfm_crypto_operation_type type, |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 88 | uint32_t handle, |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 89 | void **oper); |
| 90 | /** |
Jamie Fox | efd8273 | 2018-11-26 10:34:32 +0000 | [diff] [blame] | 91 | * \brief Retrieve a key from the provided key slot according to the key |
| 92 | * policy and algorithm provided. This function is expected to be |
| 93 | * called intra-service |
| 94 | * |
| 95 | * \param[in] key Key slot |
| 96 | * \param[in] usage Usage policy to be used on the retrieved key |
| 97 | * \param[in] alg Algorithm to be used for the retrieved key |
| 98 | * \param[out] data Buffer to hold the exported key |
| 99 | * \param[in] data_size Length of the buffer pointed to by data |
| 100 | * \param[out] data_length Length of the exported key |
| 101 | * |
| 102 | * \return Return values as described in \ref tfm_crypto_err_t |
| 103 | */ |
| 104 | enum tfm_crypto_err_t tfm_crypto_get_key(psa_key_slot_t key, |
| 105 | psa_key_usage_t usage, |
| 106 | psa_algorithm_t alg, |
| 107 | uint8_t *data, |
| 108 | size_t data_size, |
| 109 | size_t *data_length); |
| 110 | /** |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 111 | * \brief Import the key data in the provided key slot |
| 112 | * |
| 113 | * \param[in] key Key slot |
| 114 | * \param[in] type Key type |
| 115 | * \param[in] data Key data to import |
| 116 | * \param[in] data_length Length in bytes of the data field |
| 117 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 118 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 119 | */ |
| 120 | enum tfm_crypto_err_t tfm_crypto_import_key(psa_key_slot_t key, |
| 121 | psa_key_type_t type, |
| 122 | const uint8_t *data, |
| 123 | size_t data_length); |
| 124 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 125 | * \brief Destroy the key in the provided key slot |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 126 | * |
| 127 | * \param[in] key Key slot |
| 128 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 129 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 130 | */ |
| 131 | enum tfm_crypto_err_t tfm_crypto_destroy_key(psa_key_slot_t key); |
| 132 | |
| 133 | /** |
| 134 | * \brief Retrieve key information for the provided key slot |
| 135 | * |
| 136 | * \param[in] key Key slot |
| 137 | * \param[out] type Key type associated to the key slot requested |
| 138 | * \param[out] bits Length in bits of the key in the requested slot |
| 139 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 140 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 141 | */ |
| 142 | enum tfm_crypto_err_t tfm_crypto_get_key_information(psa_key_slot_t key, |
| 143 | psa_key_type_t *type, |
| 144 | size_t *bits); |
| 145 | /** |
| 146 | * \brief Export the key contained in the provided key slot |
| 147 | * |
| 148 | * \param[in] key Key slot |
| 149 | * \param[out] data Buffer to hold the exported key |
| 150 | * \param[in] data_size Length of the buffer pointed to by data |
| 151 | * \param[out] data_length Length of the exported key |
| 152 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 153 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 154 | */ |
| 155 | enum tfm_crypto_err_t tfm_crypto_export_key(psa_key_slot_t key, |
| 156 | uint8_t *data, |
| 157 | size_t data_size, |
| 158 | size_t *data_length); |
Jamie Fox | efd8273 | 2018-11-26 10:34:32 +0000 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * \brief Initialise the key policy to a default that forbids any use of the |
| 162 | * key |
| 163 | * |
| 164 | * \param[out] policy Key policy to initialise |
| 165 | * |
| 166 | * \return Return values as described in \ref tfm_crypto_err_t |
| 167 | */ |
| 168 | enum tfm_crypto_err_t tfm_crypto_key_policy_init(psa_key_policy_t *policy); |
| 169 | |
| 170 | /** |
| 171 | * \brief Set the permitted usage and algorithm for the provided key policy |
| 172 | * |
| 173 | * \param[out] policy Key policy to modify |
| 174 | * \param[in] usage Permitted usage |
| 175 | * \param[in] alg Permitted algorithm |
| 176 | * |
| 177 | * \return Return values as described in \ref tfm_crypto_err_t |
| 178 | */ |
| 179 | enum tfm_crypto_err_t tfm_crypto_key_policy_set_usage(psa_key_policy_t *policy, |
| 180 | psa_key_usage_t usage, |
| 181 | psa_algorithm_t alg); |
| 182 | |
| 183 | /** |
| 184 | * \brief Get the permitted usage for the provided key policy |
| 185 | * |
| 186 | * \param[in] policy Key policy |
| 187 | * \param[out] usage Permitted usage for this key policy |
| 188 | * |
| 189 | * \return Return values as described in \ref tfm_crypto_err_t |
| 190 | */ |
| 191 | enum tfm_crypto_err_t tfm_crypto_key_policy_get_usage( |
| 192 | const psa_key_policy_t *policy, |
| 193 | psa_key_usage_t *usage); |
| 194 | |
| 195 | /** |
| 196 | * \brief Get the permitted algorithm for the provided key policy |
| 197 | * |
| 198 | * \param[in] policy Key policy |
| 199 | * \param[out] alg Permitted algorithm for this key policy |
| 200 | * |
| 201 | * \return Return values as described in \ref tfm_crypto_err_t |
| 202 | */ |
| 203 | enum tfm_crypto_err_t tfm_crypto_key_policy_get_algorithm( |
| 204 | const psa_key_policy_t *policy, |
| 205 | psa_algorithm_t *alg); |
| 206 | |
| 207 | /** |
| 208 | * \brief Set the key policy for the provided key slot |
| 209 | * |
| 210 | * \param[in] key Key slot |
| 211 | * \param[in] policy Key policy |
| 212 | * |
| 213 | * \return Return values as described in \ref tfm_crypto_err_t |
| 214 | */ |
| 215 | enum tfm_crypto_err_t tfm_crypto_set_key_policy(psa_key_slot_t key, |
| 216 | const psa_key_policy_t *policy); |
| 217 | |
| 218 | /** |
| 219 | * \brief Get the key policy for the provided key slot |
| 220 | * |
| 221 | * \param[in] key Key slot |
| 222 | * \param[out] policy Key policy |
| 223 | * |
| 224 | * \return Return values as described in \ref tfm_crypto_err_t |
| 225 | */ |
| 226 | enum tfm_crypto_err_t tfm_crypto_get_key_policy(psa_key_slot_t key, |
| 227 | psa_key_policy_t *policy); |
| 228 | |
| 229 | /** |
| 230 | * \brief Set the lifetime for the provided key slot |
| 231 | * |
| 232 | * \param[in] key Key slot |
| 233 | * \param[in] lifetime Lifetime value |
| 234 | * |
| 235 | * \return Return values as described in \ref tfm_crypto_err_t |
| 236 | */ |
| 237 | enum tfm_crypto_err_t tfm_crypto_set_key_lifetime(psa_key_slot_t key, |
| 238 | psa_key_lifetime_t lifetime); |
| 239 | |
| 240 | /** |
| 241 | * \brief Get the lifetime for the provided key slot |
| 242 | * |
| 243 | * \param[in] key Key slot |
| 244 | * \param[out] lifetime Lifetime value |
| 245 | * |
| 246 | * \return Return values as described in \ref tfm_crypto_err_t |
| 247 | */ |
| 248 | enum tfm_crypto_err_t tfm_crypto_get_key_lifetime(psa_key_slot_t key, |
| 249 | psa_key_lifetime_t *lifetime); |
| 250 | |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 251 | /** |
| 252 | * \brief Export the public key contained in the provided key slot |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 253 | * for an asymmetric key pair |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 254 | * |
| 255 | * \param[in] key Key slot |
| 256 | * \param[out] data Buffer to hold the exported key |
| 257 | * \param[in] data_size Length of the buffer pointed to by data |
| 258 | * \param[out] data_length Length of the exported key |
| 259 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 260 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 261 | */ |
| 262 | enum tfm_crypto_err_t tfm_crypto_export_public_key(psa_key_slot_t key, |
| 263 | uint8_t *data, |
| 264 | size_t data_size, |
| 265 | size_t *data_length); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 266 | /** |
| 267 | * \brief Set the initialisation vector on the provided cipher operation |
| 268 | * |
| 269 | * \param[in] operation Cipher operation context |
| 270 | * \param[in] iv Buffer that contains the IV |
| 271 | * \param[in] iv_length Length of the provided IV |
| 272 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 273 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 274 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 275 | enum tfm_crypto_err_t tfm_crypto_cipher_set_iv( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 276 | psa_cipher_operation_t *operation, |
| 277 | const unsigned char *iv, |
| 278 | size_t iv_length); |
| 279 | /** |
| 280 | * \brief Set the cipher operation using the provided algorithm and key slot, |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 281 | * for encryption context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 282 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 283 | * \note A successful call to this function initialises a cipher operation |
| 284 | * context which will be referred using the operation parameter |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 285 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 286 | * \param[out] operation Cipher operation context |
| 287 | * \param[in] key Key slot to bind to the cipher context |
| 288 | * \param[in] alg Algorithm to use for the cipher operation |
| 289 | * |
| 290 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 291 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 292 | enum tfm_crypto_err_t tfm_crypto_cipher_encrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 293 | psa_cipher_operation_t *operation, |
| 294 | psa_key_slot_t key, |
| 295 | psa_algorithm_t alg); |
| 296 | /** |
| 297 | * \brief Set the cipher operation using the provided algorithm and key slot, |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 298 | * for decryption context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 299 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 300 | * \note A successful call to this function initialises a cipher operation |
| 301 | * context which will be referred using the operation parameter |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 302 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 303 | * \param[out] operation Cipher operation context |
| 304 | * \param[in] key Key slot to bind to the cipher context |
| 305 | * \param[in] alg Algorithm to use for the cipher operation |
| 306 | * |
| 307 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 308 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 309 | enum tfm_crypto_err_t tfm_crypto_cipher_decrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 310 | psa_cipher_operation_t *operation, |
| 311 | psa_key_slot_t key, |
| 312 | psa_algorithm_t alg); |
| 313 | /** |
| 314 | * \brief Update the cipher context with a chunk of input data to create a |
| 315 | * chunk of encrypted output data (for encryption contexts), or to |
| 316 | * decrypt a chunk of encrypted input data to obtain decrypted data |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 317 | * (for decryption contexts) |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 318 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 319 | * \param[in/out] operation Cipher operation context |
| 320 | * \param[in] input Buffer containing input data |
| 321 | * \param[in] input_length Input length |
| 322 | * \param[out] output Buffer containing output data |
| 323 | * \param[in] output_size Size of the output buffer |
| 324 | * \param[out] output_length Size of the produced output |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 325 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 326 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 327 | */ |
| 328 | enum tfm_crypto_err_t tfm_crypto_cipher_update( |
| 329 | psa_cipher_operation_t *operation, |
| 330 | const uint8_t *input, |
| 331 | size_t input_length, |
| 332 | unsigned char *output, |
| 333 | size_t output_size, |
| 334 | size_t *output_length); |
| 335 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 336 | * \brief Finalise a cipher context flushing out any remaining block of |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 337 | * output data |
| 338 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 339 | * \note A successful call to this function de-initialises the cipher operation |
| 340 | * context provided as parameter |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 341 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 342 | * \param[in/out] operation Cipher operation context |
| 343 | * \param[out] output Buffer containing output data |
| 344 | * \param[in] output_size Size of the output buffer |
| 345 | * \param[out] output_length Size of the produced output |
| 346 | * |
| 347 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 348 | */ |
| 349 | enum tfm_crypto_err_t tfm_crypto_cipher_finish( |
| 350 | psa_cipher_operation_t *operation, |
| 351 | uint8_t *output, |
| 352 | size_t output_size, |
| 353 | size_t *output_length); |
| 354 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 355 | * \brief Abort a cipher operation, clears the operation context provided |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 356 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 357 | * \note A successful call to this function de-initialises the cipher operation |
| 358 | * context provided as parameter |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 359 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 360 | * \param[in/out] operation Cipher operation context |
| 361 | * |
| 362 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 363 | */ |
| 364 | enum tfm_crypto_err_t tfm_crypto_cipher_abort( |
| 365 | psa_cipher_operation_t *operation); |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 366 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 367 | * \brief Start a hash operation with the provided algorithm |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 368 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 369 | * \note A successful call to this function initialises a hash operation |
| 370 | * context which will be referred using the operation parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 371 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 372 | * \param[out] operation Hash operation context |
| 373 | * \param[in] alg Algorithm chosen as hash |
| 374 | * |
| 375 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 376 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 377 | enum tfm_crypto_err_t tfm_crypto_hash_setup(psa_hash_operation_t *operation, |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 378 | psa_algorithm_t alg); |
| 379 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 380 | * \brief Add a new input chunk to the data for which the final hash value |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 381 | * will be computed |
| 382 | * |
| 383 | * \param[in] operation Hash operation context |
| 384 | * \param[in] input Buffer containing the input data |
| 385 | * \param[in] input_length Size of the provided input data |
| 386 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 387 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 388 | */ |
| 389 | enum tfm_crypto_err_t tfm_crypto_hash_update(psa_hash_operation_t *operation, |
| 390 | const uint8_t *input, |
| 391 | size_t input_length); |
| 392 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 393 | * \brief Finalise a hash context operation producing the final hash value |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 394 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 395 | * \note A successful call to this function de-initialises the hash operation |
| 396 | * context provided as parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 397 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 398 | * \param[in/out] operation Hash operation context |
| 399 | * \param[out] hash Buffer containing hash data |
| 400 | * \param[in] hash_size Size of the hash buffer |
| 401 | * \param[out] hash_length Size of the produced hash |
| 402 | * |
| 403 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 404 | */ |
| 405 | enum tfm_crypto_err_t tfm_crypto_hash_finish(psa_hash_operation_t *operation, |
| 406 | uint8_t *hash, |
| 407 | size_t hash_size, |
| 408 | size_t *hash_length); |
| 409 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 410 | * \brief Finalise a hash context operation, verifying that the final hash |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 411 | * value matches the one provided as input |
| 412 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 413 | * \note A successful call to this function de-initialises the hash operation |
| 414 | * context provided as parameter. The hash operation is de-initialised |
| 415 | * also in case TFM_CRYPTO_ERR_PSA_ERROR_INVALID_SIGNATURE is returned |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 416 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 417 | * \param[in/out] operation Hash operation context |
| 418 | * \param[in] hash Buffer containing the provided hash value |
| 419 | * \param[in] hash_length Size of the provided hash value |
| 420 | * |
| 421 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 422 | */ |
| 423 | enum tfm_crypto_err_t tfm_crypto_hash_verify(psa_hash_operation_t *operation, |
| 424 | const uint8_t *hash, |
| 425 | size_t hash_length); |
| 426 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 427 | * \brief Abort a hash operation, clears the operation context provided |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 428 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 429 | * \note A successful call to this function de-initialises the hash operation |
| 430 | * context provided as parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 431 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 432 | * \param[in/out] operation Hash operation context |
| 433 | * |
| 434 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 435 | */ |
| 436 | enum tfm_crypto_err_t tfm_crypto_hash_abort(psa_hash_operation_t *operation); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 437 | |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 438 | /** |
| 439 | * \brief Start a MAC operation with the provided algorithm (for signing) |
| 440 | * |
| 441 | * \note A successful call to this function initialises a MAC operation |
| 442 | * context which will be referred using the operation parameter |
| 443 | * |
| 444 | * \param[out] operation MAC operation context |
| 445 | * \param[in] key Key slot to bind to the MAC context |
| 446 | * \param[in] alg Algorithm chosen as MAC |
| 447 | * |
| 448 | * \return Return values as described in \ref tfm_crypto_err_t |
| 449 | */ |
| 450 | enum tfm_crypto_err_t tfm_crypto_mac_sign_setup(psa_mac_operation_t *operation, |
| 451 | psa_key_slot_t key, |
| 452 | psa_algorithm_t alg); |
| 453 | /** |
| 454 | * \brief Start a MAC operation with the provided algorithm (for verifying) |
| 455 | * |
| 456 | * \note A successful call to this function initialises a MAC operation |
| 457 | * context which will be referred using the operation parameter |
| 458 | * |
| 459 | * \param[out] operation MAC operation context |
| 460 | * \param[in] key Key slot to bind to the MAC context |
| 461 | * \param[in] alg Algorithm chosen as MAC |
| 462 | * |
| 463 | * \return Return values as described in \ref tfm_crypto_err_t |
| 464 | */ |
| 465 | enum tfm_crypto_err_t tfm_crypto_mac_verify_setup( |
| 466 | psa_mac_operation_t *operation, |
| 467 | psa_key_slot_t key, |
| 468 | psa_algorithm_t alg); |
| 469 | /** |
| 470 | * \brief Adds a new input chunk to the data for which the final MAC value |
| 471 | * will be computed |
| 472 | * |
| 473 | * \param[in] operation MAC operation context |
| 474 | * \param[in] input Buffer containing the input data |
| 475 | * \param[in] input_length Size of the provided input data |
| 476 | * |
| 477 | * \return Return values as described in \ref tfm_crypto_err_t |
| 478 | */ |
| 479 | enum tfm_crypto_err_t tfm_crypto_mac_update(psa_mac_operation_t *operation, |
| 480 | const uint8_t *input, |
| 481 | size_t input_length); |
| 482 | /** |
| 483 | * \brief Finalise a MAC context operation producing the final MAC value |
| 484 | * |
| 485 | * \param[in/out] operation Mac operation context |
| 486 | * \param[out] mac Buffer containing MAC data |
| 487 | * \param[in] mac_size Size of the mac buffer |
| 488 | * \param[out] mac_length Size of the produced mac |
| 489 | * |
| 490 | * \return Return values as described in \ref tfm_crypto_err_t |
| 491 | */ |
| 492 | enum tfm_crypto_err_t tfm_crypto_mac_sign_finish(psa_mac_operation_t *operation, |
| 493 | uint8_t *mac, |
| 494 | size_t mac_size, |
| 495 | size_t *mac_length); |
| 496 | /** |
| 497 | * \brief Finalise a MAC context operation, verifying that the final MAC value |
| 498 | * matches the one provided as input |
| 499 | * |
| 500 | * \param[in/out] operation MAC operation context |
| 501 | * \param[in] mac Buffer containing the provided MAC value |
| 502 | * \param[in] mac_length Size of the provided MAC value |
| 503 | * |
| 504 | * \return Return values as described in \ref tfm_crypto_err_t |
| 505 | */ |
| 506 | enum tfm_crypto_err_t tfm_crypto_mac_verify_finish( |
| 507 | psa_mac_operation_t *operation, |
| 508 | const uint8_t *mac, |
| 509 | size_t mac_length); |
| 510 | /** |
| 511 | * \brief Abort a MAC operation, clear the operation context provided |
| 512 | * |
| 513 | * \param[in/out] operation MAC operation context |
| 514 | * |
| 515 | * \return Return values as described in \ref tfm_crypto_err_t |
| 516 | */ |
| 517 | enum tfm_crypto_err_t tfm_crypto_mac_abort(psa_mac_operation_t *operation); |
| 518 | |
Antonio de Angelis | 3a48099 | 2018-11-07 11:53:28 +0000 | [diff] [blame] | 519 | /** |
| 520 | * \brief Perform an AEAD encryption operation on input data with additional |
| 521 | * data to be authenticated, producing ciphertext in output with an |
| 522 | * appended authentication tag |
| 523 | * |
| 524 | * \param[in] key Key slot for the key |
| 525 | * \param[in] alg Algorithm to be used |
| 526 | * \param[in] nonce Pointer to a buffer holding a nonce or IV |
| 527 | * to use |
| 528 | * \param[in] nonce_length Size in bytes of the nonce or IV data |
| 529 | * \param[in] additional_data Additional information to be authenticated |
| 530 | * \param[in] additional_data_length Size in bytes of the additional data |
| 531 | * \param[in] plaintext Buffer pointing to data to be encrypted |
| 532 | * \param[in] plaintext_length Size in bytes of the plain text buffer |
| 533 | * \param[out] ciphertext Output encrypted data, with the |
| 534 | * authentication tag appended |
| 535 | * \param[in] ciphertext_size Size in bytes of the buffer to hold the |
| 536 | * cipher text plus authentication tag |
| 537 | * \param[out] ciphertext_length Size of the ciphertext plus tag produced |
| 538 | * as output |
| 539 | * |
| 540 | * \return Return values as described in \ref tfm_crypto_err_t |
| 541 | */ |
| 542 | enum tfm_crypto_err_t tfm_crypto_aead_encrypt(psa_key_slot_t key, |
| 543 | psa_algorithm_t alg, |
| 544 | const uint8_t *nonce, |
| 545 | size_t nonce_length, |
| 546 | const uint8_t *additional_data, |
| 547 | size_t additional_data_length, |
| 548 | const uint8_t *plaintext, |
| 549 | size_t plaintext_length, |
| 550 | uint8_t *ciphertext, |
| 551 | size_t ciphertext_size, |
| 552 | size_t *ciphertext_length); |
| 553 | /** |
| 554 | * \brief Perform an AEAD decryption operation on input data with additional |
| 555 | * data to be verified, producing back the original plain text in case |
| 556 | * the verification of the authentication tag is successful |
| 557 | * |
| 558 | * \param[in] key Key slot for the key |
| 559 | * \param[in] alg Algorithm to be used |
| 560 | * \param[in] nonce Pointer to a buffer holding a nonce or IV |
| 561 | * to use |
| 562 | * \param[in] nonce_length Size in bytes of the nonce or IV data |
| 563 | * \param[in] additional_data Additional information which was |
| 564 | * authenticated but not encrypted |
| 565 | * \param[in] additional_data_length Size in bytes of the additional data |
| 566 | * \param[in] ciphertext Buffer pointing to data be decrypted |
| 567 | * \param[in] ciphertext_length Size in bytes of the cipher text buffer |
| 568 | * \param[out] plaintext Buffer for decrypted output data |
| 569 | * \param[in] plaintext_size Size in bytes of the buffer to hold the |
| 570 | * plain text |
| 571 | * \param[out] plaintext_length Size of the plain text actually produced |
| 572 | * |
| 573 | * \return Return values as described in \ref tfm_crypto_err_t |
| 574 | */ |
| 575 | enum tfm_crypto_err_t tfm_crypto_aead_decrypt(psa_key_slot_t key, |
| 576 | psa_algorithm_t alg, |
| 577 | const uint8_t *nonce, |
| 578 | size_t nonce_length, |
| 579 | const uint8_t *additional_data, |
| 580 | size_t additional_data_length, |
| 581 | const uint8_t *ciphertext, |
| 582 | size_t ciphertext_length, |
| 583 | uint8_t *plaintext, |
| 584 | size_t plaintext_size, |
| 585 | size_t *plaintext_length); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 586 | #ifdef __cplusplus |
| 587 | } |
| 588 | #endif |
| 589 | |
| 590 | #endif /* __TFM_CRYPTO_API_H__ */ |