blob: 36e889b5301babc9bc312b5a5bd8e2d766a4df7d [file] [log] [blame]
Ronald Cron0bec41a2021-03-23 09:33:25 +01001/*
2 * Test driver for hash driver entry points.
3 */
4/* Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Ronald Cron0bec41a2021-03-23 09:33:25 +01006 */
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
20typedef 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 Cronc4bc12e2021-04-13 12:41:34 +020028} mbedtls_test_driver_hash_hooks_t;
Ronald Cron0bec41a2021-03-23 09:33:25 +010029
Ronald Cronc4bc12e2021-04-13 12:41:34 +020030#define MBEDTLS_TEST_DRIVER_HASH_INIT { 0, 0, 0 }
31static inline mbedtls_test_driver_hash_hooks_t
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010032mbedtls_test_driver_hash_hooks_init(void)
Ronald Cron0bec41a2021-03-23 09:33:25 +010033{
Ronald Cronc4bc12e2021-04-13 12:41:34 +020034 const mbedtls_test_driver_hash_hooks_t v = MBEDTLS_TEST_DRIVER_HASH_INIT;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010035 return v;
Ronald Cron0bec41a2021-03-23 09:33:25 +010036}
37
Ronald Cronc4bc12e2021-04-13 12:41:34 +020038extern mbedtls_test_driver_hash_hooks_t mbedtls_test_driver_hash_hooks;
Ronald Cron0bec41a2021-03-23 09:33:25 +010039
Ronald Cronc4bc12e2021-04-13 12:41:34 +020040psa_status_t mbedtls_test_transparent_hash_compute(
Ronald Cron0bec41a2021-03-23 09:33:25 +010041 psa_algorithm_t alg,
42 const uint8_t *input, size_t input_length,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010043 uint8_t *hash, size_t hash_size, size_t *hash_length);
Ronald Cron0bec41a2021-03-23 09:33:25 +010044
Ronald Cronc4bc12e2021-04-13 12:41:34 +020045psa_status_t mbedtls_test_transparent_hash_setup(
Ronald Cron0bec41a2021-03-23 09:33:25 +010046 mbedtls_transparent_test_driver_hash_operation_t *operation,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010047 psa_algorithm_t alg);
Ronald Cron0bec41a2021-03-23 09:33:25 +010048
Ronald Cronc4bc12e2021-04-13 12:41:34 +020049psa_status_t mbedtls_test_transparent_hash_clone(
Ronald Cron0bec41a2021-03-23 09:33:25 +010050 const mbedtls_transparent_test_driver_hash_operation_t *source_operation,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010051 mbedtls_transparent_test_driver_hash_operation_t *target_operation);
Ronald Cron0bec41a2021-03-23 09:33:25 +010052
Ronald Cronc4bc12e2021-04-13 12:41:34 +020053psa_status_t mbedtls_test_transparent_hash_update(
Ronald Cron0bec41a2021-03-23 09:33:25 +010054 mbedtls_transparent_test_driver_hash_operation_t *operation,
55 const uint8_t *input,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010056 size_t input_length);
Ronald Cron0bec41a2021-03-23 09:33:25 +010057
Ronald Cronc4bc12e2021-04-13 12:41:34 +020058psa_status_t mbedtls_test_transparent_hash_finish(
Ronald Cron0bec41a2021-03-23 09:33:25 +010059 mbedtls_transparent_test_driver_hash_operation_t *operation,
60 uint8_t *hash,
61 size_t hash_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010062 size_t *hash_length);
Ronald Cron0bec41a2021-03-23 09:33:25 +010063
Ronald Cronc4bc12e2021-04-13 12:41:34 +020064psa_status_t mbedtls_test_transparent_hash_abort(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010065 mbedtls_transparent_test_driver_hash_operation_t *operation);
Ronald Cron0bec41a2021-03-23 09:33:25 +010066
Ronald Cron0bec41a2021-03-23 09:33:25 +010067#endif /* PSA_CRYPTO_DRIVER_TEST */
68#endif /* PSA_CRYPTO_TEST_DRIVERS_HASH_H */