Skip to content

Commit fefd9d9

Browse files
[crypto] update mbedtls psa crypto context structs.
1 parent 76c12d9 commit fefd9d9

9 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/core/config/platform.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@
177177
#define OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE 0
178178
#endif
179179

180+
/**
181+
* @def OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
182+
*
183+
* Define to 1 to enable platform allocation of crypto contexts.
184+
*/
185+
#ifndef OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
186+
#define OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS 0
187+
#endif
188+
180189
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT
181190
#if (!defined(OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE) || \
182191
!defined(OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN) || \

src/core/crypto/aes_ecb.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ namespace Crypto {
4040

4141
AesEcb::AesEcb(void)
4242
{
43+
#if OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
44+
mContext.mContext = nullptr;
45+
mContext.mContextSize = 0;
46+
#else
4347
mContext.mContext = mContextStorage;
4448
mContext.mContextSize = sizeof(mContextStorage);
49+
#endif
4550
SuccessOrAssert(otPlatCryptoAesInit(&mContext));
4651
}
4752

src/core/crypto/aes_ecb.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ class AesEcb
8686

8787
private:
8888
otCryptoContext mContext;
89+
#if !OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
8990
OT_DEFINE_ALIGNED_VAR(mContextStorage, kAesContextSize, uint64_t);
91+
#endif
9092
};
9193

9294
/**

src/core/crypto/hkdf_sha256.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ namespace Crypto {
4444

4545
HkdfSha256::HkdfSha256(void)
4646
{
47+
#if OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
48+
mContext.mContext = nullptr;
49+
mContext.mContextSize = 0;
50+
#else
4751
mContext.mContext = mContextStorage;
4852
mContext.mContextSize = sizeof(mContextStorage);
53+
#endif
4954
SuccessOrAssert(otPlatCryptoHkdfInit(&mContext));
5055
}
5156

src/core/crypto/hkdf_sha256.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ class HkdfSha256
9494

9595
private:
9696
otCryptoContext mContext;
97+
#if !OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
9798
OT_DEFINE_ALIGNED_VAR(mContextStorage, kHkdfContextSize, uint64_t);
99+
#endif
98100
};
99101

100102
/**

src/core/crypto/hmac_sha256.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ namespace Crypto {
4141

4242
HmacSha256::HmacSha256(void)
4343
{
44+
#if OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
45+
mContext.mContext = nullptr;
46+
mContext.mContextSize = 0;
47+
#else
4448
mContext.mContext = mContextStorage;
4549
mContext.mContextSize = sizeof(mContextStorage);
50+
#endif
4651

4752
SuccessOrAssert(otPlatCryptoHmacSha256Init(&mContext));
4853
}

src/core/crypto/hmac_sha256.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ class HmacSha256
124124

125125
private:
126126
otCryptoContext mContext;
127+
#if !OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
127128
OT_DEFINE_ALIGNED_VAR(mContextStorage, kHmacSha256ContextSize, uint64_t);
129+
#endif
128130
};
129131

130132
/**

src/core/crypto/sha256.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ namespace Crypto {
4242

4343
Sha256::Sha256(void)
4444
{
45+
#if OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
46+
mContext.mContext = nullptr;
47+
mContext.mContextSize = 0;
48+
#else
4549
mContext.mContext = mContextStorage;
4650
mContext.mContextSize = sizeof(mContextStorage);
51+
#endif
52+
4753
SuccessOrAssert(otPlatCryptoSha256Init(&mContext));
4854
}
4955

src/core/crypto/sha256.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ class Sha256
136136

137137
private:
138138
otCryptoContext mContext;
139+
#if !OPENTHREAD_CONFIG_PLATFORM_ALLOCS_CRYPTO_CONTEXTS
139140
OT_DEFINE_ALIGNED_VAR(mContextStorage, kSha256ContextSize, uint64_t);
141+
#endif
140142
};
141143

142144
/**

0 commit comments

Comments
 (0)