1 /*
2 * Test driver for signature functions.
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_SIGNATURE_H
9 #define PSA_CRYPTO_TEST_DRIVERS_SIGNATURE_H
10
11 #include "mbedtls/build_info.h"
12
13 #if defined(PSA_CRYPTO_DRIVER_TEST)
14 #include <psa/crypto_driver_common.h>
15
16 typedef struct {
17 /* If non-null, on success, copy this to the output. */
18 void *forced_output;
19 size_t forced_output_length;
20 /* If not PSA_SUCCESS, return this error code instead of processing the
21 * function call. */
22 psa_status_t forced_status;
23 /* Count the amount of times one of the signature driver functions is called. */
24 unsigned long hits;
25 } mbedtls_test_driver_signature_hooks_t;
26
27 #define MBEDTLS_TEST_DRIVER_SIGNATURE_INIT { NULL, 0, PSA_SUCCESS, 0 }
28 static inline mbedtls_test_driver_signature_hooks_t
mbedtls_test_driver_signature_hooks_init(void)29 mbedtls_test_driver_signature_hooks_init(void)
30 {
31 const mbedtls_test_driver_signature_hooks_t
32 v = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT;
33 return v;
34 }
35
36 extern mbedtls_test_driver_signature_hooks_t
37 mbedtls_test_driver_signature_sign_hooks;
38 extern mbedtls_test_driver_signature_hooks_t
39 mbedtls_test_driver_signature_verify_hooks;
40
41 psa_status_t mbedtls_test_transparent_signature_sign_message(
42 const psa_key_attributes_t *attributes,
43 const uint8_t *key,
44 size_t key_length,
45 psa_algorithm_t alg,
46 const uint8_t *input,
47 size_t input_length,
48 uint8_t *signature,
49 size_t signature_size,
50 size_t *signature_length);
51
52 psa_status_t mbedtls_test_opaque_signature_sign_message(
53 const psa_key_attributes_t *attributes,
54 const uint8_t *key,
55 size_t key_length,
56 psa_algorithm_t alg,
57 const uint8_t *input,
58 size_t input_length,
59 uint8_t *signature,
60 size_t signature_size,
61 size_t *signature_length);
62
63 psa_status_t mbedtls_test_transparent_signature_verify_message(
64 const psa_key_attributes_t *attributes,
65 const uint8_t *key,
66 size_t key_length,
67 psa_algorithm_t alg,
68 const uint8_t *input,
69 size_t input_length,
70 const uint8_t *signature,
71 size_t signature_length);
72
73 psa_status_t mbedtls_test_opaque_signature_verify_message(
74 const psa_key_attributes_t *attributes,
75 const uint8_t *key,
76 size_t key_length,
77 psa_algorithm_t alg,
78 const uint8_t *input,
79 size_t input_length,
80 const uint8_t *signature,
81 size_t signature_length);
82
83 psa_status_t mbedtls_test_transparent_signature_sign_hash(
84 const psa_key_attributes_t *attributes,
85 const uint8_t *key, size_t key_length,
86 psa_algorithm_t alg,
87 const uint8_t *hash, size_t hash_length,
88 uint8_t *signature, size_t signature_size, size_t *signature_length);
89
90 psa_status_t mbedtls_test_opaque_signature_sign_hash(
91 const psa_key_attributes_t *attributes,
92 const uint8_t *key, size_t key_length,
93 psa_algorithm_t alg,
94 const uint8_t *hash, size_t hash_length,
95 uint8_t *signature, size_t signature_size, size_t *signature_length);
96
97 psa_status_t mbedtls_test_transparent_signature_verify_hash(
98 const psa_key_attributes_t *attributes,
99 const uint8_t *key, size_t key_length,
100 psa_algorithm_t alg,
101 const uint8_t *hash, size_t hash_length,
102 const uint8_t *signature, size_t signature_length);
103
104 psa_status_t mbedtls_test_opaque_signature_verify_hash(
105 const psa_key_attributes_t *attributes,
106 const uint8_t *key, size_t key_length,
107 psa_algorithm_t alg,
108 const uint8_t *hash, size_t hash_length,
109 const uint8_t *signature, size_t signature_length);
110
111 #endif /* PSA_CRYPTO_DRIVER_TEST */
112 #endif /* PSA_CRYPTO_TEST_DRIVERS_SIGNATURE_H */
113