blob: c247bab08d6221cf3f4d002691fb9de66f48f886 [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 Starzykf2b11a92021-05-21 09:33:46 +020020#define MBEDTLS_ALLOW_PRIVATE_ACCESS
21
Ronald Cronde822812021-03-17 16:08:20 +010022#if !defined(MBEDTLS_CONFIG_FILE)
23#include "mbedtls/config.h"
24#else
25#include MBEDTLS_CONFIG_FILE
26#endif
27
Mateusz Starzyk2c09c9b2021-05-14 22:20:10 +020028#include <test/helpers.h>
29
Ronald Cronde822812021-03-17 16:08:20 +010030#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
31#include "psa_crypto_aead.h"
32
33#include "test/drivers/aead.h"
34
Ronald Cron7f13fa22021-04-13 12:41:34 +020035mbedtls_test_driver_aead_hooks_t
36 mbedtls_test_driver_aead_hooks = MBEDTLS_TEST_DRIVER_AEAD_INIT;
Ronald Cronbfe551d2021-03-23 09:33:25 +010037
Ronald Cron7f13fa22021-04-13 12:41:34 +020038psa_status_t mbedtls_test_transparent_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010039 const psa_key_attributes_t *attributes,
40 const uint8_t *key_buffer, size_t key_buffer_size,
41 psa_algorithm_t alg,
42 const uint8_t *nonce, size_t nonce_length,
43 const uint8_t *additional_data, size_t additional_data_length,
44 const uint8_t *plaintext, size_t plaintext_length,
45 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
46{
Ronald Cron7f13fa22021-04-13 12:41:34 +020047 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010048
Ronald Cron7f13fa22021-04-13 12:41:34 +020049 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010050 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020051 mbedtls_test_driver_aead_hooks.driver_status =
52 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010053 }
54 else
55 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020056 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010057 mbedtls_psa_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010058 attributes, key_buffer, key_buffer_size,
59 alg,
60 nonce, nonce_length,
61 additional_data, additional_data_length,
62 plaintext, plaintext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010063 ciphertext, ciphertext_size, ciphertext_length );
64 }
65
Ronald Cron7f13fa22021-04-13 12:41:34 +020066 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010067}
68
Ronald Cron7f13fa22021-04-13 12:41:34 +020069psa_status_t mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010070 const psa_key_attributes_t *attributes,
71 const uint8_t *key_buffer, size_t key_buffer_size,
72 psa_algorithm_t alg,
73 const uint8_t *nonce, size_t nonce_length,
74 const uint8_t *additional_data, size_t additional_data_length,
75 const uint8_t *ciphertext, size_t ciphertext_length,
76 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
77{
Ronald Cron7f13fa22021-04-13 12:41:34 +020078 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010079
Ronald Cron7f13fa22021-04-13 12:41:34 +020080 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +010081 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020082 mbedtls_test_driver_aead_hooks.driver_status =
83 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +010084 }
85 else
86 {
Ronald Cron7f13fa22021-04-13 12:41:34 +020087 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010088 mbedtls_psa_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010089 attributes, key_buffer, key_buffer_size,
90 alg,
91 nonce, nonce_length,
92 additional_data, additional_data_length,
93 ciphertext, ciphertext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010094 plaintext, plaintext_size, plaintext_length );
95 }
96
Ronald Cron7f13fa22021-04-13 12:41:34 +020097 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010098}
99
100#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */