1 /*
2  * Test driver for asymmetric encryption.
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_ASYMMETRIC_ENCRYPTION_H
9 #define PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H
10 
11 #include "mbedtls/build_info.h"
12 
13 #if defined(PSA_CRYPTO_DRIVER_TEST)
14 #include <psa/crypto_driver_common.h>
15 #include <psa/crypto.h>
16 
17 typedef struct {
18     /* If non-null, on success, copy this to the output. */
19     void *forced_output;
20     size_t forced_output_length;
21     /* If not PSA_SUCCESS, return this error code instead of processing the
22      * function call. */
23     psa_status_t forced_status;
24     /* Count the amount of times one of the asymmetric_encryption driver
25        functions is called. */
26     unsigned long hits;
27 } mbedtls_test_driver_asymmetric_encryption_hooks_t;
28 
29 #define MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT { NULL, 0, PSA_SUCCESS, 0 }
30 
31 static inline mbedtls_test_driver_asymmetric_encryption_hooks_t
mbedtls_test_driver_asymmetric_encryption_hooks_init(void)32 mbedtls_test_driver_asymmetric_encryption_hooks_init(void)
33 {
34     const mbedtls_test_driver_asymmetric_encryption_hooks_t v =
35         MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT;
36     return v;
37 }
38 
39 extern mbedtls_test_driver_asymmetric_encryption_hooks_t
40     mbedtls_test_driver_asymmetric_encryption_hooks;
41 
42 psa_status_t mbedtls_test_transparent_asymmetric_encrypt(
43     const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
44     size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
45     size_t input_length, const uint8_t *salt, size_t salt_length,
46     uint8_t *output, size_t output_size, size_t *output_length);
47 
48 psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
49     const psa_key_attributes_t *attributes, const uint8_t *key,
50     size_t key_length, psa_algorithm_t alg, const uint8_t *input,
51     size_t input_length, const uint8_t *salt, size_t salt_length,
52     uint8_t *output, size_t output_size, size_t *output_length);
53 
54 psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
55     const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
56     size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
57     size_t input_length, const uint8_t *salt, size_t salt_length,
58     uint8_t *output, size_t output_size, size_t *output_length);
59 
60 psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
61     const psa_key_attributes_t *attributes, const uint8_t *key,
62     size_t key_length, psa_algorithm_t alg, const uint8_t *input,
63     size_t input_length, const uint8_t *salt, size_t salt_length,
64     uint8_t *output, size_t output_size, size_t *output_length);
65 
66 #endif /* PSA_CRYPTO_DRIVER_TEST */
67 #endif /* PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H */
68