1 /*
2 * Test driver for hash driver entry points.
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_HASH_H
9 #define PSA_CRYPTO_TEST_DRIVERS_HASH_H
10
11 #if !defined(MBEDTLS_CONFIG_FILE)
12 #include "mbedtls/config.h"
13 #else
14 #include MBEDTLS_CONFIG_FILE
15 #endif
16
17 #if defined(PSA_CRYPTO_DRIVER_TEST)
18 #include <psa/crypto_driver_common.h>
19
20 typedef struct {
21 /* If not PSA_SUCCESS, return this error code instead of processing the
22 * function call. */
23 psa_status_t forced_status;
24 /* Count the amount of times hash driver entry points are called. */
25 unsigned long hits;
26 /* Status returned by the last hash driver entry point call. */
27 psa_status_t driver_status;
28 } mbedtls_test_driver_hash_hooks_t;
29
30 #define MBEDTLS_TEST_DRIVER_HASH_INIT { 0, 0, 0 }
31 static inline mbedtls_test_driver_hash_hooks_t
mbedtls_test_driver_hash_hooks_init(void)32 mbedtls_test_driver_hash_hooks_init(void)
33 {
34 const mbedtls_test_driver_hash_hooks_t v = MBEDTLS_TEST_DRIVER_HASH_INIT;
35 return v;
36 }
37
38 extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks;
39
40 psa_status_t mbedtls_test_transparent_hash_compute(
41 psa_algorithm_t alg,
42 const uint8_t *input, size_t input_length,
43 uint8_t *hash, size_t hash_size, size_t *hash_length);
44
45 psa_status_t mbedtls_test_transparent_hash_setup(
46 mbedtls_transparent_test_driver_hash_operation_t *operation,
47 psa_algorithm_t alg);
48
49 psa_status_t mbedtls_test_transparent_hash_clone(
50 const mbedtls_transparent_test_driver_hash_operation_t *source_operation,
51 mbedtls_transparent_test_driver_hash_operation_t *target_operation);
52
53 psa_status_t mbedtls_test_transparent_hash_update(
54 mbedtls_transparent_test_driver_hash_operation_t *operation,
55 const uint8_t *input,
56 size_t input_length);
57
58 psa_status_t mbedtls_test_transparent_hash_finish(
59 mbedtls_transparent_test_driver_hash_operation_t *operation,
60 uint8_t *hash,
61 size_t hash_size,
62 size_t *hash_length);
63
64 psa_status_t mbedtls_test_transparent_hash_abort(
65 mbedtls_transparent_test_driver_hash_operation_t *operation);
66
67 #endif /* PSA_CRYPTO_DRIVER_TEST */
68 #endif /* PSA_CRYPTO_TEST_DRIVERS_HASH_H */
69