123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #include "sdk_common.h"
- #if NRF_MODULE_ENABLED(NRF_CRYPTO)
- #include "nrf_crypto_init.h"
- #include "nrf_section.h"
- NRF_SECTION_DEF(crypto_data, const nrf_crypto_backend_info_t);
- #define NRF_CRYPTO_BACKEND_SECTION_ITEM_GET(i) NRF_SECTION_ITEM_GET(crypto_data, nrf_crypto_backend_info_t, (i))
- #define NRF_CRYPTO_BACKEND_SECTION_ITEM_COUNT NRF_SECTION_ITEM_COUNT(crypto_data, nrf_crypto_backend_info_t)
- typedef enum
- {
- UNINITIALIZED,
- INITIALIZING,
- INITIALIZED,
- } nrf_crypto_state_t;
- static volatile nrf_crypto_state_t m_state = UNINITIALIZED;
- ret_code_t nrf_crypto_init(void)
- {
- ret_code_t ret_val;
- size_t const num_backends = NRF_CRYPTO_BACKEND_SECTION_ITEM_COUNT;
- m_state = INITIALIZING;
-
- for (size_t i = 0; i < num_backends; i++)
- {
- nrf_crypto_backend_info_t const * p_backend = NRF_CRYPTO_BACKEND_SECTION_ITEM_GET(i);
- ret_val = p_backend->init_fn();
- if (ret_val != NRF_SUCCESS)
- {
- return ret_val;
- }
- }
-
- m_state = INITIALIZED;
- return NRF_SUCCESS;
- }
- ret_code_t nrf_crypto_uninit(void)
- {
- ret_code_t ret_val;
- size_t const num_backends = NRF_CRYPTO_BACKEND_SECTION_ITEM_COUNT;
-
- for (size_t i = 0; i < num_backends; i++)
- {
- nrf_crypto_backend_info_t const * p_backend = NRF_CRYPTO_BACKEND_SECTION_ITEM_GET(i);
- ret_val = p_backend->uninit_fn();
- if (ret_val != NRF_SUCCESS)
- {
- return ret_val;
- }
- }
-
- m_state = UNINITIALIZED;
- return NRF_SUCCESS;
- }
- bool nrf_crypto_is_initialized(void)
- {
- return (m_state == INITIALIZED);
- }
- bool nrf_crypto_is_initializing(void)
- {
- return ((m_state == INITIALIZED) || m_state == INITIALIZING);
- }
- #endif
|