cipher.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Test driver for cipher functions
  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_CIPHER_H
  20. #define PSA_CRYPTO_TEST_DRIVERS_CIPHER_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. #include <psa/crypto.h>
  29. #include "mbedtls/cipher.h"
  30. typedef struct {
  31. /* If non-null, on success, copy this to the output. */
  32. void *forced_output;
  33. size_t forced_output_length;
  34. /* If not PSA_SUCCESS, return this error code instead of processing the
  35. * function call. */
  36. psa_status_t forced_status;
  37. /* Count the amount of times one of the cipher driver functions is called. */
  38. unsigned long hits;
  39. } mbedtls_test_driver_cipher_hooks_t;
  40. #define MBEDTLS_TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
  41. static inline mbedtls_test_driver_cipher_hooks_t
  42. mbedtls_test_driver_cipher_hooks_init( void )
  43. {
  44. const mbedtls_test_driver_cipher_hooks_t v = MBEDTLS_TEST_DRIVER_CIPHER_INIT;
  45. return( v );
  46. }
  47. extern mbedtls_test_driver_cipher_hooks_t mbedtls_test_driver_cipher_hooks;
  48. psa_status_t mbedtls_test_transparent_cipher_encrypt(
  49. const psa_key_attributes_t *attributes,
  50. const uint8_t *key, size_t key_length,
  51. psa_algorithm_t alg,
  52. const uint8_t *iv, size_t iv_length,
  53. const uint8_t *input, size_t input_length,
  54. uint8_t *output, size_t output_size, size_t *output_length);
  55. psa_status_t mbedtls_test_transparent_cipher_decrypt(
  56. const psa_key_attributes_t *attributes,
  57. const uint8_t *key, size_t key_length,
  58. psa_algorithm_t alg,
  59. const uint8_t *input, size_t input_length,
  60. uint8_t *output, size_t output_size, size_t *output_length);
  61. psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
  62. mbedtls_transparent_test_driver_cipher_operation_t *operation,
  63. const psa_key_attributes_t *attributes,
  64. const uint8_t *key, size_t key_length,
  65. psa_algorithm_t alg);
  66. psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
  67. mbedtls_transparent_test_driver_cipher_operation_t *operation,
  68. const psa_key_attributes_t *attributes,
  69. const uint8_t *key, size_t key_length,
  70. psa_algorithm_t alg);
  71. psa_status_t mbedtls_test_transparent_cipher_abort(
  72. mbedtls_transparent_test_driver_cipher_operation_t *operation );
  73. psa_status_t mbedtls_test_transparent_cipher_set_iv(
  74. mbedtls_transparent_test_driver_cipher_operation_t *operation,
  75. const uint8_t *iv, size_t iv_length);
  76. psa_status_t mbedtls_test_transparent_cipher_update(
  77. mbedtls_transparent_test_driver_cipher_operation_t *operation,
  78. const uint8_t *input, size_t input_length,
  79. uint8_t *output, size_t output_size, size_t *output_length);
  80. psa_status_t mbedtls_test_transparent_cipher_finish(
  81. mbedtls_transparent_test_driver_cipher_operation_t *operation,
  82. uint8_t *output, size_t output_size, size_t *output_length);
  83. /*
  84. * opaque versions
  85. */
  86. psa_status_t mbedtls_test_opaque_cipher_encrypt(
  87. const psa_key_attributes_t *attributes,
  88. const uint8_t *key, size_t key_length,
  89. psa_algorithm_t alg,
  90. const uint8_t *iv, size_t iv_length,
  91. const uint8_t *input, size_t input_length,
  92. uint8_t *output, size_t output_size, size_t *output_length);
  93. psa_status_t mbedtls_test_opaque_cipher_decrypt(
  94. const psa_key_attributes_t *attributes,
  95. const uint8_t *key, size_t key_length,
  96. psa_algorithm_t alg,
  97. const uint8_t *input, size_t input_length,
  98. uint8_t *output, size_t output_size, size_t *output_length);
  99. psa_status_t mbedtls_test_opaque_cipher_encrypt_setup(
  100. mbedtls_opaque_test_driver_cipher_operation_t *operation,
  101. const psa_key_attributes_t *attributes,
  102. const uint8_t *key, size_t key_length,
  103. psa_algorithm_t alg);
  104. psa_status_t mbedtls_test_opaque_cipher_decrypt_setup(
  105. mbedtls_opaque_test_driver_cipher_operation_t *operation,
  106. const psa_key_attributes_t *attributes,
  107. const uint8_t *key, size_t key_length,
  108. psa_algorithm_t alg);
  109. psa_status_t mbedtls_test_opaque_cipher_abort(
  110. mbedtls_opaque_test_driver_cipher_operation_t *operation);
  111. psa_status_t mbedtls_test_opaque_cipher_set_iv(
  112. mbedtls_opaque_test_driver_cipher_operation_t *operation,
  113. const uint8_t *iv, size_t iv_length);
  114. psa_status_t mbedtls_test_opaque_cipher_update(
  115. mbedtls_opaque_test_driver_cipher_operation_t *operation,
  116. const uint8_t *input, size_t input_length,
  117. uint8_t *output, size_t output_size, size_t *output_length);
  118. psa_status_t mbedtls_test_opaque_cipher_finish(
  119. mbedtls_opaque_test_driver_cipher_operation_t *operation,
  120. uint8_t *output, size_t output_size, size_t *output_length);
  121. #endif /* PSA_CRYPTO_DRIVER_TEST */
  122. #endif /* PSA_CRYPTO_TEST_DRIVERS_CIPHER_H */