psa_crypto_invasive.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * \file psa_crypto_invasive.h
  3. *
  4. * \brief PSA cryptography module: invasive interfaces for test only.
  5. *
  6. * The interfaces in this file are intended for testing purposes only.
  7. * They MUST NOT be made available to clients over IPC in integrations
  8. * with isolation, and they SHOULD NOT be made available in library
  9. * integrations except when building the library for testing.
  10. */
  11. /*
  12. * Copyright The Mbed TLS Contributors
  13. * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  14. */
  15. #ifndef PSA_CRYPTO_INVASIVE_H
  16. #define PSA_CRYPTO_INVASIVE_H
  17. /*
  18. * Include the build-time configuration information header. Here, we do not
  19. * include `"mbedtls/build_info.h"` directly but `"psa/build_info.h"`, which
  20. * is basically just an alias to it. This is to ease the maintenance of the
  21. * TF-PSA-Crypto repository which has a different build system and
  22. * configuration.
  23. */
  24. #include "psa/build_info.h"
  25. #include "psa/crypto.h"
  26. #include "common.h"
  27. #include "mbedtls/entropy.h"
  28. #if !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
  29. /** \brief Configure entropy sources.
  30. *
  31. * This function may only be called before a call to psa_crypto_init(),
  32. * or after a call to mbedtls_psa_crypto_free() and before any
  33. * subsequent call to psa_crypto_init().
  34. *
  35. * This function is only intended for test purposes. The functionality
  36. * it provides is also useful for system integrators, but
  37. * system integrators should configure entropy drivers instead of
  38. * breaking through to the Mbed TLS API.
  39. *
  40. * \param entropy_init Function to initialize the entropy context
  41. * and set up the desired entropy sources.
  42. * It is called by psa_crypto_init().
  43. * By default this is mbedtls_entropy_init().
  44. * This function cannot report failures directly.
  45. * To indicate a failure, set the entropy context
  46. * to a state where mbedtls_entropy_func() will
  47. * return an error.
  48. * \param entropy_free Function to free the entropy context
  49. * and associated resources.
  50. * It is called by mbedtls_psa_crypto_free().
  51. * By default this is mbedtls_entropy_free().
  52. *
  53. * \retval #PSA_SUCCESS
  54. * Success.
  55. * \retval #PSA_ERROR_NOT_PERMITTED
  56. * The caller does not have the permission to configure
  57. * entropy sources.
  58. * \retval #PSA_ERROR_BAD_STATE
  59. * The library has already been initialized.
  60. */
  61. psa_status_t mbedtls_psa_crypto_configure_entropy_sources(
  62. void (* entropy_init)(mbedtls_entropy_context *ctx),
  63. void (* entropy_free)(mbedtls_entropy_context *ctx));
  64. #endif /* !defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) */
  65. #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C)
  66. psa_status_t psa_mac_key_can_do(
  67. psa_algorithm_t algorithm,
  68. psa_key_type_t key_type);
  69. psa_status_t psa_crypto_copy_input(const uint8_t *input, size_t input_len,
  70. uint8_t *input_copy, size_t input_copy_len);
  71. psa_status_t psa_crypto_copy_output(const uint8_t *output_copy, size_t output_copy_len,
  72. uint8_t *output, size_t output_len);
  73. /*
  74. * Test hooks to use for memory unpoisoning/poisoning in copy functions.
  75. */
  76. extern void (*psa_input_pre_copy_hook)(const uint8_t *input, size_t input_len);
  77. extern void (*psa_input_post_copy_hook)(const uint8_t *input, size_t input_len);
  78. extern void (*psa_output_pre_copy_hook)(const uint8_t *output, size_t output_len);
  79. extern void (*psa_output_post_copy_hook)(const uint8_t *output, size_t output_len);
  80. #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_PSA_CRYPTO_C */
  81. #endif /* PSA_CRYPTO_INVASIVE_H */