1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

Fix spaces/tabs so that a single convention is used in each file.

This commit is contained in:
Andrew Kozlik 2019-02-12 15:46:28 +01:00 committed by Pavol Rusnak
parent 8502ee61a3
commit 0e48a1a39a
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
7 changed files with 138 additions and 138 deletions

View File

@ -27,6 +27,6 @@ uint32_t timer_ms(void) {
struct timespec t; struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &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; return msec;
} }

View File

@ -238,7 +238,7 @@ void layoutHome(void)
char label[MAX_LABEL_LEN + 1] = _("Go to trezor.io/start"); char label[MAX_LABEL_LEN + 1] = _("Go to trezor.io/start");
if (config_isInitialized()) { if (config_isInitialized()) {
config_getLabel(label, sizeof(label)); config_getLabel(label, sizeof(label));
} }
uint8_t homescreen[HOMESCREEN_SIZE]; uint8_t homescreen[HOMESCREEN_SIZE];
@ -257,12 +257,12 @@ void layoutHome(void)
} }
} }
bool no_backup = false; bool no_backup = false;
bool unfinished_backup = false; bool unfinished_backup = false;
bool needs_backup = false; bool needs_backup = false;
config_getNoBackup(&no_backup); config_getNoBackup(&no_backup);
config_getUnfinishedBackup(&unfinished_backup); config_getUnfinishedBackup(&unfinished_backup);
config_getNeedsBackup(&needs_backup); config_getNeedsBackup(&needs_backup);
if (no_backup) { if (no_backup) {
oledBox(0, 0, 127, 8, false); oledBox(0, 0, 127, 8, false);
oledDrawStringCenter(OLED_WIDTH / 2, 0, "SEEDLESS", FONT_STANDARD); oledDrawStringCenter(OLED_WIDTH / 2, 0, "SEEDLESS", FONT_STANDARD);

View File

@ -149,34 +149,34 @@ const char *requestPin(PinMatrixRequestType type, const char *text)
secbool protectPinUiCallback(uint32_t wait, uint32_t progress) secbool protectPinUiCallback(uint32_t wait, uint32_t progress)
{ {
(void) progress; (void) progress;
// Convert wait to secstr string. // Convert wait to secstr string.
char secstrbuf[] = _("________0 seconds"); char secstrbuf[] = _("________0 seconds");
char *secstr = secstrbuf + 9; char *secstr = secstrbuf + 9;
uint32_t secs = wait; uint32_t secs = wait;
do { do {
secstr--; secstr--;
*secstr = (secs % 10) + '0'; *secstr = (secs % 10) + '0';
secs /= 10; secs /= 10;
} while (secs > 0 && secstr >= secstrbuf); } while (secs > 0 && secstr >= secstrbuf);
if (wait == 1) { if (wait == 1) {
// Change "seconds" to "second". // Change "seconds" to "second".
secstrbuf[16] = 0; secstrbuf[16] = 0;
} }
layoutDialog(&bmp_icon_info, NULL, NULL, NULL, _("Verifying PIN"), NULL, _("Please wait"), secstr, _("to continue ..."), NULL); layoutDialog(&bmp_icon_info, NULL, NULL, NULL, _("Verifying PIN"), NULL, _("Please wait"), secstr, _("to continue ..."), NULL);
// Check for Cancel / Initialize. // Check for Cancel / Initialize.
protectAbortedByCancel = (msg_tiny_id == MessageType_MessageType_Cancel); protectAbortedByCancel = (msg_tiny_id == MessageType_MessageType_Cancel);
protectAbortedByInitialize = (msg_tiny_id == MessageType_MessageType_Initialize); protectAbortedByInitialize = (msg_tiny_id == MessageType_MessageType_Initialize);
if (protectAbortedByCancel || protectAbortedByInitialize) { if (protectAbortedByCancel || protectAbortedByInitialize) {
msg_tiny_id = 0xFFFF; msg_tiny_id = 0xFFFF;
usbTiny(0); usbTiny(0);
fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); fsm_sendFailure(FailureType_Failure_PinCancelled, NULL);
return sectrue; return sectrue;
} }
return secfalse; return secfalse;
} }
bool protectPin(bool use_cached) bool protectPin(bool use_cached)
@ -187,77 +187,77 @@ bool protectPin(bool use_cached)
const char *pin = ""; const char *pin = "";
if (config_hasPin()) { if (config_hasPin()) {
pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:")); pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:"));
if (!pin) { if (!pin) {
fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); fsm_sendFailure(FailureType_Failure_PinCancelled, NULL);
return false; return false;
} }
} }
usbTiny(1); usbTiny(1);
bool ret = config_containsPin(pin); bool ret = config_containsPin(pin);
usbTiny(0); usbTiny(0);
if (!ret) { if (!ret) {
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL); fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
} }
return ret; return ret;
} }
bool protectChangePin(bool removal) bool protectChangePin(bool removal)
{ {
static CONFIDENTIAL char old_pin[MAX_PIN_LEN + 1] = ""; static CONFIDENTIAL char old_pin[MAX_PIN_LEN + 1] = "";
static CONFIDENTIAL char new_pin[MAX_PIN_LEN + 1] = ""; static CONFIDENTIAL char new_pin[MAX_PIN_LEN + 1] = "";
const char* pin = NULL; const char* pin = NULL;
if (config_hasPin()) { if (config_hasPin()) {
pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:")); pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_Current, _("Please enter current PIN:"));
if (pin == NULL) { if (pin == NULL) {
fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); fsm_sendFailure(FailureType_Failure_PinCancelled, NULL);
return false; return false;
} }
strlcpy(old_pin, pin, sizeof(old_pin)); strlcpy(old_pin, pin, sizeof(old_pin));
} }
if (!removal) { if (!removal) {
pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewFirst, _("Please enter new PIN:")); pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewFirst, _("Please enter new PIN:"));
if (pin == NULL) { if (pin == NULL) {
memzero(old_pin, sizeof(old_pin)); memzero(old_pin, sizeof(old_pin));
fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); fsm_sendFailure(FailureType_Failure_PinCancelled, NULL);
return false; return false;
} }
strlcpy(new_pin, pin, sizeof(new_pin)); strlcpy(new_pin, pin, sizeof(new_pin));
pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewSecond, _("Please re-enter new PIN:")); pin = requestPin(PinMatrixRequestType_PinMatrixRequestType_NewSecond, _("Please re-enter new PIN:"));
if (pin == NULL) { if (pin == NULL) {
memzero(old_pin, sizeof(old_pin)); memzero(old_pin, sizeof(old_pin));
memzero(new_pin, sizeof(new_pin)); memzero(new_pin, sizeof(new_pin));
fsm_sendFailure(FailureType_Failure_PinCancelled, NULL); fsm_sendFailure(FailureType_Failure_PinCancelled, NULL);
return false; return false;
} }
if (strncmp(new_pin, pin, sizeof(new_pin)) != 0) { if (strncmp(new_pin, pin, sizeof(new_pin)) != 0) {
memzero(old_pin, sizeof(old_pin)); memzero(old_pin, sizeof(old_pin));
memzero(new_pin, sizeof(new_pin)); memzero(new_pin, sizeof(new_pin));
fsm_sendFailure(FailureType_Failure_PinMismatch, NULL); fsm_sendFailure(FailureType_Failure_PinMismatch, NULL);
return false; return false;
} }
} }
usbTiny(1); usbTiny(1);
bool ret = config_changePin(old_pin, new_pin); bool ret = config_changePin(old_pin, new_pin);
usbTiny(0); usbTiny(0);
memzero(old_pin, sizeof(old_pin)); memzero(old_pin, sizeof(old_pin));
memzero(new_pin, sizeof(new_pin)); memzero(new_pin, sizeof(new_pin));
if (ret == false) { if (ret == false) {
fsm_sendFailure(FailureType_Failure_PinInvalid, NULL); fsm_sendFailure(FailureType_Failure_PinInvalid, NULL);
} }
return ret; return ret;
} }
bool protectPassphrase(void) bool protectPassphrase(void)
{ {
bool passphrase_protection = false; bool passphrase_protection = false;
config_getPassphraseProtection(&passphrase_protection); config_getPassphraseProtection(&passphrase_protection);
if (!passphrase_protection || session_isPassphraseCached()) { if (!passphrase_protection || session_isPassphraseCached()) {
return true; return true;
} }

View File

@ -165,13 +165,13 @@ static void recovery_done(void) {
if (!dry_run) { if (!dry_run) {
// Update mnemonic on config. // Update mnemonic on config.
if (config_setMnemonic(new_mnemonic)) { if (config_setMnemonic(new_mnemonic)) {
if (!enforce_wordlist) { if (!enforce_wordlist) {
// not enforcing => mark config as imported // not enforcing => mark config as imported
config_setImported(true); config_setImported(true);
} }
fsm_sendSuccess(_("Device recovered")); fsm_sendSuccess(_("Device recovered"));
} else { } 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)); memzero(new_mnemonic, sizeof(new_mnemonic));
} else { } else {

View File

@ -97,7 +97,7 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len)
fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Not in Reset mode")); fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Not in Reset mode"));
return; return;
} }
awaiting_entropy = false; awaiting_entropy = false;
SHA256_CTX ctx; SHA256_CTX ctx;
sha256_Init(&ctx); sha256_Init(&ctx);
@ -108,21 +108,21 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len)
memzero(int_entropy, 32); memzero(int_entropy, 32);
if (skip_backup || no_backup) { if (skip_backup || no_backup) {
if (no_backup) { if (no_backup) {
config_setNoBackup(); config_setNoBackup();
} else { } else {
config_setNeedsBackup(true); config_setNeedsBackup(true);
} }
if (config_setMnemonic(mnemonic)) { if (config_setMnemonic(mnemonic)) {
fsm_sendSuccess(_("Device successfully initialized")); fsm_sendSuccess(_("Device successfully initialized"));
} else { } else {
fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic")); fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic"));
} }
layoutHome(); layoutHome();
} else { } else {
reset_backup(false, mnemonic); reset_backup(false, mnemonic);
} }
mnemonic_clear(); mnemonic_clear();
} }
static char current_word[10]; static char current_word[10];
@ -131,15 +131,15 @@ static char current_word[10];
void reset_backup(bool separated, const char* mnemonic) void reset_backup(bool separated, const char* mnemonic)
{ {
if (separated) { if (separated) {
bool needs_backup = false; bool needs_backup = false;
config_getNeedsBackup(&needs_backup); config_getNeedsBackup(&needs_backup);
if (!needs_backup) { if (!needs_backup) {
fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Seed already backed up")); fsm_sendFailure(FailureType_Failure_UnexpectedMessage, _("Seed already backed up"));
return; return;
} }
config_setUnfinishedBackup(true); config_setUnfinishedBackup(true);
config_setNeedsBackup(false); config_setNeedsBackup(false);
} }
for (int pass = 0; pass < 2; pass++) { for (int pass = 0; pass < 2; pass++) {
@ -173,12 +173,12 @@ void reset_backup(bool separated, const char* mnemonic)
if (separated) { if (separated) {
fsm_sendSuccess(_("Seed successfully backed up")); fsm_sendSuccess(_("Seed successfully backed up"));
} else { } else {
config_setNeedsBackup(false); config_setNeedsBackup(false);
if (config_setMnemonic(mnemonic)) { if (config_setMnemonic(mnemonic)) {
fsm_sendSuccess(_("Device successfully initialized")); fsm_sendSuccess(_("Device successfully initialized"));
} else { } else {
fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic")); fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to store mnemonic"));
} }
} }
layoutHome(); layoutHome();
} }

View File

@ -90,9 +90,9 @@ void check_lock_screen(void)
int main(void) int main(void)
{ {
#if EMULATOR #if EMULATOR
memzero(HW_ENTROPY_DATA, HW_ENTROPY_LEN); memzero(HW_ENTROPY_DATA, HW_ENTROPY_LEN);
#else #else
desig_get_unique_id((uint32_t*)HW_ENTROPY_DATA); desig_get_unique_id((uint32_t*)HW_ENTROPY_DATA);
#endif #endif
#ifndef APPVER #ifndef APPVER

38
flash.c
View File

@ -43,7 +43,7 @@ static const uint32_t FLASH_SECTOR_TABLE[FLASH_SECTOR_COUNT + 1] = {
static secbool flash_check_success(uint32_t status) 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) void flash_init(void)
@ -58,7 +58,7 @@ secbool flash_unlock_write(void)
secbool flash_lock_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) 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) secbool flash_erase(uint8_t sector)
{ {
ensure(flash_unlock_write(), NULL); ensure(flash_unlock_write(), NULL);
svc_flash_erase_sector(sector); svc_flash_erase_sector(sector);
ensure(flash_lock_write(), NULL); ensure(flash_lock_write(), NULL);
// Check whether the sector was really deleted (contains only 0xFF). // 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]; 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) { for (uint32_t addr = addr_start; addr < addr_end; addr += 4) {
if (*((const uint32_t *)FLASH_PTR(addr)) != 0xFFFFFFFF) { if (*((const uint32_t *)FLASH_PTR(addr)) != 0xFFFFFFFF) {
return secfalse; return secfalse;
} }
} }
return sectrue; return sectrue;
} }
@ -98,14 +98,14 @@ secbool flash_write_byte(uint8_t sector, uint32_t offset, uint8_t data)
} }
if ((*address & data) != data) { if ((*address & data) != data) {
return secfalse; return secfalse;
} }
svc_flash_program(FLASH_CR_PROGRAM_X8); svc_flash_program(FLASH_CR_PROGRAM_X8);
*(volatile uint8_t *) address = data; *(volatile uint8_t *) address = data;
if (*address != data) { if (*address != data) {
return secfalse; return secfalse;
} }
return sectrue; return sectrue;
@ -123,14 +123,14 @@ secbool flash_write_word(uint8_t sector, uint32_t offset, uint32_t data)
} }
if ((*address & data) != data) { if ((*address & data) != data) {
return secfalse; return secfalse;
} }
svc_flash_program(FLASH_CR_PROGRAM_X32); svc_flash_program(FLASH_CR_PROGRAM_X32);
*(volatile uint32_t *) address = data; *(volatile uint32_t *) address = data;
if (*address != data) { if (*address != data) {
return secfalse; return secfalse;
} }
return sectrue; return sectrue;