Struan Clark 2 лет назад
Родитель
Сommit
0413ca4a44
5 измененных файлов с 53 добавлено и 41 удалено
  1. 0 1
      README.md
  2. 2 2
      application.fam
  3. 1 1
      flipbip.h
  4. 37 36
      lib/crypto/rand.c
  5. 13 1
      views/flipbip_scene_1.c

+ 0 - 1
README.md

@@ -3,7 +3,6 @@
 [![Build](https://github.com/xtruan/FlipBIP/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/xtruan/FlipBIP/actions/workflows/build.yml)
 [![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
 ## Crypto toolkit for Flipper Zero
-- Built against `0.79.1` Flipper Zero firmware release
 - Using Trezor crypto libs from `core/v2.5.3` release
 - Using Trezor crypto libs from `core/v2.5.3` release
 - Included in [RogueMaster Custom Firmware](https://github.com/RogueMaster/flipperzero-firmware-wPlugins)
 - Included in [RogueMaster Custom Firmware](https://github.com/RogueMaster/flipperzero-firmware-wPlugins)
 
 

+ 2 - 2
application.fam

@@ -1,6 +1,6 @@
 App(
 App(
     appid="flipbip",
     appid="flipbip",
-    name="FlipBIP Crypto Tool",
+    name="FlipBIP Crypto Wallet",
     apptype=FlipperAppType.EXTERNAL,
     apptype=FlipperAppType.EXTERNAL,
     entry_point="flipbip_app",
     entry_point="flipbip_app",
     requires=[
     requires=[
@@ -15,7 +15,7 @@ App(
             name="crypto",
             name="crypto",
         ),
         ),
     ],
     ],
-    fap_category="Tools",
+    fap_category="Misc",
     fap_description="Crypto toolkit for Flipper",
     fap_description="Crypto toolkit for Flipper",
     fap_author="Struan Clark (xtruan)",
     fap_author="Struan Clark (xtruan)",
     fap_weburl="https://github.com/xtruan/FlipBIP",
     fap_weburl="https://github.com/xtruan/FlipBIP",

+ 1 - 1
flipbip.h

@@ -15,7 +15,7 @@
 #include "views/flipbip_startscreen.h"
 #include "views/flipbip_startscreen.h"
 #include "views/flipbip_scene_1.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_BTC 0
 #define COIN_DOGE 3
 #define COIN_DOGE 3

+ 37 - 36
lib/crypto/rand.c

@@ -21,28 +21,18 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  * 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"
 #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;
 static uint32_t seed = 0;
 
 
@@ -50,14 +40,6 @@ void random_reseed(const uint32_t value) {
     seed = 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:
 // Flipper Zero RNG code:
 uint32_t random32(void) {
 uint32_t random32(void) {
     return furi_hal_random_get();
     return furi_hal_random_get();
@@ -68,22 +50,41 @@ void random_buffer(uint8_t* buf, size_t len) {
     furi_hal_random_fill_buf(buf, 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
 // 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 random_uniform(uint32_t n) {
     uint32_t x = 0, max = 0xFFFFFFFF - (0xFFFFFFFF % n);
     uint32_t x = 0, max = 0xFFFFFFFF - (0xFFFFFFFF % n);

+ 13 - 1
views/flipbip_scene_1.c

@@ -99,6 +99,10 @@ static CONFIDENTIAL char* s_disp_text5 = NULL;
 static CONFIDENTIAL char* s_disp_text6 = NULL;
 static CONFIDENTIAL char* s_disp_text6 = NULL;
 // Derivation path text
 // Derivation path text
 static const char* s_derivation_text = TEXT_DEFAULT_DERIV;
 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;
 //static bool s_busy = false;
 
 
 void flipbip_scene_1_set_callback(
 void flipbip_scene_1_set_callback(
@@ -307,7 +311,12 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
         canvas_set_font(canvas, FontPrimary);
         canvas_set_font(canvas, FontPrimary);
         canvas_draw_str(canvas, 2, 10, TEXT_LOADING);
         canvas_draw_str(canvas, 2, 10, TEXT_LOADING);
         canvas_draw_str(canvas, 7, 30, s_derivation_text);
         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) {
     } else if(model->page >= PAGE_ADDR_BEGIN && model->page <= PAGE_ADDR_END) {
         // draw address header
         // draw address header
         canvas_set_font(canvas, FontSecondary);
         canvas_set_font(canvas, FontSecondary);
@@ -629,6 +638,9 @@ void flipbip_scene_1_enter(void* context) {
     const char* passphrase_text = "";
     const char* passphrase_text = "";
     if(app->passphrase == FlipBipPassphraseOn && strlen(app->passphrase_text) > 0) {
     if(app->passphrase == FlipBipPassphraseOn && strlen(app->passphrase_text) > 0) {
         passphrase_text = app->passphrase_text;
         passphrase_text = app->passphrase_text;
+        s_warn_insecure = false;
+    } else {
+        s_warn_insecure = true;
     }
     }
 
 
     // BIP44 Coin setting
     // BIP44 Coin setting