blob: bb2c6d4f9f6a8676af52cc30dadfc4326f027d8c [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/**
22 * \brief Import the key data on the provided key slot (veneer function)
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 */
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 *
60 * \param[in] key Key slot
61 * \param[out] data Buffer to hold the exported key
62 * \param[in] data_size Length of the buffer pointed to by data
63 * \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 *
89 * \param[in] operation Cipher operation context
90 * \param[in] key Key slot to bind to the cipher context
91 * \param[in] alg Algorithm to use for the cipher operation
92 *
93 * \return Return values as described in \ref tfm_crypto_err_t
94 */
Antonio de Angelis377a1552018-11-22 17:02:40 +000095enum tfm_crypto_err_t tfm_crypto_veneer_cipher_encrypt_setup(
Antonio de Angelis8908f472018-08-31 15:44:25 +010096 psa_cipher_operation_t *operation,
97 psa_key_slot_t key,
98 psa_algorithm_t alg);
99/**
100 * \brief Set the cipher operation using the provided algorithm and key slot,
101 * for decryption context (veneer function)
102 *
103 * \param[in] operation Cipher operation context
104 * \param[in] key Key slot to bind to the cipher context
105 * \param[in] alg Algorithm to use for the cipher operation
106 *
107 * \return Return values as described in \ref tfm_crypto_err_t
108 */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000109enum tfm_crypto_err_t tfm_crypto_veneer_cipher_decrypt_setup(
Antonio de Angelis8908f472018-08-31 15:44:25 +0100110 psa_cipher_operation_t *operation,
111 psa_key_slot_t key,
112 psa_algorithm_t alg);
113/**
114 * \brief Update the cipher context with a chunk of input data to create a
115 * chunk of encrypted output data (for encryption contexts), or to
116 * decrypt a chunk of encrypted input data to obtain decrypted data
117 * (for decryption contexts) (veneer function)
118 *
119 * \param[in] operation Cipher operation context
120 * \param[in] input_s Pointer to the struct containing input parameters
121 * \param[out] output_s Pointer to the struct containing output parameters
122 *
123 * \return Return values as described in \ref tfm_crypto_err_t
124 */
125enum tfm_crypto_err_t tfm_crypto_veneer_cipher_update(
126 psa_cipher_operation_t *operation,
127 struct psa_cipher_update_input *input_s,
128 struct psa_cipher_update_output *output_s);
129/**
130 * \brief Abort a cipher operation, clears the operation context provided
131 * (veneer function)
132 *
133 * \param[in] operation Cipher operation context
134 *
135 * \return Return values as described in \ref tfm_crypto_err_t
136 */
137enum tfm_crypto_err_t tfm_crypto_veneer_cipher_abort(
138 psa_cipher_operation_t *operation);
139
140/**
141 * \brief Finalise a cipher context flushing out any remaining block of
142 * output data (veneer function)
143 *
144 * \param[in] operation Cipher operation context
145 * \param[out] output Buffer containing output data
146 * \param[in] output_size Size of the output buffer
147 * \param[out] output_length Size of the produced output
148 *
149 * \return Return values as described in \ref tfm_crypto_err_t
150 */
151enum tfm_crypto_err_t tfm_crypto_veneer_cipher_finish(
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100152 psa_cipher_operation_t *operation,
153 uint8_t *output,
154 size_t output_size,
155 size_t *output_length);
156/**
Antonio de Angelis377a1552018-11-22 17:02:40 +0000157 * \brief Setup a hash operation with the provided algorithm (veneer function)
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100158 *
159 * \param[in] operation Hash operation context
160 * \param[in] alg Algorithm chosen as hash
161 *
162 * \return Returns values as described in \ref tfm_crypto_err_t
163 */
Antonio de Angelis377a1552018-11-22 17:02:40 +0000164enum tfm_crypto_err_t tfm_crypto_veneer_hash_setup(
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100165 psa_hash_operation_t *operation,
166 psa_algorithm_t alg);
167/**
168 * \brief Adds a new input chunk to the data for which the final hash value
169 * will be computed (veneer function)
170 *
171 * \param[in] operation Hash operation context
172 * \param[in] input Buffer containing the input data
173 * \param[in] input_length Size of the provided input data
174 *
175 * \return Returns values as described in \ref tfm_crypto_err_t
176 */
177enum tfm_crypto_err_t tfm_crypto_veneer_hash_update(
178 psa_hash_operation_t *operation,
179 const uint8_t *input,
180 size_t input_length);
181/**
182 * \brief Finalises a hash context operation producing the final hash value
183 * (veneer function)
184 *
185 * \param[in] operation Hash operation context
186 * \param[out] hash Buffer containing hash data
187 * \param[in] hash_size Size of the hash buffer
188 * \param[out] hash_length Size of the produced hash
189 *
190 * \return Returns values as described in \ref tfm_crypto_err_t
191 */
192enum tfm_crypto_err_t tfm_crypto_veneer_hash_finish(
193 psa_hash_operation_t *operation,
194 uint8_t *hash,
195 size_t hash_size,
196 size_t *hash_length);
197/**
198 * \brief Finalises a hash context operation, verifying that the final hash
199 * value matches the one provided as input (veneer function)
200 *
201 * \param[in] operation Hash operation context
202 * \param[in] hash Buffer containing the provided hash value
203 * \param[in] hash_length Size of the provided hash value
204 *
205 * \return Returns values as described in \ref tfm_crypto_err_t
206 */
207enum tfm_crypto_err_t tfm_crypto_veneer_hash_verify(
208 psa_hash_operation_t *operation,
209 const uint8_t *hash,
210 size_t hash_length);
211/**
212 * \brief Aborts a hash operation, clears the operation context provided
213 * (veneer function)
214 *
215 * \param[in] operation Hash operation context
216 *
217 * \return Returns values as described in \ref tfm_crypto_err_t
218 */
219enum tfm_crypto_err_t tfm_crypto_veneer_hash_abort(
220 psa_hash_operation_t *operation);
221
Antonio de Angelis8908f472018-08-31 15:44:25 +0100222#ifdef __cplusplus
223}
224#endif
225
226#endif /* __TFM_CRYPTO_VENEERS_H__ */