aead.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Test driver for AEAD 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_AEAD_H
  20. #define PSA_CRYPTO_TEST_DRIVERS_AEAD_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 AEAD driver functions are called. */
  29. unsigned long hits_encrypt;
  30. unsigned long hits_decrypt;
  31. unsigned long hits_encrypt_setup;
  32. unsigned long hits_decrypt_setup;
  33. unsigned long hits_set_nonce;
  34. unsigned long hits_set_lengths;
  35. unsigned long hits_update_ad;
  36. unsigned long hits_update;
  37. unsigned long hits_finish;
  38. unsigned long hits_verify;
  39. unsigned long hits_abort;
  40. /* Status returned by the last AEAD driver function call. */
  41. psa_status_t driver_status;
  42. } mbedtls_test_driver_aead_hooks_t;
  43. #define MBEDTLS_TEST_DRIVER_AEAD_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  44. static inline mbedtls_test_driver_aead_hooks_t
  45. mbedtls_test_driver_aead_hooks_init(void)
  46. {
  47. const mbedtls_test_driver_aead_hooks_t v = MBEDTLS_TEST_DRIVER_AEAD_INIT;
  48. return v;
  49. }
  50. extern mbedtls_test_driver_aead_hooks_t mbedtls_test_driver_aead_hooks;
  51. psa_status_t mbedtls_test_transparent_aead_encrypt(
  52. const psa_key_attributes_t *attributes,
  53. const uint8_t *key_buffer, size_t key_buffer_size,
  54. psa_algorithm_t alg,
  55. const uint8_t *nonce, size_t nonce_length,
  56. const uint8_t *additional_data, size_t additional_data_length,
  57. const uint8_t *plaintext, size_t plaintext_length,
  58. uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length);
  59. psa_status_t mbedtls_test_transparent_aead_decrypt(
  60. const psa_key_attributes_t *attributes,
  61. const uint8_t *key_buffer, size_t key_buffer_size,
  62. psa_algorithm_t alg,
  63. const uint8_t *nonce, size_t nonce_length,
  64. const uint8_t *additional_data, size_t additional_data_length,
  65. const uint8_t *ciphertext, size_t ciphertext_length,
  66. uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length);
  67. psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
  68. mbedtls_transparent_test_driver_aead_operation_t *operation,
  69. const psa_key_attributes_t *attributes,
  70. const uint8_t *key_buffer, size_t key_buffer_size,
  71. psa_algorithm_t alg);
  72. psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
  73. mbedtls_transparent_test_driver_aead_operation_t *operation,
  74. const psa_key_attributes_t *attributes,
  75. const uint8_t *key_buffer, size_t key_buffer_size,
  76. psa_algorithm_t alg);
  77. psa_status_t mbedtls_test_transparent_aead_set_nonce(
  78. mbedtls_transparent_test_driver_aead_operation_t *operation,
  79. const uint8_t *nonce,
  80. size_t nonce_length);
  81. psa_status_t mbedtls_test_transparent_aead_set_lengths(
  82. mbedtls_transparent_test_driver_aead_operation_t *operation,
  83. size_t ad_length,
  84. size_t plaintext_length);
  85. psa_status_t mbedtls_test_transparent_aead_update_ad(
  86. mbedtls_transparent_test_driver_aead_operation_t *operation,
  87. const uint8_t *input,
  88. size_t input_length);
  89. psa_status_t mbedtls_test_transparent_aead_update(
  90. mbedtls_transparent_test_driver_aead_operation_t *operation,
  91. const uint8_t *input,
  92. size_t input_length,
  93. uint8_t *output,
  94. size_t output_size,
  95. size_t *output_length);
  96. psa_status_t mbedtls_test_transparent_aead_finish(
  97. mbedtls_transparent_test_driver_aead_operation_t *operation,
  98. uint8_t *ciphertext,
  99. size_t ciphertext_size,
  100. size_t *ciphertext_length,
  101. uint8_t *tag,
  102. size_t tag_size,
  103. size_t *tag_length);
  104. psa_status_t mbedtls_test_transparent_aead_verify(
  105. mbedtls_transparent_test_driver_aead_operation_t *operation,
  106. uint8_t *plaintext,
  107. size_t plaintext_size,
  108. size_t *plaintext_length,
  109. const uint8_t *tag,
  110. size_t tag_length);
  111. psa_status_t mbedtls_test_transparent_aead_abort(
  112. mbedtls_transparent_test_driver_aead_operation_t *operation);
  113. #endif /* PSA_CRYPTO_DRIVER_TEST */
  114. #endif /* PSA_CRYPTO_TEST_DRIVERS_AEAD_H */