asymmetric_encryption.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Test driver for asymmetric encryption.
  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_ASYMMETRIC_ENCRYPTION_H
  20. #define PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H
  21. #include "mbedtls/build_info.h"
  22. #if defined(PSA_CRYPTO_DRIVER_TEST)
  23. #include <psa/crypto_driver_common.h>
  24. #include <psa/crypto.h>
  25. typedef struct {
  26. /* If non-null, on success, copy this to the output. */
  27. void *forced_output;
  28. size_t forced_output_length;
  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 one of the asymmetric_encryption driver
  33. functions is called. */
  34. unsigned long hits;
  35. } mbedtls_test_driver_asymmetric_encryption_hooks_t;
  36. #define MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT { NULL, 0, PSA_SUCCESS, 0 }
  37. static inline mbedtls_test_driver_asymmetric_encryption_hooks_t
  38. mbedtls_test_driver_asymmetric_encryption_hooks_init(void)
  39. {
  40. const mbedtls_test_driver_asymmetric_encryption_hooks_t v =
  41. MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT;
  42. return v;
  43. }
  44. extern mbedtls_test_driver_asymmetric_encryption_hooks_t
  45. mbedtls_test_driver_asymmetric_encryption_hooks;
  46. psa_status_t mbedtls_test_transparent_asymmetric_encrypt(
  47. const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
  48. size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
  49. size_t input_length, const uint8_t *salt, size_t salt_length,
  50. uint8_t *output, size_t output_size, size_t *output_length);
  51. psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
  52. const psa_key_attributes_t *attributes, const uint8_t *key,
  53. size_t key_length, psa_algorithm_t alg, const uint8_t *input,
  54. size_t input_length, const uint8_t *salt, size_t salt_length,
  55. uint8_t *output, size_t output_size, size_t *output_length);
  56. psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
  57. const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
  58. size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
  59. size_t input_length, const uint8_t *salt, size_t salt_length,
  60. uint8_t *output, size_t output_size, size_t *output_length);
  61. psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
  62. const psa_key_attributes_t *attributes, const uint8_t *key,
  63. size_t key_length, psa_algorithm_t alg, const uint8_t *input,
  64. size_t input_length, const uint8_t *salt, size_t salt_length,
  65. uint8_t *output, size_t output_size, size_t *output_length);
  66. #endif /* PSA_CRYPTO_DRIVER_TEST */
  67. #endif /* PSA_CRYPTO_TEST_DRIVERS_ASYMMETRIC_ENCRYPTION_H */