From c29194ec465aaf3c5478c6b03ec70e4772518216 Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Tue, 17 Oct 2023 15:55:24 +0200 Subject: [PATCH] Review --- src/globals.h | 6 +++++- src/process_transaction.c | 2 ++ src/set_partner_key.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/globals.h b/src/globals.h index 2f6d1b27..7bf77b88 100644 --- a/src/globals.h +++ b/src/globals.h @@ -14,7 +14,7 @@ #define MAX_DER_SIGNATURE_LENGTH 72U #define CURVE_SECP256K1 0x00 -#define CURVE_256R1 0x01 +#define CURVE_SECP256R1 0x01 #define ENCODING_BYTES_ARRAY 0x00 #define ENCODING_BASE_64_URL 0x01 @@ -86,6 +86,10 @@ typedef struct swap_app_context_s { }; }; + // During TX reception, we don't know if we'll receive the signature of the (TX), or the + // signature of the ('.' + TX). + // Storing the whole TX to calculate the hash during signature checking would use too much + // stack, so we calculate the two hashes and we'll decide later which one to use. uint8_t sha256_digest_prefixed[32]; uint8_t sha256_digest_no_prefix[32]; diff --git a/src/process_transaction.c b/src/process_transaction.c index 002d88e7..b01f6e74 100644 --- a/src/process_transaction.c +++ b/src/process_transaction.c @@ -103,6 +103,8 @@ static bool calculate_sha256_digest(buf_t payload) { cx_sha256_init(&sha256_prefix); cx_sha256_init(&sha256_no_prefix); + // Calculate both WITH and WITHOUT the dot prefix. + // We don't know which one we'll need yet unsigned char dot = '.'; if (cx_hash_no_throw(&sha256_prefix.header, 0, &dot, 1, NULL, 0) != CX_OK) { PRINTF("Error: cx_hash_no_throw\n"); diff --git a/src/set_partner_key.c b/src/set_partner_key.c index b96e3257..91cd6c90 100644 --- a/src/set_partner_key.c +++ b/src/set_partner_key.c @@ -46,7 +46,7 @@ static uint16_t parse_set_partner_key_command(const command_t *cmd, } if (curve_id == CURVE_SECP256K1) { *curve = CX_CURVE_SECP256K1; - } else if (curve_id == CURVE_256R1) { + } else if (curve_id == CURVE_SECP256R1) { *curve = CX_CURVE_256R1; } else { PRINTF("Error: Incorrect curve specifier %d\n", curve_id);