1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 03:18:09 +00:00

Add CPUID, flash size and unique device ID as salt to storage_init().

This commit is contained in:
andrew 2019-01-02 16:14:12 +01:00 committed by Pavol Rusnak
parent 4cea4d2a4a
commit 5f94b6a6d2
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
7 changed files with 196 additions and 3 deletions

View File

@ -278,6 +278,7 @@ SOURCE_TREZORHAL = [
'embed/trezorhal/usbd_core.c',
'embed/trezorhal/usbd_ctlreq.c',
'embed/trezorhal/usbd_ioreq.c',
'embed/trezorhal/utils.c',
'embed/trezorhal/util.s',
'embed/trezorhal/vectortable.s',
]

View File

@ -257,6 +257,7 @@ SOURCE_UNIX = [
'embed/unix/sbu.c',
'embed/unix/touch.c',
'embed/unix/usb.c',
'embed/unix/utils.c',
]
SOURCE_QSTR = SOURCE_MOD + SOURCE_MICROPYTHON + SOURCE_UNIX

View File

@ -26,6 +26,7 @@
#include "embed/extmod/trezorobj.h"
#include "storage.h"
#include "utils.h"
STATIC mp_obj_t ui_wait_callback = mp_const_none;
@ -41,12 +42,18 @@ STATIC void wrapped_ui_wait_callback(uint32_t wait, uint32_t progress) {
/// called from this module!
/// '''
STATIC mp_obj_t mod_trezorconfig_init(size_t n_args, const mp_obj_t *args) {
// TODO: Add salt.
uint32_t salt[] = {
utils_get_cpu_id(),
utils_get_flash_size(),
utils_get_uid_word0(),
utils_get_uid_word1(),
utils_get_uid_word2()
};
if (n_args > 0) {
ui_wait_callback = args[0];
storage_init(wrapped_ui_wait_callback, (const uint8_t*)"", 0);
storage_init(wrapped_ui_wait_callback, (const uint8_t*)salt, sizeof(salt));
} else {
storage_init(NULL, (const uint8_t*)"", 0);
storage_init(NULL, (const uint8_t*)salt, sizeof(salt));
}
return mp_const_none;
}

62
embed/trezorhal/utils.c Normal file
View File

@ -0,0 +1,62 @@
/*
* This file is part of the TREZOR project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utils.h"
#include STM32_HAL_H
#include "stm32l4xx_ll_utils.h"
/*
* Returns the CPUID Base Register of the System Control Block.
*/
uint32_t utils_get_cpu_id()
{
return SCB->CPUID;
}
/*
* Returns the size of the device flash memory expressed in kilobytes, e.g. 0x040 corresponds to 64 kB.
*/
uint32_t utils_get_flash_size()
{
return LL_GetFlashSize();
}
/*
* Returns word 0 of the unique device identifier.
*/
uint32_t utils_get_uid_word0()
{
return LL_GetUID_Word0();
}
/*
* Returns word 1 of the unique device identifier.
*/
uint32_t utils_get_uid_word1()
{
return LL_GetUID_Word1();
}
/*
* Returns word 2 of the unique device identifier.
*/
uint32_t utils_get_uid_word2()
{
return LL_GetUID_Word2();
}

31
embed/trezorhal/utils.h Normal file
View File

@ -0,0 +1,31 @@
/*
* This file is part of the TREZOR project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TREZORHAL_UTILS_H__
#define __TREZORHAL_UTILS_H__
#include <stdint.h>
uint32_t utils_get_cpu_id();
uint32_t utils_get_flash_size();
uint32_t utils_get_uid_word0();
uint32_t utils_get_uid_word1();
uint32_t utils_get_uid_word2();
#endif

60
embed/unix/utils.c Normal file
View File

@ -0,0 +1,60 @@
/*
* This file is part of the TREZOR project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utils.h"
/*
* Returns the CPUID Base Register of the System Control Block.
*/
uint32_t utils_get_cpu_id()
{
return 0;
}
/*
* Returns the size of the device flash memory expressed in kilobytes, e.g. 0x040 corresponds to 64 kB.
*/
uint32_t utils_get_flash_size()
{
return 0;
}
/*
* Returns word 0 of the unique device identifier.
*/
uint32_t utils_get_uid_word0()
{
return 0;
}
/*
* Returns word 1 of the unique device identifier.
*/
uint32_t utils_get_uid_word1()
{
return 0;
}
/*
* Returns word 2 of the unique device identifier.
*/
uint32_t utils_get_uid_word2()
{
return 0;
}

31
embed/unix/utils.h Normal file
View File

@ -0,0 +1,31 @@
/*
* This file is part of the TREZOR project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TREZORHAL_UTILS_H__
#define __TREZORHAL_UTILS_H__
#include <stdint.h>
uint32_t utils_get_cpu_id();
uint32_t utils_get_flash_size();
uint32_t utils_get_uid_word0();
uint32_t utils_get_uid_word1();
uint32_t utils_get_uid_word2();
#endif