diff --git a/Makefile.include b/Makefile.include index 773be5037..8fba93094 100644 --- a/Makefile.include +++ b/Makefile.include @@ -65,6 +65,12 @@ else CFLAGS += -DMEMORY_PROTECT=1 endif +ifeq ($(DEBUG_RNG), 1) +CFLAGS += -DDEBUG_RNG=1 +else +CFLAGS += -DDEBUG_RNG=0 +endif + LDFLAGS += --static \ -Wl,--start-group \ -lc \ diff --git a/firmware/fsm.c b/firmware/fsm.c index 85c077bba..dfcef8bad 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -330,12 +330,14 @@ void fsm_msgWipeDevice(WipeDevice *msg) void fsm_msgGetEntropy(GetEntropy *msg) { +#if !DEBUG_RNG layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you really want to"), _("send entropy?"), NULL, NULL, NULL, NULL); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } +#endif RESP_INIT(Entropy); uint32_t len = msg->size; if (len > 1024) { diff --git a/rng.c b/rng.c index 39aea9771..f9aaf5dee 100644 --- a/rng.c +++ b/rng.c @@ -27,7 +27,7 @@ uint32_t random32(void) { static uint32_t last = 0, new = 0; while (new == last) { - if (((RNG_SR & (RNG_SR_SEIS | RNG_SR_CEIS)) == 0) && ((RNG_SR & RNG_SR_DRDY) > 0)) { + if ((RNG_SR & (RNG_SR_SECS | RNG_SR_CECS | RNG_SR_DRDY)) == RNG_SR_DRDY) { new = RNG_DR; } } diff --git a/setup.c b/setup.c index 2537a0143..0795a9b96 100644 --- a/setup.c +++ b/setup.c @@ -42,7 +42,7 @@ void setup(void) // enable RNG rcc_periph_clock_enable(RCC_RNG); - RNG_CR |= RNG_CR_IE | RNG_CR_RNGEN; + RNG_CR |= RNG_CR_RNGEN; // to be extra careful and heed the STM32F205xx Reference manual, Section 20.3.1 // we don't use the first random number generated after setting the RNGEN bit in setup random32(); @@ -73,6 +73,9 @@ void setup(void) void setupApp(void) { + // for completeness, disable RNG peripheral interrupts for old bootloaders that had + // enabled them in RNG control register (the RNG interrupt was never enabled in the NVIC) + RNG_CR &= ~RNG_CR_IE; // the static variables in random32 are separate between the bootloader and firmware. // therefore, they need to be initialized here so that we can be sure to avoid dupes. // this is to try to comply with STM32F205xx Reference manual - Section 20.3.1: