1/*
2 * Test driver for AEAD driver 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#ifndef PSA_CRYPTO_TEST_DRIVERS_AEAD_H
21#define PSA_CRYPTO_TEST_DRIVERS_AEAD_H
22
23#include "mbedtls/build_info.h"
24
25#if defined(PSA_CRYPTO_DRIVER_TEST)
26#include <psa/crypto_driver_common.h>
27
28typedef struct {
29    /* If not PSA_SUCCESS, return this error code instead of processing the
30     * function call. */
31    psa_status_t forced_status;
32    /* Count the amount of times AEAD driver functions are called. */
33    unsigned long hits_encrypt;
34    unsigned long hits_decrypt;
35    unsigned long hits_encrypt_setup;
36    unsigned long hits_decrypt_setup;
37    unsigned long hits_set_nonce;
38    unsigned long hits_set_lengths;
39    unsigned long hits_update_ad;
40    unsigned long hits_update;
41    unsigned long hits_finish;
42    unsigned long hits_verify;
43    unsigned long hits_abort;
44
45    /* Status returned by the last AEAD driver function call. */
46    psa_status_t driver_status;
47} mbedtls_test_driver_aead_hooks_t;
48
49#define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
50static inline mbedtls_test_driver_aead_hooks_t
51mbedtls_test_driver_aead_hooks_init(void)
52{
53    const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT;
54    return v;
55}
56
57extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks;
58
59psa_status_t mbedtls_test_transparent_aead_encrypt(
60    const psa_key_attributes_t *attributes,
61    const uint8_t *key_buffer, size_t key_buffer_size,
62    psa_algorithm_t alg,
63    const uint8_t *nonce, size_t nonce_length,
64    const uint8_t *additional_data, size_t additional_data_length,
65    const uint8_t *plaintext, size_t plaintext_length,
66    uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length);
67
68psa_status_t mbedtls_test_transparent_aead_decrypt(
69    const psa_key_attributes_t *attributes,
70    const uint8_t *key_buffer, size_t key_buffer_size,
71    psa_algorithm_t alg,
72    const uint8_t *nonce, size_t nonce_length,
73    const uint8_t *additional_data, size_t additional_data_length,
74    const uint8_t *ciphertext, size_t ciphertext_length,
75    uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length);
76
77psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
78    mbedtls_transparent_test_driver_aead_operation_t *operation,
79    const psa_key_attributes_t *attributes,
80    const uint8_t *key_buffer, size_t key_buffer_size,
81    psa_algorithm_t alg);
82
83psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
84    mbedtls_transparent_test_driver_aead_operation_t *operation,
85    const psa_key_attributes_t *attributes,
86    const uint8_t *key_buffer, size_t key_buffer_size,
87    psa_algorithm_t alg);
88
89psa_status_t mbedtls_test_transparent_aead_set_nonce(
90    mbedtls_transparent_test_driver_aead_operation_t *operation,
91    const uint8_t *nonce,
92    size_t nonce_length);
93
94psa_status_t mbedtls_test_transparent_aead_set_lengths(
95    mbedtls_transparent_test_driver_aead_operation_t *operation,
96    size_t ad_length,
97    size_t plaintext_length);
98
99psa_status_t mbedtls_test_transparent_aead_update_ad(
100    mbedtls_transparent_test_driver_aead_operation_t *operation,
101    const uint8_t *input,
102    size_t input_length);
103
104psa_status_t mbedtls_test_transparent_aead_update(
105    mbedtls_transparent_test_driver_aead_operation_t *operation,
106    const uint8_t *input,
107    size_t input_length,
108    uint8_t *output,
109    size_t output_size,
110    size_t *output_length);
111
112psa_status_t mbedtls_test_transparent_aead_finish(
113    mbedtls_transparent_test_driver_aead_operation_t *operation,
114    uint8_t *ciphertext,
115    size_t ciphertext_size,
116    size_t *ciphertext_length,
117    uint8_t *tag,
118    size_t tag_size,
119    size_t *tag_length);
120
121psa_status_t mbedtls_test_transparent_aead_verify(
122    mbedtls_transparent_test_driver_aead_operation_t *operation,
123    uint8_t *plaintext,
124    size_t plaintext_size,
125    size_t *plaintext_length,
126    const uint8_t *tag,
127    size_t tag_length);
128
129psa_status_t mbedtls_test_transparent_aead_abort(
130    mbedtls_transparent_test_driver_aead_operation_t *operation);
131
132#endif /* PSA_CRYPTO_DRIVER_TEST */
133#endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */
134