Skip to content

Commit 13cdec8

Browse files
Damian-Nordicnordicjm
authored andcommittedMar 11, 2025
modules: openthread: platform: optimize stack usage in crypto_psa
A PSA crypto operation object can be initialized in multiple ways according to the documentation. For example, 1. Using a dedicated psa_xxx_operation_init() function that returns an initialized object. 2. Using memset() to zero out the operation object. For some PSA crypto driver implementations, using the first method causes an excessive stack usage if the operation object is large and psa_xxx_operation_init() is not inlined. Instead, it is better to stick to memset() for this purpose. Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎modules/openthread/platform/crypto_psa.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <mbedtls/asn1.h>
2020
#endif
2121

22+
#include <string.h>
23+
2224
static otError psaToOtError(psa_status_t aStatus)
2325
{
2426
switch (aStatus) {
@@ -226,7 +228,7 @@ otError otPlatCryptoHmacSha256Init(otCryptoContext *aContext)
226228
}
227229

228230
operation = aContext->mContext;
229-
*operation = psa_mac_operation_init();
231+
memset(operation, 0, sizeof(*operation));
230232

231233
return OT_ERROR_NONE;
232234
}
@@ -347,7 +349,7 @@ otError otPlatCryptoSha256Init(otCryptoContext *aContext)
347349
}
348350

349351
operation = aContext->mContext;
350-
*operation = psa_hash_operation_init();
352+
memset(operation, 0, sizeof(*operation));
351353

352354
return OT_ERROR_NONE;
353355
}

0 commit comments

Comments
 (0)
Please sign in to comment.