nrf_crypto_init.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Copyright (c) 2018, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRF_CRYPTO_INIT_H__
  41. #define NRF_CRYPTO_INIT_H__
  42. /** @file
  43. *
  44. * @defgroup nrf_crypto_initialization Initialization
  45. * @{
  46. * @ingroup nrf_crypto
  47. *
  48. * @brief Initialization related functions for nrf_crypto .
  49. *
  50. * @details @ref lib_crypto is responsible for global initialization of the nrf_crypto
  51. * frontend and backends that are enabled in @ref sdk_config.
  52. */
  53. #include <stdint.h>
  54. #include <stdbool.h>
  55. #include "nrf_section.h"
  56. #include "sdk_errors.h"
  57. #include "nrf_crypto_types.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /**@internal @brief Macro for registering a nrf_crypto backend for initialization by using
  62. * nrf_section.
  63. *
  64. * @details This macro places a variable in a section named "crypto_data", which
  65. * is initialized by @ref nrf_crypto_init.
  66. *
  67. * @note This macro is used internally based on sdk_config.h configurations for nrf_crypto
  68. */
  69. #define CRYPTO_BACKEND_REGISTER(crypto_var) NRF_SECTION_ITEM_REGISTER(crypto_data, crypto_var)
  70. /**@internal @brief Type definition of function pointer to initialize the nrf_crypto backend.
  71. *
  72. * This function type is used internally. See @nrf_crypto_init for documentation.
  73. */
  74. typedef ret_code_t (*nrf_crypto_backend_init_fn_t)(void);
  75. /**@internal @brief Type definition of function pointer to uninitialize the nrf_crypto backend.
  76. *
  77. * This function type is used internally. Please see @nrf_crypto_uninit for documentation.
  78. */
  79. typedef ret_code_t (*nrf_crypto_backend_uninit_fn_t)(void);
  80. /**@internal @brief Type definition for structure holding the calling interface to
  81. * init, uninit, enable, or disable an nrf_crypto_backend
  82. *
  83. * @note Some backends require no expressive init, uninit, enable, or disable.
  84. * In this case, the backend will not use this structure type or only select
  85. * to implement
  86. */
  87. typedef struct
  88. {
  89. nrf_crypto_backend_init_fn_t const init_fn;
  90. nrf_crypto_backend_uninit_fn_t const uninit_fn;
  91. } nrf_crypto_backend_info_t;
  92. /**@brief Function for initializing nrf_crypto and all registered backends.
  93. *
  94. * @details Must always be called before any other @ref nrf_crypto function.
  95. *
  96. * @retval NRF_SUCCESS The initialization was successful.
  97. * @retval NRF_ERROR_INTERNAL An internal error occured in the nrf_crypt backend init.
  98. */
  99. ret_code_t nrf_crypto_init(void);
  100. /**@brief Function for uninitializing nrf_crypto and all registered backends.
  101. *
  102. * @retval NRF_SUCCESS If unititialization was successful.
  103. * @retval NRF_ERROR_INTERNAL If an internal error occured in the nrf_crypt backend init.
  104. */
  105. ret_code_t nrf_crypto_uninit(void);
  106. /**@brief Function reporting if nrf_crypto has been initialized.
  107. *
  108. * @retval True If cryptographic library is initialized.
  109. * @retval False If cryptographic library is not initialized.
  110. */
  111. bool nrf_crypto_is_initialized(void);
  112. /**@brief Function reporting if nrf_crypto is initialized or is in the process of being initialized.
  113. *
  114. * @retval True If cryptographic library is initializing or already initialized.
  115. * @retval False If cryptographic library is not initialized.
  116. */
  117. bool nrf_crypto_is_initializing(void);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. /**@} */
  122. #endif // NRF_CRYPTO_INIT_H__