blob: 5eabf17de4300145546eb5c63c449947c34ccb07 [file] [log] [blame]
Ronald Cronde822812021-03-17 16:08:20 +01001/*
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#if !defined(MBEDTLS_CONFIG_FILE)
24#include "mbedtls/config.h"
25#else
26#include MBEDTLS_CONFIG_FILE
27#endif
28
29#if defined(PSA_CRYPTO_DRIVER_TEST)
30#include <psa/crypto_driver_common.h>
31
Ronald Cronbfe551d2021-03-23 09:33:25 +010032typedef struct {
33 /* If not PSA_SUCCESS, return this error code instead of processing the
34 * function call. */
35 psa_status_t forced_status;
36 /* Count the amount of times AEAD driver functions are called. */
Paul Elliottfcb5cdc2021-06-23 09:40:12 +010037 unsigned long hits_encrypt;
38 unsigned long hits_decrypt;
39 unsigned long hits_encrypt_setup;
40 unsigned long hits_decrypt_setup;
41 unsigned long hits_set_nonce;
42 unsigned long hits_set_lengths;
43 unsigned long hits_update_ad;
44 unsigned long hits_update;
45 unsigned long hits_finish;
46 unsigned long hits_verify;
47 unsigned long hits_abort;
48
Ronald Cronbfe551d2021-03-23 09:33:25 +010049 /* Status returned by the last AEAD driver function call. */
50 psa_status_t driver_status;
Ronald Cron7f13fa22021-04-13 12:41:34 +020051} mbedtls_test_driver_aead_hooks_t;
Ronald Cronbfe551d2021-03-23 09:33:25 +010052
Paul Elliottfcb5cdc2021-06-23 09:40:12 +010053#define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
Ronald Cron7f13fa22021-04-13 12:41:34 +020054static inline mbedtls_test_driver_aead_hooks_t
55 mbedtls_test_driver_aead_hooks_init( void )
Ronald Cronbfe551d2021-03-23 09:33:25 +010056{
Ronald Cron7f13fa22021-04-13 12:41:34 +020057 const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT;
Ronald Cronbfe551d2021-03-23 09:33:25 +010058 return( v );
59}
60
Ronald Cron7f13fa22021-04-13 12:41:34 +020061extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks;
Ronald Cronbfe551d2021-03-23 09:33:25 +010062
Ronald Cron7f13fa22021-04-13 12:41:34 +020063psa_status_t mbedtls_test_transparent_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010064 const psa_key_attributes_t *attributes,
65 const uint8_t *key_buffer, size_t key_buffer_size,
66 psa_algorithm_t alg,
67 const uint8_t *nonce, size_t nonce_length,
68 const uint8_t *additional_data, size_t additional_data_length,
69 const uint8_t *plaintext, size_t plaintext_length,
70 uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length );
71
Ronald Cron7f13fa22021-04-13 12:41:34 +020072psa_status_t mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010073 const psa_key_attributes_t *attributes,
74 const uint8_t *key_buffer, size_t key_buffer_size,
75 psa_algorithm_t alg,
76 const uint8_t *nonce, size_t nonce_length,
77 const uint8_t *additional_data, size_t additional_data_length,
78 const uint8_t *ciphertext, size_t ciphertext_length,
79 uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length );
80
Paul Elliotta218ceb2021-05-07 15:10:31 +010081psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
Paul Elliott7f0a1802021-05-11 17:43:42 +010082 mbedtls_psa_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +010083 const psa_key_attributes_t *attributes,
84 const uint8_t *key_buffer, size_t key_buffer_size,
85 psa_algorithm_t alg );
86
Paul Elliotta218ceb2021-05-07 15:10:31 +010087psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
Paul Elliott7f0a1802021-05-11 17:43:42 +010088 mbedtls_psa_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +010089 const psa_key_attributes_t *attributes,
90 const uint8_t *key_buffer, size_t key_buffer_size,
91 psa_algorithm_t alg );
92
Paul Elliotta218ceb2021-05-07 15:10:31 +010093psa_status_t mbedtls_test_transparent_aead_set_nonce(
Paul Elliott7f0a1802021-05-11 17:43:42 +010094 mbedtls_psa_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +010095 const uint8_t *nonce,
96 size_t nonce_length );
97
Paul Elliotta218ceb2021-05-07 15:10:31 +010098psa_status_t mbedtls_test_transparent_aead_set_lengths(
Paul Elliott7f0a1802021-05-11 17:43:42 +010099 mbedtls_psa_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100100 size_t ad_length,
101 size_t plaintext_length );
102
Paul Elliotta218ceb2021-05-07 15:10:31 +0100103psa_status_t mbedtls_test_transparent_aead_update_ad(
Paul Elliott7f0a1802021-05-11 17:43:42 +0100104 mbedtls_psa_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100105 const uint8_t *input,
106 size_t input_length );
107
Paul Elliotta218ceb2021-05-07 15:10:31 +0100108psa_status_t mbedtls_test_transparent_aead_update(
Paul Elliott7f0a1802021-05-11 17:43:42 +0100109 mbedtls_psa_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100110 const uint8_t *input,
111 size_t input_length,
112 uint8_t *output,
113 size_t output_size,
114 size_t *output_length );
115
Paul Elliotta218ceb2021-05-07 15:10:31 +0100116psa_status_t mbedtls_test_transparent_aead_finish(
Paul Elliott7f0a1802021-05-11 17:43:42 +0100117 mbedtls_psa_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100118 uint8_t *ciphertext,
119 size_t ciphertext_size,
120 size_t *ciphertext_length,
121 uint8_t *tag,
122 size_t tag_size,
123 size_t *tag_length );
124
Paul Elliotta218ceb2021-05-07 15:10:31 +0100125psa_status_t mbedtls_test_transparent_aead_verify(
Paul Elliott7f0a1802021-05-11 17:43:42 +0100126 mbedtls_psa_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100127 uint8_t *plaintext,
128 size_t plaintext_size,
129 size_t *plaintext_length,
130 const uint8_t *tag,
131 size_t tag_length );
132
Paul Elliotta218ceb2021-05-07 15:10:31 +0100133psa_status_t mbedtls_test_transparent_aead_abort(
Paul Elliott7f0a1802021-05-11 17:43:42 +0100134 mbedtls_psa_aead_operation_t *operation );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100135
Ronald Cronde822812021-03-17 16:08:20 +0100136#endif /* PSA_CRYPTO_DRIVER_TEST */
137#endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */