Skip to content

Commit

Permalink
More changes after code review
Browse files Browse the repository at this point in the history
- Added WORDS_BUFFER_SIZE constant for onboard_t
- Using sizeof() instead of SEEDSIZE constant for handling seed buffer
  • Loading branch information
italo-sampaio committed Nov 10, 2022
1 parent 9796225 commit 99af851
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 5 additions & 6 deletions ledger/src/ui/src/onboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,15 @@ unsigned int onboard_device(onboard_t *onboard_ctx, pin_t *pin_ctx) {
// Generate 32 bytes of random with onboard rng
cx_rng((unsigned char *)onboard_ctx->seed, sizeof(onboard_ctx->seed));
// XOR with host-generated 32 bytes random
for (int i = 0; i < SEEDSIZE; i++) {
for (unsigned int i = 0; i < sizeof(onboard_ctx->seed); i++) {
onboard_ctx->seed[i] ^= onboard_ctx->host_seed[i];
}
// The seed is now in onboard_ctx->seed, generate the mnemonic
os_memset(onboard_ctx->words_buffer, 0, sizeof(onboard_ctx->words_buffer));
onboard_ctx->words_buffer_length =
bolos_ux_mnemonic_from_data((unsigned char *)onboard_ctx->seed,
SEEDSIZE,
(unsigned char *)onboard_ctx->words_buffer,
sizeof(onboard_ctx->words_buffer));
bolos_ux_mnemonic_from_data((unsigned char *)onboard_ctx->seed,
sizeof(onboard_ctx->seed),
(unsigned char *)onboard_ctx->words_buffer,
sizeof(onboard_ctx->words_buffer));
// Clear the seed
explicit_bzero(onboard_ctx->seed, sizeof(onboard_ctx->seed));

Expand Down
5 changes: 3 additions & 2 deletions ledger/src/ui/src/onboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
#include "os_io_seproxyhal.h"
#include "pin.h"

// 128 of words (215 => hashed to 64, or 128) + HMAC_LENGTH*2 = 256
#define WORDS_BUFFER_SIZE 257
// Onboard context
typedef struct {
union {
unsigned char words_buffer[257];
unsigned char words_buffer[WORDS_BUFFER_SIZE];
unsigned char host_seed[SEEDSIZE];
};
unsigned char seed[SEEDSIZE];
unsigned int words_buffer_length;
} onboard_t;

/*
Expand Down

0 comments on commit 99af851

Please sign in to comment.