hash.h 2.7 KB

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