1a8e1175bSopenharmony_ci/* 2a8e1175bSopenharmony_ci * Test driver for AEAD driver entry points. 3a8e1175bSopenharmony_ci */ 4a8e1175bSopenharmony_ci/* Copyright The Mbed TLS Contributors 5a8e1175bSopenharmony_ci * SPDX-License-Identifier: Apache-2.0 6a8e1175bSopenharmony_ci * 7a8e1175bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); you may 8a8e1175bSopenharmony_ci * not use this file except in compliance with the License. 9a8e1175bSopenharmony_ci * You may obtain a copy of the License at 10a8e1175bSopenharmony_ci * 11a8e1175bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12a8e1175bSopenharmony_ci * 13a8e1175bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14a8e1175bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15a8e1175bSopenharmony_ci * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16a8e1175bSopenharmony_ci * See the License for the specific language governing permissions and 17a8e1175bSopenharmony_ci * limitations under the License. 18a8e1175bSopenharmony_ci */ 19a8e1175bSopenharmony_ci 20a8e1175bSopenharmony_ci#ifndef PSA_CRYPTO_TEST_DRIVERS_AEAD_H 21a8e1175bSopenharmony_ci#define PSA_CRYPTO_TEST_DRIVERS_AEAD_H 22a8e1175bSopenharmony_ci 23a8e1175bSopenharmony_ci#include "mbedtls/build_info.h" 24a8e1175bSopenharmony_ci 25a8e1175bSopenharmony_ci#if defined(PSA_CRYPTO_DRIVER_TEST) 26a8e1175bSopenharmony_ci#include <psa/crypto_driver_common.h> 27a8e1175bSopenharmony_ci 28a8e1175bSopenharmony_citypedef struct { 29a8e1175bSopenharmony_ci /* If not PSA_SUCCESS, return this error code instead of processing the 30a8e1175bSopenharmony_ci * function call. */ 31a8e1175bSopenharmony_ci psa_status_t forced_status; 32a8e1175bSopenharmony_ci /* Count the amount of times AEAD driver functions are called. */ 33a8e1175bSopenharmony_ci unsigned long hits_encrypt; 34a8e1175bSopenharmony_ci unsigned long hits_decrypt; 35a8e1175bSopenharmony_ci unsigned long hits_encrypt_setup; 36a8e1175bSopenharmony_ci unsigned long hits_decrypt_setup; 37a8e1175bSopenharmony_ci unsigned long hits_set_nonce; 38a8e1175bSopenharmony_ci unsigned long hits_set_lengths; 39a8e1175bSopenharmony_ci unsigned long hits_update_ad; 40a8e1175bSopenharmony_ci unsigned long hits_update; 41a8e1175bSopenharmony_ci unsigned long hits_finish; 42a8e1175bSopenharmony_ci unsigned long hits_verify; 43a8e1175bSopenharmony_ci unsigned long hits_abort; 44a8e1175bSopenharmony_ci 45a8e1175bSopenharmony_ci /* Status returned by the last AEAD driver function call. */ 46a8e1175bSopenharmony_ci psa_status_t driver_status; 47a8e1175bSopenharmony_ci} mbedtls_test_driver_aead_hooks_t; 48a8e1175bSopenharmony_ci 49a8e1175bSopenharmony_ci#define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 50a8e1175bSopenharmony_cistatic inline mbedtls_test_driver_aead_hooks_t 51a8e1175bSopenharmony_cimbedtls_test_driver_aead_hooks_init(void) 52a8e1175bSopenharmony_ci{ 53a8e1175bSopenharmony_ci const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT; 54a8e1175bSopenharmony_ci return v; 55a8e1175bSopenharmony_ci} 56a8e1175bSopenharmony_ci 57a8e1175bSopenharmony_ciextern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks; 58a8e1175bSopenharmony_ci 59a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_encrypt( 60a8e1175bSopenharmony_ci const psa_key_attributes_t *attributes, 61a8e1175bSopenharmony_ci const uint8_t *key_buffer, size_t key_buffer_size, 62a8e1175bSopenharmony_ci psa_algorithm_t alg, 63a8e1175bSopenharmony_ci const uint8_t *nonce, size_t nonce_length, 64a8e1175bSopenharmony_ci const uint8_t *additional_data, size_t additional_data_length, 65a8e1175bSopenharmony_ci const uint8_t *plaintext, size_t plaintext_length, 66a8e1175bSopenharmony_ci uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length); 67a8e1175bSopenharmony_ci 68a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_decrypt( 69a8e1175bSopenharmony_ci const psa_key_attributes_t *attributes, 70a8e1175bSopenharmony_ci const uint8_t *key_buffer, size_t key_buffer_size, 71a8e1175bSopenharmony_ci psa_algorithm_t alg, 72a8e1175bSopenharmony_ci const uint8_t *nonce, size_t nonce_length, 73a8e1175bSopenharmony_ci const uint8_t *additional_data, size_t additional_data_length, 74a8e1175bSopenharmony_ci const uint8_t *ciphertext, size_t ciphertext_length, 75a8e1175bSopenharmony_ci uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length); 76a8e1175bSopenharmony_ci 77a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_encrypt_setup( 78a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation, 79a8e1175bSopenharmony_ci const psa_key_attributes_t *attributes, 80a8e1175bSopenharmony_ci const uint8_t *key_buffer, size_t key_buffer_size, 81a8e1175bSopenharmony_ci psa_algorithm_t alg); 82a8e1175bSopenharmony_ci 83a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_decrypt_setup( 84a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation, 85a8e1175bSopenharmony_ci const psa_key_attributes_t *attributes, 86a8e1175bSopenharmony_ci const uint8_t *key_buffer, size_t key_buffer_size, 87a8e1175bSopenharmony_ci psa_algorithm_t alg); 88a8e1175bSopenharmony_ci 89a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_set_nonce( 90a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation, 91a8e1175bSopenharmony_ci const uint8_t *nonce, 92a8e1175bSopenharmony_ci size_t nonce_length); 93a8e1175bSopenharmony_ci 94a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_set_lengths( 95a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation, 96a8e1175bSopenharmony_ci size_t ad_length, 97a8e1175bSopenharmony_ci size_t plaintext_length); 98a8e1175bSopenharmony_ci 99a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_update_ad( 100a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation, 101a8e1175bSopenharmony_ci const uint8_t *input, 102a8e1175bSopenharmony_ci size_t input_length); 103a8e1175bSopenharmony_ci 104a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_update( 105a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation, 106a8e1175bSopenharmony_ci const uint8_t *input, 107a8e1175bSopenharmony_ci size_t input_length, 108a8e1175bSopenharmony_ci uint8_t *output, 109a8e1175bSopenharmony_ci size_t output_size, 110a8e1175bSopenharmony_ci size_t *output_length); 111a8e1175bSopenharmony_ci 112a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_finish( 113a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation, 114a8e1175bSopenharmony_ci uint8_t *ciphertext, 115a8e1175bSopenharmony_ci size_t ciphertext_size, 116a8e1175bSopenharmony_ci size_t *ciphertext_length, 117a8e1175bSopenharmony_ci uint8_t *tag, 118a8e1175bSopenharmony_ci size_t tag_size, 119a8e1175bSopenharmony_ci size_t *tag_length); 120a8e1175bSopenharmony_ci 121a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_verify( 122a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation, 123a8e1175bSopenharmony_ci uint8_t *plaintext, 124a8e1175bSopenharmony_ci size_t plaintext_size, 125a8e1175bSopenharmony_ci size_t *plaintext_length, 126a8e1175bSopenharmony_ci const uint8_t *tag, 127a8e1175bSopenharmony_ci size_t tag_length); 128a8e1175bSopenharmony_ci 129a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_aead_abort( 130a8e1175bSopenharmony_ci mbedtls_transparent_test_driver_aead_operation_t *operation); 131a8e1175bSopenharmony_ci 132a8e1175bSopenharmony_ci#endif /* PSA_CRYPTO_DRIVER_TEST */ 133a8e1175bSopenharmony_ci#endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */ 134