Skip to content

Commit

Permalink
Fixes for PUF ROT
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Feb 3, 2025
1 parent 7cf327f commit 39af424
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
31 changes: 21 additions & 10 deletions hal/zynq.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ void wc_Sha3_384_Free(wc_Sha3* sha)
#endif

/* CSU PUF */
#define PUF_REG_TIMEOUT 500000
#ifdef CSU_PUF_ROT
#define CSU_PUF_SYNDROME_WORDS 386
#ifndef CSU_PUF_REG_TIMEOUT
#define CSU_PUF_REG_TIMEOUT 500000
#endif
int csu_puf_register(uint32_t* syndrome, uint32_t* syndromeSz, uint32_t* chash,
uint32_t* aux)
{
Expand All @@ -299,16 +303,19 @@ int csu_puf_register(uint32_t* syndrome, uint32_t* syndromeSz, uint32_t* chash,
wolfBoot_printf("CSU Puf Register\n");
#endif

pmu_mmio_write(CSU_PUF_CFG0, CSU_PUF_CFG0_INIT);
pmu_mmio_write(CSU_PUF_CFG1, CSU_PUF_CFG1_INIT);
pmu_mmio_write(CSU_PUF_SHUTTER, CSU_PUF_SHUTTER_INIT);
pmu_mmio_write(CSU_PUF_CMD, CSU_PUF_CMD_REGISTRATION);
while (1) {
ret = pmu_mmio_write(CSU_PUF_CFG0, CSU_PUF_CFG0_INIT);
if (ret == 0)
ret = pmu_mmio_write(CSU_PUF_CFG1, CSU_PUF_CFG1_INIT);
if (ret == 0)
ret = pmu_mmio_write(CSU_PUF_SHUTTER, CSU_PUF_SHUTTER_INIT);
if (ret == 0)
ret = pmu_mmio_write(CSU_PUF_CMD, CSU_PUF_CMD_REGISTRATION);
while (ret == 0) {
/* Wait for PUF status done */
while (((puf_status = pmu_mmio_read(CSU_PUF_STATUS))
& CSU_PUF_STATUS_SYN_WRD_RDY_MASK) == 0
&& ++timeout < PUF_REG_TIMEOUT);
if (timeout == PUF_REG_TIMEOUT) {
&& ++timeout < CSU_PUF_REG_TIMEOUT);
if (timeout == CSU_PUF_REG_TIMEOUT) {
ret = -1; /* timeout */
break;
}
Expand Down Expand Up @@ -341,14 +348,16 @@ int csu_puf_register(uint32_t* syndrome, uint32_t* syndromeSz, uint32_t* chash,

return ret;
}
#endif /* CSU_PUF_ROT */

#define CSU_PUF_SYNDROME_WORDS 386
int csu_init(void)
{
int ret;
int ret = 0;
#ifdef CSU_PUF_ROT
uint32_t syndrome[CSU_PUF_SYNDROME_WORDS];
uint32_t syndromeSz = (uint32_t)sizeof(syndrome);
uint32_t chash=0, aux=0;
#endif
uint32_t reg1 = pmu_mmio_read(CSU_IDCODE);
uint32_t reg2 = pmu_mmio_read(CSU_VERSION);

Expand All @@ -371,7 +380,9 @@ int csu_init(void)
hal_delay_ms(500); /* give time for debugger to break */
#endif

#ifdef CSU_PUF_ROT
ret = csu_puf_register(syndrome, &syndromeSz, &chash, &aux);
#endif

return ret;
}
Expand Down
16 changes: 8 additions & 8 deletions hal/zynq.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,14 @@
#define CSU_PUF_CMD_REGISTRATION 0x1 /* Key registration */

#define CSU_PUF_CFG0_INIT 0x2
#define CSU_PUF_CFG1_INIT 0x0C230090 /* 0x00080080 */
#define CSU_PUF_SHUTTER_INIT 0x0100005E /* 0x01000100 */

#define CSU_PUF_STATUS_OVERFLOW_MASK 0x30000000 /* Overflow, if bits are not 0. Reduce SHUT[SOPEN] value. */
#define CSU_PUF_STATUS_AUX_MASK 0x0FFFFFF0 /* During provisioning, auxiliary sundrome bits are stored here and must be written to the eFuse or boot image. */
#define CSU_PUF_STATUS_KEY_RDY_MASK 0x00000008
#define CSU_PUF_STATUS_KEY_ZERO_MASK 0x00000002 /* Indicates that the PUF key has been zeroized */
#define CSU_PUF_STATUS_SYN_WRD_RDY_MASK 0x00000001 /* Indicates a syndrome word is ready in the PUF_WORD register. */
#define CSU_PUF_CFG1_INIT 0x0C230090U /* 4K */
#define CSU_PUF_SHUTTER_INIT 0x00100005E /* 0x01000100 */

#define CSU_PUF_STATUS_OVERFLOW_MASK (0x3U << 28) /* Overflow, if bits are not 0. Reduce SHUT[SOPEN] value. */
#define CSU_PUF_STATUS_AUX_MASK (0xFFFFFFU << 4) /* During provisioning, auxiliary sundrome bits are stored here and must be written to the eFuse or boot image. */
#define CSU_PUF_STATUS_KEY_RDY_MASK (0x1U << 3) /* Indicates that the key is ready */
#define CSU_PUF_STATUS_KEY_ZERO_MASK (0x1U << 1) /* Indicates that the PUF key has been zeroized */
#define CSU_PUF_STATUS_SYN_WRD_RDY_MASK (0x1U << 0) /* Indicates a syndrome word is ready in the PUF_WORD register */

/* SHA3 */
#define CSU_SHA_START (CSU_BASE + 0x2000U)
Expand Down

0 comments on commit 39af424

Please sign in to comment.