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_VENEERS_H__ |
| 9 | #define __TFM_CRYPTO_VENEERS_H__ |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | #include "tfm_crypto_defs.h" |
| 16 | |
| 17 | #include "psa_crypto.h" |
| 18 | |
| 19 | #include "crypto_psa_wrappers.h" |
| 20 | |
| 21 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 22 | * \brief Import the key data in the provided key slot (veneer function) |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 23 | * |
| 24 | * \param[in] key Key slot |
| 25 | * \param[in] type Key type |
| 26 | * \param[in] data Key data to import |
| 27 | * \param[in] data_length Length in bytes of the data field |
| 28 | * |
| 29 | * \return Return values as described in \ref tfm_crypto_err_t |
| 30 | */ |
| 31 | enum tfm_crypto_err_t tfm_crypto_veneer_import_key(psa_key_slot_t key, |
| 32 | psa_key_type_t type, |
| 33 | const uint8_t *data, |
| 34 | size_t data_length); |
| 35 | /** |
| 36 | * \brief Destroy the key in the provided key slot (veneer function) |
| 37 | * |
| 38 | * \param[in] key Key slot |
| 39 | * |
| 40 | * \return Return values as described in \ref tfm_crypto_err_t |
| 41 | */ |
| 42 | enum tfm_crypto_err_t tfm_crypto_veneer_destroy_key(psa_key_slot_t key); |
| 43 | |
| 44 | /** |
| 45 | * \brief Retrieve key information for the provided key slot (veneer function) |
| 46 | * |
| 47 | * \param[in] key Key slot |
| 48 | * \param[out] type Key type associated to the key slot requested |
| 49 | * \param[out] bits Length in bits of the key in the requested slot |
| 50 | * |
| 51 | * \return Return values as described in \ref tfm_crypto_err_t |
| 52 | */ |
| 53 | enum tfm_crypto_err_t tfm_crypto_veneer_get_key_information( |
| 54 | psa_key_slot_t key, |
| 55 | psa_key_type_t *type, |
| 56 | size_t *bits); |
| 57 | /** |
| 58 | * \brief Export the key contained in the provided key slot (veneer function) |
| 59 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 60 | * \param[in] key Key slot |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 61 | * \param[out] data Buffer to hold the exported key |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 62 | * \param[in] data_size Length of the buffer pointed to by data |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 63 | * \param[out] data_length Length of the exported key |
| 64 | * |
| 65 | * \return Return values as described in \ref tfm_crypto_err_t |
| 66 | */ |
| 67 | enum tfm_crypto_err_t tfm_crypto_veneer_export_key(psa_key_slot_t key, |
| 68 | uint8_t *data, |
| 69 | size_t data_size, |
| 70 | size_t *data_length); |
| 71 | /** |
| 72 | * \brief Set the initialisation vector on the provided cipher operation (veneer |
| 73 | * function) |
| 74 | * |
| 75 | * \param[in] operation Cipher operation context |
| 76 | * \param[in] iv Buffer that contains the IV |
| 77 | * \param[in] iv_length Length of the provided IV |
| 78 | * |
| 79 | * \return Return values as described in \ref tfm_crypto_err_t |
| 80 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 81 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_set_iv( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 82 | psa_cipher_operation_t *operation, |
| 83 | const unsigned char *iv, |
| 84 | size_t iv_length); |
| 85 | /** |
| 86 | * \brief Set the cipher operation using the provided algorithm and key slot, |
| 87 | * for encryption context (veneer function) |
| 88 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 89 | * \note A successful call to this function initialises a cipher operation |
| 90 | * context which will be referred using the operation parameter |
| 91 | * |
| 92 | * \param[out] operation Cipher operation context |
| 93 | * \param[in] key Key slot to bind to the cipher context |
| 94 | * \param[in] alg Algorithm to use for the cipher operation |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 95 | * |
| 96 | * \return Return values as described in \ref tfm_crypto_err_t |
| 97 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 98 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_encrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 99 | psa_cipher_operation_t *operation, |
| 100 | psa_key_slot_t key, |
| 101 | psa_algorithm_t alg); |
| 102 | /** |
| 103 | * \brief Set the cipher operation using the provided algorithm and key slot, |
| 104 | * for decryption context (veneer function) |
| 105 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 106 | * \note A successful call to this function initialises a cipher operation |
| 107 | * context which will be referred using the operation parameter |
| 108 | * |
| 109 | * \param[out] operation Cipher operation context |
| 110 | * \param[in] key Key slot to bind to the cipher context |
| 111 | * \param[in] alg Algorithm to use for the cipher operation |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 112 | * |
| 113 | * \return Return values as described in \ref tfm_crypto_err_t |
| 114 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 115 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_decrypt_setup( |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 116 | psa_cipher_operation_t *operation, |
| 117 | psa_key_slot_t key, |
| 118 | psa_algorithm_t alg); |
| 119 | /** |
| 120 | * \brief Update the cipher context with a chunk of input data to create a |
| 121 | * chunk of encrypted output data (for encryption contexts), or to |
| 122 | * decrypt a chunk of encrypted input data to obtain decrypted data |
| 123 | * (for decryption contexts) (veneer function) |
| 124 | * |
| 125 | * \param[in] operation Cipher operation context |
| 126 | * \param[in] input_s Pointer to the struct containing input parameters |
| 127 | * \param[out] output_s Pointer to the struct containing output parameters |
| 128 | * |
| 129 | * \return Return values as described in \ref tfm_crypto_err_t |
| 130 | */ |
| 131 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_update( |
| 132 | psa_cipher_operation_t *operation, |
| 133 | struct psa_cipher_update_input *input_s, |
| 134 | struct psa_cipher_update_output *output_s); |
| 135 | /** |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 136 | * \brief Finalise a cipher context flushing out any remaining block of |
| 137 | * output data (veneer function) |
| 138 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 139 | * \note A successful call to this function releases the cipher operation |
| 140 | * context provided as parameter |
| 141 | * |
| 142 | * \param[in/out] operation Cipher operation context |
| 143 | * \param[out] output Buffer containing output data |
| 144 | * \param[in] output_size Size of the output buffer |
| 145 | * \param[out] output_length Size of the produced output |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 146 | * |
| 147 | * \return Return values as described in \ref tfm_crypto_err_t |
| 148 | */ |
| 149 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_finish( |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 150 | psa_cipher_operation_t *operation, |
| 151 | uint8_t *output, |
| 152 | size_t output_size, |
| 153 | size_t *output_length); |
| 154 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 155 | * \brief Abort a cipher operation, clear the operation context provided |
| 156 | * (veneer function) |
| 157 | * |
| 158 | * \note A successful call to this function releases the cipher operation |
| 159 | * context provided as parameter |
| 160 | * |
| 161 | * \param[in/out] operation Cipher operation context |
| 162 | * |
| 163 | * \return Return values as described in \ref tfm_crypto_err_t |
| 164 | */ |
| 165 | enum tfm_crypto_err_t tfm_crypto_veneer_cipher_abort( |
| 166 | psa_cipher_operation_t *operation); |
| 167 | /** |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 168 | * \brief Setup a hash operation with the provided algorithm (veneer function) |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 169 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 170 | * \note A successful call to this function initialises a hash operation |
| 171 | * context which will be referred using the operation parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 172 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 173 | * \param[out] operation Hash operation context |
| 174 | * \param[in] alg Algorithm chosen as hash |
| 175 | * |
| 176 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 177 | */ |
Antonio de Angelis | 377a155 | 2018-11-22 17:02:40 +0000 | [diff] [blame] | 178 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_setup( |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 179 | psa_hash_operation_t *operation, |
| 180 | psa_algorithm_t alg); |
| 181 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 182 | * \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] | 183 | * will be computed (veneer function) |
| 184 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 185 | * \param[in/out] operation Hash operation context |
| 186 | * \param[in] input Buffer containing the input data |
| 187 | * \param[in] input_length Size of the provided input data |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 188 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 189 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 190 | */ |
| 191 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_update( |
| 192 | psa_hash_operation_t *operation, |
| 193 | const uint8_t *input, |
| 194 | size_t input_length); |
| 195 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 196 | * \brief Finalise a hash context operation producing the final hash value |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 197 | * (veneer function) |
| 198 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 199 | * \note A successful call to this function releases the hash operation |
| 200 | * context provided as parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 201 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 202 | * \param[in/out] operation Hash operation context |
| 203 | * \param[out] hash Buffer containing hash data |
| 204 | * \param[in] hash_size Size of the hash buffer |
| 205 | * \param[out] hash_length Size of the produced hash |
| 206 | * |
| 207 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 208 | */ |
| 209 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_finish( |
| 210 | psa_hash_operation_t *operation, |
| 211 | uint8_t *hash, |
| 212 | size_t hash_size, |
| 213 | size_t *hash_length); |
| 214 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 215 | * \brief Finalise a hash context operation, verifying that the final hash |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 216 | * value matches the one provided as input (veneer function) |
| 217 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 218 | * \note A successful call to this function releases the hash operation |
| 219 | * context provided as parameter. The hash operation is released |
| 220 | * 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] | 221 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 222 | * \param[in/out] operation Hash operation context |
| 223 | * \param[in] hash Buffer containing the provided hash value |
| 224 | * \param[in] hash_length Size of the provided hash value |
| 225 | * |
| 226 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 227 | */ |
| 228 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_verify( |
| 229 | psa_hash_operation_t *operation, |
| 230 | const uint8_t *hash, |
| 231 | size_t hash_length); |
| 232 | /** |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 233 | * \brief Abort a hash operation, clears the operation context provided |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 234 | * (veneer function) |
| 235 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 236 | * \note A successful call to this function releases the hash operation |
| 237 | * context provided as parameter |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 238 | * |
Antonio de Angelis | cf85ba2 | 2018-10-09 13:29:40 +0100 | [diff] [blame^] | 239 | * \param[in/out] operation Hash operation context |
| 240 | * |
| 241 | * \return Return values as described in \ref tfm_crypto_err_t |
Antonio de Angelis | a6f7216 | 2018-09-05 11:00:37 +0100 | [diff] [blame] | 242 | */ |
| 243 | enum tfm_crypto_err_t tfm_crypto_veneer_hash_abort( |
| 244 | psa_hash_operation_t *operation); |
| 245 | |
Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame] | 246 | #ifdef __cplusplus |
| 247 | } |
| 248 | #endif |
| 249 | |
| 250 | #endif /* __TFM_CRYPTO_VENEERS_H__ */ |