blob: b5619603fdf7902f9865d3d39861de48e4941b32 [file] [log] [blame]
Ronald Cronde822812021-03-17 16:08:20 +01001/*
2 * Test driver for AEAD entry points.
3 */
4/* Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
Mateusz Starzyk2c09c9b2021-05-14 22:20:10 +020020#include <test/helpers.h>
Ronald Cronde822812021-03-17 16:08:20 +010021
22#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
23#include "psa_crypto_aead.h"
Paul Elliott0a6a5692021-07-23 15:29:21 +010024#include "psa_crypto_core.h"
Ronald Cronde822812021-03-17 16:08:20 +010025
26#include "test/drivers/aead.h"
27
Ronald Cron7f13fa22021-04-13 12:41:34 +020028mbedtls_test_driver_aead_hooks_t
29 mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT;
Ronald Cronbfe551d2021-03-23 09:33:25 +010030
Ronald Cron7f13fa22021-04-13 12:41:34 +020031psa_status_t mbedtls_test_transparent_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010032 const psa_key_attributes_t *attributes,
33 const uint8_t *key_buffer, size_t key_buffer_size,
34 psa_algorithm_t alg,
35 const uint8_t *nonce, size_t nonce_length,
36 const uint8_t *additional_data, size_t additional_data_length,
37 const uint8_t *plaintext, size_t plaintext_length,
38 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
39{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +010040 mbedtls_test_driver_aead_hooks.hits_encrypt++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010041
Ronald Cron7f13fa22021-04-13 12:41:34 +020042 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010043 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020044 mbedtls_test_driver_aead_hooks.driver_status =
45 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010046 }
47 else
48 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +020049#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Ronald Cron7f13fa22021-04-13 12:41:34 +020050 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010051 mbedtls_psa_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010052 attributes, key_buffer, key_buffer_size,
53 alg,
54 nonce, nonce_length,
55 additional_data, additional_data_length,
56 plaintext, plaintext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010057 ciphertext, ciphertext_size, ciphertext_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +020058#else
59 (void) attributes;
60 (void) key_buffer;
61 (void) key_buffer_size;
62 (void) alg;
63 (void) nonce;
64 (void) nonce_length;
65 (void) additional_data;
66 (void) additional_data_length;
67 (void) plaintext;
68 (void) plaintext_length;
69 (void) ciphertext;
70 (void) ciphertext_size;
71 (void) ciphertext_length;
72 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
73#endif
Ronald Cronbfe551d2021-03-23 09:33:25 +010074 }
75
Ronald Cron7f13fa22021-04-13 12:41:34 +020076 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010077}
78
Ronald Cron7f13fa22021-04-13 12:41:34 +020079psa_status_t mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010080 const psa_key_attributes_t *attributes,
81 const uint8_t *key_buffer, size_t key_buffer_size,
82 psa_algorithm_t alg,
83 const uint8_t *nonce, size_t nonce_length,
84 const uint8_t *additional_data, size_t additional_data_length,
85 const uint8_t *ciphertext, size_t ciphertext_length,
86 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
87{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +010088 mbedtls_test_driver_aead_hooks.hits_decrypt++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010089
Ronald Cron7f13fa22021-04-13 12:41:34 +020090 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010091 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020092 mbedtls_test_driver_aead_hooks.driver_status =
93 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010094 }
95 else
96 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +020097#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Ronald Cron7f13fa22021-04-13 12:41:34 +020098 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010099 mbedtls_psa_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +0100100 attributes, key_buffer, key_buffer_size,
101 alg,
102 nonce, nonce_length,
103 additional_data, additional_data_length,
104 ciphertext, ciphertext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +0100105 plaintext, plaintext_size, plaintext_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200106#else
107 (void) attributes;
108 (void) key_buffer;
109 (void) key_buffer_size;
110 (void) alg;
111 (void) nonce;
112 (void) nonce_length;
113 (void) additional_data;
114 (void) additional_data_length;
115 (void) ciphertext;
116 (void) ciphertext_length;
117 (void) plaintext;
118 (void) plaintext_size;
119 (void) plaintext_length;
120 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
121#endif
Ronald Cronbfe551d2021-03-23 09:33:25 +0100122 }
123
Ronald Cron7f13fa22021-04-13 12:41:34 +0200124 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +0100125}
126
Paul Elliotta218ceb2021-05-07 15:10:31 +0100127psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100128 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100129 const psa_key_attributes_t *attributes,
130 const uint8_t *key_buffer, size_t key_buffer_size,
131 psa_algorithm_t alg )
132{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100133 mbedtls_test_driver_aead_hooks.hits_encrypt_setup++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100134
Paul Elliotta218ceb2021-05-07 15:10:31 +0100135 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100136 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100137 mbedtls_test_driver_aead_hooks.driver_status =
138 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100139 }
140 else
141 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200142#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliotta218ceb2021-05-07 15:10:31 +0100143 mbedtls_test_driver_aead_hooks.driver_status =
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100144 mbedtls_psa_aead_encrypt_setup( operation, attributes, key_buffer,
145 key_buffer_size, alg );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200146#else
147 (void) operation;
148 (void) attributes;
149 (void) key_buffer;
150 (void) key_buffer_size;
151 (void) alg;
152 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
153#endif
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100154 }
155
Paul Elliotta218ceb2021-05-07 15:10:31 +0100156 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100157}
158
Paul Elliotta218ceb2021-05-07 15:10:31 +0100159psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100160 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100161 const psa_key_attributes_t *attributes,
162 const uint8_t *key_buffer, size_t key_buffer_size,
163 psa_algorithm_t alg )
164{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100165 mbedtls_test_driver_aead_hooks.hits_decrypt_setup++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100166
Paul Elliotta218ceb2021-05-07 15:10:31 +0100167 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100168 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100169 mbedtls_test_driver_aead_hooks.driver_status =
170 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100171 }
172 else
173 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200174#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliotta218ceb2021-05-07 15:10:31 +0100175 mbedtls_test_driver_aead_hooks.driver_status =
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100176 mbedtls_psa_aead_decrypt_setup( operation, attributes, key_buffer,
177 key_buffer_size, alg );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200178#else
179 (void) operation;
180 (void) attributes;
181 (void) key_buffer;
182 (void) key_buffer_size;
183 (void) alg;
184 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
185#endif
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100186 }
187
Paul Elliotta218ceb2021-05-07 15:10:31 +0100188 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100189}
190
Paul Elliotta218ceb2021-05-07 15:10:31 +0100191psa_status_t mbedtls_test_transparent_aead_set_nonce(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100192 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100193 const uint8_t *nonce,
194 size_t nonce_length )
195{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100196 mbedtls_test_driver_aead_hooks.hits_set_nonce++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100197
Paul Elliotta218ceb2021-05-07 15:10:31 +0100198 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100199 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100200 mbedtls_test_driver_aead_hooks.driver_status =
201 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100202 }
203 else
204 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200205#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliotta218ceb2021-05-07 15:10:31 +0100206 mbedtls_test_driver_aead_hooks.driver_status =
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100207 mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200208#else
209 (void) operation;
210 (void) nonce;
211 (void) nonce_length;
212 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
213#endif
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100214 }
215
Paul Elliotta218ceb2021-05-07 15:10:31 +0100216 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100217}
218
Paul Elliotta218ceb2021-05-07 15:10:31 +0100219psa_status_t mbedtls_test_transparent_aead_set_lengths(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100220 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100221 size_t ad_length,
222 size_t plaintext_length )
223{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100224 mbedtls_test_driver_aead_hooks.hits_set_lengths++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100225
Paul Elliotta218ceb2021-05-07 15:10:31 +0100226 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100227 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100228 mbedtls_test_driver_aead_hooks.driver_status =
229 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100230 }
231 else
232 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200233#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliottdff6c5d2021-09-28 11:00:20 +0100234 mbedtls_test_driver_aead_hooks.driver_status =
235 mbedtls_psa_aead_set_lengths( operation, ad_length,
236 plaintext_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200237#else
238 (void) operation;
239 (void) ad_length;
240 (void) plaintext_length;
241 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
242#endif
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100243 }
244
Paul Elliotta218ceb2021-05-07 15:10:31 +0100245 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100246}
247
Paul Elliotta218ceb2021-05-07 15:10:31 +0100248psa_status_t mbedtls_test_transparent_aead_update_ad(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100249 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100250 const uint8_t *input,
251 size_t input_length )
252{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100253 mbedtls_test_driver_aead_hooks.hits_update_ad++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100254
Paul Elliotta218ceb2021-05-07 15:10:31 +0100255 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100256 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100257 mbedtls_test_driver_aead_hooks.driver_status =
258 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100259 }
260 else
261 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200262#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliotta218ceb2021-05-07 15:10:31 +0100263 mbedtls_test_driver_aead_hooks.driver_status =
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100264 mbedtls_psa_aead_update_ad( operation, input, input_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200265#else
266 (void) operation;
267 (void) input;
268 (void) input_length;
269 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
270#endif
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100271 }
272
Paul Elliotta218ceb2021-05-07 15:10:31 +0100273 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100274}
275
Paul Elliotta218ceb2021-05-07 15:10:31 +0100276psa_status_t mbedtls_test_transparent_aead_update(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100277 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100278 const uint8_t *input,
279 size_t input_length,
280 uint8_t *output,
281 size_t output_size,
282 size_t *output_length )
283{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100284 mbedtls_test_driver_aead_hooks.hits_update++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100285
Paul Elliotta218ceb2021-05-07 15:10:31 +0100286 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100287 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100288 mbedtls_test_driver_aead_hooks.driver_status =
289 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100290 }
291 else
292 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200293#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliotta218ceb2021-05-07 15:10:31 +0100294 mbedtls_test_driver_aead_hooks.driver_status =
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100295 mbedtls_psa_aead_update( operation, input, input_length, output,
296 output_size, output_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200297#else
298 (void) operation;
299 (void) input;
300 (void) input_length;
301 (void) output;
302 (void) output_size;
303 (void) output_length;
304 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
305#endif
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100306 }
307
Paul Elliotta218ceb2021-05-07 15:10:31 +0100308 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100309}
310
Paul Elliotta218ceb2021-05-07 15:10:31 +0100311psa_status_t mbedtls_test_transparent_aead_finish(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100312 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100313 uint8_t *ciphertext,
314 size_t ciphertext_size,
315 size_t *ciphertext_length,
316 uint8_t *tag,
317 size_t tag_size,
318 size_t *tag_length )
319{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100320 mbedtls_test_driver_aead_hooks.hits_finish++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100321
Paul Elliotta218ceb2021-05-07 15:10:31 +0100322 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100323 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100324 mbedtls_test_driver_aead_hooks.driver_status =
325 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100326 }
327 else
328 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200329#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliotta218ceb2021-05-07 15:10:31 +0100330 mbedtls_test_driver_aead_hooks.driver_status =
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100331 mbedtls_psa_aead_finish( operation, ciphertext, ciphertext_size,
Paul Elliotta218ceb2021-05-07 15:10:31 +0100332 ciphertext_length, tag, tag_size,
333 tag_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200334#else
335 (void) operation;
336 (void) ciphertext;
337 (void) ciphertext_size;
338 (void) ciphertext_length;
339 (void) tag;
340 (void) tag_size;
341 (void) tag_length;
342 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
343#endif
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100344 }
345
Paul Elliotta218ceb2021-05-07 15:10:31 +0100346 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100347}
348
Paul Elliotta218ceb2021-05-07 15:10:31 +0100349psa_status_t mbedtls_test_transparent_aead_verify(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100350 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100351 uint8_t *plaintext,
352 size_t plaintext_size,
353 size_t *plaintext_length,
354 const uint8_t *tag,
355 size_t tag_length )
356{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100357 mbedtls_test_driver_aead_hooks.hits_verify++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100358
Paul Elliotta218ceb2021-05-07 15:10:31 +0100359 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100360 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100361 mbedtls_test_driver_aead_hooks.driver_status =
362 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100363 }
364 else
365 {
Paul Elliott26f4aef2021-07-22 21:47:27 +0100366 uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE];
367 size_t check_tag_length;
368
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200369#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliott26f4aef2021-07-22 21:47:27 +0100370 mbedtls_test_driver_aead_hooks.driver_status =
371 mbedtls_psa_aead_finish( operation,
372 plaintext,
373 plaintext_size,
374 plaintext_length,
375 check_tag,
Paul Elliott0f32b7d2021-09-20 18:46:03 +0100376 sizeof( check_tag ),
Paul Elliott26f4aef2021-07-22 21:47:27 +0100377 &check_tag_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200378#else
379 (void) operation;
380 (void) plaintext;
381 (void) plaintext_size;
382 (void) plaintext_length;
383 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
384#endif
Paul Elliott26f4aef2021-07-22 21:47:27 +0100385
386 if( mbedtls_test_driver_aead_hooks.driver_status == PSA_SUCCESS )
387 {
388 if( tag_length != check_tag_length ||
389 mbedtls_psa_safer_memcmp( tag, check_tag, tag_length )
390 != 0 )
391 mbedtls_test_driver_aead_hooks.driver_status =
392 PSA_ERROR_INVALID_SIGNATURE;
393 }
Paul Elliott0f32b7d2021-09-20 18:46:03 +0100394
395 mbedtls_platform_zeroize( check_tag, sizeof( check_tag ) );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100396 }
397
Paul Elliotta218ceb2021-05-07 15:10:31 +0100398 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100399}
400
Paul Elliotta218ceb2021-05-07 15:10:31 +0100401psa_status_t mbedtls_test_transparent_aead_abort(
Paul Elliottcbbde5f2021-05-10 18:19:46 +0100402 mbedtls_transparent_test_driver_aead_operation_t *operation )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100403{
Paul Elliottfcb5cdc2021-06-23 09:40:12 +0100404 mbedtls_test_driver_aead_hooks.hits_abort++;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100405
Paul Elliotta218ceb2021-05-07 15:10:31 +0100406 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100407 {
Paul Elliotta218ceb2021-05-07 15:10:31 +0100408 mbedtls_test_driver_aead_hooks.driver_status =
409 mbedtls_test_driver_aead_hooks.forced_status;
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100410 }
411 else
412 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200413#if defined(MBEDTLS_PSA_BUILTIN_AEAD)
Paul Elliotta218ceb2021-05-07 15:10:31 +0100414 mbedtls_test_driver_aead_hooks.driver_status =
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100415 mbedtls_psa_aead_abort( operation );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200416#else
417 (void) operation;
418 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
419#endif
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100420 }
421
Paul Elliotta218ceb2021-05-07 15:10:31 +0100422 return( mbedtls_test_driver_aead_hooks.driver_status );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100423}
424
Ronald Cronde822812021-03-17 16:08:20 +0100425#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */