hash.h 2.6 KB

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