1 /* 2 * Test driver for MAC driver entry points. 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_MAC_H 21 #define PSA_CRYPTO_TEST_DRIVERS_MAC_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 not PSA_SUCCESS, return this error code instead of processing the 30 * function call. */ 31 psa_status_t forced_status; 32 /* Count the amount of times MAC driver functions are called. */ 33 unsigned long hits; 34 /* Status returned by the last MAC driver function call. */ 35 psa_status_t driver_status; 36 } mbedtls_test_driver_mac_hooks_t; 37 38 #define MBEDTLS_TEST_DRIVER_MAC_INIT { 0, 0, 0 } 39 static inline mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks_init(void)40 mbedtls_test_driver_mac_hooks_init( void ) 41 { 42 const mbedtls_test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT; 43 return( v ); 44 } 45 46 extern mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks; 47 48 psa_status_t mbedtls_test_transparent_mac_compute( 49 const psa_key_attributes_t *attributes, 50 const uint8_t *key_buffer, 51 size_t key_buffer_size, 52 psa_algorithm_t alg, 53 const uint8_t *input, 54 size_t input_length, 55 uint8_t *mac, 56 size_t mac_size, 57 size_t *mac_length ); 58 59 psa_status_t mbedtls_test_transparent_mac_sign_setup( 60 mbedtls_transparent_test_driver_mac_operation_t *operation, 61 const psa_key_attributes_t *attributes, 62 const uint8_t *key_buffer, 63 size_t key_buffer_size, 64 psa_algorithm_t alg ); 65 66 psa_status_t mbedtls_test_transparent_mac_verify_setup( 67 mbedtls_transparent_test_driver_mac_operation_t *operation, 68 const psa_key_attributes_t *attributes, 69 const uint8_t *key_buffer, 70 size_t key_buffer_size, 71 psa_algorithm_t alg ); 72 73 psa_status_t mbedtls_test_transparent_mac_update( 74 mbedtls_transparent_test_driver_mac_operation_t *operation, 75 const uint8_t *input, 76 size_t input_length ); 77 78 psa_status_t mbedtls_test_transparent_mac_sign_finish( 79 mbedtls_transparent_test_driver_mac_operation_t *operation, 80 uint8_t *mac, 81 size_t mac_size, 82 size_t *mac_length ); 83 84 psa_status_t mbedtls_test_transparent_mac_verify_finish( 85 mbedtls_transparent_test_driver_mac_operation_t *operation, 86 const uint8_t *mac, 87 size_t mac_length ); 88 89 psa_status_t mbedtls_test_transparent_mac_abort( 90 mbedtls_transparent_test_driver_mac_operation_t *operation ); 91 92 psa_status_t mbedtls_test_opaque_mac_compute( 93 const psa_key_attributes_t *attributes, 94 const uint8_t *key_buffer, 95 size_t key_buffer_size, 96 psa_algorithm_t alg, 97 const uint8_t *input, 98 size_t input_length, 99 uint8_t *mac, 100 size_t mac_size, 101 size_t *mac_length ); 102 103 psa_status_t mbedtls_test_opaque_mac_sign_setup( 104 mbedtls_opaque_test_driver_mac_operation_t *operation, 105 const psa_key_attributes_t *attributes, 106 const uint8_t *key_buffer, 107 size_t key_buffer_size, 108 psa_algorithm_t alg ); 109 110 psa_status_t mbedtls_test_opaque_mac_verify_setup( 111 mbedtls_opaque_test_driver_mac_operation_t *operation, 112 const psa_key_attributes_t *attributes, 113 const uint8_t *key_buffer, 114 size_t key_buffer_size, 115 psa_algorithm_t alg ); 116 117 psa_status_t mbedtls_test_opaque_mac_update( 118 mbedtls_opaque_test_driver_mac_operation_t *operation, 119 const uint8_t *input, 120 size_t input_length ); 121 122 psa_status_t mbedtls_test_opaque_mac_sign_finish( 123 mbedtls_opaque_test_driver_mac_operation_t *operation, 124 uint8_t *mac, 125 size_t mac_size, 126 size_t *mac_length ); 127 128 psa_status_t mbedtls_test_opaque_mac_verify_finish( 129 mbedtls_opaque_test_driver_mac_operation_t *operation, 130 const uint8_t *mac, 131 size_t mac_length ); 132 133 psa_status_t mbedtls_test_opaque_mac_abort( 134 mbedtls_opaque_test_driver_mac_operation_t *operation ); 135 136 #endif /* PSA_CRYPTO_DRIVER_TEST */ 137 #endif /* PSA_CRYPTO_TEST_DRIVERS_MAC_H */ 138