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, |
| 30 | TFM_CRYPTO_KEY_POLICY = 4, |
| 31 | |
| 32 | /* Used to force the enum size */ |
| 33 | TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX |
| 34 | }; |
| 35 | |
| 36 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 37 | * \brief Initialise the service |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 38 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 39 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 40 | */ |
| 41 | enum tfm_crypto_err_t tfm_crypto_init(void); |
| 42 | |
| 43 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 44 | * \brief Initialise the Key module |
| 45 | * |
| 46 | * \return Return values as described in \ref tfm_crypto_err_t |
| 47 | */ |
| 48 | enum tfm_crypto_err_t tfm_crypto_init_key(void); |
| 49 | |
| 50 | /** |
| 51 | * \brief Initialise the Alloc module |
| 52 | * |
| 53 | * \return Return values as described in \ref tfm_crypto_err_t |
| 54 | */ |
| 55 | enum tfm_crypto_err_t tfm_crypto_init_alloc(void); |
| 56 | |
| 57 | /** |
| 58 | * \brief Allocate an operation object |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 59 | * |
| 60 | * \param[in] type Type of the operation object to allocate |
| 61 | * \param[out] handle Pointer to the corresponding handle assigned |
| 62 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 63 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 64 | */ |
| 65 | enum tfm_crypto_err_t tfm_crypto_operation_alloc( |
| 66 | enum tfm_crypto_operation_type type, |
| 67 | uint32_t *handle); |
| 68 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 69 | * \brief Release an operation object |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 70 | * |
| 71 | * \param[in] handle Pointer to the handle for the release of the |
| 72 | * corresponding object |
| 73 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 74 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 75 | */ |
| 76 | enum tfm_crypto_err_t tfm_crypto_operation_release(uint32_t *handle); |
| 77 | |
| 78 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 79 | * \brief Look up an operation object pointer from the corresponding handle |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 80 | * |
| 81 | * \param[in] type Type of the operation object to look up |
| 82 | * \param[in] handle Handle to the operation object to look up |
| 83 | * \param[out] oper Double pointer to the corresponding object |
| 84 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 85 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 86 | */ |
| 87 | enum tfm_crypto_err_t tfm_crypto_operation_lookup( |
| 88 | enum tfm_crypto_operation_type type, |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 89 | uint32_t handle, |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 90 | void **oper); |
| 91 | /** |
| 92 | * \brief Import the key data in the provided key slot |
| 93 | * |
| 94 | * \param[in] key Key slot |
| 95 | * \param[in] type Key type |
| 96 | * \param[in] data Key data to import |
| 97 | * \param[in] data_length Length in bytes of the data field |
| 98 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 99 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 100 | */ |
| 101 | enum tfm_crypto_err_t tfm_crypto_import_key(psa_key_slot_t key, |
| 102 | psa_key_type_t type, |
| 103 | const uint8_t *data, |
| 104 | size_t data_length); |
| 105 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 106 | * \brief Destroy the key in the provided key slot |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 107 | * |
| 108 | * \param[in] key Key slot |
| 109 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 110 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 111 | */ |
| 112 | enum tfm_crypto_err_t tfm_crypto_destroy_key(psa_key_slot_t key); |
| 113 | |
| 114 | /** |
| 115 | * \brief Retrieve key information for the provided key slot |
| 116 | * |
| 117 | * \param[in] key Key slot |
| 118 | * \param[out] type Key type associated to the key slot requested |
| 119 | * \param[out] bits Length in bits of the key in the requested slot |
| 120 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 121 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 122 | */ |
| 123 | enum tfm_crypto_err_t tfm_crypto_get_key_information(psa_key_slot_t key, |
| 124 | psa_key_type_t *type, |
| 125 | size_t *bits); |
| 126 | /** |
| 127 | * \brief Export the key contained in the provided key slot |
| 128 | * |
| 129 | * \param[in] key Key slot |
| 130 | * \param[out] data Buffer to hold the exported key |
| 131 | * \param[in] data_size Length of the buffer pointed to by data |
| 132 | * \param[out] data_length Length of the exported key |
| 133 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 134 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 135 | */ |
| 136 | enum tfm_crypto_err_t tfm_crypto_export_key(psa_key_slot_t key, |
| 137 | uint8_t *data, |
| 138 | size_t data_size, |
| 139 | size_t *data_length); |
| 140 | /** |
| 141 | * \brief Export the public key contained in the provided key slot |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 142 | * for an asymmetric key pair |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 143 | * |
| 144 | * \param[in] key Key slot |
| 145 | * \param[out] data Buffer to hold the exported key |
| 146 | * \param[in] data_size Length of the buffer pointed to by data |
| 147 | * \param[out] data_length Length of the exported key |
| 148 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 149 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 150 | */ |
| 151 | enum tfm_crypto_err_t tfm_crypto_export_public_key(psa_key_slot_t key, |
| 152 | uint8_t *data, |
| 153 | size_t data_size, |
| 154 | size_t *data_length); |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 155 | /** |
| 156 | * \brief Set the initialisation vector on the provided cipher operation |
| 157 | * |
| 158 | * \param[in] operation Cipher operation context |
| 159 | * \param[in] iv Buffer that contains the IV |
| 160 | * \param[in] iv_length Length of the provided IV |
| 161 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 162 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 163 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 164 | enum tfm_crypto_err_t tfm_crypto_cipher_set_iv( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 165 | psa_cipher_operation_t *operation, |
| 166 | const unsigned char *iv, |
| 167 | size_t iv_length); |
| 168 | /** |
| 169 | * \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] | 170 | * for encryption context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 171 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 172 | * \note A successful call to this function initialises a cipher operation |
| 173 | * context which will be referred using the operation parameter |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 174 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 175 | * \param[out] operation Cipher operation context |
| 176 | * \param[in] key Key slot to bind to the cipher context |
| 177 | * \param[in] alg Algorithm to use for the cipher operation |
| 178 | * |
| 179 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 180 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 181 | enum tfm_crypto_err_t tfm_crypto_cipher_encrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 182 | psa_cipher_operation_t *operation, |
| 183 | psa_key_slot_t key, |
| 184 | psa_algorithm_t alg); |
| 185 | /** |
| 186 | * \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] | 187 | * for decryption context |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 188 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 189 | * \note A successful call to this function initialises a cipher operation |
| 190 | * context which will be referred using the operation parameter |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 191 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 192 | * \param[out] operation Cipher operation context |
| 193 | * \param[in] key Key slot to bind to the cipher context |
| 194 | * \param[in] alg Algorithm to use for the cipher operation |
| 195 | * |
| 196 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 197 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 198 | enum tfm_crypto_err_t tfm_crypto_cipher_decrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 199 | psa_cipher_operation_t *operation, |
| 200 | psa_key_slot_t key, |
| 201 | psa_algorithm_t alg); |
| 202 | /** |
| 203 | * \brief Update the cipher context with a chunk of input data to create a |
| 204 | * chunk of encrypted output data (for encryption contexts), or to |
| 205 | * decrypt a chunk of encrypted input data to obtain decrypted data |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 206 | * (for decryption contexts) |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 207 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 208 | * \param[in/out] operation Cipher operation context |
| 209 | * \param[in] input Buffer containing input data |
| 210 | * \param[in] input_length Input length |
| 211 | * \param[out] output Buffer containing output data |
| 212 | * \param[in] output_size Size of the output buffer |
| 213 | * \param[out] output_length Size of the produced output |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 214 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 215 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 216 | */ |
| 217 | enum tfm_crypto_err_t tfm_crypto_cipher_update( |
| 218 | psa_cipher_operation_t *operation, |
| 219 | const uint8_t *input, |
| 220 | size_t input_length, |
| 221 | unsigned char *output, |
| 222 | size_t output_size, |
| 223 | size_t *output_length); |
| 224 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 225 | * \brief Finalise a cipher context flushing out any remaining block of |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 226 | * output data |
| 227 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 228 | * \note A successful call to this function de-initialises the cipher operation |
| 229 | * context provided as parameter |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 230 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 231 | * \param[in/out] operation Cipher operation context |
| 232 | * \param[out] output Buffer containing output data |
| 233 | * \param[in] output_size Size of the output buffer |
| 234 | * \param[out] output_length Size of the produced output |
| 235 | * |
| 236 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 237 | */ |
| 238 | enum tfm_crypto_err_t tfm_crypto_cipher_finish( |
| 239 | psa_cipher_operation_t *operation, |
| 240 | uint8_t *output, |
| 241 | size_t output_size, |
| 242 | size_t *output_length); |
| 243 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 244 | * \brief Abort a cipher operation, clears the operation context provided |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 245 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 246 | * \note A successful call to this function de-initialises the cipher operation |
| 247 | * context provided as parameter |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 248 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 249 | * \param[in/out] operation Cipher operation context |
| 250 | * |
| 251 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 252 | */ |
| 253 | enum tfm_crypto_err_t tfm_crypto_cipher_abort( |
| 254 | psa_cipher_operation_t *operation); |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 255 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 256 | * \brief Start a hash operation with the provided algorithm |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 257 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 258 | * \note A successful call to this function initialises a hash operation |
| 259 | * context which will be referred using the operation parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 260 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 261 | * \param[out] operation Hash operation context |
| 262 | * \param[in] alg Algorithm chosen as hash |
| 263 | * |
| 264 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 265 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 266 | 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] | 267 | psa_algorithm_t alg); |
| 268 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 269 | * \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] | 270 | * will be computed |
| 271 | * |
| 272 | * \param[in] operation Hash operation context |
| 273 | * \param[in] input Buffer containing the input data |
| 274 | * \param[in] input_length Size of the provided input data |
| 275 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 276 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 277 | */ |
| 278 | enum tfm_crypto_err_t tfm_crypto_hash_update(psa_hash_operation_t *operation, |
| 279 | const uint8_t *input, |
| 280 | size_t input_length); |
| 281 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 282 | * \brief Finalise a hash context operation producing the final hash value |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 283 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 284 | * \note A successful call to this function de-initialises the hash operation |
| 285 | * context provided as parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 286 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 287 | * \param[in/out] operation Hash operation context |
| 288 | * \param[out] hash Buffer containing hash data |
| 289 | * \param[in] hash_size Size of the hash buffer |
| 290 | * \param[out] hash_length Size of the produced hash |
| 291 | * |
| 292 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 293 | */ |
| 294 | enum tfm_crypto_err_t tfm_crypto_hash_finish(psa_hash_operation_t *operation, |
| 295 | uint8_t *hash, |
| 296 | size_t hash_size, |
| 297 | size_t *hash_length); |
| 298 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 299 | * \brief Finalise a hash context operation, verifying that the final hash |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 300 | * value matches the one provided as input |
| 301 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 302 | * \note A successful call to this function de-initialises the hash operation |
| 303 | * context provided as parameter. The hash operation is de-initialised |
| 304 | * 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] | 305 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 306 | * \param[in/out] operation Hash operation context |
| 307 | * \param[in] hash Buffer containing the provided hash value |
| 308 | * \param[in] hash_length Size of the provided hash value |
| 309 | * |
| 310 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 311 | */ |
| 312 | enum tfm_crypto_err_t tfm_crypto_hash_verify(psa_hash_operation_t *operation, |
| 313 | const uint8_t *hash, |
| 314 | size_t hash_length); |
| 315 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 316 | * \brief Abort a hash operation, clears the operation context provided |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 317 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 318 | * \note A successful call to this function de-initialises the hash operation |
| 319 | * context provided as parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 320 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame] | 321 | * \param[in/out] operation Hash operation context |
| 322 | * |
| 323 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 324 | */ |
| 325 | 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] | 326 | |
Louis Mayencourt | 7a36f78 | 2018-09-24 14:00:57 +0100 | [diff] [blame] | 327 | /** |
| 328 | * \brief Start a MAC operation with the provided algorithm (for signing) |
| 329 | * |
| 330 | * \note A successful call to this function initialises a MAC operation |
| 331 | * context which will be referred using the operation parameter |
| 332 | * |
| 333 | * \param[out] operation MAC operation context |
| 334 | * \param[in] key Key slot to bind to the MAC context |
| 335 | * \param[in] alg Algorithm chosen as MAC |
| 336 | * |
| 337 | * \return Return values as described in \ref tfm_crypto_err_t |
| 338 | */ |
| 339 | enum tfm_crypto_err_t tfm_crypto_mac_sign_setup(psa_mac_operation_t *operation, |
| 340 | psa_key_slot_t key, |
| 341 | psa_algorithm_t alg); |
| 342 | /** |
| 343 | * \brief Start a MAC operation with the provided algorithm (for verifying) |
| 344 | * |
| 345 | * \note A successful call to this function initialises a MAC operation |
| 346 | * context which will be referred using the operation parameter |
| 347 | * |
| 348 | * \param[out] operation MAC operation context |
| 349 | * \param[in] key Key slot to bind to the MAC context |
| 350 | * \param[in] alg Algorithm chosen as MAC |
| 351 | * |
| 352 | * \return Return values as described in \ref tfm_crypto_err_t |
| 353 | */ |
| 354 | enum tfm_crypto_err_t tfm_crypto_mac_verify_setup( |
| 355 | psa_mac_operation_t *operation, |
| 356 | psa_key_slot_t key, |
| 357 | psa_algorithm_t alg); |
| 358 | /** |
| 359 | * \brief Adds a new input chunk to the data for which the final MAC value |
| 360 | * will be computed |
| 361 | * |
| 362 | * \param[in] operation MAC operation context |
| 363 | * \param[in] input Buffer containing the input data |
| 364 | * \param[in] input_length Size of the provided input data |
| 365 | * |
| 366 | * \return Return values as described in \ref tfm_crypto_err_t |
| 367 | */ |
| 368 | enum tfm_crypto_err_t tfm_crypto_mac_update(psa_mac_operation_t *operation, |
| 369 | const uint8_t *input, |
| 370 | size_t input_length); |
| 371 | /** |
| 372 | * \brief Finalise a MAC context operation producing the final MAC value |
| 373 | * |
| 374 | * \param[in/out] operation Mac operation context |
| 375 | * \param[out] mac Buffer containing MAC data |
| 376 | * \param[in] mac_size Size of the mac buffer |
| 377 | * \param[out] mac_length Size of the produced mac |
| 378 | * |
| 379 | * \return Return values as described in \ref tfm_crypto_err_t |
| 380 | */ |
| 381 | enum tfm_crypto_err_t tfm_crypto_mac_sign_finish(psa_mac_operation_t *operation, |
| 382 | uint8_t *mac, |
| 383 | size_t mac_size, |
| 384 | size_t *mac_length); |
| 385 | /** |
| 386 | * \brief Finalise a MAC context operation, verifying that the final MAC value |
| 387 | * matches the one provided as input |
| 388 | * |
| 389 | * \param[in/out] operation MAC operation context |
| 390 | * \param[in] mac Buffer containing the provided MAC value |
| 391 | * \param[in] mac_length Size of the provided MAC value |
| 392 | * |
| 393 | * \return Return values as described in \ref tfm_crypto_err_t |
| 394 | */ |
| 395 | enum tfm_crypto_err_t tfm_crypto_mac_verify_finish( |
| 396 | psa_mac_operation_t *operation, |
| 397 | const uint8_t *mac, |
| 398 | size_t mac_length); |
| 399 | /** |
| 400 | * \brief Abort a MAC operation, clear the operation context provided |
| 401 | * |
| 402 | * \param[in/out] operation MAC operation context |
| 403 | * |
| 404 | * \return Return values as described in \ref tfm_crypto_err_t |
| 405 | */ |
| 406 | enum tfm_crypto_err_t tfm_crypto_mac_abort(psa_mac_operation_t *operation); |
| 407 | |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 408 | #ifdef __cplusplus |
| 409 | } |
| 410 | #endif |
| 411 | |
| 412 | #endif /* __TFM_CRYPTO_API_H__ */ |