mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +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
|
CFLAGS += -DMEMORY_PROTECT=1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(DEBUG_RNG), 1)
|
||||||
|
CFLAGS += -DDEBUG_RNG=1
|
||||||
|
else
|
||||||
|
CFLAGS += -DDEBUG_RNG=0
|
||||||
|
endif
|
||||||
|
|
||||||
LDFLAGS += --static \
|
LDFLAGS += --static \
|
||||||
-Wl,--start-group \
|
-Wl,--start-group \
|
||||||
-lc \
|
-lc \
|
||||||
|
@ -330,12 +330,14 @@ void fsm_msgWipeDevice(WipeDevice *msg)
|
|||||||
|
|
||||||
void fsm_msgGetEntropy(GetEntropy *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);
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, _("Do you really want to"), _("send entropy?"), NULL, NULL, NULL, NULL);
|
||||||
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
|
if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) {
|
||||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||||
layoutHome();
|
layoutHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
RESP_INIT(Entropy);
|
RESP_INIT(Entropy);
|
||||||
uint32_t len = msg->size;
|
uint32_t len = msg->size;
|
||||||
if (len > 1024) {
|
if (len > 1024) {
|
||||||
|
2
rng.c
2
rng.c
@ -27,7 +27,7 @@ uint32_t random32(void)
|
|||||||
{
|
{
|
||||||
static uint32_t last = 0, new = 0;
|
static uint32_t last = 0, new = 0;
|
||||||
while (new == last) {
|
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;
|
new = RNG_DR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
setup.c
5
setup.c
@ -42,7 +42,7 @@ void setup(void)
|
|||||||
|
|
||||||
// enable RNG
|
// enable RNG
|
||||||
rcc_periph_clock_enable(RCC_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
|
// 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
|
// we don't use the first random number generated after setting the RNGEN bit in setup
|
||||||
random32();
|
random32();
|
||||||
@ -73,6 +73,9 @@ void setup(void)
|
|||||||
|
|
||||||
void setupApp(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.
|
// 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.
|
// 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:
|
// this is to try to comply with STM32F205xx Reference manual - Section 20.3.1:
|
||||||
|
Loading…
Reference in New Issue
Block a user