123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #ifndef NRF_CRYPTO_MEM_H__
- #define NRF_CRYPTO_MEM_H__
- #include <stdint.h>
- #include "sdk_common.h"
- #include "sdk_config.h"
- #include "nrf_crypto_types.h"
- #include "sdk_alloca.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #ifndef __SDK_DOXYGEN__
- #define NRF_CRYPTO_ALLOCATOR_DEFAULT 0
- #define NRF_CRYPTO_ALLOCATOR_USER 1
- #define NRF_CRYPTO_ALLOCATOR_ALLOCA 2
- #define NRF_CRYPTO_ALLOCATOR_MALLOC 3
- #define NRF_CRYPTO_ALLOCATOR_NRF_MALLOC 4
- #ifndef NRF_CRYPTO_ALLOCATOR
- #define NRF_CRYPTO_ALLOCATOR NRF_CRYPTO_ALLOCATOR_DEFAULT
- #endif
- #if NRF_CRYPTO_ALLOCATOR == NRF_CRYPTO_ALLOCATOR_DEFAULT
- #undef NRF_CRYPTO_ALLOCATOR
- #if SDK_ALLOCA_DEFINED && !NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_MBEDTLS)
- #define NRF_CRYPTO_ALLOCATOR NRF_CRYPTO_ALLOCATOR_ALLOCA
- #else
- #define NRF_CRYPTO_ALLOCATOR NRF_CRYPTO_ALLOCATOR_NRF_MALLOC
- #endif
- #endif
- #if NRF_CRYPTO_ALLOCATOR == NRF_CRYPTO_ALLOCATOR_USER
- #include "nrf_crypto_allocator.h"
- #ifndef NRF_CRYPTO_ALLOC
- #error "User defined allocator for nrf_crypto does not define NRF_CRYPTO_ALLOC"
- #endif
- #ifndef NRF_CRYPTO_FREE
- #error "User defined allocator for nrf_crypto does not define NRF_CRYPTO_FREE"
- #endif
- #ifndef NRF_CRYPTO_ALLOC_ON_STACK
- #error "User defined allocator for nrf_crypto does not define NRF_CRYPTO_ALLOC_ON_STACK"
- #endif
- #elif NRF_CRYPTO_ALLOCATOR == NRF_CRYPTO_ALLOCATOR_ALLOCA
- #if !SDK_ALLOCA_DEFINED
- #warning "Stack based allocation is selected, but alloca() is not supported on this platform"
- #endif
- #define NRF_CRYPTO_ALLOC(size) (alloca((size_t)(size)))
- #define NRF_CRYPTO_FREE(p_buffer)
- #define NRF_CRYPTO_ALLOC_ON_STACK 1
- #elif NRF_CRYPTO_ALLOCATOR == NRF_CRYPTO_ALLOCATOR_MALLOC
- #include "stdlib.h"
- #define NRF_CRYPTO_ALLOC(size) (malloc((size_t)(size)))
- #define NRF_CRYPTO_FREE(p_buffer) (free((void *)(p_buffer)))
- #define NRF_CRYPTO_ALLOC_ON_STACK 0
- #elif NRF_CRYPTO_ALLOCATOR == NRF_CRYPTO_ALLOCATOR_NRF_MALLOC
- #include "mem_manager.h"
- #define NRF_CRYPTO_ALLOC(size) (nrf_malloc((uint32_t)(size)))
- #define NRF_CRYPTO_FREE(p_buffer) (nrf_free((void *)(p_buffer)))
- #define NRF_CRYPTO_ALLOC_ON_STACK 0
- #else
- #error "Invalid NRF_CRYPTO_ALLOCATOR configuration value"
- #endif
- #else
- #define NRF_CRYPTO_ALLOC(size)
- #define NRF_CRYPTO_FREE(p_buffer)
- #define NRF_CRYPTO_ALLOC_ON_STACK
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|