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