Skip to content

Commit 8f1623f

Browse files
committed
[M2351] Add consistency check for CRYPTO/CRPT's secure attribute and TRNG/Mbed TLS H/W
1 parent 2854b57 commit 8f1623f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/crypto/crypto-misc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "nu_bitutil.h"
2525
#include "crypto-misc.h"
2626

27+
#if DEVICE_TRNG || defined(MBEDTLS_CONFIG_HW_SUPPORT)
28+
2729
/* NOTE: There's inconsistency in cryptography related naming, Crpt or Crypto. For example, cryptography IRQ
2830
* handler could be CRPT_IRQHandler or CRYPTO_IRQHandler. To override default cryptography IRQ handler, see
2931
* device/startup_{CHIP}.c for its name or call NVIC_SetVector regardless of its name. */
@@ -327,3 +329,5 @@ void CRPT_IRQHandler()
327329
ECC_CLR_INT_FLAG(CRYPTO_MODBASE());
328330
}
329331
}
332+
333+
#endif /* #if DEVICE_TRNG || defined(MBEDTLS_CONFIG_HW_SUPPORT) */

targets/TARGET_NUVOTON/TARGET_M2351/crypto/crypto-misc.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@
2020
#include <stdbool.h>
2121
#include "partition_M2351.h"
2222

23+
/* Policy for configuring secure attribute of CRYPTO/CRPT module:
24+
*
25+
* There's only one CRYPTO/CRPT module and we have the following policy for configuring its secure attribute:
26+
*
27+
* 1. TRNG or mbedtls H/W support can be enabled on either secure target or non-secure target, but not both.
28+
* 2. TRNG and mbedtls H/W supports cannot be enabled on different targets.
29+
* 3. On secure target, if TRNG or mbedtls H/W support is enabled, CRYPTO/CRPT must configure to secure.
30+
* 4. On non-secure target, if TRNG or mbedtls H/W support is enabled, CRYPTO/CRPT must configure to non-secure.
31+
*/
32+
#if DEVICE_TRNG || defined(MBEDTLS_CONFIG_HW_SUPPORT)
33+
#if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
34+
#if defined(SCU_INIT_PNSSET1_VAL) && (SCU_INIT_PNSSET1_VAL & (1 << 18))
35+
#error("CRYPTO/CRPT must configure to secure for secure target which supports TRNG or mbedtls H/W")
36+
#endif
37+
#else
38+
#if (! defined(SCU_INIT_PNSSET1_VAL)) || (! (SCU_INIT_PNSSET1_VAL & (1 << 18)))
39+
#error("CRYPTO/CRPT must configure to non-secure for non-secure target which supports TRNG or mbedtls H/W")
40+
#endif
41+
#endif
42+
#endif
43+
44+
#if DEVICE_TRNG || defined(MBEDTLS_CONFIG_HW_SUPPORT)
45+
2346
#ifdef __cplusplus
2447
extern "C" {
2548
#endif
@@ -102,4 +125,6 @@ bool crypto_dma_buffs_overlap(const void *in_buff, size_t in_buff_size, const vo
102125
}
103126
#endif
104127

128+
#endif /* #if DEVICE_TRNG || defined(MBEDTLS_CONFIG_HW_SUPPORT) */
129+
105130
#endif

0 commit comments

Comments
 (0)