Skip to content

Commit 75f3c96

Browse files
committed
chore: slight refactor of crypto lib for consistency
1 parent b81adf6 commit 75f3c96

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

lib/crypto/bip32.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
#include <string.h>
2727

2828
#include "address.h"
29+
#if USE_NEM
2930
#include "aes/aes.h"
31+
#endif
3032
#include "base58.h"
3133
#include "bignum.h"
3234
#include "bip32.h"

lib/crypto/memzero.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void memzero(void* const pnt, const size_t len) {
5050
SecureZeroMemory(pnt, len);
5151
#elif defined(HAVE_MEMSET_S)
5252
memset_s(pnt, (rsize_t)len, 0, (rsize_t)len);
53+
// REMOVED - Flipper Zero does not have this function
5354
// #elif defined(HAVE_EXPLICIT_BZERO)
5455
// explicit_bzero(pnt, len);
5556
#elif defined(HAVE_EXPLICIT_MEMSET)

lib/crypto/options.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,14 @@
8686
#define USE_KECCAK 1
8787
#endif
8888

89-
// add way how to mark confidential data
89+
// add a way to mark confidential data
9090
#ifndef CONFIDENTIAL
9191
#define CONFIDENTIAL
9292
#endif
9393

94+
// use Flipper Zero hardware random number generator
95+
#ifndef USE_FLIPPER_HAL_RANDOM
96+
#define USE_FLIPPER_HAL_RANDOM 1
97+
#endif
98+
9499
#endif

lib/crypto/rand.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
* OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

24-
#define FLIPPER_HAL_RANDOM
25-
2624
#include "rand.h"
2725

28-
#ifdef FLIPPER_HAL_RANDOM
26+
#if USE_FLIPPER_HAL_RANDOM
2927

3028
// NOTE:
3129
// random32() and random_buffer() have been replaced in this implementation
@@ -67,14 +65,16 @@ void random_buffer(uint8_t* buf, size_t len) {
6765
// The following code is platform independent
6866
//
6967

68+
static uint32_t seed = 0;
69+
7070
uint32_t random32(void) {
7171
// Linear congruential generator from Numerical Recipes
7272
// https://en.wikipedia.org/wiki/Linear_congruential_generator
7373
seed = 1664525 * seed + 1013904223;
7474
return seed;
7575
}
7676

77-
void __attribute__((weak)) random_buffer(uint8_t *buf, size_t len) {
77+
void random_buffer(uint8_t *buf, size_t len) {
7878
uint32_t r = 0;
7979
for (size_t i = 0; i < len; i++) {
8080
if (i % 4 == 0) {
@@ -84,7 +84,7 @@ void __attribute__((weak)) random_buffer(uint8_t *buf, size_t len) {
8484
}
8585
}
8686

87-
#endif /* FLIPPER_HAL_RANDOM */
87+
#endif /* USE_FLIPPER_HAL_RANDOM */
8888

8989
uint32_t random_uniform(uint32_t n) {
9090
uint32_t x = 0, max = 0xFFFFFFFF - (0xFFFFFFFF % n);

lib/crypto/rand.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <stdint.h>
2828
#include <stdlib.h>
29+
#include "options.h"
2930

3031
void random_reseed(const uint32_t value);
3132
uint32_t random32(void);

0 commit comments

Comments
 (0)