blob: a1471632416eb902caf05c54ff6af46df6591d81 [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
Mateusz Starzyk2c09c9b2021-05-14 22:20:10 +020026#include <test/helpers.h>
27
Ronald Cronde822812021-03-17 16:08:20 +010028#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
29#include "psa_crypto_aead.h"
30
31#include "test/drivers/aead.h"
32
Ronald Cron7f13fa22021-04-13 12:41:34 +020033mbedtls_test_driver_aead_hooks_t
34 mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT;
Ronald Cronbfe551d2021-03-23 09:33:25 +010035
Ronald Cron7f13fa22021-04-13 12:41:34 +020036psa_status_t mbedtls_test_transparent_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010037 const psa_key_attributes_t *attributes,
38 const uint8_t *key_buffer, size_t key_buffer_size,
39 psa_algorithm_t alg,
40 const uint8_t *nonce, size_t nonce_length,
41 const uint8_t *additional_data, size_t additional_data_length,
42 const uint8_t *plaintext, size_t plaintext_length,
43 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
44{
Ronald Cron7f13fa22021-04-13 12:41:34 +020045 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010046
Ronald Cron7f13fa22021-04-13 12:41:34 +020047 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010048 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020049 mbedtls_test_driver_aead_hooks.driver_status =
50 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010051 }
52 else
53 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020054 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010055 mbedtls_psa_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010056 attributes, key_buffer, key_buffer_size,
57 alg,
58 nonce, nonce_length,
59 additional_data, additional_data_length,
60 plaintext, plaintext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010061 ciphertext, ciphertext_size, ciphertext_length );
62 }
63
Ronald Cron7f13fa22021-04-13 12:41:34 +020064 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010065}
66
Ronald Cron7f13fa22021-04-13 12:41:34 +020067psa_status_t mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010068 const psa_key_attributes_t *attributes,
69 const uint8_t *key_buffer, size_t key_buffer_size,
70 psa_algorithm_t alg,
71 const uint8_t *nonce, size_t nonce_length,
72 const uint8_t *additional_data, size_t additional_data_length,
73 const uint8_t *ciphertext, size_t ciphertext_length,
74 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
75{
Ronald Cron7f13fa22021-04-13 12:41:34 +020076 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010077
Ronald Cron7f13fa22021-04-13 12:41:34 +020078 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010079 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020080 mbedtls_test_driver_aead_hooks.driver_status =
81 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010082 }
83 else
84 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020085 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010086 mbedtls_psa_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010087 attributes, key_buffer, key_buffer_size,
88 alg,
89 nonce, nonce_length,
90 additional_data, additional_data_length,
91 ciphertext, ciphertext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010092 plaintext, plaintext_size, plaintext_length );
93 }
94
Ronald Cron7f13fa22021-04-13 12:41:34 +020095 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010096}
97
98#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */