Skip to content

Commit c0131bd

Browse files
committed
Also support derivation paths of length 3.
1 parent 07885ed commit c0131bd

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

app/src/addr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ zxerr_t addr_getItem(int8_t displayIdx,
5555

5656
snprintf(outKey, outKeyLen, "Your Path");
5757
char buffer[300];
58-
bip32_to_str(buffer, sizeof(buffer), hdPath, HDPATH_LEN_DEFAULT);
58+
bip32_to_str(buffer, sizeof(buffer), hdPath, hdPathLen);
5959
pageString(outVal, outValLen, buffer, pageIdx, pageCount);
6060
return zxerr_ok;
6161
}

app/src/apdu_handler.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ __Z_INLINE void extractHDPath(uint32_t rx, uint32_t offset) {
3939
ZEMU_LOGF(50, "Extract HDPath\n")
4040
tx_initialized = false;
4141

42-
const uint8_t pathLength = G_io_apdu_buffer[offset];
42+
hdPathLen = G_io_apdu_buffer[offset];
4343
offset++;
4444

45-
if (pathLength != HDPATH_LEN_DEFAULT || (rx - offset) != sizeof(uint32_t) * pathLength) {
45+
if ((hdPathLen != HDPATH_LEN_DEFAULT && hdPathLen != IDENTITY_DER_PATH_LEN) || (rx - offset) != sizeof(uint32_t) * hdPathLen) {
4646
THROW(APDU_CODE_WRONG_LENGTH);
4747
}
4848

49-
memcpy(hdPath, G_io_apdu_buffer + offset, sizeof(uint32_t) * HDPATH_LEN_DEFAULT);
49+
memcpy(hdPath, G_io_apdu_buffer + offset, sizeof(uint32_t) * hdPathLen);
5050

5151
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT &&
5252
hdPath[1] == HDPATH_1_DEFAULT;

app/src/coin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern "C" {
2222
#define CLA 0x57
2323

2424
#define HDPATH_LEN_DEFAULT 5
25+
#define IDENTITY_DER_PATH_LEN 3
2526
#define HDPATH_0_DEFAULT (0x80000000u | 0x2cu) //44
2627

2728
#define HDPATH_1_DEFAULT (0x80000000u | 0x36d) //877

app/src/crypto.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static zxerr_t crypto_extractPublicKey_ed25519(uint8_t *pubKey, uint16_t pubKeyL
7070
CATCH_CXERROR(os_derive_bip32_with_seed_no_throw(HDW_ED25519_SLIP10,
7171
CX_CURVE_Ed25519,
7272
hdPath,
73-
HDPATH_LEN_DEFAULT,
73+
hdPathLen,
7474
privateKeyData,
7575
NULL,
7676
NULL,
@@ -111,7 +111,7 @@ static zxerr_t crypto_sign_ed25519(uint8_t *output, uint16_t outputLen, const ui
111111
CATCH_CXERROR(os_derive_bip32_with_seed_no_throw(HDW_ED25519_SLIP10,
112112
CX_CURVE_Ed25519,
113113
hdPath,
114-
HDPATH_LEN_DEFAULT,
114+
hdPathLen,
115115
privateKeyData,
116116
NULL,
117117
NULL,
@@ -550,7 +550,7 @@ zxerr_t crypto_computeSaplingSeed(uint8_t spendingKey[static KEY_LENGTH]) {
550550
CATCH_CXERROR(os_derive_bip32_with_seed_no_throw(HDW_NORMAL,
551551
CX_CURVE_Ed25519,
552552
hdPath,
553-
HDPATH_LEN_DEFAULT,
553+
hdPathLen,
554554
privateKeyData,
555555
NULL, NULL, 0));
556556
memcpy(spendingKey, privateKeyData, KEY_LENGTH);

app/src/crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern "C" {
2727
#include "parser_txdef.h"
2828

2929
extern uint32_t hdPath[HDPATH_LEN_DEFAULT];
30+
extern uint8_t hdPathLen;
3031

3132
zxerr_t crypto_fillAddress(signing_key_type_e addressKind, uint8_t *buffer, uint16_t bufferLen, uint16_t *cmdResponseLen);
3233
zxerr_t crypto_sign(const parser_tx_t *txObj, uint8_t *output, uint16_t outputLen);

app/src/crypto_helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "blake2.h"
5353

5454
uint32_t hdPath[HDPATH_LEN_DEFAULT];
55+
uint8_t hdPathLen;
5556

5657
uint8_t bech32_hrp_len;
5758
char bech32_hrp[MAX_BECH32_HRP_LEN + 1];

app/src/review_keys.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ zxerr_t getItemPublicAddress(int8_t displayIdx, char *outKey, uint16_t outKeyLen
5151
case 1: {
5252
snprintf(outKey, outKeyLen, "HD Path");
5353
char buffer[200] = {0};
54-
bip32_to_str(buffer, sizeof(buffer), hdPath, HDPATH_LEN_DEFAULT);
54+
bip32_to_str(buffer, sizeof(buffer), hdPath, hdPathLen);
5555
pageString(outVal, outValLen, buffer, pageIdx, pageCount);
5656
break;
5757
}
@@ -90,7 +90,7 @@ zxerr_t getItemProofGenerationKey(int8_t displayIdx, char *outKey, uint16_t outK
9090
case 2: {
9191
snprintf(outKey, outKeyLen, "HD Path");
9292
char buffer[200] = {0};
93-
bip32_to_str(buffer, sizeof(buffer), hdPath, HDPATH_LEN_DEFAULT);
93+
bip32_to_str(buffer, sizeof(buffer), hdPath, hdPathLen);
9494
pageString(outVal, outValLen, buffer, pageIdx, pageCount);
9595
break;
9696
}
@@ -135,7 +135,7 @@ zxerr_t getItemViewKey(int8_t displayIdx, char *outKey, uint16_t outKeyLen, char
135135
case 3: {
136136
snprintf(outKey, outKeyLen, "HD Path");
137137
char buffer[200] = {0};
138-
bip32_to_str(buffer, sizeof(buffer), hdPath, HDPATH_LEN_DEFAULT);
138+
bip32_to_str(buffer, sizeof(buffer), hdPath, hdPathLen);
139139
pageString(outVal, outValLen, buffer, pageIdx, pageCount);
140140
break;
141141
}

0 commit comments

Comments
 (0)