Skip to content

Commit

Permalink
Assert HMAC return valuess
Browse files Browse the repository at this point in the history
  • Loading branch information
aido committed Jan 27, 2024
1 parent 51a95aa commit 156cf78
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Change log

## [1.6.1] - 2024-01-19
## [1.6.1] - 2024-01-27
### Added
- Added a Release Policy document

### Changed
- Updated version of cmocka used for unit tests
- Updated version of github actions used
- Assert HMAC return values

### Fixed
- Fixed failing Ledger rule enforcer check
Expand Down
8 changes: 2 additions & 6 deletions src/nano/nanos_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ void compare_recovery_phrase(void) {
cx_hmac_sha512_t ctx;
const char key[] = "Bitcoin seed";

CX_CHECK(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key)));
CX_CHECK(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64));
CX_ASSERT(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key)));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64));
PRINTF("Root key from input:\n%.*H\n", 64, buffer);

// get rootkey from device's seed
Expand All @@ -457,10 +457,6 @@ void compare_recovery_phrase(void) {
memzero(buffer, 64);
memzero(buffer_device, 64);

if ((error == CX_INVALID_PARAMETER) || (error == CX_INTERNAL_ERROR)) {
PRINTF("ERROR: compare_recovery_phrase(): %d\n", error);
}

if (error != CX_OK) {
(G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_BIP39)
? ux_flow_init(0, ux_bip39_nomatch_flow, NULL)
Expand Down
8 changes: 2 additions & 6 deletions src/nano/nanox_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ static uint8_t compare_recovery_phrase(void) {
cx_hmac_sha512_t ctx;
const char key[] = "Bitcoin seed";

CX_CHECK(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key)));
CX_CHECK(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64));
CX_ASSERT(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key)));
CX_ASSERT(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64));
PRINTF("Root key from BIP39 input:\n%.*H\n", 64, buffer);

// get rootkey from device's seed
Expand All @@ -505,10 +505,6 @@ static uint8_t compare_recovery_phrase(void) {
memzero(buffer, 64);
memzero(buffer_device, 64);

if ((error == CX_INVALID_PARAMETER) || (error == CX_INTERNAL_ERROR)) {
PRINTF("ERROR: compare_recovery_phrase(): %d\n", error);
}

if (error != CX_OK) {
return 0;
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/ux_common/onboarding_seed_sskr.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

// Return the CRC-32 checksum of the input buffer in network byte order (big endian).
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define cx_crc32_nbo(...) cx_crc32(__VA_ARGS__)
#define crc32_nbo(...) crc32(__VA_ARGS__)
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define cx_crc32_nbo(...) os_swap_u32(cx_crc32(__VA_ARGS__))
#define crc32_nbo(...) os_swap_u32(crc32(__VA_ARGS__))
#else
#error "What kind of system is this?"
#endif
Expand All @@ -23,7 +23,7 @@
// The following function is a temporary workaround that can be removed once cx_crc32_hw()
// works on all Ledger devices

uint32_t cx_crc32(const uint8_t *data, size_t len) {
uint32_t crc32(const uint8_t *data, size_t len) {
uint32_t crc = ~0;
const uint8_t *end = data + len;

Expand Down Expand Up @@ -245,7 +245,7 @@ unsigned int bolos_ux_bip39_to_sskr_convert(unsigned char *bip39_words_buffer,
memcpy(cbor_share_crc_buffer + cbor_len,
share_buffer + share_len * share,
share_len);
checksum = cx_crc32_nbo(cbor_share_crc_buffer, cbor_len + share_len);
checksum = crc32_nbo(cbor_share_crc_buffer, cbor_len + share_len);
memcpy(cbor_share_crc_buffer + cbor_len + share_len, &checksum, checksum_len);

if (bolos_ux_sskr_mnemonic_encode(
Expand Down Expand Up @@ -279,7 +279,7 @@ unsigned int bolos_ux_sskr_hex_check(unsigned char *mnemonic_hex,
uint8_t checksum_len = sizeof(checksum);

for (unsigned int i = 0; i < sskr_shares_count; i++) {
checksum = cx_crc32_nbo(mnemonic_hex + i * (mnemonic_length / sskr_shares_count),
checksum = crc32_nbo(mnemonic_hex + i * (mnemonic_length / sskr_shares_count),
(mnemonic_length / sskr_shares_count) - checksum_len);
// First 8 bytes of all shares in group should be same
// Test checksum
Expand Down

0 comments on commit 156cf78

Please sign in to comment.