• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Function signatures for functionality that can be provided by
3  *  cryptographic accelerators.
4  */
5 /*  Copyright The Mbed TLS Contributors
6  *  SPDX-License-Identifier: Apache-2.0
7  *
8  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
9  *  not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License.
19  */
20 
21 #ifndef PSA_CRYPTO_DRIVER_WRAPPERS_H
22 #define PSA_CRYPTO_DRIVER_WRAPPERS_H
23 
24 #include "psa/crypto.h"
25 #include "psa/crypto_driver_common.h"
26 
27 /*
28  * Initialization and termination functions
29  */
30 psa_status_t psa_driver_wrapper_init(void);
31 void psa_driver_wrapper_free(void);
32 
33 /*
34  * Signature functions
35  */
36 psa_status_t psa_driver_wrapper_sign_message(
37     const psa_key_attributes_t *attributes,
38     const uint8_t *key_buffer,
39     size_t key_buffer_size,
40     psa_algorithm_t alg,
41     const uint8_t *input,
42     size_t input_length,
43     uint8_t *signature,
44     size_t signature_size,
45     size_t *signature_length);
46 
47 psa_status_t psa_driver_wrapper_verify_message(
48     const psa_key_attributes_t *attributes,
49     const uint8_t *key_buffer,
50     size_t key_buffer_size,
51     psa_algorithm_t alg,
52     const uint8_t *input,
53     size_t input_length,
54     const uint8_t *signature,
55     size_t signature_length);
56 
57 psa_status_t psa_driver_wrapper_sign_hash(
58     const psa_key_attributes_t *attributes,
59     const uint8_t *key_buffer, size_t key_buffer_size,
60     psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
61     uint8_t *signature, size_t signature_size, size_t *signature_length);
62 
63 psa_status_t psa_driver_wrapper_verify_hash(
64     const psa_key_attributes_t *attributes,
65     const uint8_t *key_buffer, size_t key_buffer_size,
66     psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
67     const uint8_t *signature, size_t signature_length);
68 
69 /*
70  * Interruptible Signature functions
71  */
72 
73 uint32_t psa_driver_wrapper_sign_hash_get_num_ops(
74     psa_sign_hash_interruptible_operation_t *operation);
75 
76 uint32_t psa_driver_wrapper_verify_hash_get_num_ops(
77     psa_verify_hash_interruptible_operation_t *operation);
78 
79 psa_status_t psa_driver_wrapper_sign_hash_start(
80     psa_sign_hash_interruptible_operation_t *operation,
81     const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
82     size_t key_buffer_size, psa_algorithm_t alg,
83     const uint8_t *hash, size_t hash_length);
84 
85 psa_status_t psa_driver_wrapper_sign_hash_complete(
86     psa_sign_hash_interruptible_operation_t *operation,
87     uint8_t *signature, size_t signature_size,
88     size_t *signature_length);
89 
90 psa_status_t psa_driver_wrapper_sign_hash_abort(
91     psa_sign_hash_interruptible_operation_t *operation);
92 
93 psa_status_t psa_driver_wrapper_verify_hash_start(
94     psa_verify_hash_interruptible_operation_t *operation,
95     const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
96     size_t key_buffer_size, psa_algorithm_t alg,
97     const uint8_t *hash, size_t hash_length,
98     const uint8_t *signature, size_t signature_length);
99 
100 psa_status_t psa_driver_wrapper_verify_hash_complete(
101     psa_verify_hash_interruptible_operation_t *operation);
102 
103 psa_status_t psa_driver_wrapper_verify_hash_abort(
104     psa_verify_hash_interruptible_operation_t *operation);
105 
106 /*
107  * Key handling functions
108  */
109 
110 psa_status_t psa_driver_wrapper_import_key(
111     const psa_key_attributes_t *attributes,
112     const uint8_t *data, size_t data_length,
113     uint8_t *key_buffer, size_t key_buffer_size,
114     size_t *key_buffer_length, size_t *bits);
115 
116 psa_status_t psa_driver_wrapper_export_key(
117     const psa_key_attributes_t *attributes,
118     const uint8_t *key_buffer, size_t key_buffer_size,
119     uint8_t *data, size_t data_size, size_t *data_length);
120 
121 psa_status_t psa_driver_wrapper_export_public_key(
122     const psa_key_attributes_t *attributes,
123     const uint8_t *key_buffer, size_t key_buffer_size,
124     uint8_t *data, size_t data_size, size_t *data_length);
125 
126 psa_status_t psa_driver_wrapper_get_key_buffer_size(
127     const psa_key_attributes_t *attributes,
128     size_t *key_buffer_size);
129 
130 psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data(
131     const psa_key_attributes_t *attributes,
132     const uint8_t *data,
133     size_t data_length,
134     size_t *key_buffer_size);
135 
136 psa_status_t psa_driver_wrapper_generate_key(
137     const psa_key_attributes_t *attributes,
138     uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length);
139 
140 psa_status_t psa_driver_wrapper_get_builtin_key(
141     psa_drv_slot_number_t slot_number,
142     psa_key_attributes_t *attributes,
143     uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length);
144 
145 psa_status_t psa_driver_wrapper_copy_key(
146     psa_key_attributes_t *attributes,
147     const uint8_t *source_key, size_t source_key_length,
148     uint8_t *target_key_buffer, size_t target_key_buffer_size,
149     size_t *target_key_buffer_length);
150 /*
151  * Cipher functions
152  */
153 psa_status_t psa_driver_wrapper_cipher_encrypt(
154     const psa_key_attributes_t *attributes,
155     const uint8_t *key_buffer,
156     size_t key_buffer_size,
157     psa_algorithm_t alg,
158     const uint8_t *iv,
159     size_t iv_length,
160     const uint8_t *input,
161     size_t input_length,
162     uint8_t *output,
163     size_t output_size,
164     size_t *output_length);
165 
166 psa_status_t psa_driver_wrapper_cipher_decrypt(
167     const psa_key_attributes_t *attributes,
168     const uint8_t *key_buffer,
169     size_t key_buffer_size,
170     psa_algorithm_t alg,
171     const uint8_t *input,
172     size_t input_length,
173     uint8_t *output,
174     size_t output_size,
175     size_t *output_length);
176 
177 psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
178     psa_cipher_operation_t *operation,
179     const psa_key_attributes_t *attributes,
180     const uint8_t *key_buffer, size_t key_buffer_size,
181     psa_algorithm_t alg);
182 
183 psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
184     psa_cipher_operation_t *operation,
185     const psa_key_attributes_t *attributes,
186     const uint8_t *key_buffer, size_t key_buffer_size,
187     psa_algorithm_t alg);
188 
189 psa_status_t psa_driver_wrapper_cipher_set_iv(
190     psa_cipher_operation_t *operation,
191     const uint8_t *iv,
192     size_t iv_length);
193 
194 psa_status_t psa_driver_wrapper_cipher_update(
195     psa_cipher_operation_t *operation,
196     const uint8_t *input,
197     size_t input_length,
198     uint8_t *output,
199     size_t output_size,
200     size_t *output_length);
201 
202 psa_status_t psa_driver_wrapper_cipher_finish(
203     psa_cipher_operation_t *operation,
204     uint8_t *output,
205     size_t output_size,
206     size_t *output_length);
207 
208 psa_status_t psa_driver_wrapper_cipher_abort(
209     psa_cipher_operation_t *operation);
210 
211 /*
212  * Hashing functions
213  */
214 psa_status_t psa_driver_wrapper_hash_compute(
215     psa_algorithm_t alg,
216     const uint8_t *input,
217     size_t input_length,
218     uint8_t *hash,
219     size_t hash_size,
220     size_t *hash_length);
221 
222 psa_status_t psa_driver_wrapper_hash_setup(
223     psa_hash_operation_t *operation,
224     psa_algorithm_t alg);
225 
226 psa_status_t psa_driver_wrapper_hash_clone(
227     const psa_hash_operation_t *source_operation,
228     psa_hash_operation_t *target_operation);
229 
230 psa_status_t psa_driver_wrapper_hash_update(
231     psa_hash_operation_t *operation,
232     const uint8_t *input,
233     size_t input_length);
234 
235 psa_status_t psa_driver_wrapper_hash_finish(
236     psa_hash_operation_t *operation,
237     uint8_t *hash,
238     size_t hash_size,
239     size_t *hash_length);
240 
241 psa_status_t psa_driver_wrapper_hash_abort(
242     psa_hash_operation_t *operation);
243 
244 /*
245  * AEAD functions
246  */
247 
248 psa_status_t psa_driver_wrapper_aead_encrypt(
249     const psa_key_attributes_t *attributes,
250     const uint8_t *key_buffer, size_t key_buffer_size,
251     psa_algorithm_t alg,
252     const uint8_t *nonce, size_t nonce_length,
253     const uint8_t *additional_data, size_t additional_data_length,
254     const uint8_t *plaintext, size_t plaintext_length,
255     uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length);
256 
257 psa_status_t psa_driver_wrapper_aead_decrypt(
258     const psa_key_attributes_t *attributes,
259     const uint8_t *key_buffer, size_t key_buffer_size,
260     psa_algorithm_t alg,
261     const uint8_t *nonce, size_t nonce_length,
262     const uint8_t *additional_data, size_t additional_data_length,
263     const uint8_t *ciphertext, size_t ciphertext_length,
264     uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length);
265 
266 psa_status_t psa_driver_wrapper_aead_encrypt_setup(
267     psa_aead_operation_t *operation,
268     const psa_key_attributes_t *attributes,
269     const uint8_t *key_buffer, size_t key_buffer_size,
270     psa_algorithm_t alg);
271 
272 psa_status_t psa_driver_wrapper_aead_decrypt_setup(
273     psa_aead_operation_t *operation,
274     const psa_key_attributes_t *attributes,
275     const uint8_t *key_buffer, size_t key_buffer_size,
276     psa_algorithm_t alg);
277 
278 psa_status_t psa_driver_wrapper_aead_set_nonce(
279     psa_aead_operation_t *operation,
280     const uint8_t *nonce,
281     size_t nonce_length);
282 
283 psa_status_t psa_driver_wrapper_aead_set_lengths(
284     psa_aead_operation_t *operation,
285     size_t ad_length,
286     size_t plaintext_length);
287 
288 psa_status_t psa_driver_wrapper_aead_update_ad(
289     psa_aead_operation_t *operation,
290     const uint8_t *input,
291     size_t input_length);
292 
293 psa_status_t psa_driver_wrapper_aead_update(
294     psa_aead_operation_t *operation,
295     const uint8_t *input,
296     size_t input_length,
297     uint8_t *output,
298     size_t output_size,
299     size_t *output_length);
300 
301 psa_status_t psa_driver_wrapper_aead_finish(
302     psa_aead_operation_t *operation,
303     uint8_t *ciphertext,
304     size_t ciphertext_size,
305     size_t *ciphertext_length,
306     uint8_t *tag,
307     size_t tag_size,
308     size_t *tag_length);
309 
310 psa_status_t psa_driver_wrapper_aead_verify(
311     psa_aead_operation_t *operation,
312     uint8_t *plaintext,
313     size_t plaintext_size,
314     size_t *plaintext_length,
315     const uint8_t *tag,
316     size_t tag_length);
317 
318 psa_status_t psa_driver_wrapper_aead_abort(
319     psa_aead_operation_t *operation);
320 
321 /*
322  * MAC functions
323  */
324 psa_status_t psa_driver_wrapper_mac_compute(
325     const psa_key_attributes_t *attributes,
326     const uint8_t *key_buffer,
327     size_t key_buffer_size,
328     psa_algorithm_t alg,
329     const uint8_t *input,
330     size_t input_length,
331     uint8_t *mac,
332     size_t mac_size,
333     size_t *mac_length);
334 
335 psa_status_t psa_driver_wrapper_mac_sign_setup(
336     psa_mac_operation_t *operation,
337     const psa_key_attributes_t *attributes,
338     const uint8_t *key_buffer,
339     size_t key_buffer_size,
340     psa_algorithm_t alg);
341 
342 psa_status_t psa_driver_wrapper_mac_verify_setup(
343     psa_mac_operation_t *operation,
344     const psa_key_attributes_t *attributes,
345     const uint8_t *key_buffer,
346     size_t key_buffer_size,
347     psa_algorithm_t alg);
348 
349 psa_status_t psa_driver_wrapper_mac_update(
350     psa_mac_operation_t *operation,
351     const uint8_t *input,
352     size_t input_length);
353 
354 psa_status_t psa_driver_wrapper_mac_sign_finish(
355     psa_mac_operation_t *operation,
356     uint8_t *mac,
357     size_t mac_size,
358     size_t *mac_length);
359 
360 psa_status_t psa_driver_wrapper_mac_verify_finish(
361     psa_mac_operation_t *operation,
362     const uint8_t *mac,
363     size_t mac_length);
364 
365 psa_status_t psa_driver_wrapper_mac_abort(
366     psa_mac_operation_t *operation);
367 
368 /*
369  * Asymmetric cryptography
370  */
371 psa_status_t psa_driver_wrapper_asymmetric_encrypt(
372     const psa_key_attributes_t *attributes,
373     const uint8_t *key_buffer,
374     size_t key_buffer_size,
375     psa_algorithm_t alg,
376     const uint8_t *input,
377     size_t input_length,
378     const uint8_t *salt,
379     size_t salt_length,
380     uint8_t *output,
381     size_t output_size,
382     size_t *output_length);
383 
384 psa_status_t psa_driver_wrapper_asymmetric_decrypt(
385     const psa_key_attributes_t *attributes,
386     const uint8_t *key_buffer,
387     size_t key_buffer_size,
388     psa_algorithm_t alg,
389     const uint8_t *input,
390     size_t input_length,
391     const uint8_t *salt,
392     size_t salt_length,
393     uint8_t *output,
394     size_t output_size,
395     size_t *output_length);
396 
397 /*
398  * Raw Key Agreement
399  */
400 psa_status_t psa_driver_wrapper_key_agreement(
401     const psa_key_attributes_t *attributes,
402     const uint8_t *key_buffer,
403     size_t key_buffer_size,
404     psa_algorithm_t alg,
405     const uint8_t *peer_key,
406     size_t peer_key_length,
407     uint8_t *shared_secret,
408     size_t shared_secret_size,
409     size_t *shared_secret_length);
410 
411 /*
412  * PAKE functions.
413  */
414 psa_status_t psa_driver_wrapper_pake_setup(
415     psa_pake_operation_t *operation,
416     const psa_crypto_driver_pake_inputs_t *inputs);
417 
418 psa_status_t psa_driver_wrapper_pake_output(
419     psa_pake_operation_t *operation,
420     psa_crypto_driver_pake_step_t step,
421     uint8_t *output,
422     size_t output_size,
423     size_t *output_length);
424 
425 psa_status_t psa_driver_wrapper_pake_input(
426     psa_pake_operation_t *operation,
427     psa_crypto_driver_pake_step_t step,
428     const uint8_t *input,
429     size_t input_length);
430 
431 psa_status_t psa_driver_wrapper_pake_get_implicit_key(
432     psa_pake_operation_t *operation,
433     uint8_t *output, size_t output_size,
434     size_t *output_length);
435 
436 psa_status_t psa_driver_wrapper_pake_abort(
437     psa_pake_operation_t *operation);
438 
439 #endif /* PSA_CRYPTO_DRIVER_WRAPPERS_H */
440 
441 /* End of automatically generated file. */
442