mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 23:08:14 +00:00
fix hangs due to stale rng status (#195)
This commit is contained in:
parent
980bae6cb5
commit
1c55ec0fb3
@ -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 \
|
||||
|
@ -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) {
|
||||
|
2
rng.c
2
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;
|
||||
}
|
||||
}
|
||||
|
5
setup.c
5
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:
|
||||
|
Loading…
Reference in New Issue
Block a user