Skip to content

Commit 0443a1e

Browse files
committed
updating to add beginnings of key generation
1 parent f2934ba commit 0443a1e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

crypto/bip39.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ void mnemonic_to_seed(const char *mnemonic, const char *passphrase,
189189
void (*progress_callback)(uint32_t current,
190190
uint32_t total)) {
191191
int mnemoniclen = strlen(mnemonic);
192-
int passphraselen = strnlen(passphrase, 256);
192+
int passphraselen = strlen(passphrase);
193+
if (passphraselen > 256) passphraselen = 256;
193194
#if USE_BIP39_CACHE
194195
// check cache
195196
if (mnemoniclen < 256 && passphraselen < 64) {

views/flipbip39_scene_1.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct FlipBip39Scene1 {
2424

2525
typedef struct {
2626
int strength;
27+
const char* seed;
2728
const char* mnemonic1;
2829
const char* mnemonic2;
2930
const char* mnemonic3;
@@ -63,7 +64,7 @@ void flipbip39_scene_1_draw(Canvas* canvas, FlipBip39Scene1Model* model) {
6364
static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, const int strength) {
6465
// Generate a random mnemonic using trezor-crypto
6566
model->strength = strength;
66-
const char* mnemonic = mnemonic_generate(strength);
67+
const char* mnemonic = mnemonic_generate(model->strength);
6768

6869
// Delineate 6 sections of the mnemonic
6970
char *str = malloc(strlen(mnemonic) + 1);
@@ -78,7 +79,12 @@ static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, cons
7879
}
7980
}
8081

81-
// Split the mnemonic into 6 parts
82+
// Generate a seed from the mnemonic
83+
uint8_t seed[64];
84+
//mnemonic_to_seed(mnemonic, "", seed, 0);
85+
model->seed = (char *)seed;
86+
87+
// Split the mnemonic into parts
8288
char *ptr = strtok (str, ",");
8389
int partnum = 0;
8490
while(ptr != NULL)
@@ -97,12 +103,11 @@ static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, cons
97103
ptr = strtok(NULL, ",");
98104
}
99105

106+
100107
// WIP / TODO: Generate a BIP32 root key from the mnemonic
101108

102109
// //bool root_set = false;
103110
// HDNode root;
104-
// uint8_t seed[64];
105-
// mnemonic_to_seed(mnemonic, "", seed, 0);
106111
// hdnode_from_seed(seed, 64, SECP256K1_NAME, &root);
107112
// //root_set = true;
108113

@@ -192,6 +197,7 @@ void flipbip39_scene_1_exit(void* context) {
192197
{
193198
// Clear the mnemonic from memory
194199
model->strength = 0;
200+
memzero((void*)model->seed, strlen(model->seed));
195201
memzero((void*)model->mnemonic1, strlen(model->mnemonic1));
196202
memzero((void*)model->mnemonic2, strlen(model->mnemonic2));
197203
memzero((void*)model->mnemonic3, strlen(model->mnemonic3));

0 commit comments

Comments
 (0)