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