Skip to content

Commit

Permalink
address @gebart's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterKietzmann committed Jul 3, 2018
1 parent fb99050 commit fb3b6f3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
4 changes: 3 additions & 1 deletion cpu/cc2538/vectors.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
extern uint32_t _srelocate;

void pre_startup(void) {
puf_sram_uint32((uint8_t *)&_srelocate);
if (!puf_sram_softreset()) {
puf_sram_generate((uint8_t *)&_srelocate, SEED_RAM_LEN);
}
}
#endif

Expand Down
5 changes: 1 addition & 4 deletions cpu/samd21/vectors.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@
/* SRAM memory marker defined in the linker script */
extern uint32_t _srelocate;

/* stack of the idle thread defined in kernel initialization */
extern char idle_stack[];

void pre_startup(void) {
/* only generate a new seed when no software (or button) reset was detected */
if (!puf_sram_softreset()) {
puf_sram_uint32((uint8_t *)&_srelocate);
puf_sram_generate((uint8_t *)&_srelocate, SEED_RAM_LEN);
}
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion cpu/stm32f4/vectors.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
extern uint32_t _srelocate;

void pre_startup(void) {
puf_sram_uint32((uint8_t *)&_srelocate);
if (!puf_sram_softreset()) {
puf_sram_generate((uint8_t *)&_srelocate, SEED_RAM_LEN);
}
}
#endif

Expand Down
1 change: 1 addition & 0 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ ifneq (native,$(BOARD))
endif

ifneq (,$(filter puf_sram,$(USEMODULE)))
# allocate space for 3 x 32 Bit integers: seed, state, marker
export PUF_SRAM_LEN ?= 12
export LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_puf_sram_len=$(PUF_SRAM_LEN)
endif
13 changes: 9 additions & 4 deletions sys/include/puf_sram.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,30 @@ extern uint32_t puf_sram_seed;

/**
* @brief Global seed state, allocated on the stack in puf_sram.c
* 0 means seed was generated from SRAM pattern,
1 means missing power cycle detected,
2 means power cycle detected. The state will most likely
be overwritten with 0 in the next steps
*/
extern uint32_t puf_sram_state;

/**
* @brief builds hash from @p SEED_RAM_LEN bytes uninitialized SRAM, writs it
* @brief builds hash from @p SEED_RAM_LEN bytes uninitialized SRAM, writes it
* to the global variable @p puf_sram_seed and returns the value
*
* @param[in] ram pointer to SRAM memory
* @param[in] len length of the memroy to consider
*
* @return a random number
*/
uint32_t puf_sram_uint32(const uint8_t *ram);
uint32_t puf_sram_generate(const uint8_t *ram, size_t len);

/**
* @brief checks for a memory marker determine whether memory contains old data.
Otherwise it assumes a reboot from power down mode
*
* @return 0 when preceding power down phase is expected
* @return 1 when reset without power down was detected
* @return 0 when reset with power cycle was detected
* @return 1 when reset without power cycle was detected
*/
bool puf_sram_softreset(void);

Expand Down
11 changes: 5 additions & 6 deletions sys/puf_sram/puf_sram.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ __attribute__((used,section(".puf_stack"))) uint32_t puf_sram_state;
/* Allocation of the memory marker */
__attribute__((used,section(".puf_stack"))) uint32_t puf_sram_marker;

uint32_t puf_sram_uint32(const uint8_t *ram)
uint32_t puf_sram_generate(const uint8_t *ram, size_t len)
{
/* seting state to 0 means seed was generated from
* SRAM pattern*/
puf_sram_seed = dek_hash(ram, SEED_RAM_LEN);
/* build hash from start-up pattern */
puf_sram_seed = dek_hash(ram, len);
/* write marker to a defined section for subsequent reset detection */
puf_sram_marker = PUF_SRAM_MARKER;
/* seting state to 0 means seed was generated from SRAM pattern */
puf_sram_state = 0;
return puf_sram_seed;
}

#ifndef HAVE_REBOOT_DETECTION
bool puf_sram_softreset(void)
{
if(puf_sram_marker != PUF_SRAM_MARKER){
Expand All @@ -47,4 +47,3 @@ bool puf_sram_softreset(void)
puf_sram_state = 1;
return 1;
}
#endif

0 comments on commit fb3b6f3

Please sign in to comment.