Skip to content

Commit cf74a0c

Browse files
degjorvacarlescufi
authored andcommitted
nrf_security: CRACEN: Add workaround for trng on CRACEN lite
CRACEN lite has the wrong configuration for TRNG. Add workaround to set these directly during startup of TRNG This might be possible to remove in the future Signed-off-by: Dag Erik Gjørvad <[email protected]>
1 parent 06c894a commit cf74a0c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src/ba431regs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#define BA431_REG_Key3_OFST (0x1Cu)
3030
/** TestData: Test data register. */
3131
#define BA431_REG_TestData_OFST (0x20u)
32+
/** RepeatThreshold: Repetition test cut-off register. */
33+
#define BA431_REG_REPEATTHRESHOLD (0x24u)
34+
/** PropThreshold: Proportion test cut-off. */
35+
#define BA431_REG_PROPTHRESHOLD (0x28u)
3236
/** Status: Status register. */
3337
#define BA431_REG_Status_OFST (0x30u)
3438
/** InitWaitVal: Initial wait counter value. */

subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src/trng.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
BA431_FLD_Control_HealthTestBypass_MASK | \
2828
BA431_FLD_Control_Conditioning_Bypass_MASK)
2929

30+
#if defined(CONFIG_CRACEN_HW_VERSION_LITE)
31+
#define RNG_REPEATTHRESHOLD_VAL (21)
32+
#define RNG_PROPTESTCUTOFF_VAL (311)
33+
#endif
34+
3035
static int ba431_check_state(void)
3136
{
3237
uint32_t state = sx_rd_trng(BA431_REG_Status_OFST);
@@ -115,6 +120,13 @@ int sx_trng_open(struct sx_trng *ctx, const struct sx_trng_config *config)
115120
sx_wr_trng(BA431_REG_ClkDiv_OFST, rng_clkdiv);
116121
sx_wr_trng(BA431_REG_InitWaitVal_OFST, rng_init_wait_val);
117122

123+
/* CRACEN Lite has incorrect values for the TRNG tests. We update these here as a workaround
124+
*/
125+
#if defined(CONFIG_CRACEN_HW_VERSION_LITE)
126+
sx_wr_trng(BA431_REG_REPEATTHRESHOLD, RNG_REPEATTHRESHOLD_VAL);
127+
sx_wr_trng(BA431_REG_PROPTHRESHOLD, RNG_PROPTESTCUTOFF_VAL);
128+
#endif /* CONFIG_CRACEN_HW_VERSION_LITE */
129+
118130
/* Configure the control register and set the enable bit */
119131
control = (RNG_NB_128BIT_BLOCKS << BA431_FLD_Control_Nb128BitBlocks_LSB);
120132
control |= ctrlbitmask;

0 commit comments

Comments
 (0)