blob: c87752502a03cf02b652f1ddc3fbc3e7f9fc6ba7 [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 Cronbfe551d2021-03-23 09:33:25 +010031test_driver_aead_hooks_t test_driver_aead_hooks = TEST_DRIVER_AEAD_INIT;
32
Ronald Cronde822812021-03-17 16:08:20 +010033psa_status_t test_transparent_aead_encrypt(
34 const psa_key_attributes_t *attributes,
35 const uint8_t *key_buffer, size_t key_buffer_size,
36 psa_algorithm_t alg,
37 const uint8_t *nonce, size_t nonce_length,
38 const uint8_t *additional_data, size_t additional_data_length,
39 const uint8_t *plaintext, size_t plaintext_length,
40 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
41{
Ronald Cronbfe551d2021-03-23 09:33:25 +010042 test_driver_aead_hooks.hits++;
43
44 if( test_driver_aead_hooks.forced_status != PSA_SUCCESS )
45 {
46 test_driver_aead_hooks.driver_status =
47 test_driver_aead_hooks.forced_status;
48 }
49 else
50 {
51 test_driver_aead_hooks.driver_status =
52 mbedtls_psa_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010053 attributes, key_buffer, key_buffer_size,
54 alg,
55 nonce, nonce_length,
56 additional_data, additional_data_length,
57 plaintext, plaintext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010058 ciphertext, ciphertext_size, ciphertext_length );
59 }
60
61 return( test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010062}
63
64psa_status_t test_transparent_aead_decrypt(
65 const psa_key_attributes_t *attributes,
66 const uint8_t *key_buffer, size_t key_buffer_size,
67 psa_algorithm_t alg,
68 const uint8_t *nonce, size_t nonce_length,
69 const uint8_t *additional_data, size_t additional_data_length,
70 const uint8_t *ciphertext, size_t ciphertext_length,
71 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
72{
Ronald Cronbfe551d2021-03-23 09:33:25 +010073 test_driver_aead_hooks.hits++;
74
75 if( test_driver_aead_hooks.forced_status != PSA_SUCCESS )
76 {
77 test_driver_aead_hooks.driver_status =
78 test_driver_aead_hooks.forced_status;
79 }
80 else
81 {
82 test_driver_aead_hooks.driver_status =
83 mbedtls_psa_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010084 attributes, key_buffer, key_buffer_size,
85 alg,
86 nonce, nonce_length,
87 additional_data, additional_data_length,
88 ciphertext, ciphertext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010089 plaintext, plaintext_size, plaintext_length );
90 }
91
92 return( test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010093}
94
95#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */