blob: 25396c92f5e304f799a080c59a6203f480d826c7 [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
20#if !defined(MBEDTLS_CONFIG_FILE)
21#include "mbedtls/config.h"
22#else
23#include MBEDTLS_CONFIG_FILE
24#endif
25
26#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
27#include "psa_crypto_aead.h"
28
29#include "test/drivers/aead.h"
30
Ronald Cron7f13fa22021-04-13 12:41:34 +020031mbedtls_test_driver_aead_hooks_t
32 mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT;
Ronald Cronbfe551d2021-03-23 09:33:25 +010033
Ronald Cron7f13fa22021-04-13 12:41:34 +020034psa_status_t mbedtls_test_transparent_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010035 const psa_key_attributes_t *attributes,
36 const uint8_t *key_buffer, size_t key_buffer_size,
37 psa_algorithm_t alg,
38 const uint8_t *nonce, size_t nonce_length,
39 const uint8_t *additional_data, size_t additional_data_length,
40 const uint8_t *plaintext, size_t plaintext_length,
41 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
42{
Ronald Cron7f13fa22021-04-13 12:41:34 +020043 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010044
Ronald Cron7f13fa22021-04-13 12:41:34 +020045 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010046 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020047 mbedtls_test_driver_aead_hooks.driver_status =
48 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010049 }
50 else
51 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020052 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010053 mbedtls_psa_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010054 attributes, key_buffer, key_buffer_size,
55 alg,
56 nonce, nonce_length,
57 additional_data, additional_data_length,
58 plaintext, plaintext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010059 ciphertext, ciphertext_size, ciphertext_length );
60 }
61
Ronald Cron7f13fa22021-04-13 12:41:34 +020062 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010063}
64
Ronald Cron7f13fa22021-04-13 12:41:34 +020065psa_status_t mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010066 const psa_key_attributes_t *attributes,
67 const uint8_t *key_buffer, size_t key_buffer_size,
68 psa_algorithm_t alg,
69 const uint8_t *nonce, size_t nonce_length,
70 const uint8_t *additional_data, size_t additional_data_length,
71 const uint8_t *ciphertext, size_t ciphertext_length,
72 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
73{
Ronald Cron7f13fa22021-04-13 12:41:34 +020074 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010075
Ronald Cron7f13fa22021-04-13 12:41:34 +020076 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010077 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020078 mbedtls_test_driver_aead_hooks.driver_status =
79 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010080 }
81 else
82 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020083 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010084 mbedtls_psa_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010085 attributes, key_buffer, key_buffer_size,
86 alg,
87 nonce, nonce_length,
88 additional_data, additional_data_length,
89 ciphertext, ciphertext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010090 plaintext, plaintext_size, plaintext_length );
91 }
92
Ronald Cron7f13fa22021-04-13 12:41:34 +020093 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010094}
95
96#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */