mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
bip39: remove indexes functions, add mnemonic_clear function
This commit is contained in:
parent
c316e775a2
commit
d1c52401e4
43
bip39.c
43
bip39.c
@ -58,17 +58,7 @@ const char *mnemonic_generate(int strength)
|
||||
return r;
|
||||
}
|
||||
|
||||
const uint16_t *mnemonic_generate_indexes(int strength)
|
||||
{
|
||||
if (strength % 32 || strength < 128 || strength > 256) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t data[32];
|
||||
random_buffer(data, 32);
|
||||
const uint16_t *r = mnemonic_from_data_indexes(data, strength / 8);
|
||||
memzero(data, sizeof(data));
|
||||
return r;
|
||||
}
|
||||
static CONFIDENTIAL char mnemo[24 * 10];
|
||||
|
||||
const char *mnemonic_from_data(const uint8_t *data, int len)
|
||||
{
|
||||
@ -85,7 +75,6 @@ const char *mnemonic_from_data(const uint8_t *data, int len)
|
||||
memcpy(bits, data, len);
|
||||
|
||||
int mlen = len * 3 / 4;
|
||||
static CONFIDENTIAL char mnemo[24 * 10];
|
||||
|
||||
int i, j, idx;
|
||||
char *p = mnemo;
|
||||
@ -105,35 +94,9 @@ const char *mnemonic_from_data(const uint8_t *data, int len)
|
||||
return mnemo;
|
||||
}
|
||||
|
||||
const uint16_t *mnemonic_from_data_indexes(const uint8_t *data, int len)
|
||||
void mnemonic_clear(void)
|
||||
{
|
||||
if (len % 4 || len < 16 || len > 32) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t bits[32 + 1];
|
||||
|
||||
sha256_Raw(data, len, bits);
|
||||
// checksum
|
||||
bits[len] = bits[0];
|
||||
// data
|
||||
memcpy(bits, data, len);
|
||||
|
||||
int mlen = len * 3 / 4;
|
||||
static CONFIDENTIAL uint16_t mnemo[24];
|
||||
|
||||
int i, j, idx;
|
||||
for (i = 0; i < mlen; i++) {
|
||||
idx = 0;
|
||||
for (j = 0; j < 11; j++) {
|
||||
idx <<= 1;
|
||||
idx += (bits[(i * 11 + j) / 8] & (1 << (7 - ((i * 11 + j) % 8)))) > 0;
|
||||
}
|
||||
mnemo[i] = idx;
|
||||
}
|
||||
memzero(bits, sizeof(bits));
|
||||
|
||||
return mnemo;
|
||||
memzero(mnemo, sizeof(mnemo));
|
||||
}
|
||||
|
||||
int mnemonic_to_entropy(const char *mnemonic, uint8_t *entropy)
|
||||
|
4
bip39.h
4
bip39.h
@ -29,10 +29,8 @@
|
||||
#define BIP39_PBKDF2_ROUNDS 2048
|
||||
|
||||
const char *mnemonic_generate(int strength); // strength in bits
|
||||
const uint16_t *mnemonic_generate_indexes(int strength); // strength in bits
|
||||
|
||||
const char *mnemonic_from_data(const uint8_t *data, int len);
|
||||
const uint16_t *mnemonic_from_data_indexes(const uint8_t *data, int len);
|
||||
void mnemonic_clear(void);
|
||||
|
||||
int mnemonic_check(const char *mnemonic);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user