1 /*
2 * Test driver for asymmetric encryption.
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_ASYMMETRIC_ENCRYPTION_H
21 #define PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H
22
23 #include "mbedtls/build_info.h"
24
25 #if defined(PSA_CRYPTO_DRIVER_TEST)
26 #include <psa/crypto_driver_common.h>
27 #include <psa/crypto.h>
28
29 typedef struct {
30 /* If non-null, on success, copy this to the output. */
31 void *forced_output;
32 size_t forced_output_length;
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 one of the asymmetric_encryption driver
37 functions is called. */
38 unsigned long hits;
39 } mbedtls_test_driver_asymmetric_encryption_hooks_t;
40
41 #define MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT { NULL, 0, PSA_SUCCESS, 0 }
42
43 static inline mbedtls_test_driver_asymmetric_encryption_hooks_t
mbedtls_test_driver_asymmetric_encryption_hooks_init(void)44 mbedtls_test_driver_asymmetric_encryption_hooks_init(void)
45 {
46 const mbedtls_test_driver_asymmetric_encryption_hooks_t v =
47 MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT;
48 return v;
49 }
50
51 extern mbedtls_test_driver_asymmetric_encryption_hooks_t
52 mbedtls_test_driver_asymmetric_encryption_hooks;
53
54 psa_status_t mbedtls_test_transparent_asymmetric_encrypt(
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_encrypt(
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 psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
67 const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
68 size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
69 size_t input_length, const uint8_t *salt, size_t salt_length,
70 uint8_t *output, size_t output_size, size_t *output_length);
71
72 psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
73 const psa_key_attributes_t *attributes, const uint8_t *key,
74 size_t key_length, psa_algorithm_t alg, const uint8_t *input,
75 size_t input_length, const uint8_t *salt, size_t salt_length,
76 uint8_t *output, size_t output_size, size_t *output_length);
77
78 #endif /* PSA_CRYPTO_DRIVER_TEST */
79 #endif /* PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H */
80