blob: dbeb6a8d69e3ec19072e4798821ee01b61027cd4 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "tfm_crypto_veneers.h"
9#include "psa_crypto.h"
10#include "tfm_ns_lock.h"
11#include "crypto_psa_wrappers.h"
12
13psa_status_t psa_crypto_init(void)
14{
15 /* Service init is performed during TFM boot up,
16 * so application level initialisation is empty
17 */
18 return PSA_SUCCESS;
19}
20
21psa_status_t psa_import_key(psa_key_slot_t key,
22 psa_key_type_t type,
23 const uint8_t *data,
24 size_t data_length)
25{
26 enum tfm_crypto_err_t err;
27
28 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_import_key,
29 (uint32_t)key,
30 (uint32_t)type,
31 (uint32_t)data,
32 (uint32_t)data_length);
33
34 return TFM_CRYPTO_PSA_RETURN(err);
35}
36
37psa_status_t psa_destroy_key(psa_key_slot_t key)
38{
39 enum tfm_crypto_err_t err;
40
41 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_destroy_key,
42 (uint32_t)key,
43 0,
44 0,
45 0);
46
47 return TFM_CRYPTO_PSA_RETURN(err);
48}
49
50psa_status_t psa_get_key_information(psa_key_slot_t key,
51 psa_key_type_t *type,
52 size_t *bits)
53{
54 enum tfm_crypto_err_t err;
55
56 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_get_key_information,
57 (uint32_t)key,
58 (uint32_t)type,
59 (uint32_t)bits,
60 0);
61
62 return TFM_CRYPTO_PSA_RETURN(err);
63}
64
65psa_status_t psa_export_key(psa_key_slot_t key,
66 uint8_t *data,
67 size_t data_size,
68 size_t *data_length)
69{
70 enum tfm_crypto_err_t err;
71
72 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_export_key,
73 (uint32_t)key,
74 (uint32_t)data,
75 (uint32_t)data_size,
76 (uint32_t)data_length);
77
78 return TFM_CRYPTO_PSA_RETURN(err);
79}
80
81psa_status_t psa_export_public_key(psa_key_slot_t key,
82 uint8_t *data,
83 size_t data_size,
84 size_t *data_length)
85{
86 /* TODO: This API is not supported yet */
87 return PSA_ERROR_NOT_SUPPORTED;
88}
89
90psa_status_t psa_encrypt_set_iv(psa_cipher_operation_t *operation,
91 const unsigned char *iv,
92 size_t iv_length)
93{
94 enum tfm_crypto_err_t err;
95
96 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_encrypt_set_iv,
97 (uint32_t)operation,
98 (uint32_t)iv,
99 (uint32_t)iv_length,
100 0);
101
102 return TFM_CRYPTO_PSA_RETURN(err);
103}
104
105psa_status_t psa_encrypt_setup(psa_cipher_operation_t *operation,
106 psa_key_slot_t key,
107 psa_algorithm_t alg)
108{
109 enum tfm_crypto_err_t err;
110
111 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_encrypt_setup,
112 (uint32_t)operation,
113 (uint32_t)key,
114 (uint32_t)alg,
115 0);
116
117 return TFM_CRYPTO_PSA_RETURN(err);
118}
119
120psa_status_t psa_decrypt_setup(psa_cipher_operation_t *operation,
121 psa_key_slot_t key,
122 psa_algorithm_t alg)
123{
124 enum tfm_crypto_err_t err;
125
126 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_decrypt_setup,
127 (uint32_t)operation,
128 (uint32_t)key,
129 (uint32_t)alg,
130 0);
131
132 return TFM_CRYPTO_PSA_RETURN(err);
133}
134
135psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
136 const uint8_t *input,
137 size_t input_length,
138 unsigned char *output,
139 size_t output_size,
140 size_t *output_length)
141{
142 enum tfm_crypto_err_t err;
143
144 /* Packing in structures is needed to overcome the 4 parameters
145 * per call limit
146 */
147 struct psa_cipher_update_input input_s = {.input = input,
148 .input_length = input_length};
149 struct psa_cipher_update_output output_s = {.output = output,
150 .output_size = output_size,
151 .output_length =
152 output_length};
153
154 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_cipher_update,
155 (uint32_t)operation,
156 (uint32_t)&input_s,
157 (uint32_t)&output_s,
158 0);
159
160 return TFM_CRYPTO_PSA_RETURN(err);
161}
162
163psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation)
164{
165 enum tfm_crypto_err_t err;
166
167 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_cipher_abort,
168 (uint32_t)operation,
169 0,
170 0,
171 0);
172
173 return TFM_CRYPTO_PSA_RETURN(err);
174}
175
176psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
177 uint8_t *output,
178 size_t output_size,
179 size_t *output_length)
180{
181 enum tfm_crypto_err_t err;
182
183 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_cipher_finish,
184 (uint32_t)operation,
185 (uint32_t)output,
186 (uint32_t)output_size,
187 (uint32_t)output_length);
188
189 return TFM_CRYPTO_PSA_RETURN(err);
190}
Antonio de Angelisa6f72162018-09-05 11:00:37 +0100191
192psa_status_t psa_hash_start(psa_hash_operation_t *operation,
193 psa_algorithm_t alg)
194{
195 enum tfm_crypto_err_t err;
196
197 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_start,
198 (uint32_t)operation,
199 (uint32_t)alg,
200 0,
201 0);
202
203 return TFM_CRYPTO_PSA_RETURN(err);
204}
205
206psa_status_t psa_hash_update(psa_hash_operation_t *operation,
207 const uint8_t *input,
208 size_t input_length)
209{
210 enum tfm_crypto_err_t err;
211
212 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_update,
213 (uint32_t)operation,
214 (uint32_t)input,
215 (uint32_t)input_length,
216 0);
217
218 return TFM_CRYPTO_PSA_RETURN(err);
219}
220
221psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
222 uint8_t *hash,
223 size_t hash_size,
224 size_t *hash_length)
225{
226 enum tfm_crypto_err_t err;
227
228 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_finish,
229 (uint32_t)operation,
230 (uint32_t)hash,
231 (uint32_t)hash_size,
232 (uint32_t)hash_length);
233
234 return TFM_CRYPTO_PSA_RETURN(err);
235}
236
237psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
238 const uint8_t *hash,
239 size_t hash_length)
240{
241 enum tfm_crypto_err_t err;
242
243 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_verify,
244 (uint32_t)operation,
245 (uint32_t)hash,
246 (uint32_t)hash_length,
247 0);
248
249 return TFM_CRYPTO_PSA_RETURN(err);
250}
251
252psa_status_t psa_hash_abort(psa_hash_operation_t *operation)
253{
254 enum tfm_crypto_err_t err;
255
256 err = tfm_ns_lock_dispatch((veneer_fn)tfm_crypto_veneer_hash_abort,
257 (uint32_t)operation,
258 0,
259 0,
260 0);
261
262 return TFM_CRYPTO_PSA_RETURN(err);
263}