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  * Key handling functions
71  */
72 
73 psa_status_t psa_driver_wrapper_import_key(
74     const psa_key_attributes_t *attributes,
75     const uint8_t *data, size_t data_length,
76     uint8_t *key_buffer, size_t key_buffer_size,
77     size_t *key_buffer_length, size_t *bits );
78 
79 psa_status_t psa_driver_wrapper_export_key(
80     const psa_key_attributes_t *attributes,
81     const uint8_t *key_buffer, size_t key_buffer_size,
82     uint8_t *data, size_t data_size, size_t *data_length );
83 
84 psa_status_t psa_driver_wrapper_export_public_key(
85     const psa_key_attributes_t *attributes,
86     const uint8_t *key_buffer, size_t key_buffer_size,
87     uint8_t *data, size_t data_size, size_t *data_length );
88 
89 psa_status_t psa_driver_wrapper_get_key_buffer_size(
90     const psa_key_attributes_t *attributes,
91     size_t *key_buffer_size );
92 
93 psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data(
94     const psa_key_attributes_t *attributes,
95     const uint8_t *data,
96     size_t data_length,
97     size_t *key_buffer_size );
98 
99 psa_status_t psa_driver_wrapper_generate_key(
100     const psa_key_attributes_t *attributes,
101     uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length );
102 
103 psa_status_t psa_driver_wrapper_get_builtin_key(
104     psa_drv_slot_number_t slot_number,
105     psa_key_attributes_t *attributes,
106     uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length );
107 
108 psa_status_t psa_driver_wrapper_copy_key(
109     psa_key_attributes_t *attributes,
110     const uint8_t *source_key, size_t source_key_length,
111     uint8_t *target_key_buffer, size_t target_key_buffer_size,
112     size_t *target_key_buffer_length );
113 /*
114  * Cipher functions
115  */
116 psa_status_t psa_driver_wrapper_cipher_encrypt(
117     const psa_key_attributes_t *attributes,
118     const uint8_t *key_buffer,
119     size_t key_buffer_size,
120     psa_algorithm_t alg,
121     const uint8_t *iv,
122     size_t iv_length,
123     const uint8_t *input,
124     size_t input_length,
125     uint8_t *output,
126     size_t output_size,
127     size_t *output_length );
128 
129 psa_status_t psa_driver_wrapper_cipher_decrypt(
130     const psa_key_attributes_t *attributes,
131     const uint8_t *key_buffer,
132     size_t key_buffer_size,
133     psa_algorithm_t alg,
134     const uint8_t *input,
135     size_t input_length,
136     uint8_t *output,
137     size_t output_size,
138     size_t *output_length );
139 
140 psa_status_t psa_driver_wrapper_cipher_encrypt_setup(
141     psa_cipher_operation_t *operation,
142     const psa_key_attributes_t *attributes,
143     const uint8_t *key_buffer, size_t key_buffer_size,
144     psa_algorithm_t alg );
145 
146 psa_status_t psa_driver_wrapper_cipher_decrypt_setup(
147     psa_cipher_operation_t *operation,
148     const psa_key_attributes_t *attributes,
149     const uint8_t *key_buffer, size_t key_buffer_size,
150     psa_algorithm_t alg );
151 
152 psa_status_t psa_driver_wrapper_cipher_set_iv(
153     psa_cipher_operation_t *operation,
154     const uint8_t *iv,
155     size_t iv_length );
156 
157 psa_status_t psa_driver_wrapper_cipher_update(
158     psa_cipher_operation_t *operation,
159     const uint8_t *input,
160     size_t input_length,
161     uint8_t *output,
162     size_t output_size,
163     size_t *output_length );
164 
165 psa_status_t psa_driver_wrapper_cipher_finish(
166     psa_cipher_operation_t *operation,
167     uint8_t *output,
168     size_t output_size,
169     size_t *output_length );
170 
171 psa_status_t psa_driver_wrapper_cipher_abort(
172     psa_cipher_operation_t *operation );
173 
174 /*
175  * Hashing functions
176  */
177 psa_status_t psa_driver_wrapper_hash_compute(
178     psa_algorithm_t alg,
179     const uint8_t *input,
180     size_t input_length,
181     uint8_t *hash,
182     size_t hash_size,
183     size_t *hash_length);
184 
185 psa_status_t psa_driver_wrapper_hash_setup(
186     psa_hash_operation_t *operation,
187     psa_algorithm_t alg );
188 
189 psa_status_t psa_driver_wrapper_hash_clone(
190     const psa_hash_operation_t *source_operation,
191     psa_hash_operation_t *target_operation );
192 
193 psa_status_t psa_driver_wrapper_hash_update(
194     psa_hash_operation_t *operation,
195     const uint8_t *input,
196     size_t input_length );
197 
198 psa_status_t psa_driver_wrapper_hash_finish(
199     psa_hash_operation_t *operation,
200     uint8_t *hash,
201     size_t hash_size,
202     size_t *hash_length );
203 
204 psa_status_t psa_driver_wrapper_hash_abort(
205     psa_hash_operation_t *operation );
206 
207 /*
208  * AEAD functions
209  */
210 
211 psa_status_t psa_driver_wrapper_aead_encrypt(
212     const psa_key_attributes_t *attributes,
213     const uint8_t *key_buffer, size_t key_buffer_size,
214     psa_algorithm_t alg,
215     const uint8_t *nonce, size_t nonce_length,
216     const uint8_t *additional_data, size_t additional_data_length,
217     const uint8_t *plaintext, size_t plaintext_length,
218     uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length );
219 
220 psa_status_t psa_driver_wrapper_aead_decrypt(
221     const psa_key_attributes_t *attributes,
222     const uint8_t *key_buffer, size_t key_buffer_size,
223     psa_algorithm_t alg,
224     const uint8_t *nonce, size_t nonce_length,
225     const uint8_t *additional_data, size_t additional_data_length,
226     const uint8_t *ciphertext, size_t ciphertext_length,
227     uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length );
228 
229 psa_status_t psa_driver_wrapper_aead_encrypt_setup(
230     psa_aead_operation_t *operation,
231     const psa_key_attributes_t *attributes,
232     const uint8_t *key_buffer, size_t key_buffer_size,
233     psa_algorithm_t alg );
234 
235 psa_status_t psa_driver_wrapper_aead_decrypt_setup(
236     psa_aead_operation_t *operation,
237     const psa_key_attributes_t *attributes,
238     const uint8_t *key_buffer, size_t key_buffer_size,
239     psa_algorithm_t alg );
240 
241 psa_status_t psa_driver_wrapper_aead_set_nonce(
242     psa_aead_operation_t *operation,
243     const uint8_t *nonce,
244     size_t nonce_length );
245 
246 psa_status_t psa_driver_wrapper_aead_set_lengths(
247     psa_aead_operation_t *operation,
248     size_t ad_length,
249     size_t plaintext_length );
250 
251 psa_status_t psa_driver_wrapper_aead_update_ad(
252     psa_aead_operation_t *operation,
253     const uint8_t *input,
254     size_t input_length );
255 
256 psa_status_t psa_driver_wrapper_aead_update(
257     psa_aead_operation_t *operation,
258     const uint8_t *input,
259     size_t input_length,
260     uint8_t *output,
261     size_t output_size,
262     size_t *output_length );
263 
264 psa_status_t psa_driver_wrapper_aead_finish(
265     psa_aead_operation_t *operation,
266     uint8_t *ciphertext,
267     size_t ciphertext_size,
268     size_t *ciphertext_length,
269     uint8_t *tag,
270     size_t tag_size,
271     size_t *tag_length );
272 
273 psa_status_t psa_driver_wrapper_aead_verify(
274     psa_aead_operation_t *operation,
275     uint8_t *plaintext,
276     size_t plaintext_size,
277     size_t *plaintext_length,
278     const uint8_t *tag,
279     size_t tag_length );
280 
281 psa_status_t psa_driver_wrapper_aead_abort(
282     psa_aead_operation_t *operation );
283 
284 /*
285  * MAC functions
286  */
287 psa_status_t psa_driver_wrapper_mac_compute(
288     const psa_key_attributes_t *attributes,
289     const uint8_t *key_buffer,
290     size_t key_buffer_size,
291     psa_algorithm_t alg,
292     const uint8_t *input,
293     size_t input_length,
294     uint8_t *mac,
295     size_t mac_size,
296     size_t *mac_length );
297 
298 psa_status_t psa_driver_wrapper_mac_sign_setup(
299     psa_mac_operation_t *operation,
300     const psa_key_attributes_t *attributes,
301     const uint8_t *key_buffer,
302     size_t key_buffer_size,
303     psa_algorithm_t alg );
304 
305 psa_status_t psa_driver_wrapper_mac_verify_setup(
306     psa_mac_operation_t *operation,
307     const psa_key_attributes_t *attributes,
308     const uint8_t *key_buffer,
309     size_t key_buffer_size,
310     psa_algorithm_t alg );
311 
312 psa_status_t psa_driver_wrapper_mac_update(
313     psa_mac_operation_t *operation,
314     const uint8_t *input,
315     size_t input_length );
316 
317 psa_status_t psa_driver_wrapper_mac_sign_finish(
318     psa_mac_operation_t *operation,
319     uint8_t *mac,
320     size_t mac_size,
321     size_t *mac_length );
322 
323 psa_status_t psa_driver_wrapper_mac_verify_finish(
324     psa_mac_operation_t *operation,
325     const uint8_t *mac,
326     size_t mac_length );
327 
328 psa_status_t psa_driver_wrapper_mac_abort(
329     psa_mac_operation_t *operation );
330 
331 /*
332  * Asymmetric cryptography
333  */
334 psa_status_t psa_driver_wrapper_asymmetric_encrypt(
335     const psa_key_attributes_t *attributes,
336     const uint8_t *key_buffer,
337     size_t key_buffer_size,
338     psa_algorithm_t alg,
339     const uint8_t *input,
340     size_t input_length,
341     const uint8_t *salt,
342     size_t salt_length,
343     uint8_t *output,
344     size_t output_size,
345     size_t *output_length );
346 
347 psa_status_t psa_driver_wrapper_asymmetric_decrypt(
348     const psa_key_attributes_t *attributes,
349     const uint8_t *key_buffer,
350     size_t key_buffer_size,
351     psa_algorithm_t alg,
352     const uint8_t *input,
353     size_t input_length,
354     const uint8_t *salt,
355     size_t salt_length,
356     uint8_t *output,
357     size_t output_size,
358     size_t *output_length );
359 
360 /*
361  * Raw Key Agreement
362  */
363 psa_status_t psa_driver_wrapper_key_agreement(
364     const psa_key_attributes_t *attributes,
365     const uint8_t *key_buffer,
366     size_t key_buffer_size,
367     psa_algorithm_t alg,
368     const uint8_t *peer_key,
369     size_t peer_key_length,
370     uint8_t *shared_secret,
371     size_t shared_secret_size,
372     size_t *shared_secret_length );
373 
374 #endif /* PSA_CRYPTO_DRIVER_WRAPPERS_H */
375 
376 /* End of automatically generated file. */
377