From 0e48a1a39a481b67463ab3233f683f24787d2e7d Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Tue, 12 Feb 2019 15:46:28 +0100 Subject: [PATCH] Fix spaces/tabs so that a single convention is used in each file. --- emulator/timer.c | 2 +- firmware/layout2.c | 14 ++-- firmware/protect.c | 170 ++++++++++++++++++++++---------------------- firmware/recovery.c | 12 ++-- firmware/reset.c | 54 +++++++------- firmware/trezor.c | 4 +- flash.c | 40 +++++------ 7 files changed, 148 insertions(+), 148 deletions(-) diff --git a/emulator/timer.c b/emulator/timer.c index eadbf76cc..efb95564b 100644 --- a/emulator/timer.c +++ b/emulator/timer.c @@ -27,6 +27,6 @@ uint32_t timer_ms(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); - uint32_t msec = t.tv_sec * 1000 + (t.tv_nsec / 1000000); + uint32_t msec = t.tv_sec * 1000 + (t.tv_nsec / 1000000); return msec; } diff --git a/firmware/layout2.c b/firmware/layout2.c index 36e02829f..1080ef278 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -238,7 +238,7 @@ void layoutHome(void) char label[MAX_LABEL_LEN + 1] = _("Go to trezor.io/start"); if (config_isInitialized()) { - config_getLabel(label, sizeof(label)); + config_getLabel(label, sizeof(label)); } uint8_t homescreen[HOMESCREEN_SIZE]; @@ -257,12 +257,12 @@ void layoutHome(void) } } - bool no_backup = false; - bool unfinished_backup = false; - bool needs_backup = false; - config_getNoBackup(&no_backup); - config_getUnfinishedBackup(&unfinished_backup); - config_getNeedsBackup(&needs_backup); + bool no_backup = false; + bool unfinished_backup = false; + bool needs_backup = false; + config_getNoBackup(&no_backup); + config_getUnfinishedBackup(&unfinished_backup); + config_getNeedsBackup(&needs_backup); if (no_backup) { oledBox(0, 0, 127, 8, false); oledDrawStringCenter(OLED_WIDTH / 2, 0, "SEEDLESS", FONT_STANDARD); diff --git a/firmware/protect.c b/firmware/protect.c index 796997d1f..51f0754a0 100644 --- a/firmware/protect.c +++ b/firmware/protect.c @@ -149,34 +149,34 @@ const char *requestPin(PinMatrixRequestType type, const char *text) secbool protectPinUiCallback(uint32_t wait, uint32_t progress) { - (void) progress; - - // Convert wait to secstr string. - char secstrbuf[] = _("________0 seconds"); - char *secstr = secstrbuf + 9; - uint32_t secs = wait; - do { - secstr--; - *secstr = (secs % 10) + '0'; - secs /= 10; - } while (secs > 0 && secstr >= secstrbuf); - if (wait == 1) { - // Change "seconds" to "second". - secstrbuf[16] = 0; - } - layoutDialog(&bmp_icon_info, NULL, NULL, NULL, _("Verifying PIN"), NULL, _("Please wait"), secstr, _("to continue ..."), NULL); - - // Check for Cancel / Initialize. - protectAbortedByCancel = (msg_tiny_id == MessageType_MessageType_Cancel); - protectAbortedByInitialize = (msg_tiny_id == MessageType_MessageType_Initialize); - if (protectAbortedByCancel || protectAbortedByInitialize) { - msg_tiny_id = 0xFFFF; - usbTiny(0); - fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); - return sectrue; - } - - return secfalse; + (void) progress; + + // Convert wait to secstr string. + char secstrbuf[] = _("________0 seconds"); + char *secstr = secstrbuf + 9; + uint32_t secs = wait; + do { + secstr--; + *secstr = (secs % 10) + '0'; + secs /= 10; + } while (secs > 0 && secstr >= secstrbuf); + if (wait == 1) { + // Change "seconds" to "second". + secstrbuf[16] = 0; + } + layoutDialog(&bmp_icon_info, NULL, NULL, NULL, _("Verifying PIN"), NULL, _("Please wait"), secstr, _("to continue ..."), NULL); + + // Check for Cancel / Initialize. + protectAbortedByCancel = (msg_tiny_id == MessageType_MessageType_Cancel); + protectAbortedByInitialize = (msg_tiny_id == MessageType_MessageType_Initialize); + if (protectAbortedByCancel || protectAbortedByInitialize) { + msg_tiny_id = 0xFFFF; + usbTiny(0); + fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); + return sectrue; + } + + return secfalse; } bool protectPin(bool use_cached) @@ -187,77 +187,77 @@ bool protectPin(bool use_cached) const char *pin = ""; if (config_hasPin()) { - pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:")); - if (!pin) { - fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); - return false; - } + pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:")); + if (!pin) { + fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); + return false; + } } - usbTiny(1); + usbTiny(1); bool ret = config_containsPin(pin); - usbTiny(0); + usbTiny(0); if (!ret) { fsm_sendFailure(FailureType_Failure_PinInvalid, NULL); } - return ret; + return ret; } bool protectChangePin(bool removal) { - static CONFIDENTIAL char old_pin[MAX_PIN_LEN + 1] = ""; - static CONFIDENTIAL char new_pin[MAX_PIN_LEN + 1] = ""; - const char* pin = NULL; - - if (config_hasPin()) { - pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:")); - if (pin == NULL) { - fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); - return false; - } - strlcpy(old_pin, pin, sizeof(old_pin)); - } - - if (!removal) { - pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewFirst, _("Please enter new PIN:")); - if (pin == NULL) { - memzero(old_pin, sizeof(old_pin)); - fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); - return false; - } - strlcpy(new_pin, pin, sizeof(new_pin)); - - pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewSecond, _("Please re-enter new PIN:")); - if (pin == NULL) { - memzero(old_pin, sizeof(old_pin)); - memzero(new_pin, sizeof(new_pin)); - fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); - return false; - } - - if (strncmp(new_pin, pin, sizeof(new_pin)) != 0) { - memzero(old_pin, sizeof(old_pin)); - memzero(new_pin, sizeof(new_pin)); - fsm_sendFailure(FailureType_Failure_PinMismatch, NULL); - return false; - } - } - - usbTiny(1); - bool ret = config_changePin(old_pin, new_pin); - usbTiny(0); - memzero(old_pin, sizeof(old_pin)); - memzero(new_pin, sizeof(new_pin)); - if (ret == false) { - fsm_sendFailure(FailureType_Failure_PinInvalid, NULL); - } - return ret; + static CONFIDENTIAL char old_pin[MAX_PIN_LEN + 1] = ""; + static CONFIDENTIAL char new_pin[MAX_PIN_LEN + 1] = ""; + const char* pin = NULL; + + if (config_hasPin()) { + pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:")); + if (pin == NULL) { + fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); + return false; + } + strlcpy(old_pin, pin, sizeof(old_pin)); + } + + if (!removal) { + pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewFirst, _("Please enter new PIN:")); + if (pin == NULL) { + memzero(old_pin, sizeof(old_pin)); + fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); + return false; + } + strlcpy(new_pin, pin, sizeof(new_pin)); + + pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewSecond, _("Please re-enter new PIN:")); + if (pin == NULL) { + memzero(old_pin, sizeof(old_pin)); + memzero(new_pin, sizeof(new_pin)); + fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); + return false; + } + + if (strncmp(new_pin, pin, sizeof(new_pin)) != 0) { + memzero(old_pin, sizeof(old_pin)); + memzero(new_pin, sizeof(new_pin)); + fsm_sendFailure(FailureType_Failure_PinMismatch, NULL); + return false; + } + } + + usbTiny(1); + bool ret = config_changePin(old_pin, new_pin); + usbTiny(0); + memzero(old_pin, sizeof(old_pin)); + memzero(new_pin, sizeof(new_pin)); + if (ret == false) { + fsm_sendFailure(FailureType_Failure_PinInvalid, NULL); + } + return ret; } bool protectPassphrase(void) { - bool passphrase_protection = false; - config_getPassphraseProtection(&passphrase_protection); + bool passphrase_protection = false; + config_getPassphraseProtection(&passphrase_protection); if (!passphrase_protection || session_isPassphraseCached()) { return true; } diff --git a/firmware/recovery.c b/firmware/recovery.c index f7e5460fc..dd3b7edb0 100644 --- a/firmware/recovery.c +++ b/firmware/recovery.c @@ -165,13 +165,13 @@ static void recovery_done(void) { if (!dry_run) { // Update mnemonic on config. if (config_setMnemonic(new_mnemonic)) { - if (!enforce_wordlist) { - // not enforcing => mark config as imported - config_setImported(true); - } - fsm_sendSuccess(_("Device recovered")); + if (!enforce_wordlist) { + // not enforcing => mark config as imported + config_setImported(true); + } + fsm_sendSuccess(_("Device recovered")); } else { - fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic")); + fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic")); } memzero(new_mnemonic, sizeof(new_mnemonic)); } else { diff --git a/firmware/reset.c b/firmware/reset.c index 9813c0969..82bf7191d 100644 --- a/firmware/reset.c +++ b/firmware/reset.c @@ -97,7 +97,7 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len) fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Not in Reset mode")); return; } - awaiting_entropy = false; + awaiting_entropy = false; SHA256_CTX ctx; sha256_Init(&ctx); @@ -108,21 +108,21 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len) memzero(int_entropy, 32); if (skip_backup || no_backup) { - if (no_backup) { - config_setNoBackup(); - } else { - config_setNeedsBackup(true); - } - if (config_setMnemonic(mnemonic)) { - fsm_sendSuccess(_("Device successfully initialized")); - } else { - fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic")); - } + if (no_backup) { + config_setNoBackup(); + } else { + config_setNeedsBackup(true); + } + if (config_setMnemonic(mnemonic)) { + fsm_sendSuccess(_("Device successfully initialized")); + } else { + fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic")); + } layoutHome(); } else { reset_backup(false, mnemonic); } - mnemonic_clear(); + mnemonic_clear(); } static char current_word[10]; @@ -131,15 +131,15 @@ static char current_word[10]; void reset_backup(bool separated, const char* mnemonic) { if (separated) { - bool needs_backup = false; - config_getNeedsBackup(&needs_backup); - if (!needs_backup) { - fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Seed already backed up")); - return; - } - - config_setUnfinishedBackup(true); - config_setNeedsBackup(false); + bool needs_backup = false; + config_getNeedsBackup(&needs_backup); + if (!needs_backup) { + fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Seed already backed up")); + return; + } + + config_setUnfinishedBackup(true); + config_setNeedsBackup(false); } for (int pass = 0; pass < 2; pass++) { @@ -173,12 +173,12 @@ void reset_backup(bool separated, const char* mnemonic) if (separated) { fsm_sendSuccess(_("Seed successfully backed up")); } else { - config_setNeedsBackup(false); - if (config_setMnemonic(mnemonic)) { - fsm_sendSuccess(_("Device successfully initialized")); - } else { - fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic")); - } + config_setNeedsBackup(false); + if (config_setMnemonic(mnemonic)) { + fsm_sendSuccess(_("Device successfully initialized")); + } else { + fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic")); + } } layoutHome(); } diff --git a/firmware/trezor.c b/firmware/trezor.c index 50b7b60ee..97b5ddd69 100644 --- a/firmware/trezor.c +++ b/firmware/trezor.c @@ -90,9 +90,9 @@ void check_lock_screen(void) int main(void) { #if EMULATOR - memzero(HW_ENTROPY_DATA, HW_ENTROPY_LEN); + memzero(HW_ENTROPY_DATA, HW_ENTROPY_LEN); #else - desig_get_unique_id((uint32_t*)HW_ENTROPY_DATA); + desig_get_unique_id((uint32_t*)HW_ENTROPY_DATA); #endif #ifndef APPVER diff --git a/flash.c b/flash.c index 998219c0b..1501b6aa2 100644 --- a/flash.c +++ b/flash.c @@ -43,7 +43,7 @@ static const uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = { static secbool flash_check_success(uint32_t status) { - return (status & (FLASH_SR_PGAERR | FLASH_SR_PGPERR | FLASH_SR_PGSERR | FLASH_SR_WRPERR)) ? secfalse : sectrue; + return (status & (FLASH_SR_PGAERR | FLASH_SR_PGPERR | FLASH_SR_PGSERR | FLASH_SR_WRPERR)) ? secfalse : sectrue; } void flash_init(void) @@ -58,7 +58,7 @@ secbool flash_unlock_write(void) secbool flash_lock_write(void) { - return flash_check_success(svc_flash_lock()); + return flash_check_success(svc_flash_lock()); } const void *flash_get_address(uint8_t sector, uint32_t offset, uint32_t size) @@ -77,16 +77,16 @@ const void *flash_get_address(uint8_t sector, uint32_t offset, uint32_t size) secbool flash_erase(uint8_t sector) { ensure(flash_unlock_write(), NULL); - svc_flash_erase_sector(sector); - ensure(flash_lock_write(), NULL); - - // Check whether the sector was really deleted (contains only 0xFF). - const uint32_t addr_start = FLASH_SECTOR_TABLE[sector], addr_end = FLASH_SECTOR_TABLE[sector + 1]; - for (uint32_t addr = addr_start; addr < addr_end; addr += 4) { - if (*((const uint32_t *)FLASH_PTR(addr)) != 0xFFFFFFFF) { - return secfalse; - } - } + svc_flash_erase_sector(sector); + ensure(flash_lock_write(), NULL); + + // Check whether the sector was really deleted (contains only 0xFF). + const uint32_t addr_start = FLASH_SECTOR_TABLE[sector], addr_end = FLASH_SECTOR_TABLE[sector + 1]; + for (uint32_t addr = addr_start; addr < addr_end; addr += 4) { + if (*((const uint32_t *)FLASH_PTR(addr)) != 0xFFFFFFFF) { + return secfalse; + } + } return sectrue; } @@ -98,14 +98,14 @@ secbool flash_write_byte(uint8_t sector, uint32_t offset, uint8_t data) } if ((*address & data) != data) { - return secfalse; + return secfalse; } - svc_flash_program(FLASH_CR_PROGRAM_X8); - *(volatile uint8_t *) address = data; + svc_flash_program(FLASH_CR_PROGRAM_X8); + *(volatile uint8_t *) address = data; if (*address != data) { - return secfalse; + return secfalse; } return sectrue; @@ -123,14 +123,14 @@ secbool flash_write_word(uint8_t sector, uint32_t offset, uint32_t data) } if ((*address & data) != data) { - return secfalse; + return secfalse; } - svc_flash_program(FLASH_CR_PROGRAM_X32); - *(volatile uint32_t *) address = data; + svc_flash_program(FLASH_CR_PROGRAM_X32); + *(volatile uint32_t *) address = data; if (*address != data) { - return secfalse; + return secfalse; } return sectrue;