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