Skip to content

Commit

Permalink
Merge pull request #15 from xtruan/develop
Browse files Browse the repository at this point in the history
Minor updates
  • Loading branch information
xtruan authored Jul 10, 2023
2 parents 07c2f1e + 7ab548a commit 740a2f8
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- develop

env:
firmware_version: '0.79.1'
firmware_version: '0.86.1'

jobs:
build:
Expand All @@ -27,4 +27,4 @@ jobs:
- name: Build FAPs
run: ./fbt COMPACT=1 DEBUG=0 faps
- name: Check FlipBIP Built
run: test -f build/f7-firmware-C/.extapps/FlipBIP.fap
run: test -f build/f7-firmware-C/.extapps/flipbip.fap
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'v[0-9]+.[0-9]+.[0-9]+'

env:
firmware_version: '0.79.1'
firmware_version: '0.86.1'

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Build](https://github.com/xtruan/FlipBIP/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/xtruan/FlipBIP/actions/workflows/build.yml)

## Crypto toolkit for Flipper Zero
- Built against `0.79.1` Flipper Zero firmware release
- Last built against `0.86.1` Flipper Zero firmware release
- Using Trezor crypto libs from `core/v2.5.3` release
- Included in [RogueMaster Custom Firmware](https://github.com/RogueMaster/flipperzero-firmware-wPlugins)

Expand Down
8 changes: 4 additions & 4 deletions application.fam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
App(
appid="FlipBIP",
name="FlipBIP Crypto Tool",
appid="flipbip",
name="FlipBIP Crypto Wallet",
apptype=FlipperAppType.EXTERNAL,
entry_point="flipbip_app",
requires=[
Expand All @@ -15,8 +15,8 @@ App(
name="crypto",
),
],
fap_category="Tools",
fap_category="Misc",
fap_description="Crypto toolkit for Flipper",
fap_author="Struan Clark (xtruan)",
fap_weburl="https://github.com/xtruan/FlipBIP",
)
)
2 changes: 1 addition & 1 deletion flipbip.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "views/flipbip_startscreen.h"
#include "views/flipbip_scene_1.h"

#define FLIPBIP_VERSION "v0.0.9"
#define FLIPBIP_VERSION "v1.0.0"

#define COIN_BTC 0
#define COIN_DOGE 3
Expand Down
73 changes: 37 additions & 36 deletions lib/crypto/rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,25 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

// NOTE:
// random32() and random_buffer() have been replaced in this implementation
// with Flipper Zero specific code. The original code is commented out below.
#define FLIPPER_HAL_RANDOM

#include "rand.h"

// Flipper Zero RNG code:
#include <furi_hal_random.h>

#ifndef RAND_PLATFORM_INDEPENDENT
#ifdef FLIPPER_HAL_RANDOM

// Original code:
// #pragma message("NOT SUITABLE FOR PRODUCTION USE! Replace random32() function with your own secure code.")
// NOTE:
// random32() and random_buffer() have been replaced in this implementation
// with Flipper Zero specific code. The original code is disabled by #define.

// The following code is not supposed to be used in a production environment.
// It's included only to make the library testable.
// The message above tries to prevent any accidental use outside of the test
// environment.
//
// You are supposed to replace the random8() and random32() function with your
// own secure code. There is also a possibility to replace the random_buffer()
// function as it is defined as a weak symbol.
// Flipper Zero RNG code:
#include <furi_hal_random.h>

static uint32_t seed = 0;

void random_reseed(const uint32_t value) {
seed = value;
}

// Original code:
// uint32_t random32(void) {
// // Linear congruential generator from Numerical Recipes
// // https://en.wikipedia.org/wiki/Linear_congruential_generator
// seed = 1664525 * seed + 1013904223;
// return seed;
// }

// Flipper Zero RNG code:
uint32_t random32(void) {
return furi_hal_random_get();
Expand All @@ -68,22 +50,41 @@ void random_buffer(uint8_t* buf, size_t len) {
furi_hal_random_fill_buf(buf, len);
}

#endif /* RAND_PLATFORM_INDEPENDENT */
#else /* PLATFORM INDEPENDENT */

#pragma message("NOT SUITABLE FOR PRODUCTION USE! Replace random32() function with your own secure code.")

// The following code is not supposed to be used in a production environment.
// It's included only to make the library testable.
// The message above tries to prevent any accidental use outside of the test
// environment.
//
// You are supposed to replace the random8() and random32() function with your
// own secure code. There is also a possibility to replace the random_buffer()
// function as it is defined as a weak symbol.

//
// The following code is platform independent
//

// Original code:
// void __attribute__((weak)) random_buffer(uint8_t *buf, size_t len) {
// uint32_t r = 0;
// for (size_t i = 0; i < len; i++) {
// if (i % 4 == 0) {
// r = random32();
// }
// buf[i] = (r >> ((i % 4) * 8)) & 0xFF;
// }
// }
uint32_t random32(void) {
// Linear congruential generator from Numerical Recipes
// https://en.wikipedia.org/wiki/Linear_congruential_generator
seed = 1664525 * seed + 1013904223;
return seed;
}

void __attribute__((weak)) random_buffer(uint8_t *buf, size_t len) {
uint32_t r = 0;
for (size_t i = 0; i < len; i++) {
if (i % 4 == 0) {
r = random32();
}
buf[i] = (r >> ((i % 4) * 8)) & 0xFF;
}
}

#endif /* FLIPPER_HAL_RANDOM */

uint32_t random_uniform(uint32_t n) {
uint32_t x = 0, max = 0xFFFFFFFF - (0xFFFFFFFF % n);
Expand Down
16 changes: 14 additions & 2 deletions views/flipbip_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//#include <dolphin/dolphin.h>
#include <storage/storage.h>
#include <string.h>
#include "FlipBIP_icons.h"
#include "flipbip_icons.h"
#include "../helpers/flipbip_haptic.h"
#include "../helpers/flipbip_led.h"
#include "../helpers/flipbip_string.h"
Expand Down Expand Up @@ -99,6 +99,10 @@ static CONFIDENTIAL char* s_disp_text5 = NULL;
static CONFIDENTIAL char* s_disp_text6 = NULL;
// Derivation path text
static const char* s_derivation_text = TEXT_DEFAULT_DERIV;
// Warning text
static bool s_warn_insecure = false;
#define WARN_INSECURE_TEXT_1 "Recommendation:"
#define WARN_INSECURE_TEXT_2 "Set BIP39 Passphrase"
//static bool s_busy = false;

void flipbip_scene_1_set_callback(
Expand Down Expand Up @@ -307,7 +311,12 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 2, 10, TEXT_LOADING);
canvas_draw_str(canvas, 7, 30, s_derivation_text);
canvas_draw_icon(canvas, 86, 25, &I_Keychain_39x36);
canvas_draw_icon(canvas, 86, 22, &I_Keychain_39x36);
if (s_warn_insecure) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 50, WARN_INSECURE_TEXT_1);
canvas_draw_str(canvas, 2, 60, WARN_INSECURE_TEXT_2);
}
} else if(model->page >= PAGE_ADDR_BEGIN && model->page <= PAGE_ADDR_END) {
// draw address header
canvas_set_font(canvas, FontSecondary);
Expand Down Expand Up @@ -629,6 +638,9 @@ void flipbip_scene_1_enter(void* context) {
const char* passphrase_text = "";
if(app->passphrase == FlipBipPassphraseOn && strlen(app->passphrase_text) > 0) {
passphrase_text = app->passphrase_text;
s_warn_insecure = false;
} else {
s_warn_insecure = true;
}

// BIP44 Coin setting
Expand Down
2 changes: 1 addition & 1 deletion views/flipbip_startscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <furi_hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include "FlipBIP_icons.h"
#include "flipbip_icons.h"

struct FlipBipStartscreen {
View* view;
Expand Down

0 comments on commit 740a2f8

Please sign in to comment.