mirror of
https://github.com/espressif/openthread.git
synced 2026-09-07 17:50:09 +00:00
[crypto] PSA API: introduce platform API for crypto dynamic memory mgmt
This commit adds two new functions, `otPlatCryptoCAlloc` and `otPlatCryptoFree`, which provide dynamic memory management for the crypto subsystem. They are only enabled when `OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE` is set. Signed-off-by: Łukasz Duda <[email protected]>
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
#include <openthread/instance.h>
|
||||
#include <openthread/platform/crypto.h>
|
||||
#include <openthread/platform/entropy.h>
|
||||
#include <openthread/platform/memory.h>
|
||||
#include <openthread/platform/time.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
@@ -78,6 +79,11 @@ static constexpr uint16_t kEntropyMinThreshold = 16;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
OT_TOOL_WEAK void *otPlatCryptoCAlloc(size_t aNum, size_t aSize) { return otPlatCAlloc(aNum, aSize); }
|
||||
OT_TOOL_WEAK void otPlatCryptoFree(void *aPtr) { otPlatFree(aPtr); }
|
||||
#endif
|
||||
|
||||
// AES Implementation
|
||||
OT_TOOL_WEAK otError otPlatCryptoAesInit(otCryptoContext *aContext)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <openthread/instance.h>
|
||||
#include <openthread/platform/crypto.h>
|
||||
#include <openthread/platform/entropy.h>
|
||||
#include <openthread/platform/memory.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
@@ -200,6 +201,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
OT_TOOL_WEAK void *otPlatCryptoCAlloc(size_t aNum, size_t aSize) { return otPlatCAlloc(aNum, aSize); }
|
||||
OT_TOOL_WEAK void otPlatCryptoFree(void *aPtr) { otPlatFree(aPtr); }
|
||||
#endif
|
||||
|
||||
OT_TOOL_WEAK otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef,
|
||||
otCryptoKeyType aKeyType,
|
||||
otCryptoKeyAlgorithm aKeyAlgorithm,
|
||||
|
||||
@@ -57,9 +57,9 @@ MbedTls::MbedTls(void)
|
||||
// mbedTLS's debug level is almost the same as OpenThread's
|
||||
mbedtls_debug_set_threshold(OPENTHREAD_CONFIG_LOG_LEVEL);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
|
||||
#if OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
mbedtls_platform_set_calloc_free(Heap::CAlloc, Heap::Free);
|
||||
#endif // OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
|
||||
#endif // OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
}
|
||||
|
||||
Error MbedTls::MapError(int aMbedTlsError)
|
||||
|
||||
Reference in New Issue
Block a user