blob: 314603aab71886ddd6cc0540daae7b6437b23eee [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#include "tfm_crypto_veneers.h"
9#include "secure_fw/services/crypto/tfm_crypto_api.h"
10#include "tfm_secure_api.h"
11#include "tfm_api.h"
12#include "spm_api.h"
13
14#include "psa_crypto.h"
15
16#include "crypto_psa_wrappers.h"
17
18__tfm_secure_gateway_attributes__
19enum tfm_crypto_err_t tfm_crypto_veneer_import_key(psa_key_slot_t key,
20 psa_key_type_t type,
21 const uint8_t *data,
22 size_t data_length)
23{
24 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_import_key,
25 key, type, data, data_length);
26}
27
28__tfm_secure_gateway_attributes__
29enum tfm_crypto_err_t tfm_crypto_veneer_destroy_key(psa_key_slot_t key)
30{
31 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_destroy_key,
32 key, 0, 0, 0);
33}
34
35__tfm_secure_gateway_attributes__
36enum tfm_crypto_err_t tfm_crypto_veneer_get_key_information(
37 psa_key_slot_t key,
38 psa_key_type_t *type,
39 size_t *bits)
40{
41 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_get_key_information,
42 key, type, bits, 0);
43}
44
45__tfm_secure_gateway_attributes__
46enum tfm_crypto_err_t tfm_crypto_veneer_export_key(psa_key_slot_t key,
47 uint8_t *data,
48 size_t data_size,
49 size_t *data_length)
50{
51 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_export_key,
52 key, data, data_size, data_length);
53}
54
Jamie Foxefd82732018-11-26 10:34:32 +000055__tfm_secure_gateway_attributes__
56enum tfm_crypto_err_t tfm_crypto_veneer_key_policy_init(
57 psa_key_policy_t *policy)
58{
59 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_key_policy_init,
60 policy, 0, 0, 0);
61}
62
63__tfm_secure_gateway_attributes__
64enum tfm_crypto_err_t tfm_crypto_veneer_key_policy_set_usage(
65 psa_key_policy_t *policy,
66 psa_key_usage_t usage,
67 psa_algorithm_t alg)
68{
69 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_key_policy_set_usage,
70 policy, usage, alg, 0);
71}
72
73__tfm_secure_gateway_attributes__
74enum tfm_crypto_err_t tfm_crypto_veneer_key_policy_get_usage(
75 const psa_key_policy_t *policy,
76 psa_key_usage_t *usage)
77{
78 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_key_policy_get_usage,
79 policy, usage, 0, 0);
80}
81
82__tfm_secure_gateway_attributes__
83enum tfm_crypto_err_t tfm_crypto_veneer_key_policy_get_algorithm(
84 const psa_key_policy_t *policy,
85 psa_algorithm_t *alg)
86{
87 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_key_policy_get_algorithm,
88 policy, alg, 0, 0);
89}
90
91__tfm_secure_gateway_attributes__
92enum tfm_crypto_err_t tfm_crypto_veneer_set_key_policy(
93 psa_key_slot_t key,
94 const psa_key_policy_t *policy)
95{
96 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_set_key_policy,
97 key, policy, 0, 0);
98}
99
100__tfm_secure_gateway_attributes__
101enum tfm_crypto_err_t tfm_crypto_veneer_get_key_policy(psa_key_slot_t key,
102 psa_key_policy_t *policy)
103{
104 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_get_key_policy,
105 key, policy, 0, 0);
106}
107
108__tfm_secure_gateway_attributes__
109enum tfm_crypto_err_t tfm_crypto_veneer_set_key_lifetime(
110 psa_key_slot_t key,
111 psa_key_lifetime_t lifetime)
112{
113 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_set_key_lifetime,
114 key, lifetime, 0, 0);
115}
116
117__tfm_secure_gateway_attributes__
118enum tfm_crypto_err_t tfm_crypto_veneer_get_key_lifetime(
119 psa_key_slot_t key,
120 psa_key_lifetime_t *lifetime)
121{
122 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_get_key_lifetime,
123 key, lifetime, 0, 0);
124}
Antonio de Angelis8908f472018-08-31 15:44:25 +0100125
126__tfm_secure_gateway_attributes__
Antonio de Angelis377a1552018-11-22 17:02:40 +0000127enum tfm_crypto_err_t tfm_crypto_veneer_cipher_set_iv(
Antonio de Angelis8908f472018-08-31 15:44:25 +0100128 psa_cipher_operation_t *operation,
129 const unsigned char *iv,
130 size_t iv_length)
131{
Antonio de Angelis377a1552018-11-22 17:02:40 +0000132 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_set_iv,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100133 operation, iv, iv_length, 0);
134}
135
136__tfm_secure_gateway_attributes__
Antonio de Angelis377a1552018-11-22 17:02:40 +0000137enum tfm_crypto_err_t tfm_crypto_veneer_cipher_encrypt_setup(
Antonio de Angelis8908f472018-08-31 15:44:25 +0100138 psa_cipher_operation_t *operation,
139 psa_key_slot_t key,
140 psa_algorithm_t alg)
141{
Antonio de Angelis377a1552018-11-22 17:02:40 +0000142 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_encrypt_setup,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100143 operation, key, alg, 0);
144}
145
146__tfm_secure_gateway_attributes__
Antonio de Angelis377a1552018-11-22 17:02:40 +0000147enum tfm_crypto_err_t tfm_crypto_veneer_cipher_decrypt_setup(
Antonio de Angelis8908f472018-08-31 15:44:25 +0100148 psa_cipher_operation_t *operation,
149 psa_key_slot_t key,
150 psa_algorithm_t alg)
151{
Antonio de Angelis377a1552018-11-22 17:02:40 +0000152 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_decrypt_setup,
Antonio de Angelis8908f472018-08-31 15:44:25 +0100153 operation, key, alg, 0);
154}
155
156__tfm_secure_gateway_attributes__
157enum tfm_crypto_err_t tfm_crypto_veneer_cipher_update(
158 psa_cipher_operation_t *operation,
159 struct psa_cipher_update_input *input_s,
160 struct psa_cipher_update_output *output_s)
161{
162 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_update_wrapper,
163 operation, input_s, output_s, 0);
164}
165
166__tfm_secure_gateway_attributes__
167enum tfm_crypto_err_t tfm_crypto_veneer_cipher_abort(
168 psa_cipher_operation_t *operation)
169{
170 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_abort,
171 operation, 0, 0, 0);
172}
173
174__tfm_secure_gateway_attributes__
175enum tfm_crypto_err_t tfm_crypto_veneer_cipher_finish(
176 psa_cipher_operation_t *operation,
177 uint8_t *output,
178 size_t output_size,
179 size_t *output_length)
180{
181 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_cipher_finish,
182 operation, output, output_size, output_length);
183}
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100184
185__tfm_secure_gateway_attributes__
Antonio de Angelis377a1552018-11-22 17:02:40 +0000186enum tfm_crypto_err_t tfm_crypto_veneer_hash_setup(
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100187 psa_hash_operation_t *operation,
188 psa_algorithm_t alg)
189{
Antonio de Angelis377a1552018-11-22 17:02:40 +0000190 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_setup,
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100191 operation, alg, 0, 0);
192}
193
194__tfm_secure_gateway_attributes__
195enum tfm_crypto_err_t tfm_crypto_veneer_hash_update(
196 psa_hash_operation_t *operation,
197 const uint8_t *input,
198 size_t input_length)
199{
200 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_update,
201 operation, input, input_length, 0);
202}
203
204__tfm_secure_gateway_attributes__
205enum tfm_crypto_err_t tfm_crypto_veneer_hash_finish(
206 psa_hash_operation_t *operation,
207 uint8_t *hash,
208 size_t hash_size,
209 size_t *hash_length)
210{
211 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_finish,
212 operation, hash, hash_size, hash_length);
213}
214
215__tfm_secure_gateway_attributes__
216enum tfm_crypto_err_t tfm_crypto_veneer_hash_verify(
217 psa_hash_operation_t *operation,
218 const uint8_t *hash,
219 size_t hash_length)
220{
221 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_verify,
222 operation, hash, hash_length, 0);
223}
224
225__tfm_secure_gateway_attributes__
226enum tfm_crypto_err_t tfm_crypto_veneer_hash_abort(
227 psa_hash_operation_t *operation)
228{
229 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_hash_abort,
230 operation, 0, 0, 0);
231}
Louis Mayencourt7a36f782018-09-24 14:00:57 +0100232
233__tfm_secure_gateway_attributes__
234enum tfm_crypto_err_t tfm_crypto_veneer_mac_sign_setup(
235 psa_mac_operation_t *operation,
236 psa_key_slot_t key,
237 psa_algorithm_t alg)
238{
239 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_sign_setup,
240 operation, key, alg, 0);
241}
242
243__tfm_secure_gateway_attributes__
244enum tfm_crypto_err_t tfm_crypto_veneer_mac_verify_setup(
245 psa_mac_operation_t *operation,
246 psa_key_slot_t key,
247 psa_algorithm_t alg)
248{
249 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_verify_setup,
250 operation, key, alg, 0);
251}
252
253__tfm_secure_gateway_attributes__
254enum tfm_crypto_err_t tfm_crypto_veneer_mac_update(
255 psa_mac_operation_t *operation,
256 const uint8_t *input,
257 size_t input_length)
258{
259 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_update,
260 operation, input, input_length, 0);
261}
262
263__tfm_secure_gateway_attributes__
264enum tfm_crypto_err_t tfm_crypto_veneer_mac_sign_finish(
265 psa_mac_operation_t *operation,
266 uint8_t *mac,
267 size_t mac_size,
268 size_t *mac_length)
269{
270 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_sign_finish,
271 operation, mac, mac_size, mac_length);
272}
273
274__tfm_secure_gateway_attributes__
275enum tfm_crypto_err_t tfm_crypto_veneer_mac_verify_finish(
276 psa_mac_operation_t *operation,
277 const uint8_t *mac,
278 size_t mac_length)
279{
280 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_verify_finish,
281 operation, mac, mac_length, 0);
282}
283
284__tfm_secure_gateway_attributes__
285enum tfm_crypto_err_t tfm_crypto_veneer_mac_abort(
286 psa_mac_operation_t *operation)
287{
288 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_mac_abort,
289 operation, 0, 0, 0);
290}
Antonio de Angelis3a480992018-11-07 11:53:28 +0000291
292__tfm_secure_gateway_attributes__
293enum tfm_crypto_err_t tfm_crypto_veneer_aead_encrypt(
294 struct psa_aead_encrypt_input *input_s,
295 struct psa_aead_encrypt_output *output_s)
296{
297 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_aead_encrypt_wrapper,
298 input_s, output_s, 0, 0);
299}
300
301__tfm_secure_gateway_attributes__
302enum tfm_crypto_err_t tfm_crypto_veneer_aead_decrypt(
303 struct psa_aead_decrypt_input *input_s,
304 struct psa_aead_decrypt_output *output_s)
305{
306 TFM_CORE_SFN_REQUEST(TFM_SP_CRYPTO_ID, tfm_crypto_aead_decrypt_wrapper,
307 input_s, output_s, 0, 0);
308}