Skip to content

Commit

Permalink
updating to add beginnings of key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 2, 2023
1 parent f2934ba commit 0443a1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion crypto/bip39.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ void mnemonic_to_seed(const char *mnemonic, const char *passphrase,
void (*progress_callback)(uint32_t current,
uint32_t total)) {
int mnemoniclen = strlen(mnemonic);
int passphraselen = strnlen(passphrase, 256);
int passphraselen = strlen(passphrase);
if (passphraselen > 256) passphraselen = 256;
#if USE_BIP39_CACHE
// check cache
if (mnemoniclen < 256 && passphraselen < 64) {
Expand Down
14 changes: 10 additions & 4 deletions views/flipbip39_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct FlipBip39Scene1 {

typedef struct {
int strength;
const char* seed;
const char* mnemonic1;
const char* mnemonic2;
const char* mnemonic3;
Expand Down Expand Up @@ -63,7 +64,7 @@ void flipbip39_scene_1_draw(Canvas* canvas, FlipBip39Scene1Model* model) {
static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, const int strength) {
// Generate a random mnemonic using trezor-crypto
model->strength = strength;
const char* mnemonic = mnemonic_generate(strength);
const char* mnemonic = mnemonic_generate(model->strength);

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

// Split the mnemonic into 6 parts
// Generate a seed from the mnemonic
uint8_t seed[64];
//mnemonic_to_seed(mnemonic, "", seed, 0);
model->seed = (char *)seed;

// Split the mnemonic into parts
char *ptr = strtok (str, ",");
int partnum = 0;
while(ptr != NULL)
Expand All @@ -97,12 +103,11 @@ static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, cons
ptr = strtok(NULL, ",");
}


// WIP / TODO: Generate a BIP32 root key from the mnemonic

// //bool root_set = false;
// HDNode root;
// uint8_t seed[64];
// mnemonic_to_seed(mnemonic, "", seed, 0);
// hdnode_from_seed(seed, 64, SECP256K1_NAME, &root);
// //root_set = true;

Expand Down Expand Up @@ -192,6 +197,7 @@ void flipbip39_scene_1_exit(void* context) {
{
// Clear the mnemonic from memory
model->strength = 0;
memzero((void*)model->seed, strlen(model->seed));
memzero((void*)model->mnemonic1, strlen(model->mnemonic1));
memzero((void*)model->mnemonic2, strlen(model->mnemonic2));
memzero((void*)model->mnemonic3, strlen(model->mnemonic3));
Expand Down

0 comments on commit 0443a1e

Please sign in to comment.