diff --git a/src/apdu_sign.c b/src/apdu_sign.c index b3ce5041..95bc94a8 100644 --- a/src/apdu_sign.c +++ b/src/apdu_sign.c @@ -89,28 +89,6 @@ static bool sign_reject(void) { return true; // Return to idle } -static bool is_operation_allowed(enum operation_tag tag) { - switch (tag) { - case OPERATION_TAG_DELEGATION: - case OPERATION_TAG_REVEAL: - return true; - default: - return false; - } -} - -static bool parse_allowed_operations(struct parsed_operation_group *const out, - uint8_t const *const in, - size_t const in_size, - bip32_path_with_curve_t const *const key) { - return parse_operations(out, - in, - in_size, - key->derivation_type, - &key->bip32_path, - &is_operation_allowed); -} - size_t baking_sign_complete(bool const send_hash, volatile uint32_t *flags) { switch (G.magic_byte) { case MAGIC_BYTE_BLOCK: @@ -213,8 +191,11 @@ static size_t handle_apdu(bool const enable_hashing, G.magic_byte = get_magic_byte_or_throw(buff, buff_size); if (G.magic_byte == MAGIC_BYTE_UNSAFE_OP) { // Parse the operation. It will be verified in `baking_sign_complete`. - G.maybe_ops.is_valid = - parse_allowed_operations(&G.maybe_ops.v, buff, buff_size, &global.path_with_curve); + G.maybe_ops.is_valid = parse_operations(&G.maybe_ops.v, + buff, + buff_size, + global.path_with_curve.derivation_type, + &global.path_with_curve.bip32_path); } else { // This should be a baking operation so parse it. if (!parse_baking_data(&G.parsed_baking_data, buff, buff_size)) PARSE_ERROR(); diff --git a/src/operations.c b/src/operations.c index a5cdc10d..b8b0d125 100644 --- a/src/operations.c +++ b/src/operations.c @@ -167,8 +167,7 @@ bool parse_operations_final(struct parse_state *const state, static inline bool parse_byte(uint8_t byte, struct parse_state *const state, - struct parsed_operation_group *const out, - is_operation_allowed_t is_operation_allowed) { + struct parsed_operation_group *const out) { // OP_STEP finishes the current state transition, setting the state, and introduces the next state. // For linear chains of states, this keeps the code structurally similar to equivalent imperative // parsing code. @@ -215,8 +214,6 @@ static inline bool parse_byte(uint8_t byte, state->tag = NEXT_BYTE; - if (!is_operation_allowed(state->tag)) PARSE_ERROR(); - OP_STEP // Parse 'source' @@ -344,15 +341,14 @@ static void parse_operations_throws_parse_error(struct parsed_operation_group *c void const *const data, size_t length, derivation_type_t derivation_type, - bip32_path_t const *const bip32_path, - is_operation_allowed_t is_operation_allowed) { + bip32_path_t const *const bip32_path) { size_t ix = 0; parse_operations_init(out, derivation_type, bip32_path, &G.parse_state); while (ix < length) { uint8_t byte = ((uint8_t *) data)[ix]; - parse_byte(byte, &G.parse_state, out, is_operation_allowed); + parse_byte(byte, &G.parse_state, out); PRINTF("Byte: %x - Next op_step state: %d\n", byte, G.parse_state.op_step); ix++; } @@ -364,16 +360,10 @@ bool parse_operations(struct parsed_operation_group *const out, uint8_t const *const data, size_t length, derivation_type_t derivation_type, - bip32_path_t const *const bip32_path, - is_operation_allowed_t is_operation_allowed) { + bip32_path_t const *const bip32_path) { BEGIN_TRY { TRY { - parse_operations_throws_parse_error(out, - data, - length, - derivation_type, - bip32_path, - is_operation_allowed); + parse_operations_throws_parse_error(out, data, length, derivation_type, bip32_path); } CATCH(EXC_PARSE_ERROR) { return false; diff --git a/src/operations.h b/src/operations.h index 5bfdb853..5ef66340 100644 --- a/src/operations.h +++ b/src/operations.h @@ -10,8 +10,6 @@ #include "cx.h" #include "types.h" -typedef bool (*is_operation_allowed_t)(enum operation_tag); - // Wire format that gets parsed into `signature_type`. typedef struct { uint8_t v; @@ -71,8 +69,7 @@ bool parse_operations(struct parsed_operation_group *const out, uint8_t const *const data, size_t length, derivation_type_t curve, - bip32_path_t const *const bip32_path, - is_operation_allowed_t is_operation_allowed); + bip32_path_t const *const bip32_path); bool parse_operations_final(struct parse_state *const state, struct parsed_operation_group *const out);