mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-26 06:12:01 +00:00
commit
8d7c1ec543
@ -180,11 +180,15 @@ static void ethereumFormatAmount(bignum256 *val, char buffer[25])
|
|||||||
char value[25] = {0};
|
char value[25] = {0};
|
||||||
char *value_ptr = value;
|
char *value_ptr = value;
|
||||||
|
|
||||||
|
// convert val into base 1000 for easy printing.
|
||||||
uint16_t num[26];
|
uint16_t num[26];
|
||||||
uint8_t last_used = 0;
|
uint8_t last_used = 0;
|
||||||
for (int i = 0; i < 26; i++) {
|
for (int i = 0; i < 26; i++) {
|
||||||
bn_divmod1000(val, (uint32_t *)&(num[i]));
|
uint32_t limb;
|
||||||
if (num[i] > 0) {
|
bn_divmod1000(val, &limb);
|
||||||
|
// limb is < 1000.
|
||||||
|
num[i] = (uint16_t) limb;
|
||||||
|
if (limb > 0) {
|
||||||
last_used = i;
|
last_used = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,9 @@
|
|||||||
|
|
||||||
// message methods
|
// message methods
|
||||||
|
|
||||||
static uint8_t msg_resp[MSG_OUT_SIZE];
|
static uint8_t msg_resp[MSG_OUT_SIZE] __attribute__ ((aligned));
|
||||||
|
|
||||||
#define RESP_INIT(TYPE) TYPE *resp = (TYPE *)msg_resp; \
|
#define RESP_INIT(TYPE) TYPE *resp = (TYPE *) (void *) msg_resp; \
|
||||||
_Static_assert(sizeof(msg_resp) >= sizeof(TYPE), #TYPE " is too large"); \
|
_Static_assert(sizeof(msg_resp) >= sizeof(TYPE), #TYPE " is too large"); \
|
||||||
memset(resp, 0, sizeof(TYPE));
|
memset(resp, 0, sizeof(TYPE));
|
||||||
|
|
||||||
@ -1142,10 +1142,10 @@ void fsm_msgDebugLinkMemoryWrite(DebugLinkMemoryWrite *msg)
|
|||||||
if (msg->flash) {
|
if (msg->flash) {
|
||||||
flash_clear_status_flags();
|
flash_clear_status_flags();
|
||||||
flash_unlock();
|
flash_unlock();
|
||||||
uint32_t* src = (uint32_t *) msg->memory.bytes;
|
|
||||||
for (unsigned int i = 0; i < length; i += 4) {
|
for (unsigned int i = 0; i < length; i += 4) {
|
||||||
flash_program_word(msg->address + i, *src);
|
uint32_t word;
|
||||||
src++;
|
memcpy(&word, msg->memory.bytes + i, 4);
|
||||||
|
flash_program_word(msg->address + i, word);
|
||||||
}
|
}
|
||||||
flash_lock();
|
flash_lock();
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
Storage storage;
|
Storage storage;
|
||||||
|
|
||||||
uint8_t storage_uuid[12];
|
uint32_t storage_uuid[12/sizeof(uint32_t)];
|
||||||
char storage_uuid_str[25];
|
char storage_uuid_str[25];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -77,6 +77,7 @@ be added to the storage u2f_counter to get the real counter value.
|
|||||||
#define FLASH_STORAGE_U2FAREA (FLASH_STORAGE_PINAREA + FLASH_STORAGE_PINAREA_LEN)
|
#define FLASH_STORAGE_U2FAREA (FLASH_STORAGE_PINAREA + FLASH_STORAGE_PINAREA_LEN)
|
||||||
#define FLASH_STORAGE_U2FAREA_LEN (0x100)
|
#define FLASH_STORAGE_U2FAREA_LEN (0x100)
|
||||||
#define FLASH_STORAGE_REALLEN (4 + sizeof(storage_uuid) + sizeof(Storage))
|
#define FLASH_STORAGE_REALLEN (4 + sizeof(storage_uuid) + sizeof(Storage))
|
||||||
|
|
||||||
_Static_assert(FLASH_STORAGE_START + FLASH_STORAGE_REALLEN <= FLASH_STORAGE_PINAREA, "Storage struct is too large for TREZOR flash");
|
_Static_assert(FLASH_STORAGE_START + FLASH_STORAGE_REALLEN <= FLASH_STORAGE_PINAREA, "Storage struct is too large for TREZOR flash");
|
||||||
_Static_assert((sizeof(storage_uuid) & 3) == 0, "storage uuid unaligned");
|
_Static_assert((sizeof(storage_uuid) & 3) == 0, "storage uuid unaligned");
|
||||||
_Static_assert((sizeof(storage) & 3) == 0, "storage unaligned");
|
_Static_assert((sizeof(storage) & 3) == 0, "storage unaligned");
|
||||||
@ -87,6 +88,9 @@ _Static_assert((sizeof(storage) & 3) == 0, "storage unaligned");
|
|||||||
*/
|
*/
|
||||||
static uint32_t storage_u2f_offset;
|
static uint32_t storage_u2f_offset;
|
||||||
|
|
||||||
|
/* magic constant to check validity of storage block */
|
||||||
|
static const uint32_t storage_magic = 0x726f7473; // 'stor' as uint32_t
|
||||||
|
|
||||||
static bool sessionSeedCached, sessionSeedUsesPassphrase;
|
static bool sessionSeedCached, sessionSeedUsesPassphrase;
|
||||||
|
|
||||||
static uint8_t sessionSeed[64];
|
static uint8_t sessionSeed[64];
|
||||||
@ -114,7 +118,7 @@ void storage_check_flash_errors(void)
|
|||||||
|
|
||||||
bool storage_from_flash(void)
|
bool storage_from_flash(void)
|
||||||
{
|
{
|
||||||
if (memcmp((void *)FLASH_STORAGE_START, "stor", 4) != 0) {
|
if (memcmp((void *)FLASH_STORAGE_START, &storage_magic, 4) != 0) {
|
||||||
// wrong magic
|
// wrong magic
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -182,7 +186,7 @@ void storage_init(void)
|
|||||||
void storage_reset_uuid(void)
|
void storage_reset_uuid(void)
|
||||||
{
|
{
|
||||||
// set random uuid
|
// set random uuid
|
||||||
random_buffer(storage_uuid, sizeof(storage_uuid));
|
random_buffer((uint8_t *)storage_uuid, sizeof(storage_uuid));
|
||||||
data2hex(storage_uuid, sizeof(storage_uuid), storage_uuid_str);
|
data2hex(storage_uuid, sizeof(storage_uuid), storage_uuid_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +220,7 @@ static uint32_t storage_flash_words(uint32_t addr, uint32_t *src, int nwords) {
|
|||||||
|
|
||||||
static void storage_commit_locked(void)
|
static void storage_commit_locked(void)
|
||||||
{
|
{
|
||||||
uint8_t meta_backup[FLASH_META_DESC_LEN];
|
uint32_t meta_backup[FLASH_META_DESC_LEN/4];
|
||||||
|
|
||||||
// backup meta
|
// backup meta
|
||||||
memcpy(meta_backup, (uint8_t*)FLASH_META_START, FLASH_META_DESC_LEN);
|
memcpy(meta_backup, (uint8_t*)FLASH_META_START, FLASH_META_DESC_LEN);
|
||||||
@ -225,11 +229,11 @@ static void storage_commit_locked(void)
|
|||||||
flash_erase_sector(FLASH_META_SECTOR_FIRST, FLASH_CR_PROGRAM_X32);
|
flash_erase_sector(FLASH_META_SECTOR_FIRST, FLASH_CR_PROGRAM_X32);
|
||||||
// copy meta
|
// copy meta
|
||||||
uint32_t flash = FLASH_META_START;
|
uint32_t flash = FLASH_META_START;
|
||||||
flash = storage_flash_words(flash, (uint32_t *)meta_backup, FLASH_META_DESC_LEN/4);
|
flash = storage_flash_words(flash, meta_backup, FLASH_META_DESC_LEN/4);
|
||||||
// copy storage
|
// copy storage
|
||||||
flash_program_word(flash, *(uint32_t *) "stor");
|
flash_program_word(flash, storage_magic);
|
||||||
flash += 4;
|
flash += 4;
|
||||||
flash = storage_flash_words(flash, (uint32_t *)&storage_uuid, sizeof(storage_uuid)/4);
|
flash = storage_flash_words(flash, storage_uuid, sizeof(storage_uuid)/4);
|
||||||
flash = storage_flash_words(flash, (uint32_t *)&storage, sizeof(storage)/4);
|
flash = storage_flash_words(flash, (uint32_t *)&storage, sizeof(storage)/4);
|
||||||
// fill remainder with zero for future extensions
|
// fill remainder with zero for future extensions
|
||||||
while (flash < FLASH_STORAGE_PINAREA) {
|
while (flash < FLASH_STORAGE_PINAREA) {
|
||||||
|
@ -297,7 +297,7 @@ void u2fhid_init(const U2FHID_FRAME *in)
|
|||||||
{
|
{
|
||||||
const U2FHID_INIT_REQ *init_req = (const U2FHID_INIT_REQ *)&in->init.data;
|
const U2FHID_INIT_REQ *init_req = (const U2FHID_INIT_REQ *)&in->init.data;
|
||||||
U2FHID_FRAME f;
|
U2FHID_FRAME f;
|
||||||
U2FHID_INIT_RESP *resp = (U2FHID_INIT_RESP *)f.init.data;
|
U2FHID_INIT_RESP resp;
|
||||||
|
|
||||||
debugLog(0, "", "u2fhid_init");
|
debugLog(0, "", "u2fhid_init");
|
||||||
|
|
||||||
@ -312,13 +312,14 @@ void u2fhid_init(const U2FHID_FRAME *in)
|
|||||||
f.init.bcnth = 0;
|
f.init.bcnth = 0;
|
||||||
f.init.bcntl = U2FHID_INIT_RESP_SIZE;
|
f.init.bcntl = U2FHID_INIT_RESP_SIZE;
|
||||||
|
|
||||||
memcpy(resp->nonce, init_req->nonce, sizeof(init_req->nonce));
|
memcpy(resp.nonce, init_req->nonce, sizeof(init_req->nonce));
|
||||||
resp->cid = in->cid == CID_BROADCAST ? next_cid() : in->cid;
|
resp.cid = in->cid == CID_BROADCAST ? next_cid() : in->cid;
|
||||||
resp->versionInterface = U2FHID_IF_VERSION;
|
resp.versionInterface = U2FHID_IF_VERSION;
|
||||||
resp->versionMajor = VERSION_MAJOR;
|
resp.versionMajor = VERSION_MAJOR;
|
||||||
resp->versionMinor = VERSION_MINOR;
|
resp.versionMinor = VERSION_MINOR;
|
||||||
resp->versionBuild = VERSION_PATCH;
|
resp.versionBuild = VERSION_PATCH;
|
||||||
resp->capFlags = CAPFLAG_WINK;
|
resp.capFlags = CAPFLAG_WINK;
|
||||||
|
memcpy(&f.init.data, &resp, sizeof(resp));
|
||||||
|
|
||||||
queue_u2f_pkt(&f);
|
queue_u2f_pkt(&f);
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ static void hid_u2f_rx_callback(usbd_device *dev, uint8_t ep)
|
|||||||
|
|
||||||
debugLog(0, "", "hid_u2f_rx_callback");
|
debugLog(0, "", "hid_u2f_rx_callback");
|
||||||
if ( usbd_ep_read_packet(dev, ENDPOINT_ADDRESS_U2F_OUT, buf, 64) != 64) return;
|
if ( usbd_ep_read_packet(dev, ENDPOINT_ADDRESS_U2F_OUT, buf, 64) != 64) return;
|
||||||
u2fhid_read(tiny, (const U2FHID_FRAME *)buf);
|
u2fhid_read(tiny, (const U2FHID_FRAME *) (void*) buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_LINK
|
#if DEBUG_LINK
|
||||||
|
Loading…
Reference in New Issue
Block a user