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