1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-28 16:21:03 +00:00

Add function storage_getPinWait

This commit is contained in:
Jochen Hoenicke 2018-03-22 20:12:01 +01:00 committed by Pavol Rusnak
parent c09590b54d
commit 0127c1a374
3 changed files with 10 additions and 2 deletions

View File

@ -161,7 +161,7 @@ bool protectPin(bool use_cached)
return true;
}
uint32_t fails = storage_getPinFailsOffset();
uint32_t wait = ~*(const uint32_t*)FLASH_PTR(fails);
uint32_t wait = storage_getPinWait(fails);
protectCheckMaxTry(wait);
usbTiny(1);
while (wait > 0) {
@ -206,7 +206,7 @@ bool protectPin(bool use_cached)
storage_resetPinFails(fails);
return true;
} else {
protectCheckMaxTry(~*(const uint32_t*)FLASH_PTR(fails));
protectCheckMaxTry(storage_getPinWait(fails));
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
return false;
}

View File

@ -797,6 +797,13 @@ bool storage_increasePinFails(uint32_t flash_pinfails)
return *(const uint32_t*)FLASH_PTR(flash_pinfails) == newctr;
}
uint32_t storage_getPinWait(uint32_t flash_pinfails)
{
// The pin failure word is the inverted wait time in seconds.
// It's inverted because flash allows changing 1 to 0 but not vice versa.
return ~*(const uint32_t*)FLASH_PTR(flash_pinfails);
}
uint32_t storage_getPinFailsOffset(void)
{
uint32_t flash_pinfails = FLASH_STORAGE_PINAREA;

View File

@ -124,6 +124,7 @@ bool session_isPinCached(void);
void storage_clearPinArea(void);
void storage_resetPinFails(uint32_t flash_pinfails);
bool storage_increasePinFails(uint32_t flash_pinfails);
uint32_t storage_getPinWait(uint32_t flash_pinfails);
uint32_t storage_getPinFailsOffset(void);
uint32_t storage_nextU2FCounter(void);