1a8e1175bSopenharmony_ci/* 2a8e1175bSopenharmony_ci * Test driver for asymmetric encryption. 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_ASYMMETRIC_ENCRYPTION_H 21a8e1175bSopenharmony_ci#define PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_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#include <psa/crypto.h> 28a8e1175bSopenharmony_ci 29a8e1175bSopenharmony_citypedef struct { 30a8e1175bSopenharmony_ci /* If non-null, on success, copy this to the output. */ 31a8e1175bSopenharmony_ci void *forced_output; 32a8e1175bSopenharmony_ci size_t forced_output_length; 33a8e1175bSopenharmony_ci /* If not PSA_SUCCESS, return this error code instead of processing the 34a8e1175bSopenharmony_ci * function call. */ 35a8e1175bSopenharmony_ci psa_status_t forced_status; 36a8e1175bSopenharmony_ci /* Count the amount of times one of the asymmetric_encryption driver 37a8e1175bSopenharmony_ci functions is called. */ 38a8e1175bSopenharmony_ci unsigned long hits; 39a8e1175bSopenharmony_ci} mbedtls_test_driver_asymmetric_encryption_hooks_t; 40a8e1175bSopenharmony_ci 41a8e1175bSopenharmony_ci#define MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT { NULL, 0, PSA_SUCCESS, 0 } 42a8e1175bSopenharmony_ci 43a8e1175bSopenharmony_cistatic inline mbedtls_test_driver_asymmetric_encryption_hooks_t 44a8e1175bSopenharmony_cimbedtls_test_driver_asymmetric_encryption_hooks_init(void) 45a8e1175bSopenharmony_ci{ 46a8e1175bSopenharmony_ci const mbedtls_test_driver_asymmetric_encryption_hooks_t v = 47a8e1175bSopenharmony_ci MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT; 48a8e1175bSopenharmony_ci return v; 49a8e1175bSopenharmony_ci} 50a8e1175bSopenharmony_ci 51a8e1175bSopenharmony_ciextern mbedtls_test_driver_asymmetric_encryption_hooks_t 52a8e1175bSopenharmony_ci mbedtls_test_driver_asymmetric_encryption_hooks; 53a8e1175bSopenharmony_ci 54a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_asymmetric_encrypt( 55a8e1175bSopenharmony_ci const psa_key_attributes_t *attributes, const uint8_t *key_buffer, 56a8e1175bSopenharmony_ci size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, 57a8e1175bSopenharmony_ci size_t input_length, const uint8_t *salt, size_t salt_length, 58a8e1175bSopenharmony_ci uint8_t *output, size_t output_size, size_t *output_length); 59a8e1175bSopenharmony_ci 60a8e1175bSopenharmony_cipsa_status_t mbedtls_test_opaque_asymmetric_encrypt( 61a8e1175bSopenharmony_ci const psa_key_attributes_t *attributes, const uint8_t *key, 62a8e1175bSopenharmony_ci size_t key_length, psa_algorithm_t alg, const uint8_t *input, 63a8e1175bSopenharmony_ci size_t input_length, const uint8_t *salt, size_t salt_length, 64a8e1175bSopenharmony_ci uint8_t *output, size_t output_size, size_t *output_length); 65a8e1175bSopenharmony_ci 66a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_asymmetric_decrypt( 67a8e1175bSopenharmony_ci const psa_key_attributes_t *attributes, const uint8_t *key_buffer, 68a8e1175bSopenharmony_ci size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input, 69a8e1175bSopenharmony_ci size_t input_length, const uint8_t *salt, size_t salt_length, 70a8e1175bSopenharmony_ci uint8_t *output, size_t output_size, size_t *output_length); 71a8e1175bSopenharmony_ci 72a8e1175bSopenharmony_cipsa_status_t mbedtls_test_opaque_asymmetric_decrypt( 73a8e1175bSopenharmony_ci const psa_key_attributes_t *attributes, const uint8_t *key, 74a8e1175bSopenharmony_ci size_t key_length, psa_algorithm_t alg, const uint8_t *input, 75a8e1175bSopenharmony_ci size_t input_length, const uint8_t *salt, size_t salt_length, 76a8e1175bSopenharmony_ci uint8_t *output, size_t output_size, size_t *output_length); 77a8e1175bSopenharmony_ci 78a8e1175bSopenharmony_ci#endif /* PSA_CRYPTO_DRIVER_TEST */ 79a8e1175bSopenharmony_ci#endif /* PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H */ 80