Skip to content

Commit

Permalink
moved signing-input-length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
shufps committed Feb 9, 2024
1 parent 9bebb7d commit 3402b35
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
9 changes: 0 additions & 9 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,6 @@ uint32_t api_prepare_blindsigning(uint8_t num_hashes)
// multiple of 32byte chunks
uint16_t signing_input_len = (uint16_t)num_hashes << 5;

if ((api.protocol == PROTOCOL_STARDUST &&
signing_input_len != BLAKE2B_SIZE_BYTES) ||
(api.protocol == PROTOCOL_NOVA &&
(signing_input_len != SIGNING_INPUT_NOVE_32BYTE ||
signing_input_len != SIGNING_INPUT_NOVE_64BYTE))) {
THROW(SW_INCORRECT_P1P2);
}


// we allow to prepare without blindsigning enabled but the user will only
// get an error message that blindsigning is not enabled on the Nano when
// trying to sign what is the most consistent behaviour because the outcome
Expand Down
1 change: 0 additions & 1 deletion src/iota/abstraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ uint8_t address_encode_bech32(const API_CTX *api, const uint8_t *addr_with_type,
uint8_t essence_parse_and_validate(API_CTX *api);

uint8_t get_amount(const API_CTX *api, int index, char *dst, size_t dst_len);

9 changes: 6 additions & 3 deletions src/iota/blindsigning.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ validate_inputs_bip32(const uint8_t *data, uint32_t *idx, uint16_t inputs_count,


uint8_t parse_and_validate_blindsigning(API_CTX *api,
uint16_t signing_input_len)
uint16_t signing_input_len)
{
uint32_t idx = 0;

// validate signing input length
MUST(signing_input_len == ESSENCE_HASH_SIZE_BYTES);
MUST((api.protocol == PROTOCOL_STARDUST &&
signing_input_len == BLAKE2B_SIZE_BYTES) ||
(api.protocol == PROTOCOL_NOVA &&
(signing_input_len == SIGNING_INPUT_NOVA_32BYTE ||
signing_input_len == SIGNING_INPUT_NOVA_64BYTE)));

api->essence.signing_input_len = signing_input_len;

Expand Down
3 changes: 2 additions & 1 deletion src/iota/blindsigning.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

#include "api.h"

uint8_t parse_and_validate_blindsigning(API_CTX *api, uint16_t signing_input_len);
uint8_t parse_and_validate_blindsigning(API_CTX *api,
uint16_t signing_input_len);
4 changes: 2 additions & 2 deletions src/iota/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
#define ESSENCE_HASH_SIZE_BYTES 32

#define SIGNING_INPUT_MAX_BYTES 64
#define SIGNING_INPUT_NOVE_32BYTE 32
#define SIGNING_INPUT_NOVE_64BYTE 32
#define SIGNING_INPUT_NOVA_32BYTE 32
#define SIGNING_INPUT_NOVA_64BYTE 32

// address type of ED25519 addresses
#define ADDRESS_TYPE_ED25519 0
Expand Down

0 comments on commit 3402b35

Please sign in to comment.