1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00
trezor-firmware/firmware/storage.h

156 lines
4.4 KiB
C
Raw Normal View History

2014-04-29 12:26:51 +00:00
/*
* This file is part of the TREZOR project, https://trezor.io/
2014-04-29 12:26:51 +00:00
*
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STORAGE_H__
#define __STORAGE_H__
#include "bip32.h"
#include "messages-management.pb.h"
2014-04-29 12:26:51 +00:00
2017-12-18 21:16:05 +00:00
#define STORAGE_FIELD(TYPE, NAME) \
bool has_##NAME; \
TYPE NAME;
#define STORAGE_STRING(NAME, SIZE) \
bool has_##NAME; \
char NAME[SIZE];
#define STORAGE_BYTES(NAME, SIZE) \
bool has_##NAME; \
struct { \
uint32_t size; \
2017-12-18 21:16:05 +00:00
uint8_t bytes[SIZE]; \
} NAME;
#define STORAGE_BOOL(NAME) STORAGE_FIELD(bool, NAME)
#define STORAGE_NODE(NAME) STORAGE_FIELD(StorageHDNode, NAME)
#define STORAGE_UINT32(NAME) STORAGE_FIELD(uint32_t, NAME)
typedef struct {
uint32_t depth;
uint32_t fingerprint;
uint32_t child_num;
struct {
uint32_t size;
2017-12-18 21:16:05 +00:00
uint8_t bytes[32];
} chain_code;
STORAGE_BYTES(private_key, 32);
STORAGE_BYTES(public_key, 33);
} StorageHDNode;
typedef struct _Storage {
uint32_t version;
STORAGE_NODE (node)
STORAGE_STRING (mnemonic, 241)
STORAGE_BOOL (passphrase_protection)
STORAGE_UINT32 (pin_failed_attempts)
STORAGE_STRING (pin, 10)
STORAGE_STRING (language, 17)
STORAGE_STRING (label, 33)
STORAGE_BOOL (imported)
STORAGE_BYTES (homescreen, 1024)
STORAGE_UINT32 (u2f_counter)
STORAGE_BOOL (needs_backup)
STORAGE_UINT32 (flags)
STORAGE_NODE (u2froot)
STORAGE_BOOL (unfinished_backup)
STORAGE_UINT32 (auto_lock_delay_ms)
2017-12-18 21:16:05 +00:00
} Storage;
extern Storage storageUpdate;
2014-04-29 12:26:51 +00:00
void storage_init(void);
void storage_generate_uuid(void);
void storage_clear_update(void);
void storage_update(void);
2015-03-31 14:31:29 +00:00
void session_clear(bool clear_pin);
2014-04-29 12:26:51 +00:00
void storage_loadDevice(LoadDevice *msg);
2016-05-19 23:49:20 +00:00
const uint8_t *storage_getSeed(bool usePassphrase);
bool storage_getU2FRoot(HDNode *node);
2016-05-19 23:49:20 +00:00
bool storage_getRootNode(HDNode *node, const char *curve, bool usePassphrase);
2014-04-29 12:26:51 +00:00
const char *storage_getLabel(void);
void storage_setLabel(const char *label);
const char *storage_getLanguage(void);
void storage_setLanguage(const char *lang);
void storage_setPassphraseProtection(bool passphrase_protection);
bool storage_hasPassphraseProtection(void);
2015-02-04 20:27:07 +00:00
const uint8_t *storage_getHomescreen(void);
void storage_setHomescreen(const uint8_t *data, uint32_t size);
2014-04-29 12:26:51 +00:00
void session_cachePassphrase(const char *passphrase);
bool session_isPassphraseCached(void);
2018-03-03 21:22:45 +00:00
bool session_getState(const uint8_t *salt, uint8_t *state, const char *passphrase);
2014-04-29 12:26:51 +00:00
void storage_setMnemonic(const char *mnemonic);
bool storage_containsMnemonic(const char *mnemonic);
bool storage_hasMnemonic(void);
const char *storage_getMnemonic(void);
bool storage_hasNode(void);
2017-12-18 21:16:05 +00:00
#if DEBUG_LINK
void storage_dumpNode(HDNodeType *node);
#endif
bool storage_containsPin(const char *pin);
2014-04-29 12:26:51 +00:00
bool storage_hasPin(void);
const char *storage_getPin(void);
2014-04-29 12:26:51 +00:00
void storage_setPin(const char *pin);
void session_cachePin(void);
2014-04-29 12:26:51 +00:00
bool session_isPinCached(void);
void storage_clearPinArea(void);
void storage_resetPinFails(uint32_t flash_pinfails);
bool storage_increasePinFails(uint32_t flash_pinfails);
2018-03-22 19:12:01 +00:00
uint32_t storage_getPinWait(uint32_t flash_pinfails);
uint32_t storage_getPinFailsOffset(void);
2014-04-29 12:26:51 +00:00
2015-11-02 23:08:18 +00:00
uint32_t storage_nextU2FCounter(void);
2016-06-12 21:39:28 +00:00
void storage_setU2FCounter(uint32_t u2fcounter);
2015-11-02 23:08:18 +00:00
2014-04-29 12:26:51 +00:00
bool storage_isInitialized(void);
bool storage_isImported(void);
void storage_setImported(bool imported);
bool storage_needsBackup(void);
void storage_setNeedsBackup(bool needs_backup);
bool storage_unfinishedBackup(void);
void storage_setUnfinishedBackup(bool unfinished_backup);
void storage_applyFlags(uint32_t flags);
uint32_t storage_getFlags(void);
uint32_t storage_getAutoLockDelayMs(void);
void storage_setAutoLockDelayMs(uint32_t auto_lock_delay_ms);
void storage_wipe(void);
2014-04-29 12:26:51 +00:00
extern char storage_uuid_str[25];
#endif