Skip to content

Commit

Permalink
Prefix all globals and provide API to reset them
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Oct 17, 2022
1 parent 0049887 commit d7b0615
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/getPubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
#include "utils.h"
#include "sol/printer.h"

static uint8_t publicKey[PUBKEY_LENGTH];
static char publicKeyStr[BASE58_PUBKEY_LENGTH];
static uint8_t G_publicKey[PUBKEY_LENGTH];
static char G_publicKeyStr[BASE58_PUBKEY_LENGTH];

void reset_getpubkey_globals(void) {
MEMCLEAR(G_publicKey);
MEMCLEAR(G_publicKeyStr);
}

static uint8_t set_result_get_pubkey() {
memcpy(G_io_apdu_buffer, publicKey, PUBKEY_LENGTH);
memcpy(G_io_apdu_buffer, G_publicKey, PUBKEY_LENGTH);
return PUBKEY_LENGTH;
}

Expand All @@ -19,7 +24,7 @@ UX_STEP_NOCB(ux_display_public_flow_5_step,
bnnn_paging,
{
.title = "Pubkey",
.text = publicKeyStr,
.text = G_publicKeyStr,
});
UX_STEP_CB(ux_display_public_flow_6_step,
pb,
Expand Down Expand Up @@ -49,8 +54,8 @@ void handle_get_pubkey(volatile unsigned int *flags, volatile unsigned int *tx)
THROW(ApduReplySdkInvalidParameter);
}

get_public_key(publicKey, G_command.derivation_path, G_command.derivation_path_length);
encode_base58(publicKey, PUBKEY_LENGTH, publicKeyStr, BASE58_PUBKEY_LENGTH);
get_public_key(G_publicKey, G_command.derivation_path, G_command.derivation_path_length);
encode_base58(G_publicKey, PUBKEY_LENGTH, G_publicKeyStr, BASE58_PUBKEY_LENGTH);

if (G_command.non_confirm) {
*tx = set_result_get_pubkey();
Expand Down
2 changes: 2 additions & 0 deletions src/getPubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef _GET_PUBKEY_H_
#define _GET_PUBKEY_H_

void reset_getpubkey_globals(void);

void handle_get_pubkey(volatile unsigned int *flags, volatile unsigned int *tx);

#endif
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
ApduCommand G_command;
unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];

static void reset_main_globals(void) {
MEMCLEAR(G_command);
MEMCLEAR(G_io_seproxyhal_spi_buffer);
}

void handleApdu(volatile unsigned int *flags, volatile unsigned int *tx, int rx) {
if (!flags || !tx) {
THROW(ApduReplySdkInvalidParameter);
Expand Down Expand Up @@ -80,7 +85,8 @@ void app_main(void) {

// Stores the information about the current command. Some commands expect
// multiple APDUs before they become complete and executed.
explicit_bzero(&G_command, sizeof(ApduCommand));
reset_getpubkey_globals();
reset_main_globals();

// DESIGN NOTE: the bootloader ignores the way APDU are fetched. The only
// goal is to retrieve APDU.
Expand Down

0 comments on commit d7b0615

Please sign in to comment.