1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-17 10:51:00 +00:00

feat(crypto): API for clearing internal caches

This commit is contained in:
matejcik 2022-02-14 12:14:56 +01:00 committed by matejcik
parent 0e27423cff
commit 2ce1e6ba7d
4 changed files with 19 additions and 0 deletions

View File

@ -374,6 +374,13 @@ static CONFIDENTIAL struct {
HDNode node;
} private_ckd_cache[BIP32_CACHE_SIZE];
void bip32_cache_clear(void) {
private_ckd_cache_root_set = false;
private_ckd_cache_index = 0;
memzero(&private_ckd_cache_root, sizeof(private_ckd_cache_root));
memzero(private_ckd_cache, sizeof(private_ckd_cache));
}
int hdnode_private_ckd_cached(HDNode *inout, const uint32_t *i, size_t i_count,
uint32_t *fingerprint) {
if (i_count == 0) {

View File

@ -89,6 +89,7 @@ void hdnode_public_ckd_address_optimized(const curve_point *pub,
int addrsize, int addrformat);
#if USE_BIP32_CACHE
void bip32_cache_clear(void);
int hdnode_private_ckd_cached(HDNode *inout, const uint32_t *i, size_t i_count,
uint32_t *fingerprint);
#endif

View File

@ -44,6 +44,11 @@ static CONFIDENTIAL struct {
uint8_t seed[512 / 8];
} bip39_cache[BIP39_CACHE_SIZE];
void bip39_cache_clear(void) {
memzero(bip39_cache, sizeof(bip39_cache));
bip39_cache_index = 0;
}
#endif
const char *mnemonic_generate(int strength) {

View File

@ -27,9 +27,15 @@
#include <stdbool.h>
#include <stdint.h>
#include "options.h"
#define BIP39_WORDS 2048
#define BIP39_PBKDF2_ROUNDS 2048
#if USE_BIP39_CACHE
void bip39_cache_clear(void);
#endif
const char *mnemonic_generate(int strength); // strength in bits
const char *mnemonic_from_data(const uint8_t *data, int len);
void mnemonic_clear(void);