blob: 33e1f50cdc39f7cb542f8da65bfdf91b95997b5c [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
Bence Szépkútic662b362021-05-27 11:25:03 +020023#include "mbedtls/build_info.h"
Ronald Cronde822812021-03-17 16:08:20 +010024
25#if defined(PSA_CRYPTO_DRIVER_TEST)
26#include <psa/crypto_driver_common.h>
27
Ronald Cronbfe551d2021-03-23 09:33:25 +010028typedef 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. */
Paul Elliottfcb5cdc2021-06-23 09:40:12 +010033 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
Ronald Cronbfe551d2021-03-23 09:33:25 +010045 /* Status returned by the last AEAD driver function call. */
46 psa_status_t driver_status;
Ronald Cron7f13fa22021-04-13 12:41:34 +020047} mbedtls_test_driver_aead_hooks_t;
Ronald Cronbfe551d2021-03-23 09:33:25 +010048
Paul Elliottfcb5cdc2021-06-23 09:40:12 +010049#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 +020050static inline mbedtls_test_driver_aead_hooks_t
51 mbedtls_test_driver_aead_hooks_init( void )
Ronald Cronbfe551d2021-03-23 09:33:25 +010052{
Ronald Cron7f13fa22021-04-13 12:41:34 +020053 const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT;
Ronald Cronbfe551d2021-03-23 09:33:25 +010054 return( v );
55}
56
Ronald Cron7f13fa22021-04-13 12:41:34 +020057extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks;
Ronald Cronbfe551d2021-03-23 09:33:25 +010058
Ronald Cron7f13fa22021-04-13 12:41:34 +020059psa_status_t mbedtls_test_transparent_aead_encrypt(
Ronald Cronde822812021-03-17 16:08:20 +010060 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
Ronald Cron7f13fa22021-04-13 12:41:34 +020068psa_status_t mbedtls_test_transparent_aead_decrypt(
Ronald Cronde822812021-03-17 16:08:20 +010069 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
Paul Elliotta218ceb2021-05-07 15:10:31 +010077psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
Ronald Cron9a37ff62021-12-02 17:50:50 +010078 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +010079 const psa_key_attributes_t *attributes,
80 const uint8_t *key_buffer, size_t key_buffer_size,
81 psa_algorithm_t alg );
82
Paul Elliotta218ceb2021-05-07 15:10:31 +010083psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
Ronald Cron9a37ff62021-12-02 17:50:50 +010084 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +010085 const psa_key_attributes_t *attributes,
86 const uint8_t *key_buffer, size_t key_buffer_size,
87 psa_algorithm_t alg );
88
Paul Elliotta218ceb2021-05-07 15:10:31 +010089psa_status_t mbedtls_test_transparent_aead_set_nonce(
Ronald Cron9a37ff62021-12-02 17:50:50 +010090 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +010091 const uint8_t *nonce,
92 size_t nonce_length );
93
Paul Elliotta218ceb2021-05-07 15:10:31 +010094psa_status_t mbedtls_test_transparent_aead_set_lengths(
Ronald Cron9a37ff62021-12-02 17:50:50 +010095 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +010096 size_t ad_length,
97 size_t plaintext_length );
98
Paul Elliotta218ceb2021-05-07 15:10:31 +010099psa_status_t mbedtls_test_transparent_aead_update_ad(
Ronald Cron9a37ff62021-12-02 17:50:50 +0100100 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100101 const uint8_t *input,
102 size_t input_length );
103
Paul Elliotta218ceb2021-05-07 15:10:31 +0100104psa_status_t mbedtls_test_transparent_aead_update(
Ronald Cron9a37ff62021-12-02 17:50:50 +0100105 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100106 const uint8_t *input,
107 size_t input_length,
108 uint8_t *output,
109 size_t output_size,
110 size_t *output_length );
111
Paul Elliotta218ceb2021-05-07 15:10:31 +0100112psa_status_t mbedtls_test_transparent_aead_finish(
Ronald Cron9a37ff62021-12-02 17:50:50 +0100113 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100114 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
Paul Elliotta218ceb2021-05-07 15:10:31 +0100121psa_status_t mbedtls_test_transparent_aead_verify(
Ronald Cron9a37ff62021-12-02 17:50:50 +0100122 mbedtls_transparent_test_driver_aead_operation_t *operation,
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100123 uint8_t *plaintext,
124 size_t plaintext_size,
125 size_t *plaintext_length,
126 const uint8_t *tag,
127 size_t tag_length );
128
Paul Elliotta218ceb2021-05-07 15:10:31 +0100129psa_status_t mbedtls_test_transparent_aead_abort(
Ronald Cron9a37ff62021-12-02 17:50:50 +0100130 mbedtls_transparent_test_driver_aead_operation_t *operation );
Paul Elliott4bbe82b2021-04-27 12:11:56 +0100131
Ronald Cronde822812021-03-17 16:08:20 +0100132#endif /* PSA_CRYPTO_DRIVER_TEST */
133#endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */