blob: 8f51b667844f43b74fc228754243c13a6b5f2951 [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_API_H__
9#define __TFM_CRYPTO_API_H__
10
11#ifdef __cplusplus
12extern "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 */
25enum 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 Angelis8908f472018-08-31 15:44:25 +010030
31 /* Used to force the enum size */
32 TFM_CRYPTO_OPERATION_TYPE_MAX = INT_MAX
33};
34
35/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010036 * \brief Initialise the service
Antonio de Angelis8908f472018-08-31 15:44:25 +010037 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010038 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010039 */
40enum tfm_crypto_err_t tfm_crypto_init(void);
41
42/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010043 * \brief Initialise the Key module
44 *
45 * \return Return values as described in \ref tfm_crypto_err_t
46 */
47enum 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 */
54enum tfm_crypto_err_t tfm_crypto_init_alloc(void);
55
56/**
57 * \brief Allocate an operation object
Antonio de Angelis8908f472018-08-31 15:44:25 +010058 *
59 * \param[in] type Type of the operation object to allocate
60 * \param[out] handle Pointer to the corresponding handle assigned
61 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010062 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010063 */
64enum tfm_crypto_err_t tfm_crypto_operation_alloc(
65 enum tfm_crypto_operation_type type,
66 uint32_t *handle);
67/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010068 * \brief Release an operation object
Antonio de Angelis8908f472018-08-31 15:44:25 +010069 *
70 * \param[in] handle Pointer to the handle for the release of the
71 * corresponding object
72 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010073 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010074 */
75enum tfm_crypto_err_t tfm_crypto_operation_release(uint32_t *handle);
76
77/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010078 * \brief Look up an operation object pointer from the corresponding handle
Antonio de Angelis8908f472018-08-31 15:44:25 +010079 *
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 Angeliscf85ba22018-10-09 13:29:40 +010084 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +010085 */
86enum tfm_crypto_err_t tfm_crypto_operation_lookup(
87 enum tfm_crypto_operation_type type,
Antonio de Angelis377a1552018-11-22 17:02:40 +000088 uint32_t handle,
Antonio de Angelis8908f472018-08-31 15:44:25 +010089 void **oper);
90/**
Jamie Foxefd82732018-11-26 10:34:32 +000091 * \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 */
104enum 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 Angelis8908f472018-08-31 15:44:25 +0100111 * \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 Angeliscf85ba22018-10-09 13:29:40 +0100118 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100119 */
120enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100125 * \brief Destroy the key in the provided key slot
Antonio de Angelis8908f472018-08-31 15:44:25 +0100126 *
127 * \param[in] key Key slot
128 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100129 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100130 */
131enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100140 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100141 */
142enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100153 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100154 */
155enum 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 Foxefd82732018-11-26 10:34:32 +0000159
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 */
168enum 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 */
179enum 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 */
191enum 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 */
203enum 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 */
215enum 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 */
226enum 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 */
237enum 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 */
248enum tfm_crypto_err_t tfm_crypto_get_key_lifetime(psa_key_slot_t key,
249 psa_key_lifetime_t *lifetime);
250
Antonio de Angelis8908f472018-08-31 15:44:25 +0100251/**
252 * \brief Export the public key contained in the provided key slot
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100253 * for an asymmetric key pair
Antonio de Angelis8908f472018-08-31 15:44:25 +0100254 *
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 Angeliscf85ba22018-10-09 13:29:40 +0100260 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100261 */
262enum 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 Angelis8908f472018-08-31 15:44:25 +0100266/**
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 Angeliscf85ba22018-10-09 13:29:40 +0100273 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100274 */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000275enum tfm_crypto_err_t tfm_crypto_cipher_set_iv(
Antonio de Angelis8908f472018-08-31 15:44:25 +0100276 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 Angeliscf85ba22018-10-09 13:29:40 +0100281 * for encryption context
Antonio de Angelis8908f472018-08-31 15:44:25 +0100282 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100283 * \note A successful call to this function initialises a cipher operation
284 * context which will be referred using the operation parameter
Antonio de Angelis8908f472018-08-31 15:44:25 +0100285 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100286 * \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 Angelis8908f472018-08-31 15:44:25 +0100291 */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000292enum tfm_crypto_err_t tfm_crypto_cipher_encrypt_setup(
Antonio de Angelis8908f472018-08-31 15:44:25 +0100293 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 Angeliscf85ba22018-10-09 13:29:40 +0100298 * for decryption context
Antonio de Angelis8908f472018-08-31 15:44:25 +0100299 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100300 * \note A successful call to this function initialises a cipher operation
301 * context which will be referred using the operation parameter
Antonio de Angelis8908f472018-08-31 15:44:25 +0100302 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100303 * \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 Angelis8908f472018-08-31 15:44:25 +0100308 */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000309enum tfm_crypto_err_t tfm_crypto_cipher_decrypt_setup(
Antonio de Angelis8908f472018-08-31 15:44:25 +0100310 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 Angeliscf85ba22018-10-09 13:29:40 +0100317 * (for decryption contexts)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100318 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100319 * \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 Angelis8908f472018-08-31 15:44:25 +0100325 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100326 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100327 */
328enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100336 * \brief Finalise a cipher context flushing out any remaining block of
Antonio de Angelis8908f472018-08-31 15:44:25 +0100337 * output data
338 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100339 * \note A successful call to this function de-initialises the cipher operation
340 * context provided as parameter
Antonio de Angelis8908f472018-08-31 15:44:25 +0100341 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100342 * \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 Angelis8908f472018-08-31 15:44:25 +0100348 */
349enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100355 * \brief Abort a cipher operation, clears the operation context provided
Antonio de Angelis8908f472018-08-31 15:44:25 +0100356 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100357 * \note A successful call to this function de-initialises the cipher operation
358 * context provided as parameter
Antonio de Angelis8908f472018-08-31 15:44:25 +0100359 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100360 * \param[in/out] operation Cipher operation context
361 *
362 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelis8908f472018-08-31 15:44:25 +0100363 */
364enum tfm_crypto_err_t tfm_crypto_cipher_abort(
365 psa_cipher_operation_t *operation);
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100366/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100367 * \brief Start a hash operation with the provided algorithm
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100368 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100369 * \note A successful call to this function initialises a hash operation
370 * context which will be referred using the operation parameter
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100371 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100372 * \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 Angelisa6f72162018-09-05 11:00:37 +0100376 */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000377enum tfm_crypto_err_t tfm_crypto_hash_setup(psa_hash_operation_t *operation,
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100378 psa_algorithm_t alg);
379/**
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100380 * \brief Add a new input chunk to the data for which the final hash value
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100381 * 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 Angeliscf85ba22018-10-09 13:29:40 +0100387 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100388 */
389enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100393 * \brief Finalise a hash context operation producing the final hash value
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100394 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100395 * \note A successful call to this function de-initialises the hash operation
396 * context provided as parameter
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100397 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100398 * \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 Angelisa6f72162018-09-05 11:00:37 +0100404 */
405enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100410 * \brief Finalise a hash context operation, verifying that the final hash
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100411 * value matches the one provided as input
412 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100413 * \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 Angelisa6f72162018-09-05 11:00:37 +0100416 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100417 * \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 Angelisa6f72162018-09-05 11:00:37 +0100422 */
423enum 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 Angeliscf85ba22018-10-09 13:29:40 +0100427 * \brief Abort a hash operation, clears the operation context provided
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100428 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100429 * \note A successful call to this function de-initialises the hash operation
430 * context provided as parameter
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100431 *
Antonio de Angeliscf85ba22018-10-09 13:29:40 +0100432 * \param[in/out] operation Hash operation context
433 *
434 * \return Return values as described in \ref tfm_crypto_err_t
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100435 */
436enum tfm_crypto_err_t tfm_crypto_hash_abort(psa_hash_operation_t *operation);
Antonio de Angelis8908f472018-08-31 15:44:25 +0100437
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100438/**
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 */
450enum 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 */
465enum 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 */
479enum 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 */
492enum 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 */
506enum 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 */
517enum tfm_crypto_err_t tfm_crypto_mac_abort(psa_mac_operation_t *operation);
518
Antonio de Angelis3a480992018-11-07 11:53:28 +0000519/**
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 */
542enum 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 */
575enum 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 Angelis8908f472018-08-31 15:44:25 +0100586#ifdef __cplusplus
587}
588#endif
589
590#endif /* __TFM_CRYPTO_API_H__ */