xref: /optee_os/lib/libmbedtls/mbedtls/library/psa_crypto_aead.c (revision b0563631928755fe864b97785160fb3088e9efdc)
1*b0563631STom Van Eyck /*
2*b0563631STom Van Eyck  *  PSA AEAD entry points
3*b0563631STom Van Eyck  */
4*b0563631STom Van Eyck /*
5*b0563631STom Van Eyck  *  Copyright The Mbed TLS Contributors
6*b0563631STom Van Eyck  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7*b0563631STom Van Eyck  */
8*b0563631STom Van Eyck 
9*b0563631STom Van Eyck #include "common.h"
10*b0563631STom Van Eyck 
11*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_CRYPTO_C)
12*b0563631STom Van Eyck 
13*b0563631STom Van Eyck #include "psa_crypto_aead.h"
14*b0563631STom Van Eyck #include "psa_crypto_core.h"
15*b0563631STom Van Eyck #include "psa_crypto_cipher.h"
16*b0563631STom Van Eyck 
17*b0563631STom Van Eyck #include <string.h>
18*b0563631STom Van Eyck #include "mbedtls/platform.h"
19*b0563631STom Van Eyck 
20*b0563631STom Van Eyck #include "mbedtls/ccm.h"
21*b0563631STom Van Eyck #include "mbedtls/chachapoly.h"
22*b0563631STom Van Eyck #include "mbedtls/cipher.h"
23*b0563631STom Van Eyck #include "mbedtls/gcm.h"
24*b0563631STom Van Eyck #include "mbedtls/error.h"
25*b0563631STom Van Eyck 
psa_aead_setup(mbedtls_psa_aead_operation_t * operation,const psa_key_attributes_t * attributes,const uint8_t * key_buffer,size_t key_buffer_size,psa_algorithm_t alg)26*b0563631STom Van Eyck static psa_status_t psa_aead_setup(
27*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation,
28*b0563631STom Van Eyck     const psa_key_attributes_t *attributes,
29*b0563631STom Van Eyck     const uint8_t *key_buffer,
30*b0563631STom Van Eyck     size_t key_buffer_size,
31*b0563631STom Van Eyck     psa_algorithm_t alg)
32*b0563631STom Van Eyck {
33*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
34*b0563631STom Van Eyck     mbedtls_cipher_id_t cipher_id;
35*b0563631STom Van Eyck     mbedtls_cipher_mode_t mode;
36*b0563631STom Van Eyck     size_t key_bits = attributes->bits;
37*b0563631STom Van Eyck     (void) key_buffer_size;
38*b0563631STom Van Eyck 
39*b0563631STom Van Eyck     status = mbedtls_cipher_values_from_psa(alg, attributes->type,
40*b0563631STom Van Eyck                                             &key_bits, &mode, &cipher_id);
41*b0563631STom Van Eyck     if (status != PSA_SUCCESS) {
42*b0563631STom Van Eyck         return status;
43*b0563631STom Van Eyck     }
44*b0563631STom Van Eyck 
45*b0563631STom Van Eyck     switch (PSA_ALG_AEAD_WITH_SHORTENED_TAG(alg, 0)) {
46*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
47*b0563631STom Van Eyck         case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, 0):
48*b0563631STom Van Eyck             operation->alg = PSA_ALG_CCM;
49*b0563631STom Van Eyck             /* CCM allows the following tag lengths: 4, 6, 8, 10, 12, 14, 16.
50*b0563631STom Van Eyck              * The call to mbedtls_ccm_encrypt_and_tag or
51*b0563631STom Van Eyck              * mbedtls_ccm_auth_decrypt will validate the tag length. */
52*b0563631STom Van Eyck             if (PSA_BLOCK_CIPHER_BLOCK_LENGTH(attributes->type) != 16) {
53*b0563631STom Van Eyck                 return PSA_ERROR_INVALID_ARGUMENT;
54*b0563631STom Van Eyck             }
55*b0563631STom Van Eyck 
56*b0563631STom Van Eyck             mbedtls_ccm_init(&operation->ctx.ccm);
57*b0563631STom Van Eyck             status = mbedtls_to_psa_error(
58*b0563631STom Van Eyck                 mbedtls_ccm_setkey(&operation->ctx.ccm, cipher_id,
59*b0563631STom Van Eyck                                    key_buffer, (unsigned int) key_bits));
60*b0563631STom Van Eyck             if (status != PSA_SUCCESS) {
61*b0563631STom Van Eyck                 return status;
62*b0563631STom Van Eyck             }
63*b0563631STom Van Eyck             break;
64*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
65*b0563631STom Van Eyck 
66*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
67*b0563631STom Van Eyck         case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM, 0):
68*b0563631STom Van Eyck             operation->alg = PSA_ALG_GCM;
69*b0563631STom Van Eyck             /* GCM allows the following tag lengths: 4, 8, 12, 13, 14, 15, 16.
70*b0563631STom Van Eyck              * The call to mbedtls_gcm_crypt_and_tag or
71*b0563631STom Van Eyck              * mbedtls_gcm_auth_decrypt will validate the tag length. */
72*b0563631STom Van Eyck             if (PSA_BLOCK_CIPHER_BLOCK_LENGTH(attributes->type) != 16) {
73*b0563631STom Van Eyck                 return PSA_ERROR_INVALID_ARGUMENT;
74*b0563631STom Van Eyck             }
75*b0563631STom Van Eyck 
76*b0563631STom Van Eyck             mbedtls_gcm_init(&operation->ctx.gcm);
77*b0563631STom Van Eyck             status = mbedtls_to_psa_error(
78*b0563631STom Van Eyck                 mbedtls_gcm_setkey(&operation->ctx.gcm, cipher_id,
79*b0563631STom Van Eyck                                    key_buffer, (unsigned int) key_bits));
80*b0563631STom Van Eyck             if (status != PSA_SUCCESS) {
81*b0563631STom Van Eyck                 return status;
82*b0563631STom Van Eyck             }
83*b0563631STom Van Eyck             break;
84*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
85*b0563631STom Van Eyck 
86*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
87*b0563631STom Van Eyck         case PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CHACHA20_POLY1305, 0):
88*b0563631STom Van Eyck             operation->alg = PSA_ALG_CHACHA20_POLY1305;
89*b0563631STom Van Eyck             /* We only support the default tag length. */
90*b0563631STom Van Eyck             if (alg != PSA_ALG_CHACHA20_POLY1305) {
91*b0563631STom Van Eyck                 return PSA_ERROR_NOT_SUPPORTED;
92*b0563631STom Van Eyck             }
93*b0563631STom Van Eyck 
94*b0563631STom Van Eyck             mbedtls_chachapoly_init(&operation->ctx.chachapoly);
95*b0563631STom Van Eyck             status = mbedtls_to_psa_error(
96*b0563631STom Van Eyck                 mbedtls_chachapoly_setkey(&operation->ctx.chachapoly,
97*b0563631STom Van Eyck                                           key_buffer));
98*b0563631STom Van Eyck             if (status != PSA_SUCCESS) {
99*b0563631STom Van Eyck                 return status;
100*b0563631STom Van Eyck             }
101*b0563631STom Van Eyck             break;
102*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
103*b0563631STom Van Eyck 
104*b0563631STom Van Eyck         default:
105*b0563631STom Van Eyck             (void) status;
106*b0563631STom Van Eyck             (void) key_buffer;
107*b0563631STom Van Eyck             return PSA_ERROR_NOT_SUPPORTED;
108*b0563631STom Van Eyck     }
109*b0563631STom Van Eyck 
110*b0563631STom Van Eyck     operation->key_type = psa_get_key_type(attributes);
111*b0563631STom Van Eyck 
112*b0563631STom Van Eyck     operation->tag_length = PSA_ALG_AEAD_GET_TAG_LENGTH(alg);
113*b0563631STom Van Eyck 
114*b0563631STom Van Eyck     return PSA_SUCCESS;
115*b0563631STom Van Eyck }
116*b0563631STom Van Eyck 
mbedtls_psa_aead_encrypt(const psa_key_attributes_t * attributes,const uint8_t * key_buffer,size_t key_buffer_size,psa_algorithm_t alg,const uint8_t * nonce,size_t nonce_length,const uint8_t * additional_data,size_t additional_data_length,const uint8_t * plaintext,size_t plaintext_length,uint8_t * ciphertext,size_t ciphertext_size,size_t * ciphertext_length)117*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_encrypt(
118*b0563631STom Van Eyck     const psa_key_attributes_t *attributes,
119*b0563631STom Van Eyck     const uint8_t *key_buffer, size_t key_buffer_size,
120*b0563631STom Van Eyck     psa_algorithm_t alg,
121*b0563631STom Van Eyck     const uint8_t *nonce, size_t nonce_length,
122*b0563631STom Van Eyck     const uint8_t *additional_data, size_t additional_data_length,
123*b0563631STom Van Eyck     const uint8_t *plaintext, size_t plaintext_length,
124*b0563631STom Van Eyck     uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length)
125*b0563631STom Van Eyck {
126*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
127*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t operation = MBEDTLS_PSA_AEAD_OPERATION_INIT;
128*b0563631STom Van Eyck     uint8_t *tag;
129*b0563631STom Van Eyck 
130*b0563631STom Van Eyck     status = psa_aead_setup(&operation, attributes, key_buffer,
131*b0563631STom Van Eyck                             key_buffer_size, alg);
132*b0563631STom Van Eyck 
133*b0563631STom Van Eyck     if (status != PSA_SUCCESS) {
134*b0563631STom Van Eyck         goto exit;
135*b0563631STom Van Eyck     }
136*b0563631STom Van Eyck 
137*b0563631STom Van Eyck     /* For all currently supported modes, the tag is at the end of the
138*b0563631STom Van Eyck      * ciphertext. */
139*b0563631STom Van Eyck     if (ciphertext_size < (plaintext_length + operation.tag_length)) {
140*b0563631STom Van Eyck         status = PSA_ERROR_BUFFER_TOO_SMALL;
141*b0563631STom Van Eyck         goto exit;
142*b0563631STom Van Eyck     }
143*b0563631STom Van Eyck     tag = ciphertext + plaintext_length;
144*b0563631STom Van Eyck 
145*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
146*b0563631STom Van Eyck     if (operation.alg == PSA_ALG_CCM) {
147*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
148*b0563631STom Van Eyck             mbedtls_ccm_encrypt_and_tag(&operation.ctx.ccm,
149*b0563631STom Van Eyck                                         plaintext_length,
150*b0563631STom Van Eyck                                         nonce, nonce_length,
151*b0563631STom Van Eyck                                         additional_data,
152*b0563631STom Van Eyck                                         additional_data_length,
153*b0563631STom Van Eyck                                         plaintext, ciphertext,
154*b0563631STom Van Eyck                                         tag, operation.tag_length));
155*b0563631STom Van Eyck     } else
156*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
157*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
158*b0563631STom Van Eyck     if (operation.alg == PSA_ALG_GCM) {
159*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
160*b0563631STom Van Eyck             mbedtls_gcm_crypt_and_tag(&operation.ctx.gcm,
161*b0563631STom Van Eyck                                       MBEDTLS_GCM_ENCRYPT,
162*b0563631STom Van Eyck                                       plaintext_length,
163*b0563631STom Van Eyck                                       nonce, nonce_length,
164*b0563631STom Van Eyck                                       additional_data, additional_data_length,
165*b0563631STom Van Eyck                                       plaintext, ciphertext,
166*b0563631STom Van Eyck                                       operation.tag_length, tag));
167*b0563631STom Van Eyck     } else
168*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
169*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
170*b0563631STom Van Eyck     if (operation.alg == PSA_ALG_CHACHA20_POLY1305) {
171*b0563631STom Van Eyck         if (operation.tag_length != 16) {
172*b0563631STom Van Eyck             status = PSA_ERROR_NOT_SUPPORTED;
173*b0563631STom Van Eyck             goto exit;
174*b0563631STom Van Eyck         }
175*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
176*b0563631STom Van Eyck             mbedtls_chachapoly_encrypt_and_tag(&operation.ctx.chachapoly,
177*b0563631STom Van Eyck                                                plaintext_length,
178*b0563631STom Van Eyck                                                nonce,
179*b0563631STom Van Eyck                                                additional_data,
180*b0563631STom Van Eyck                                                additional_data_length,
181*b0563631STom Van Eyck                                                plaintext,
182*b0563631STom Van Eyck                                                ciphertext,
183*b0563631STom Van Eyck                                                tag));
184*b0563631STom Van Eyck     } else
185*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
186*b0563631STom Van Eyck     {
187*b0563631STom Van Eyck         (void) tag;
188*b0563631STom Van Eyck         (void) nonce;
189*b0563631STom Van Eyck         (void) nonce_length;
190*b0563631STom Van Eyck         (void) additional_data;
191*b0563631STom Van Eyck         (void) additional_data_length;
192*b0563631STom Van Eyck         (void) plaintext;
193*b0563631STom Van Eyck         return PSA_ERROR_NOT_SUPPORTED;
194*b0563631STom Van Eyck     }
195*b0563631STom Van Eyck 
196*b0563631STom Van Eyck     if (status == PSA_SUCCESS) {
197*b0563631STom Van Eyck         *ciphertext_length = plaintext_length + operation.tag_length;
198*b0563631STom Van Eyck     }
199*b0563631STom Van Eyck 
200*b0563631STom Van Eyck exit:
201*b0563631STom Van Eyck     mbedtls_psa_aead_abort(&operation);
202*b0563631STom Van Eyck 
203*b0563631STom Van Eyck     return status;
204*b0563631STom Van Eyck }
205*b0563631STom Van Eyck 
206*b0563631STom Van Eyck /* Locate the tag in a ciphertext buffer containing the encrypted data
207*b0563631STom Van Eyck  * followed by the tag. Return the length of the part preceding the tag in
208*b0563631STom Van Eyck  * *plaintext_length. This is the size of the plaintext in modes where
209*b0563631STom Van Eyck  * the encrypted data has the same size as the plaintext, such as
210*b0563631STom Van Eyck  * CCM and GCM. */
psa_aead_unpadded_locate_tag(size_t tag_length,const uint8_t * ciphertext,size_t ciphertext_length,size_t plaintext_size,const uint8_t ** p_tag)211*b0563631STom Van Eyck static psa_status_t psa_aead_unpadded_locate_tag(size_t tag_length,
212*b0563631STom Van Eyck                                                  const uint8_t *ciphertext,
213*b0563631STom Van Eyck                                                  size_t ciphertext_length,
214*b0563631STom Van Eyck                                                  size_t plaintext_size,
215*b0563631STom Van Eyck                                                  const uint8_t **p_tag)
216*b0563631STom Van Eyck {
217*b0563631STom Van Eyck     size_t payload_length;
218*b0563631STom Van Eyck     if (tag_length > ciphertext_length) {
219*b0563631STom Van Eyck         return PSA_ERROR_INVALID_ARGUMENT;
220*b0563631STom Van Eyck     }
221*b0563631STom Van Eyck     payload_length = ciphertext_length - tag_length;
222*b0563631STom Van Eyck     if (payload_length > plaintext_size) {
223*b0563631STom Van Eyck         return PSA_ERROR_BUFFER_TOO_SMALL;
224*b0563631STom Van Eyck     }
225*b0563631STom Van Eyck     *p_tag = ciphertext + payload_length;
226*b0563631STom Van Eyck     return PSA_SUCCESS;
227*b0563631STom Van Eyck }
228*b0563631STom Van Eyck 
mbedtls_psa_aead_decrypt(const psa_key_attributes_t * attributes,const uint8_t * key_buffer,size_t key_buffer_size,psa_algorithm_t alg,const uint8_t * nonce,size_t nonce_length,const uint8_t * additional_data,size_t additional_data_length,const uint8_t * ciphertext,size_t ciphertext_length,uint8_t * plaintext,size_t plaintext_size,size_t * plaintext_length)229*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_decrypt(
230*b0563631STom Van Eyck     const psa_key_attributes_t *attributes,
231*b0563631STom Van Eyck     const uint8_t *key_buffer, size_t key_buffer_size,
232*b0563631STom Van Eyck     psa_algorithm_t alg,
233*b0563631STom Van Eyck     const uint8_t *nonce, size_t nonce_length,
234*b0563631STom Van Eyck     const uint8_t *additional_data, size_t additional_data_length,
235*b0563631STom Van Eyck     const uint8_t *ciphertext, size_t ciphertext_length,
236*b0563631STom Van Eyck     uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length)
237*b0563631STom Van Eyck {
238*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
239*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t operation = MBEDTLS_PSA_AEAD_OPERATION_INIT;
240*b0563631STom Van Eyck     const uint8_t *tag = NULL;
241*b0563631STom Van Eyck 
242*b0563631STom Van Eyck     status = psa_aead_setup(&operation, attributes, key_buffer,
243*b0563631STom Van Eyck                             key_buffer_size, alg);
244*b0563631STom Van Eyck 
245*b0563631STom Van Eyck     if (status != PSA_SUCCESS) {
246*b0563631STom Van Eyck         goto exit;
247*b0563631STom Van Eyck     }
248*b0563631STom Van Eyck 
249*b0563631STom Van Eyck     status = psa_aead_unpadded_locate_tag(operation.tag_length,
250*b0563631STom Van Eyck                                           ciphertext, ciphertext_length,
251*b0563631STom Van Eyck                                           plaintext_size, &tag);
252*b0563631STom Van Eyck     if (status != PSA_SUCCESS) {
253*b0563631STom Van Eyck         goto exit;
254*b0563631STom Van Eyck     }
255*b0563631STom Van Eyck 
256*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
257*b0563631STom Van Eyck     if (operation.alg == PSA_ALG_CCM) {
258*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
259*b0563631STom Van Eyck             mbedtls_ccm_auth_decrypt(&operation.ctx.ccm,
260*b0563631STom Van Eyck                                      ciphertext_length - operation.tag_length,
261*b0563631STom Van Eyck                                      nonce, nonce_length,
262*b0563631STom Van Eyck                                      additional_data,
263*b0563631STom Van Eyck                                      additional_data_length,
264*b0563631STom Van Eyck                                      ciphertext, plaintext,
265*b0563631STom Van Eyck                                      tag, operation.tag_length));
266*b0563631STom Van Eyck     } else
267*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
268*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
269*b0563631STom Van Eyck     if (operation.alg == PSA_ALG_GCM) {
270*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
271*b0563631STom Van Eyck             mbedtls_gcm_auth_decrypt(&operation.ctx.gcm,
272*b0563631STom Van Eyck                                      ciphertext_length - operation.tag_length,
273*b0563631STom Van Eyck                                      nonce, nonce_length,
274*b0563631STom Van Eyck                                      additional_data,
275*b0563631STom Van Eyck                                      additional_data_length,
276*b0563631STom Van Eyck                                      tag, operation.tag_length,
277*b0563631STom Van Eyck                                      ciphertext, plaintext));
278*b0563631STom Van Eyck     } else
279*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
280*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
281*b0563631STom Van Eyck     if (operation.alg == PSA_ALG_CHACHA20_POLY1305) {
282*b0563631STom Van Eyck         if (operation.tag_length != 16) {
283*b0563631STom Van Eyck             status = PSA_ERROR_NOT_SUPPORTED;
284*b0563631STom Van Eyck             goto exit;
285*b0563631STom Van Eyck         }
286*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
287*b0563631STom Van Eyck             mbedtls_chachapoly_auth_decrypt(&operation.ctx.chachapoly,
288*b0563631STom Van Eyck                                             ciphertext_length - operation.tag_length,
289*b0563631STom Van Eyck                                             nonce,
290*b0563631STom Van Eyck                                             additional_data,
291*b0563631STom Van Eyck                                             additional_data_length,
292*b0563631STom Van Eyck                                             tag,
293*b0563631STom Van Eyck                                             ciphertext,
294*b0563631STom Van Eyck                                             plaintext));
295*b0563631STom Van Eyck     } else
296*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
297*b0563631STom Van Eyck     {
298*b0563631STom Van Eyck         (void) nonce;
299*b0563631STom Van Eyck         (void) nonce_length;
300*b0563631STom Van Eyck         (void) additional_data;
301*b0563631STom Van Eyck         (void) additional_data_length;
302*b0563631STom Van Eyck         (void) plaintext;
303*b0563631STom Van Eyck         return PSA_ERROR_NOT_SUPPORTED;
304*b0563631STom Van Eyck     }
305*b0563631STom Van Eyck 
306*b0563631STom Van Eyck     if (status == PSA_SUCCESS) {
307*b0563631STom Van Eyck         *plaintext_length = ciphertext_length - operation.tag_length;
308*b0563631STom Van Eyck     }
309*b0563631STom Van Eyck 
310*b0563631STom Van Eyck exit:
311*b0563631STom Van Eyck     mbedtls_psa_aead_abort(&operation);
312*b0563631STom Van Eyck 
313*b0563631STom Van Eyck     if (status == PSA_SUCCESS) {
314*b0563631STom Van Eyck         *plaintext_length = ciphertext_length - operation.tag_length;
315*b0563631STom Van Eyck     }
316*b0563631STom Van Eyck     return status;
317*b0563631STom Van Eyck }
318*b0563631STom Van Eyck 
319*b0563631STom Van Eyck /* Set the key and algorithm for a multipart authenticated encryption
320*b0563631STom Van Eyck  * operation. */
mbedtls_psa_aead_encrypt_setup(mbedtls_psa_aead_operation_t * operation,const psa_key_attributes_t * attributes,const uint8_t * key_buffer,size_t key_buffer_size,psa_algorithm_t alg)321*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_encrypt_setup(
322*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation,
323*b0563631STom Van Eyck     const psa_key_attributes_t *attributes,
324*b0563631STom Van Eyck     const uint8_t *key_buffer,
325*b0563631STom Van Eyck     size_t key_buffer_size,
326*b0563631STom Van Eyck     psa_algorithm_t alg)
327*b0563631STom Van Eyck {
328*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
329*b0563631STom Van Eyck 
330*b0563631STom Van Eyck     status = psa_aead_setup(operation, attributes, key_buffer,
331*b0563631STom Van Eyck                             key_buffer_size, alg);
332*b0563631STom Van Eyck 
333*b0563631STom Van Eyck     if (status == PSA_SUCCESS) {
334*b0563631STom Van Eyck         operation->is_encrypt = 1;
335*b0563631STom Van Eyck     }
336*b0563631STom Van Eyck 
337*b0563631STom Van Eyck     return status;
338*b0563631STom Van Eyck }
339*b0563631STom Van Eyck 
340*b0563631STom Van Eyck /* Set the key and algorithm for a multipart authenticated decryption
341*b0563631STom Van Eyck  * operation. */
mbedtls_psa_aead_decrypt_setup(mbedtls_psa_aead_operation_t * operation,const psa_key_attributes_t * attributes,const uint8_t * key_buffer,size_t key_buffer_size,psa_algorithm_t alg)342*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_decrypt_setup(
343*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation,
344*b0563631STom Van Eyck     const psa_key_attributes_t *attributes,
345*b0563631STom Van Eyck     const uint8_t *key_buffer,
346*b0563631STom Van Eyck     size_t key_buffer_size,
347*b0563631STom Van Eyck     psa_algorithm_t alg)
348*b0563631STom Van Eyck {
349*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
350*b0563631STom Van Eyck 
351*b0563631STom Van Eyck     status = psa_aead_setup(operation, attributes, key_buffer,
352*b0563631STom Van Eyck                             key_buffer_size, alg);
353*b0563631STom Van Eyck 
354*b0563631STom Van Eyck     if (status == PSA_SUCCESS) {
355*b0563631STom Van Eyck         operation->is_encrypt = 0;
356*b0563631STom Van Eyck     }
357*b0563631STom Van Eyck 
358*b0563631STom Van Eyck     return status;
359*b0563631STom Van Eyck }
360*b0563631STom Van Eyck 
361*b0563631STom Van Eyck /* Set a nonce for the multipart AEAD operation*/
mbedtls_psa_aead_set_nonce(mbedtls_psa_aead_operation_t * operation,const uint8_t * nonce,size_t nonce_length)362*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_set_nonce(
363*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation,
364*b0563631STom Van Eyck     const uint8_t *nonce,
365*b0563631STom Van Eyck     size_t nonce_length)
366*b0563631STom Van Eyck {
367*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
368*b0563631STom Van Eyck 
369*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
370*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_GCM) {
371*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
372*b0563631STom Van Eyck             mbedtls_gcm_starts(&operation->ctx.gcm,
373*b0563631STom Van Eyck                                operation->is_encrypt ?
374*b0563631STom Van Eyck                                MBEDTLS_GCM_ENCRYPT : MBEDTLS_GCM_DECRYPT,
375*b0563631STom Van Eyck                                nonce,
376*b0563631STom Van Eyck                                nonce_length));
377*b0563631STom Van Eyck     } else
378*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
379*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
380*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CCM) {
381*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
382*b0563631STom Van Eyck             mbedtls_ccm_starts(&operation->ctx.ccm,
383*b0563631STom Van Eyck                                operation->is_encrypt ?
384*b0563631STom Van Eyck                                MBEDTLS_CCM_ENCRYPT : MBEDTLS_CCM_DECRYPT,
385*b0563631STom Van Eyck                                nonce,
386*b0563631STom Van Eyck                                nonce_length));
387*b0563631STom Van Eyck     } else
388*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
389*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
390*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
391*b0563631STom Van Eyck         /* Note - ChaChaPoly allows an 8 byte nonce, but we would have to
392*b0563631STom Van Eyck          * allocate a buffer in the operation, copy the nonce to it and pad
393*b0563631STom Van Eyck          * it, so for now check the nonce is 12 bytes, as
394*b0563631STom Van Eyck          * mbedtls_chachapoly_starts() assumes it can read 12 bytes from the
395*b0563631STom Van Eyck          * passed in buffer. */
396*b0563631STom Van Eyck         if (nonce_length != 12) {
397*b0563631STom Van Eyck             return PSA_ERROR_INVALID_ARGUMENT;
398*b0563631STom Van Eyck         }
399*b0563631STom Van Eyck 
400*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
401*b0563631STom Van Eyck             mbedtls_chachapoly_starts(&operation->ctx.chachapoly,
402*b0563631STom Van Eyck                                       nonce,
403*b0563631STom Van Eyck                                       operation->is_encrypt ?
404*b0563631STom Van Eyck                                       MBEDTLS_CHACHAPOLY_ENCRYPT :
405*b0563631STom Van Eyck                                       MBEDTLS_CHACHAPOLY_DECRYPT));
406*b0563631STom Van Eyck     } else
407*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
408*b0563631STom Van Eyck     {
409*b0563631STom Van Eyck         (void) operation;
410*b0563631STom Van Eyck         (void) nonce;
411*b0563631STom Van Eyck         (void) nonce_length;
412*b0563631STom Van Eyck 
413*b0563631STom Van Eyck         return PSA_ERROR_NOT_SUPPORTED;
414*b0563631STom Van Eyck     }
415*b0563631STom Van Eyck 
416*b0563631STom Van Eyck     return status;
417*b0563631STom Van Eyck }
418*b0563631STom Van Eyck 
419*b0563631STom Van Eyck /* Declare the lengths of the message and additional data for AEAD. */
mbedtls_psa_aead_set_lengths(mbedtls_psa_aead_operation_t * operation,size_t ad_length,size_t plaintext_length)420*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_set_lengths(
421*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation,
422*b0563631STom Van Eyck     size_t ad_length,
423*b0563631STom Van Eyck     size_t plaintext_length)
424*b0563631STom Van Eyck {
425*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
426*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CCM) {
427*b0563631STom Van Eyck         return mbedtls_to_psa_error(
428*b0563631STom Van Eyck             mbedtls_ccm_set_lengths(&operation->ctx.ccm,
429*b0563631STom Van Eyck                                     ad_length,
430*b0563631STom Van Eyck                                     plaintext_length,
431*b0563631STom Van Eyck                                     operation->tag_length));
432*b0563631STom Van Eyck 
433*b0563631STom Van Eyck     }
434*b0563631STom Van Eyck #else /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
435*b0563631STom Van Eyck     (void) operation;
436*b0563631STom Van Eyck     (void) ad_length;
437*b0563631STom Van Eyck     (void) plaintext_length;
438*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
439*b0563631STom Van Eyck 
440*b0563631STom Van Eyck     return PSA_SUCCESS;
441*b0563631STom Van Eyck }
442*b0563631STom Van Eyck 
443*b0563631STom Van Eyck /* Pass additional data to an active multipart AEAD operation. */
mbedtls_psa_aead_update_ad(mbedtls_psa_aead_operation_t * operation,const uint8_t * input,size_t input_length)444*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_update_ad(
445*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation,
446*b0563631STom Van Eyck     const uint8_t *input,
447*b0563631STom Van Eyck     size_t input_length)
448*b0563631STom Van Eyck {
449*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
450*b0563631STom Van Eyck 
451*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
452*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_GCM) {
453*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
454*b0563631STom Van Eyck             mbedtls_gcm_update_ad(&operation->ctx.gcm, input, input_length));
455*b0563631STom Van Eyck     } else
456*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
457*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
458*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CCM) {
459*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
460*b0563631STom Van Eyck             mbedtls_ccm_update_ad(&operation->ctx.ccm, input, input_length));
461*b0563631STom Van Eyck     } else
462*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
463*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
464*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
465*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
466*b0563631STom Van Eyck             mbedtls_chachapoly_update_aad(&operation->ctx.chachapoly,
467*b0563631STom Van Eyck                                           input,
468*b0563631STom Van Eyck                                           input_length));
469*b0563631STom Van Eyck     } else
470*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
471*b0563631STom Van Eyck     {
472*b0563631STom Van Eyck         (void) operation;
473*b0563631STom Van Eyck         (void) input;
474*b0563631STom Van Eyck         (void) input_length;
475*b0563631STom Van Eyck 
476*b0563631STom Van Eyck         return PSA_ERROR_NOT_SUPPORTED;
477*b0563631STom Van Eyck     }
478*b0563631STom Van Eyck 
479*b0563631STom Van Eyck     return status;
480*b0563631STom Van Eyck }
481*b0563631STom Van Eyck 
482*b0563631STom Van Eyck /* Encrypt or decrypt a message fragment in an active multipart AEAD
483*b0563631STom Van Eyck  * operation.*/
mbedtls_psa_aead_update(mbedtls_psa_aead_operation_t * operation,const uint8_t * input,size_t input_length,uint8_t * output,size_t output_size,size_t * output_length)484*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_update(
485*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation,
486*b0563631STom Van Eyck     const uint8_t *input,
487*b0563631STom Van Eyck     size_t input_length,
488*b0563631STom Van Eyck     uint8_t *output,
489*b0563631STom Van Eyck     size_t output_size,
490*b0563631STom Van Eyck     size_t *output_length)
491*b0563631STom Van Eyck {
492*b0563631STom Van Eyck     size_t update_output_length;
493*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
494*b0563631STom Van Eyck 
495*b0563631STom Van Eyck     update_output_length = input_length;
496*b0563631STom Van Eyck 
497*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
498*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_GCM) {
499*b0563631STom Van Eyck         status =  mbedtls_to_psa_error(
500*b0563631STom Van Eyck             mbedtls_gcm_update(&operation->ctx.gcm,
501*b0563631STom Van Eyck                                input, input_length,
502*b0563631STom Van Eyck                                output, output_size,
503*b0563631STom Van Eyck                                &update_output_length));
504*b0563631STom Van Eyck     } else
505*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
506*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
507*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CCM) {
508*b0563631STom Van Eyck         if (output_size < input_length) {
509*b0563631STom Van Eyck             return PSA_ERROR_BUFFER_TOO_SMALL;
510*b0563631STom Van Eyck         }
511*b0563631STom Van Eyck 
512*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
513*b0563631STom Van Eyck             mbedtls_ccm_update(&operation->ctx.ccm,
514*b0563631STom Van Eyck                                input, input_length,
515*b0563631STom Van Eyck                                output, output_size,
516*b0563631STom Van Eyck                                &update_output_length));
517*b0563631STom Van Eyck     } else
518*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
519*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
520*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
521*b0563631STom Van Eyck         if (output_size < input_length) {
522*b0563631STom Van Eyck             return PSA_ERROR_BUFFER_TOO_SMALL;
523*b0563631STom Van Eyck         }
524*b0563631STom Van Eyck 
525*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
526*b0563631STom Van Eyck             mbedtls_chachapoly_update(&operation->ctx.chachapoly,
527*b0563631STom Van Eyck                                       input_length,
528*b0563631STom Van Eyck                                       input,
529*b0563631STom Van Eyck                                       output));
530*b0563631STom Van Eyck     } else
531*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
532*b0563631STom Van Eyck     {
533*b0563631STom Van Eyck         (void) operation;
534*b0563631STom Van Eyck         (void) input;
535*b0563631STom Van Eyck         (void) output;
536*b0563631STom Van Eyck         (void) output_size;
537*b0563631STom Van Eyck 
538*b0563631STom Van Eyck         return PSA_ERROR_NOT_SUPPORTED;
539*b0563631STom Van Eyck     }
540*b0563631STom Van Eyck 
541*b0563631STom Van Eyck     if (status == PSA_SUCCESS) {
542*b0563631STom Van Eyck         *output_length = update_output_length;
543*b0563631STom Van Eyck     }
544*b0563631STom Van Eyck 
545*b0563631STom Van Eyck     return status;
546*b0563631STom Van Eyck }
547*b0563631STom Van Eyck 
548*b0563631STom Van Eyck /* Finish encrypting a message in a multipart AEAD operation. */
mbedtls_psa_aead_finish(mbedtls_psa_aead_operation_t * operation,uint8_t * ciphertext,size_t ciphertext_size,size_t * ciphertext_length,uint8_t * tag,size_t tag_size,size_t * tag_length)549*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_finish(
550*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation,
551*b0563631STom Van Eyck     uint8_t *ciphertext,
552*b0563631STom Van Eyck     size_t ciphertext_size,
553*b0563631STom Van Eyck     size_t *ciphertext_length,
554*b0563631STom Van Eyck     uint8_t *tag,
555*b0563631STom Van Eyck     size_t tag_size,
556*b0563631STom Van Eyck     size_t *tag_length)
557*b0563631STom Van Eyck {
558*b0563631STom Van Eyck     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
559*b0563631STom Van Eyck     size_t finish_output_size = 0;
560*b0563631STom Van Eyck 
561*b0563631STom Van Eyck     if (tag_size < operation->tag_length) {
562*b0563631STom Van Eyck         return PSA_ERROR_BUFFER_TOO_SMALL;
563*b0563631STom Van Eyck     }
564*b0563631STom Van Eyck 
565*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
566*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_GCM) {
567*b0563631STom Van Eyck         status =  mbedtls_to_psa_error(
568*b0563631STom Van Eyck             mbedtls_gcm_finish(&operation->ctx.gcm,
569*b0563631STom Van Eyck                                ciphertext, ciphertext_size, ciphertext_length,
570*b0563631STom Van Eyck                                tag, operation->tag_length));
571*b0563631STom Van Eyck     } else
572*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
573*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
574*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CCM) {
575*b0563631STom Van Eyck         /* tag must be big enough to store a tag of size passed into set
576*b0563631STom Van Eyck          * lengths. */
577*b0563631STom Van Eyck         if (tag_size < operation->tag_length) {
578*b0563631STom Van Eyck             return PSA_ERROR_BUFFER_TOO_SMALL;
579*b0563631STom Van Eyck         }
580*b0563631STom Van Eyck 
581*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
582*b0563631STom Van Eyck             mbedtls_ccm_finish(&operation->ctx.ccm,
583*b0563631STom Van Eyck                                tag, operation->tag_length));
584*b0563631STom Van Eyck     } else
585*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
586*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
587*b0563631STom Van Eyck     if (operation->alg == PSA_ALG_CHACHA20_POLY1305) {
588*b0563631STom Van Eyck         /* Belt and braces. Although the above tag_size check should have
589*b0563631STom Van Eyck          * already done this, if we later start supporting smaller tag sizes
590*b0563631STom Van Eyck          * for chachapoly, then passing a tag buffer smaller than 16 into here
591*b0563631STom Van Eyck          * could cause a buffer overflow, so better safe than sorry. */
592*b0563631STom Van Eyck         if (tag_size < 16) {
593*b0563631STom Van Eyck             return PSA_ERROR_BUFFER_TOO_SMALL;
594*b0563631STom Van Eyck         }
595*b0563631STom Van Eyck 
596*b0563631STom Van Eyck         status = mbedtls_to_psa_error(
597*b0563631STom Van Eyck             mbedtls_chachapoly_finish(&operation->ctx.chachapoly,
598*b0563631STom Van Eyck                                       tag));
599*b0563631STom Van Eyck     } else
600*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
601*b0563631STom Van Eyck     {
602*b0563631STom Van Eyck         (void) ciphertext;
603*b0563631STom Van Eyck         (void) ciphertext_size;
604*b0563631STom Van Eyck         (void) ciphertext_length;
605*b0563631STom Van Eyck         (void) tag;
606*b0563631STom Van Eyck         (void) tag_size;
607*b0563631STom Van Eyck         (void) tag_length;
608*b0563631STom Van Eyck 
609*b0563631STom Van Eyck         return PSA_ERROR_NOT_SUPPORTED;
610*b0563631STom Van Eyck     }
611*b0563631STom Van Eyck 
612*b0563631STom Van Eyck     if (status == PSA_SUCCESS) {
613*b0563631STom Van Eyck         /* This will be zero for all supported algorithms currently, but left
614*b0563631STom Van Eyck          * here for future support. */
615*b0563631STom Van Eyck         *ciphertext_length = finish_output_size;
616*b0563631STom Van Eyck         *tag_length = operation->tag_length;
617*b0563631STom Van Eyck     }
618*b0563631STom Van Eyck 
619*b0563631STom Van Eyck     return status;
620*b0563631STom Van Eyck }
621*b0563631STom Van Eyck 
622*b0563631STom Van Eyck /* Abort an AEAD operation */
mbedtls_psa_aead_abort(mbedtls_psa_aead_operation_t * operation)623*b0563631STom Van Eyck psa_status_t mbedtls_psa_aead_abort(
624*b0563631STom Van Eyck     mbedtls_psa_aead_operation_t *operation)
625*b0563631STom Van Eyck {
626*b0563631STom Van Eyck     switch (operation->alg) {
627*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
628*b0563631STom Van Eyck         case PSA_ALG_CCM:
629*b0563631STom Van Eyck             mbedtls_ccm_free(&operation->ctx.ccm);
630*b0563631STom Van Eyck             break;
631*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
632*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
633*b0563631STom Van Eyck         case PSA_ALG_GCM:
634*b0563631STom Van Eyck             mbedtls_gcm_free(&operation->ctx.gcm);
635*b0563631STom Van Eyck             break;
636*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
637*b0563631STom Van Eyck #if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
638*b0563631STom Van Eyck         case PSA_ALG_CHACHA20_POLY1305:
639*b0563631STom Van Eyck             mbedtls_chachapoly_free(&operation->ctx.chachapoly);
640*b0563631STom Van Eyck             break;
641*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
642*b0563631STom Van Eyck     }
643*b0563631STom Van Eyck 
644*b0563631STom Van Eyck     operation->is_encrypt = 0;
645*b0563631STom Van Eyck 
646*b0563631STom Van Eyck     return PSA_SUCCESS;
647*b0563631STom Van Eyck }
648*b0563631STom Van Eyck 
649*b0563631STom Van Eyck #endif /* MBEDTLS_PSA_CRYPTO_C */
650