Skip to content

Commit 6619222

Browse files
committed
clean up settings, clear mnemonic memory on scene exit
1 parent e924a45 commit 6619222

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

flipbip39.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ FlipBip39* flipbip39_app_alloc() {
4141
app->haptic = 1;
4242
app->speaker = 1;
4343
app->led = 1;
44-
app->bip39_strength = 256;
44+
app->bip39_strength = 1; // 256 bits (24 words)
4545

4646
view_dispatcher_add_view(app->view_dispatcher, FlipBip39ViewIdMenu, submenu_get_view(app->submenu));
4747
app->flipbip39_startscreen = flipbip39_startscreen_alloc();

flipbip39.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ typedef enum {
5555
} FlipBip39LedState;
5656

5757
typedef enum {
58-
FlipBip39Strength128 = 128,
59-
FlipBip39Strength256 = 256,
58+
FlipBip39Strength128,
59+
FlipBip39Strength256,
6060
} FlipBip39StrengthState;

scenes/flipbip39_scene_settings.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include "../flipbip39.h"
22
#include <lib/toolbox/value_index.h>
33

4-
enum SettingsIndex {
5-
SettingsIndexBip39Strength = 10,
6-
SettingsIndexHaptic,
7-
SettingsIndexValue1,
8-
SettingsIndexValue2,
9-
};
4+
// enum SettingsIndex {
5+
// SettingsIndexBip39Strength = 10,
6+
// SettingsIndexHaptic,
7+
// SettingsIndexValue1,
8+
// SettingsIndexValue2,
9+
// };
1010

1111
const char* const haptic_text[2] = {
1212
"OFF",
@@ -36,12 +36,12 @@ const uint32_t led_value[2] = {
3636
};
3737

3838
const char* const bip39_strength_text[2] = {
39-
"24",
4039
"12",
40+
"24",
4141
};
4242
const uint32_t bip39_strength_value[2] = {
43-
FlipBip39Strength256,
4443
FlipBip39Strength128,
44+
FlipBip39Strength256,
4545
};
4646

4747
static void flipbip39_scene_settings_set_haptic(VariableItem* item) {

views/flipbip39_scene_1.c

+37-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
#include <input/input.h>
55
#include <gui/elements.h>
66
#include <dolphin/dolphin.h>
7+
#include "../helpers/flipbip39_haptic.h"
8+
#include "../helpers/flipbip39_speaker.h"
9+
#include "../helpers/flipbip39_led.h"
710

811
#include <string.h>
9-
#include "../crypto/bip32.h"
12+
// #include "../crypto/bip32.h"
1013
#include "../crypto/bip39.h"
11-
#include "../crypto/ecdsa.h"
12-
#include "../crypto/curves.h"
14+
// #include "../crypto/ecdsa.h"
15+
// #include "../crypto/curves.h"
16+
#include "../crypto/memzero.h"
1317

1418
struct FlipBip39Scene1 {
1519
View* view;
@@ -19,6 +23,7 @@ struct FlipBip39Scene1 {
1923

2024

2125
typedef struct {
26+
int strength;
2227
const char* mnemonic1;
2328
const char* mnemonic2;
2429
const char* mnemonic3;
@@ -45,6 +50,7 @@ void flipbip39_scene_1_draw(Canvas* canvas, FlipBip39Scene1Model* model) {
4550
//canvas_draw_str_aligned(canvas, 0, 10, AlignLeft, AlignTop, "This is Scene 1");
4651

4752
canvas_set_font(canvas, FontSecondary);
53+
//canvas_draw_str_aligned(canvas, 1, 2, AlignLeft, AlignTop, model->strength == 128 ? "128-bit" : "256-bit");
4854
canvas_draw_str_aligned(canvas, 1, 2, AlignLeft, AlignTop, model->mnemonic1);
4955
canvas_draw_str_aligned(canvas, 1, 12, AlignLeft, AlignTop, model->mnemonic2);
5056
canvas_draw_str_aligned(canvas, 1, 22, AlignLeft, AlignTop, model->mnemonic3);
@@ -56,6 +62,7 @@ void flipbip39_scene_1_draw(Canvas* canvas, FlipBip39Scene1Model* model) {
5662

5763
static void flipbip39_scene_1_model_init(FlipBip39Scene1Model* const model, const int strength) {
5864
// Generate a random mnemonic using trezor-crypto
65+
model->strength = strength;
5966
const char* mnemonic = mnemonic_generate(strength);
6067

6168
// Delineate 6 sections of the mnemonic
@@ -128,14 +135,36 @@ bool flipbip39_scene_1_input(InputEvent* event, void* context) {
128135

129136
void flipbip39_scene_1_exit(void* context) {
130137
furi_assert(context);
138+
FlipBip39Scene1* instance = (FlipBip39Scene1*)context;
139+
140+
with_view_model(
141+
instance->view,
142+
FlipBip39Scene1Model * model,
143+
{
144+
// Clear the mnemonic from memory
145+
model->strength = 0;
146+
memzero((void*)model->mnemonic1, strlen(model->mnemonic1));
147+
memzero((void*)model->mnemonic2, strlen(model->mnemonic2));
148+
memzero((void*)model->mnemonic3, strlen(model->mnemonic3));
149+
memzero((void*)model->mnemonic4, strlen(model->mnemonic4));
150+
memzero((void*)model->mnemonic5, strlen(model->mnemonic5));
151+
memzero((void*)model->mnemonic6, strlen(model->mnemonic6));
152+
},
153+
true
154+
);
131155
}
132156

133157
void flipbip39_scene_1_enter(void* context) {
134158
furi_assert(context);
135159
FlipBip39Scene1* instance = (FlipBip39Scene1*)context;
136160

137161
FlipBip39* app = instance->context;
138-
int strength = app->bip39_strength;
162+
int strength_setting = app->bip39_strength;
163+
int strength = 256;
164+
if (strength_setting == 0) strength = 128;
165+
166+
flipbip39_play_happy_bump(app);
167+
flipbip39_led_set_rgb(app, 255, 0, 0);
139168

140169
with_view_model(
141170
instance->view,
@@ -157,8 +186,10 @@ FlipBip39Scene1* flipbip39_scene_1_alloc() {
157186
view_set_enter_callback(instance->view, flipbip39_scene_1_enter);
158187
view_set_exit_callback(instance->view, flipbip39_scene_1_exit);
159188

160-
// FlipBip39* app = instance->view->context;
161-
// int strength = app->bip39_strength;
189+
// FlipBip39* app = instance->context;
190+
// int strength_setting = app->bip39_strength;
191+
// int strength = 256;
192+
// if (strength_setting == 0) strength = 128;
162193

163194
// with_view_model(
164195
// instance->view,

0 commit comments

Comments
 (0)