123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include "sdk_common.h"
- #include "sdk_config.h"
- #if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS)
- #include <string.h>
- #include <stdint.h>
- #include "nrf_crypto_init.h"
- #include "nrf_crypto_mem.h"
- #include "mbedtls/platform.h"
- #if NRF_CRYPTO_ALLOC_ON_STACK
- #error "MBED TLS backend does not support memory allocation on stack. Use different allocator."
- #endif
- static void * mbedtls_backend_calloc(size_t count, size_t size)
- {
- size_t total_size = count * size;
- void * p_data = NRF_CRYPTO_ALLOC(total_size);
- if (p_data != NULL)
- {
- memset(p_data, 0, total_size);
- }
- return p_data;
- }
- static void mbedtls_backend_free(void * p_data)
- {
- NRF_CRYPTO_FREE(p_data);
- }
- static ret_code_t mbedtls_backend_init(void)
- {
- (void)mbedtls_platform_set_calloc_free(mbedtls_backend_calloc, mbedtls_backend_free);
- return NRF_SUCCESS;
- }
- static ret_code_t mbedtls_backend_uninit(void)
- {
-
- return NRF_SUCCESS;
- }
- CRYPTO_BACKEND_REGISTER(nrf_crypto_backend_info_t const mbedtls_backend) =
- {
- .init_fn = mbedtls_backend_init,
- .uninit_fn = mbedtls_backend_uninit,
- };
- #endif
|