mirror of
https://github.com/espressif/openthread.git
synced 2026-07-31 16:17:47 +00:00
[nrf528xx] always enable NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT (#4210)
If all of COMMISSIONER/JOINER/TIME_SYNC switches are not enabled and CC310 is not disabled, RNG always produces the same values (even after issuing a reset). This is caused by mbed TLS library which by default uses 256 keys internally but CC310 AES module can handle only 128 bit keys. We can enable NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT options for all configurations to enable software implementation when keys longer than 128 bits are used.
This commit is contained in:
committed by
Jonathan Hui
parent
f29a2f1257
commit
f657451951
@@ -224,21 +224,6 @@
|
||||
#define OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
*
|
||||
* Define as 1 to enable AES usage in interrupt context and AES-256, by introducing a software AES under platform layer.
|
||||
*
|
||||
* @note This feature must be enabled to support AES-256 used by Commissioner and Joiner, and AES usage in interrupt
|
||||
* context used by Header IE related features.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE || OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
|
||||
#define NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT 1
|
||||
#else
|
||||
#define NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Suppress the ARMCC warning on unreachable statement,
|
||||
* e.g. break after assert(false) or ExitNow() macro.
|
||||
|
||||
+3
-21
@@ -51,23 +51,18 @@
|
||||
|
||||
#include "aes_alt_cc310.h"
|
||||
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
#include <nrf.h>
|
||||
#include "aes_alt_soft.h"
|
||||
#endif
|
||||
|
||||
void mbedtls_aes_init(mbedtls_aes_context * ctx)
|
||||
{
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
uint32_t active_vector_id = (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) >> SCB_ICSR_VECTACTIVE_Pos;
|
||||
|
||||
// Check if this function is called from main thread.
|
||||
if (active_vector_id == 0)
|
||||
{
|
||||
aes_soft_init(ctx);
|
||||
#endif
|
||||
aes_cc310_init(ctx);
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
ctx->using_cc310 = true;
|
||||
}
|
||||
else
|
||||
@@ -75,24 +70,19 @@ void mbedtls_aes_init(mbedtls_aes_context * ctx)
|
||||
aes_soft_init(ctx);
|
||||
ctx->using_cc310 = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void mbedtls_aes_free(mbedtls_aes_context * ctx)
|
||||
{
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
if (ctx->using_cc310)
|
||||
{
|
||||
#endif
|
||||
aes_cc310_free(ctx);
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
aes_soft_free(ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
aes_soft_free(ctx);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int mbedtls_aes_setkey_enc(mbedtls_aes_context * ctx,
|
||||
@@ -101,19 +91,15 @@ int mbedtls_aes_setkey_enc(mbedtls_aes_context * ctx,
|
||||
{
|
||||
int result;
|
||||
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
if (ctx->using_cc310 && keybits == 128)
|
||||
{
|
||||
#endif
|
||||
{
|
||||
result = aes_cc310_setkey_enc(ctx, key, keybits);
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
}
|
||||
else
|
||||
{
|
||||
ctx->using_cc310 = false;
|
||||
result = aes_soft_setkey_enc(ctx, key, keybits);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -132,18 +118,14 @@ int mbedtls_aes_crypt_ecb(mbedtls_aes_context * ctx,
|
||||
{
|
||||
int result;
|
||||
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
if (ctx->using_cc310)
|
||||
{
|
||||
#endif
|
||||
result = aes_cc310_crypt_ecb(ctx, mode, input, output);
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
}
|
||||
else
|
||||
{
|
||||
result = aes_soft_crypt_ecb(ctx, mode, input, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+12
-22
@@ -71,30 +71,20 @@ extern "C" {
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
bool using_cc310; ///< Indicate whether it's using cc310 or not.
|
||||
#endif
|
||||
|
||||
#if !NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
union
|
||||
struct
|
||||
{
|
||||
#endif // !NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
struct
|
||||
{
|
||||
SaSiAesUserContext_t user_context; ///< User context for CC310 AES.
|
||||
uint8_t key_buffer[32]; ///< Buffer for an encryption key.
|
||||
SaSiAesUserKeyData_t key; ///< CC310 AES key structure.
|
||||
SaSiAesEncryptMode_t mode; ///< Current context operation mode (encrypt/decrypt).
|
||||
} hardware;
|
||||
struct
|
||||
{
|
||||
int nr; ///< number of rounds */
|
||||
uint32_t *rk; ///< AES round keys */
|
||||
uint32_t buf[68]; ///< unaligned data */
|
||||
} software;
|
||||
#if !NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
};
|
||||
#endif // !NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
SaSiAesUserContext_t user_context; ///< User context for CC310 AES.
|
||||
uint8_t key_buffer[32]; ///< Buffer for an encryption key.
|
||||
SaSiAesUserKeyData_t key; ///< CC310 AES key structure.
|
||||
SaSiAesEncryptMode_t mode; ///< Current context operation mode (encrypt/decrypt).
|
||||
} hardware;
|
||||
struct
|
||||
{
|
||||
int nr; ///< number of rounds */
|
||||
uint32_t *rk; ///< AES round keys */
|
||||
uint32_t buf[68]; ///< unaligned data */
|
||||
} software;
|
||||
}
|
||||
mbedtls_aes_context;
|
||||
|
||||
|
||||
@@ -50,8 +50,6 @@
|
||||
|
||||
#ifdef MBEDTLS_AES_ALT
|
||||
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
@@ -399,6 +397,4 @@ int aes_soft_crypt_ecb( mbedtls_aes_context *ctx,
|
||||
return aes_encrypt( ctx, input, output );
|
||||
}
|
||||
|
||||
#endif /* NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT */
|
||||
|
||||
#endif /* MBEDTLS_AES_ALT */
|
||||
|
||||
@@ -52,8 +52,6 @@
|
||||
|
||||
#ifdef MBEDTLS_AES_ALT
|
||||
|
||||
#if NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
|
||||
#include "aes_alt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -106,8 +104,6 @@ int aes_soft_crypt_ecb(mbedtls_aes_context * ctx,
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT */
|
||||
|
||||
#endif /* MBEDTLS_AES_ALT */
|
||||
|
||||
#endif /* AES_ALT_SOFT_H */
|
||||
|
||||
@@ -51,19 +51,4 @@
|
||||
_Pragma("diag_suppress=68")
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT
|
||||
*
|
||||
* Define as 1 to enable AES usage in interrupt context and AES-256, by introducing a software AES under platform layer.
|
||||
*
|
||||
* @note This feature must be enabled to support AES-256 used by Commissioner and Joiner, and AES usage in interrupt context
|
||||
* used by Header IE related features.
|
||||
*
|
||||
*/
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE || OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
|
||||
#define NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT 1
|
||||
#else
|
||||
#define NRF_MBEDTLS_AES_ALT_INTERRUPT_CONTEXT 0
|
||||
#endif
|
||||
|
||||
#endif // NRF52840_MBEDTLS_CONFIG_H_
|
||||
|
||||
Reference in New Issue
Block a user