blob: 4cc7751a5d80e2ced23a44622d03a70c452fe658 [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)
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020023# include "psa_crypto_aead.h"
Ronald Cronde822812021-03-17 16:08:20 +010024
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020025# include "test/drivers/aead.h"
Ronald Cronde822812021-03-17 16:08:20 +010026
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020027mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks =
28 MBEDTLS_TEST_DRIVER_AEAD_INIT;
Ronald Cronbfe551d2021-03-23 09:33:25 +010029
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020030psa_status_t
31mbedtls_test_transparent_aead_encrypt(const psa_key_attributes_t *attributes,
32 const uint8_t *key_buffer,
33 size_t key_buffer_size,
34 psa_algorithm_t alg,
35 const uint8_t *nonce,
36 size_t nonce_length,
37 const uint8_t *additional_data,
38 size_t additional_data_length,
39 const uint8_t *plaintext,
40 size_t plaintext_length,
41 uint8_t *ciphertext,
42 size_t ciphertext_size,
43 size_t *ciphertext_length)
Ronald Cronde822812021-03-17 16:08:20 +010044{
Ronald Cron7f13fa22021-04-13 12:41:34 +020045 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010046
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020047 if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
Ronald Cron7f13fa22021-04-13 12:41:34 +020048 mbedtls_test_driver_aead_hooks.driver_status =
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020049 mbedtls_test_driver_aead_hooks.forced_status;
50 } else {
51 mbedtls_test_driver_aead_hooks.driver_status = mbedtls_psa_aead_encrypt(
52 attributes, key_buffer, key_buffer_size, alg, nonce, nonce_length,
53 additional_data, additional_data_length, plaintext,
54 plaintext_length, ciphertext, ciphertext_size, ciphertext_length);
Ronald Cronbfe551d2021-03-23 09:33:25 +010055 }
56
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020057 return mbedtls_test_driver_aead_hooks.driver_status;
Ronald Cronde822812021-03-17 16:08:20 +010058}
59
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020060psa_status_t
61mbedtls_test_transparent_aead_decrypt(const psa_key_attributes_t *attributes,
62 const uint8_t *key_buffer,
63 size_t key_buffer_size,
64 psa_algorithm_t alg,
65 const uint8_t *nonce,
66 size_t nonce_length,
67 const uint8_t *additional_data,
68 size_t additional_data_length,
69 const uint8_t *ciphertext,
70 size_t ciphertext_length,
71 uint8_t *plaintext,
72 size_t plaintext_size,
73 size_t *plaintext_length)
Ronald Cronde822812021-03-17 16:08:20 +010074{
Ronald Cron7f13fa22021-04-13 12:41:34 +020075 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010076
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020077 if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
Ronald Cron7f13fa22021-04-13 12:41:34 +020078 mbedtls_test_driver_aead_hooks.driver_status =
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020079 mbedtls_test_driver_aead_hooks.forced_status;
80 } else {
81 mbedtls_test_driver_aead_hooks.driver_status = mbedtls_psa_aead_decrypt(
82 attributes, key_buffer, key_buffer_size, alg, nonce, nonce_length,
83 additional_data, additional_data_length, ciphertext,
84 ciphertext_length, plaintext, plaintext_size, plaintext_length);
Ronald Cronbfe551d2021-03-23 09:33:25 +010085 }
86
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020087 return mbedtls_test_driver_aead_hooks.driver_status;
Ronald Cronde822812021-03-17 16:08:20 +010088}
89
90#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */