Skip to content

Commit

Permalink
[fix] Checking HMAC return values
Browse files Browse the repository at this point in the history
  • Loading branch information
lpascal-ledger committed Dec 15, 2023
1 parent 18c4e74 commit 646ccfc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/nano/nanos_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <os_io_seproxyhal.h>
#include <lcx_hmac.h>
#include <ledger_assert.h>

#include "constants.h"
#include "glyphs.h"
Expand Down Expand Up @@ -229,8 +230,10 @@ void compare_recovery_phrase(void) {
cx_hmac_sha512_t ctx;
const char key[] = "Bitcoin seed";

cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key));
cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64);
LEDGER_ASSERT(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key)) == CX_OK,
"HMAC init failed");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64) == CX_OK,
"HMAC failed");
PRINTF("Root key from input:\n%.*H\n", 64, buffer);

// get rootkey from device's seed
Expand Down
7 changes: 5 additions & 2 deletions src/nano/nanox_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <lcx_hmac.h>
#include <lcx_rng.h>
#include <ledger_assert.h>

#include "../constants.h"
#include "../ui.h"
Expand Down Expand Up @@ -410,8 +411,10 @@ static uint8_t compare_recovery_phrase(void) {
cx_hmac_sha512_t ctx;
const char key[] = "Bitcoin seed";

cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key));
cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64);
LEDGER_ASSERT(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key)) == CX_OK,
"HMAC init failed");
LEDGER_ASSERT(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64) == CX_OK,
"HMAC failed");
PRINTF("Root key from input:\n%.*H\n", 64, buffer);

// get rootkey from device's seed
Expand Down
Binary file modified tests/functional/snapshots/stax/check_previous_word/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/functional/snapshots/stax/check_previous_word/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 646ccfc

Please sign in to comment.