Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Test driver for hash driver entry points. |
| 3 | */ |
| 4 | /* Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame^] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 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; |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 28 | } mbedtls_test_driver_hash_hooks_t; |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 29 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 30 | #define MBEDTLS_TEST_DRIVER_HASH_INIT { 0, 0, 0 } |
| 31 | static inline mbedtls_test_driver_hash_hooks_t |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 32 | mbedtls_test_driver_hash_hooks_init(void) |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 33 | { |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 34 | const mbedtls_test_driver_hash_hooks_t v = MBEDTLS_TEST_DRIVER_HASH_INIT; |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 35 | return v; |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 38 | extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks; |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 39 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 40 | psa_status_t mbedtls_test_transparent_hash_compute( |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 41 | psa_algorithm_t alg, |
| 42 | const uint8_t *input, size_t input_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 43 | uint8_t *hash, size_t hash_size, size_t *hash_length); |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 44 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 45 | psa_status_t mbedtls_test_transparent_hash_setup( |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 46 | mbedtls_transparent_test_driver_hash_operation_t *operation, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 47 | psa_algorithm_t alg); |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 48 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 49 | psa_status_t mbedtls_test_transparent_hash_clone( |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 50 | const mbedtls_transparent_test_driver_hash_operation_t *source_operation, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 51 | mbedtls_transparent_test_driver_hash_operation_t *target_operation); |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 52 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 53 | psa_status_t mbedtls_test_transparent_hash_update( |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 54 | mbedtls_transparent_test_driver_hash_operation_t *operation, |
| 55 | const uint8_t *input, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 56 | size_t input_length); |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 57 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 58 | psa_status_t mbedtls_test_transparent_hash_finish( |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 59 | mbedtls_transparent_test_driver_hash_operation_t *operation, |
| 60 | uint8_t *hash, |
| 61 | size_t hash_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 62 | size_t *hash_length); |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 63 | |
Ronald Cron | c4bc12e | 2021-04-13 12:41:34 +0200 | [diff] [blame] | 64 | psa_status_t mbedtls_test_transparent_hash_abort( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 65 | mbedtls_transparent_test_driver_hash_operation_t *operation); |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 66 | |
Ronald Cron | 0bec41a | 2021-03-23 09:33:25 +0100 | [diff] [blame] | 67 | #endif /* PSA_CRYPTO_DRIVER_TEST */ |
| 68 | #endif /* PSA_CRYPTO_TEST_DRIVERS_HASH_H */ |