blob: 76afcd75f019f08d73ac8ab407b14e09942f924e [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>
21
Ronald Cronde822812021-03-17 16:08:20 +010022#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
23#include "psa_crypto_aead.h"
24
25#include "test/drivers/aead.h"
26
Ronald Cron7f13fa22021-04-13 12:41:34 +020027mbedtls_test_driver_aead_hooks_t
28 mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT;
Ronald Cronbfe551d2021-03-23 09:33:25 +010029
Ronald Cron7f13fa22021-04-13 12:41:34 +020030psa_status_t mbedtls_test_transparent_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010031 const psa_key_attributes_t *attributes,
32 const uint8_t *key_buffer, size_t key_buffer_size,
33 psa_algorithm_t alg,
34 const uint8_t *nonce, size_t nonce_length,
35 const uint8_t *additional_data, size_t additional_data_length,
36 const uint8_t *plaintext, size_t plaintext_length,
37 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
38{
Ronald Cron7f13fa22021-04-13 12:41:34 +020039 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010040
Ronald Cron7f13fa22021-04-13 12:41:34 +020041 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010042 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020043 mbedtls_test_driver_aead_hooks.driver_status =
44 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010045 }
46 else
47 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020048 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010049 mbedtls_psa_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010050 attributes, key_buffer, key_buffer_size,
51 alg,
52 nonce, nonce_length,
53 additional_data, additional_data_length,
54 plaintext, plaintext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010055 ciphertext, ciphertext_size, ciphertext_length );
56 }
57
Mateusz Starzyke36f5b12021-07-22 16:43:35 +020058 return mbedtls_test_driver_aead_hooks.driver_status ;
Ronald Cronde822812021-03-17 16:08:20 +010059}
60
Ronald Cron7f13fa22021-04-13 12:41:34 +020061psa_status_t mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010062 const psa_key_attributes_t *attributes,
63 const uint8_t *key_buffer, size_t key_buffer_size,
64 psa_algorithm_t alg,
65 const uint8_t *nonce, size_t nonce_length,
66 const uint8_t *additional_data, size_t additional_data_length,
67 const uint8_t *ciphertext, size_t ciphertext_length,
68 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
69{
Ronald Cron7f13fa22021-04-13 12:41:34 +020070 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010071
Ronald Cron7f13fa22021-04-13 12:41:34 +020072 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010073 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020074 mbedtls_test_driver_aead_hooks.driver_status =
75 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010076 }
77 else
78 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020079 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010080 mbedtls_psa_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010081 attributes, key_buffer, key_buffer_size,
82 alg,
83 nonce, nonce_length,
84 additional_data, additional_data_length,
85 ciphertext, ciphertext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010086 plaintext, plaintext_size, plaintext_length );
87 }
88
Mateusz Starzyke36f5b12021-07-22 16:43:35 +020089 return mbedtls_test_driver_aead_hooks.driver_status ;
Ronald Cronde822812021-03-17 16:08:20 +010090}
91
92#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */