blob: 312c2c31adbe4f5970f4be0d86c1bd7c1a7f6f4d [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
Antonio de Angelis377a1552018-11-22 17:02:40 +00002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003 *
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
12extern "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 Angeliscf85ba22018-10-09 13:29:40 +010022 * \brief Import the key data in the provided key slot (veneer function)
Antonio de Angelis8908f472018-08-31 15:44:25 +010023 *
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 */
31enum 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 */
42enum 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 */
53enum 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 Angeliscf85ba22018-10-09 13:29:40 +010060 * \param[in] key Key slot
Antonio de Angelis8908f472018-08-31 15:44:25 +010061 * \param[out] data Buffer to hold the exported key
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010062 * \param[in] data_size Length of the buffer pointed to by data
Antonio de Angelis8908f472018-08-31 15:44:25 +010063 * \param[out] data_length Length of the exported key
64 *
65 * \return Return values as described in \ref tfm_crypto_err_t
66 */
67enum 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 Angelis377a1552018-11-22 17:02:40 +000081enum tfm_crypto_err_t tfm_crypto_veneer_cipher_set_iv(
Antonio de Angelis8908f472018-08-31 15:44:25 +010082 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 Angeliscf85ba22018-10-09 13:29:40 +010089 * \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 Angelis8908f472018-08-31 15:44:25 +010095 *
96 * \return Return values as described in \ref tfm_crypto_err_t
97 */
Antonio de Angelis377a1552018-11-22 17:02:40 +000098enum tfm_crypto_err_t tfm_crypto_veneer_cipher_encrypt_setup(
Antonio de Angelis8908f472018-08-31 15:44:25 +010099 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 Angeliscf85ba22018-10-09 13:29:40 +0100106 * \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 Angelis8908f472018-08-31 15:44:25 +0100112 *
113 * \return Return values as described in \ref tfm_crypto_err_t
114 */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000115enum tfm_crypto_err_t tfm_crypto_veneer_cipher_decrypt_setup(
Antonio de Angelis8908f472018-08-31 15:44:25 +0100116 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 */
131enum 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 Angelis8908f472018-08-31 15:44:25 +0100136 * \brief Finalise a cipher context flushing out any remaining block of
137 * output data (veneer function)
138 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100139 * \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 Angelis8908f472018-08-31 15:44:25 +0100146 *
147 * \return Return values as described in \ref tfm_crypto_err_t
148 */
149enum tfm_crypto_err_t tfm_crypto_veneer_cipher_finish(
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100150 psa_cipher_operation_t *operation,
151 uint8_t *output,
152 size_t output_size,
153 size_t *output_length);
154/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100155 * \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 */
165enum tfm_crypto_err_t tfm_crypto_veneer_cipher_abort(
166 psa_cipher_operation_t *operation);
167/**
Antonio de Angelis377a1552018-11-22 17:02:40 +0000168 * \brief Setup a hash operation with the provided algorithm (veneer function)
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100169 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100170 * \note A successful call to this function initialises a hash operation
171 * context which will be referred using the operation parameter
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100172 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100173 * \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 Angelisa6f72162018-09-05 11:00:37 +0100177 */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000178enum tfm_crypto_err_t tfm_crypto_veneer_hash_setup(
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100179 psa_hash_operation_t *operation,
180 psa_algorithm_t alg);
181/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100182 * \brief Add a new input chunk to the data for which the final hash value
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100183 * will be computed (veneer function)
184 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100185 * \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 Angelisa6f72162018-09-05 11:00:37 +0100188 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100189 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100190 */
191enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100196 * \brief Finalise a hash context operation producing the final hash value
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100197 * (veneer function)
198 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100199 * \note A successful call to this function releases the hash operation
200 * context provided as parameter
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100201 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100202 * \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 Angelisa6f72162018-09-05 11:00:37 +0100208 */
209enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100215 * \brief Finalise a hash context operation, verifying that the final hash
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100216 * value matches the one provided as input (veneer function)
217 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100218 * \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 Angelisa6f72162018-09-05 11:00:37 +0100221 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100222 * \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 Angelisa6f72162018-09-05 11:00:37 +0100227 */
228enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100233 * \brief Abort a hash operation, clears the operation context provided
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100234 * (veneer function)
235 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100236 * \note A successful call to this function releases the hash operation
237 * context provided as parameter
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100238 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100239 * \param[in/out] operation Hash operation context
240 *
241 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100242 */
243enum tfm_crypto_err_t tfm_crypto_veneer_hash_abort(
244 psa_hash_operation_t *operation);
245
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100246/**
247 * \brief Start a MAC operation with the provided algorithm (for signing)
248 * (veneer function)
249 *
250 * \note A successful call to this function initialises a MAC operation
251 * context which will be referred using the operation parameter
252 *
253 * \param[out] operation MAC operation context
254 * \param[in] key Key slot to bind to the MAC context
255 * \param[in] alg Algorithm chosen as MAC
256 *
257 * \return Return values as described in \ref tfm_crypto_err_t
258 */
259enum tfm_crypto_err_t tfm_crypto_veneer_mac_sign_setup(
260 psa_mac_operation_t *operation,
261 psa_key_slot_t key,
262 psa_algorithm_t alg);
263/**
264 * \brief Start a MAC operation with the provided algorithm (for verifying)
265 * (veneer function)
266 *
267 * \note A successful call to this function initialises a MAC operation
268 * context which will be referred using the operation parameter
269 *
270 * \param[out] operation MAC operation context
271 * \param[in] key Key slot to bind to the MAC context
272 * \param[in] alg Algorithm chosen as MAC
273 *
274 * \return Return values as described in \ref tfm_crypto_err_t
275 */
276enum tfm_crypto_err_t tfm_crypto_veneer_mac_verify_setup(
277 psa_mac_operation_t *operation,
278 psa_key_slot_t key,
279 psa_algorithm_t alg);
280/**
281 * \brief Adds a new input chunk to the data for which the final MAC value
282 * will be computed (veneer function)
283 *
284 * \param[in/out] operation MAC operation context
285 * \param[in] input Buffer containing the input data
286 * \param[in] input_length Size of the provided input data
287 *
288 * \return Return values as described in \ref tfm_crypto_err_t
289 */
290enum tfm_crypto_err_t tfm_crypto_veneer_mac_update(
291 psa_mac_operation_t *operation,
292 const uint8_t *input,
293 size_t input_length);
294
295/**
296 * \brief Finalises a MAC context operation producing the final MAC value
297 * (veneer function)
298 *
299 * \note A successful call to this function releases the MAC operation
300 * context provided as parameter
301 *
302 * \param[in/out] operation MAC operation context
303 * \param[out] mac Buffer containing MAC data
304 * \param[in] mac_size Size of the MAC buffer
305 * \param[out] mac_length Size of the produced MAC
306 *
307 * \return Return values as described in \ref tfm_crypto_err_t
308 */
309enum tfm_crypto_err_t tfm_crypto_veneer_mac_sign_finish(
310 psa_mac_operation_t *operation,
311 uint8_t *mac,
312 size_t mac_size,
313 size_t *mac_length);
314/**
315 * \brief Finalise a MAC context operation, verifying that the final MAC value
316 * matches the one provided as input (veneer function)
317 *
318 * \note A successful call to this function releases the MAC operation
319 * context provided as parameter. The MAC operation is released
320 * also in case TFM_CRYPTO_ERR_PSA_ERROR_INVALID_SIGNATURE is returned
321 *
322 * \param[in/out] operation MAC operation context
323 * \param[in] mac Buffer containing the provided MAC value
324 * \param[in] mac_length Size of the provided MAC value
325 *
326 * \return Return values as described in \ref tfm_crypto_err_t
327 */
328enum tfm_crypto_err_t tfm_crypto_veneer_mac_verify_finish(
329 psa_mac_operation_t *operation,
330 const uint8_t *mac,
331 size_t mac_length);
332/**
333 * \brief Abort a MAC operation, clear the operation context provided
334 * (veneer function)
335 *
336 * \note A successful call to this function releases the MAC operation
337 * context provided as parameter
338 *
339 * \param[in/out] operation MAC operation context
340 *
341 * \return Return values as described in \ref tfm_crypto_err_t
342 */
343enum tfm_crypto_err_t tfm_crypto_veneer_mac_abort(
344 psa_mac_operation_t *operation);
345
Antonio de Angelis8908f472018-08-31 15:44:25 +0100346#ifdef __cplusplus
347}
348#endif
349
350#endif /* __TFM_CRYPTO_VENEERS_H__ */