mac.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Test driver for MAC 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_MAC_H
  20. #define PSA_CRYPTO_TEST_DRIVERS_MAC_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 MAC driver functions are called. */
  29. unsigned long hits;
  30. /* Status returned by the last MAC driver function call. */
  31. psa_status_t driver_status;
  32. } mbedtls_test_driver_mac_hooks_t;
  33. #define MBEDTLS_TEST_DRIVER_MAC_INIT { 0, 0, 0 }
  34. static inline mbedtls_test_driver_mac_hooks_t
  35. mbedtls_test_driver_mac_hooks_init(void)
  36. {
  37. const mbedtls_test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT;
  38. return v;
  39. }
  40. extern mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks;
  41. psa_status_t mbedtls_test_transparent_mac_compute(
  42. const psa_key_attributes_t *attributes,
  43. const uint8_t *key_buffer,
  44. size_t key_buffer_size,
  45. psa_algorithm_t alg,
  46. const uint8_t *input,
  47. size_t input_length,
  48. uint8_t *mac,
  49. size_t mac_size,
  50. size_t *mac_length);
  51. psa_status_t mbedtls_test_transparent_mac_sign_setup(
  52. mbedtls_transparent_test_driver_mac_operation_t *operation,
  53. const psa_key_attributes_t *attributes,
  54. const uint8_t *key_buffer,
  55. size_t key_buffer_size,
  56. psa_algorithm_t alg);
  57. psa_status_t mbedtls_test_transparent_mac_verify_setup(
  58. mbedtls_transparent_test_driver_mac_operation_t *operation,
  59. const psa_key_attributes_t *attributes,
  60. const uint8_t *key_buffer,
  61. size_t key_buffer_size,
  62. psa_algorithm_t alg);
  63. psa_status_t mbedtls_test_transparent_mac_update(
  64. mbedtls_transparent_test_driver_mac_operation_t *operation,
  65. const uint8_t *input,
  66. size_t input_length);
  67. psa_status_t mbedtls_test_transparent_mac_sign_finish(
  68. mbedtls_transparent_test_driver_mac_operation_t *operation,
  69. uint8_t *mac,
  70. size_t mac_size,
  71. size_t *mac_length);
  72. psa_status_t mbedtls_test_transparent_mac_verify_finish(
  73. mbedtls_transparent_test_driver_mac_operation_t *operation,
  74. const uint8_t *mac,
  75. size_t mac_length);
  76. psa_status_t mbedtls_test_transparent_mac_abort(
  77. mbedtls_transparent_test_driver_mac_operation_t *operation);
  78. psa_status_t mbedtls_test_opaque_mac_compute(
  79. const psa_key_attributes_t *attributes,
  80. const uint8_t *key_buffer,
  81. size_t key_buffer_size,
  82. psa_algorithm_t alg,
  83. const uint8_t *input,
  84. size_t input_length,
  85. uint8_t *mac,
  86. size_t mac_size,
  87. size_t *mac_length);
  88. psa_status_t mbedtls_test_opaque_mac_sign_setup(
  89. mbedtls_opaque_test_driver_mac_operation_t *operation,
  90. const psa_key_attributes_t *attributes,
  91. const uint8_t *key_buffer,
  92. size_t key_buffer_size,
  93. psa_algorithm_t alg);
  94. psa_status_t mbedtls_test_opaque_mac_verify_setup(
  95. mbedtls_opaque_test_driver_mac_operation_t *operation,
  96. const psa_key_attributes_t *attributes,
  97. const uint8_t *key_buffer,
  98. size_t key_buffer_size,
  99. psa_algorithm_t alg);
  100. psa_status_t mbedtls_test_opaque_mac_update(
  101. mbedtls_opaque_test_driver_mac_operation_t *operation,
  102. const uint8_t *input,
  103. size_t input_length);
  104. psa_status_t mbedtls_test_opaque_mac_sign_finish(
  105. mbedtls_opaque_test_driver_mac_operation_t *operation,
  106. uint8_t *mac,
  107. size_t mac_size,
  108. size_t *mac_length);
  109. psa_status_t mbedtls_test_opaque_mac_verify_finish(
  110. mbedtls_opaque_test_driver_mac_operation_t *operation,
  111. const uint8_t *mac,
  112. size_t mac_length);
  113. psa_status_t mbedtls_test_opaque_mac_abort(
  114. mbedtls_opaque_test_driver_mac_operation_t *operation);
  115. #endif /* PSA_CRYPTO_DRIVER_TEST */
  116. #endif /* PSA_CRYPTO_TEST_DRIVERS_MAC_H */