blob: d2563d50673e278a16a2fd36736a0c6570740ed7 [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
Przemek Stekielf8862412022-10-02 21:01:23 +020031#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
32#include "libtestdriver1/library/psa_crypto_aead.h"
33#endif
34
Ronald Cronc4bc12e2021-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 Cronc4bc12e2021-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 Cronc4bc12e2021-04-13 12:41:34 +020047 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +010048
Ronald Cronc4bc12e2021-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 Cronc4bc12e2021-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 {
Przemek Stekielf8862412022-10-02 21:01:23 +020056#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
57 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
58 mbedtls_test_driver_aead_hooks.driver_status =
59 libtestdriver1_mbedtls_psa_aead_encrypt(
60 (const libtestdriver1_psa_key_attributes_t *)attributes,
61 key_buffer, key_buffer_size,
62 alg,
63 nonce, nonce_length,
64 additional_data, additional_data_length,
65 plaintext, plaintext_length,
66 ciphertext, ciphertext_size, ciphertext_length );
67#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
Ronald Cronc4bc12e2021-04-13 12:41:34 +020068 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +010069 mbedtls_psa_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010070 attributes, key_buffer, key_buffer_size,
71 alg,
72 nonce, nonce_length,
73 additional_data, additional_data_length,
74 plaintext, plaintext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +010075 ciphertext, ciphertext_size, ciphertext_length );
76 }
Przemek Stekielf8862412022-10-02 21:01:23 +020077#else
78 (void) attributes;
79 (void) key_buffer;
80 (void) key_buffer_size;
81 (void) alg;
82 (void) nonce;
83 (void) nonce_length;
84 (void) additional_data;
85 (void) additional_data_length;
86 (void) plaintext;
87 (void) plaintext_length;
88 (void) ciphertext;
89 (void) ciphertext_size;
90 (void) ciphertext_length;
91 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
92#endif
93 }
Ronald Cronc4bc12e2021-04-13 12:41:34 +020094 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +010095}
96
Ronald Cronc4bc12e2021-04-13 12:41:34 +020097psa_status_t mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010098 const psa_key_attributes_t *attributes,
99 const uint8_t *key_buffer, size_t key_buffer_size,
100 psa_algorithm_t alg,
101 const uint8_t *nonce, size_t nonce_length,
102 const uint8_t *additional_data, size_t additional_data_length,
103 const uint8_t *ciphertext, size_t ciphertext_length,
104 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
105{
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200106 mbedtls_test_driver_aead_hooks.hits++;
Ronald Cronbfe551d2021-03-23 09:33:25 +0100107
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200108 if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
Ronald Cronbfe551d2021-03-23 09:33:25 +0100109 {
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200110 mbedtls_test_driver_aead_hooks.driver_status =
111 mbedtls_test_driver_aead_hooks.forced_status;
Ronald Cronbfe551d2021-03-23 09:33:25 +0100112 }
113 else
114 {
Przemek Stekielf8862412022-10-02 21:01:23 +0200115#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
116 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
117 mbedtls_test_driver_aead_hooks.driver_status =
118 libtestdriver1_mbedtls_psa_aead_decrypt(
119 (const libtestdriver1_psa_key_attributes_t *)attributes,
120 key_buffer, key_buffer_size,
121 alg,
122 nonce, nonce_length,
123 additional_data, additional_data_length,
124 ciphertext, ciphertext_length,
125 plaintext, plaintext_size, plaintext_length );
126#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200127 mbedtls_test_driver_aead_hooks.driver_status =
Ronald Cronbfe551d2021-03-23 09:33:25 +0100128 mbedtls_psa_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +0100129 attributes, key_buffer, key_buffer_size,
130 alg,
131 nonce, nonce_length,
132 additional_data, additional_data_length,
133 ciphertext, ciphertext_length,
Ronald Cronbfe551d2021-03-23 09:33:25 +0100134 plaintext, plaintext_size, plaintext_length );
135 }
Przemek Stekielf8862412022-10-02 21:01:23 +0200136#else
137 (void) attributes;
138 (void) key_buffer;
139 (void) key_buffer_size;
140 (void) alg;
141 (void) nonce;
142 (void) nonce_length;
143 (void) additional_data;
144 (void) additional_data_length;
145 (void) ciphertext;
146 (void) ciphertext_length;
147 (void) plaintext;
148 (void) plaintext_size;
149 (void) plaintext_length;
150 mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
151#endif
152 }
Ronald Cronc4bc12e2021-04-13 12:41:34 +0200153 return( mbedtls_test_driver_aead_hooks.driver_status );
Ronald Cronde822812021-03-17 16:08:20 +0100154}
155
156#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */