File tree Expand file tree Collapse file tree 6 files changed +42
-5
lines changed
Expand file tree Collapse file tree 6 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ extern "C" {
5252 *
5353 * @note This number versions both OpenThread platform and user APIs.
5454 */
55- #define OPENTHREAD_API_VERSION (570 )
55+ #define OPENTHREAD_API_VERSION (571 )
5656
5757/**
5858 * @addtogroup api-instance
Original file line number Diff line number Diff line change @@ -288,6 +288,33 @@ otError otPlatCryptoDestroyKey(otCryptoKeyRef aKeyRef);
288288 */
289289bool otPlatCryptoHasKey (otCryptoKeyRef aKeyRef );
290290
291+ /**
292+ * Dynamically allocates new memory for Crypto subsystem. On platforms that support it, should just redirect to calloc.
293+ * For those that don't support calloc, should support the same functionality:
294+ *
295+ * "The calloc() function contiguously allocates enough space for count objects that are size bytes of
296+ * memory each and returns a pointer to the allocated memory. The allocated memory is filled with bytes
297+ * of value zero."
298+ *
299+ * Is required for OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE.
300+ *
301+ * @param[in] aNum The number of blocks to allocate
302+ * @param[in] aSize The size of each block to allocate
303+ *
304+ * @retval void* The pointer to the front of the memory allocated
305+ * @retval NULL Failed to allocate the memory requested.
306+ */
307+ void * otPlatCryptoCAlloc (size_t aNum , size_t aSize );
308+
309+ /**
310+ * Frees memory that was dynamically allocated by otPlatCryptoCAlloc.
311+ *
312+ * Is required for OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE.
313+ *
314+ * @param[in] aPtr A pointer the memory blocks to free. The pointer may be NULL.
315+ */
316+ void otPlatCryptoFree (void * aPtr );
317+
291318/**
292319 * Initialize the HMAC operation.
293320 *
Original file line number Diff line number Diff line change 4747#include < openthread/instance.h>
4848#include < openthread/platform/crypto.h>
4949#include < openthread/platform/entropy.h>
50+ #include < openthread/platform/memory.h>
5051#include < openthread/platform/time.h>
5152
5253#include " common/code_utils.hpp"
@@ -78,6 +79,11 @@ static constexpr uint16_t kEntropyMinThreshold = 16;
7879#endif
7980#endif
8081
82+ #if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
83+ OT_TOOL_WEAK void *otPlatCryptoCAlloc (size_t aNum, size_t aSize) { return otPlatCAlloc (aNum, aSize); }
84+ OT_TOOL_WEAK void otPlatCryptoFree (void *aPtr) { otPlatFree (aPtr); }
85+ #endif
86+
8187OT_TOOL_WEAK void otPlatCryptoInit (void )
8288{
8389 // Intentionally empty.
Original file line number Diff line number Diff line change @@ -57,9 +57,9 @@ MbedTls::MbedTls(void)
5757 // mbedTLS's debug level is almost the same as OpenThread's
5858 mbedtls_debug_set_threshold (OPENTHREAD_CONFIG_LOG_LEVEL);
5959#endif
60- #if OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
60+ #if OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
6161 mbedtls_platform_set_calloc_free (Heap::CAlloc, Heap::Free);
62- #endif // OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
62+ #endif // OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
6363}
6464
6565Error MbedTls::MapError (int aMbedTlsError)
Original file line number Diff line number Diff line change @@ -106,6 +106,10 @@ extern "C" {
106106OT_TOOL_WEAK void *otPlatCAlloc (size_t aNum, size_t aSize) { return calloc (aNum, aSize); }
107107
108108OT_TOOL_WEAK void otPlatFree (void *aPtr) { free (aPtr); }
109+
110+ OT_TOOL_WEAK void *otPlatCryptoCAlloc (size_t aNum, size_t aSize) { return calloc (aNum, aSize); }
111+
112+ OT_TOOL_WEAK void otPlatCryptoFree (void *aPtr) { free (aPtr); }
109113#endif
110114
111115OT_TOOL_WEAK void otTaskletsSignalPending (otInstance *) {}
Original file line number Diff line number Diff line change 134134#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */
135135
136136#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
137- #define MBEDTLS_PLATFORM_STD_CALLOC otPlatCAlloc /**< Default allocator to use, can be undefined */
138- #define MBEDTLS_PLATFORM_STD_FREE otPlatFree /**< Default free to use, can be undefined */
137+ #define MBEDTLS_PLATFORM_STD_CALLOC otPlatCryptoCAlloc /**< Default allocator to use, can be undefined */
138+ #define MBEDTLS_PLATFORM_STD_FREE otPlatCryptoFree /**< Default free to use, can be undefined */
139139#else
140140#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
141141#endif
You can’t perform that action at this time.
0 commit comments