Skip to content

Commit 2a0c52a

Browse files
authored
Merge pull request #65 from Zondax/dev
Upgrade to SDK 2.0
2 parents 544d4b3 + fe8a94a commit 2a0c52a

29 files changed

+507
-406
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ cmake-build-fuzz/
8888
\fuzz/corpora/*
8989

9090
node_modules/.yarn-integrity
91+
\.vscode

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
url = https://github.com/LedgerHQ/nanos-secure-sdk.git
44
[submodule "deps/nanox-secure-sdk"]
55
path = deps/nanox-secure-sdk
6-
url = https://github.com/LedgerHQ/nanox-secure-sdk.git
6+
url = https://github.com/Zondax/nanox-secure-sdk.git
77
[submodule "deps/picohash"]
88
path = deps/picohash
99
url = https://github.com/kazuho/picohash

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if (ENABLE_FUZZING)
4343
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,bugprone-*,cert-*,clang-analyzer-*,-cert-err58-cpp,misc-*,-bugprone-suspicious-include)
4444

4545
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
46-
# require at least clang 12
46+
# require at least clang 11
4747
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0)
4848
message(FATAL_ERROR "Clang version must be at least 11.0!")
4949
endif ()

app/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ COIN=ICP
5151
endif
5252

5353
APPVERSION_M=0
54-
APPVERSION_N=3
55-
APPVERSION_P=4
54+
APPVERSION_N=4
55+
APPVERSION_P=0
5656

5757
$(info COIN = [$(COIN)])
5858
ifeq ($(COIN),ICP)
@@ -135,7 +135,6 @@ SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
135135
else
136136
# Assume Nano S
137137
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
138-
DEFINES += COMPLIANCE_UX_160 HAVE_UX_LEGACY
139138
endif
140139

141140
# X specific
@@ -149,8 +148,8 @@ DEFINES += LEDGER_SPECIFIC
149148

150149
ifneq ($(BOLOS_ENV),)
151150
$(info BOLOS_ENV is $(BOLOS_ENV))
152-
CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/
153-
GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/
151+
CLANGPATH := /usr/bin/
152+
GCCPATH := /usr/bin/
154153
else
155154
$(info BOLOS_ENV is not set: falling back to CLANGPATH and GCCPATH)
156155
endif
@@ -166,7 +165,7 @@ endif
166165
#########################
167166

168167
CC := $(CLANGPATH)clang
169-
CFLAGS += -O3 -Os -Wno-unknown-pragmas
168+
CFLAGS += -O3 -Os -Wno-unknown-pragmas -Wno-implicit-fallthrough
170169

171170
AS := $(GCCPATH)arm-none-eabi-gcc
172171
AFLAGS +=

app/src/addr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "app_mode.h"
2222
#include "crypto.h"
2323
#include "actions.h"
24+
#include "formatting.h"
2425

2526
zxerr_t addr_getNumItems(uint8_t *num_items) {
2627
zemu_log_stack("addr_getNumItems");

app/src/base32.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121

2222
#include <string.h>
2323

24-
uint32_t base32_encode(const uint8_t *data, unsigned int length, char *result, uint32_t bufSize) {
24+
uint32_t base32_encode(const uint8_t *data,
25+
uint32_t length,
26+
char *result,
27+
uint32_t resultLen) {
2528
if (length < 0 || length > (1 << 28)) {
2629
return -1;
2730
}
@@ -30,7 +33,7 @@ uint32_t base32_encode(const uint8_t *data, unsigned int length, char *result, u
3033
uint32_t buffer = data[0];
3134
uint32_t next = 1;
3235
uint32_t bitsLeft = 8;
33-
while (count < bufSize && (bitsLeft > 0 || next < length)) {
36+
while (count < resultLen && (bitsLeft > 0 || next < length)) {
3437
if (bitsLeft < 5) {
3538
if (next < length) {
3639
buffer <<= 8;
@@ -47,7 +50,7 @@ uint32_t base32_encode(const uint8_t *data, unsigned int length, char *result, u
4750
result[count++] = "abcdefghijklmnopqrstuvwxyz234567"[index];
4851
}
4952
}
50-
if (count < bufSize) {
53+
if (count < resultLen) {
5154
result[count] = '\000';
5255
}
5356
return count;

app/src/common/actions.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
extern uint16_t action_addrResponseLen;
2727

2828
__Z_INLINE void app_sign() {
29-
const uint8_t *message = tx_get_buffer();
30-
const uint16_t messageLength = tx_get_buffer_length();
3129
uint16_t replyLen = 0;
3230

3331
MEMZERO(G_io_apdu_buffer, IO_APDU_BUFFER_SIZE);
34-
zxerr_t err = crypto_sign(G_io_apdu_buffer, IO_APDU_BUFFER_SIZE - 3, message, messageLength, &replyLen);
32+
zxerr_t err = crypto_sign(G_io_apdu_buffer, IO_APDU_BUFFER_SIZE - 3, &replyLen);
3533

3634
if (err != zxerr_ok || replyLen == 0) {
3735
set_code(G_io_apdu_buffer, 0, APDU_CODE_SIGN_VERIFY_ERROR);
@@ -43,6 +41,7 @@ __Z_INLINE void app_sign() {
4341
}
4442

4543
__Z_INLINE void app_reject() {
44+
MEMZERO(G_io_apdu_buffer, IO_APDU_BUFFER_SIZE);
4645
set_code(G_io_apdu_buffer, 0, APDU_CODE_COMMAND_NOT_ALLOWED);
4746
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
4847
}

app/src/common/app_main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];
3434

3535
unsigned char io_event(unsigned char channel) {
36+
UNUSED(channel);
37+
3638
switch (G_io_seproxyhal_spi_buffer[0]) {
3739
case SEPROXYHAL_TAG_FINGER_EVENT: //
3840
UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer);
@@ -111,6 +113,7 @@ void extractHDPath(uint32_t rx, uint32_t offset) {
111113
}
112114

113115
bool process_chunk(volatile uint32_t *tx, uint32_t rx) {
116+
UNUSED(tx);
114117
const uint8_t payloadType = G_io_apdu_buffer[OFFSET_PAYLOAD_TYPE];
115118

116119
if (G_io_apdu_buffer[OFFSET_P2] != 0) {
@@ -146,7 +149,9 @@ bool process_chunk(volatile uint32_t *tx, uint32_t rx) {
146149
}
147150

148151
void handle_generic_apdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
149-
if (rx > 4 && os_memcmp(G_io_apdu_buffer, "\xE0\x01\x00\x00", 4) == 0) {
152+
UNUSED(flags);
153+
154+
if (rx > 4 && MEMCMP(G_io_apdu_buffer, "\xE0\x01\x00\x00", 4) == 0) {
150155
// Respond to get device info command
151156
uint8_t *p = G_io_apdu_buffer;
152157
// Target ID 4 bytes

app/src/common/app_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx);
4747
void handle_generic_apdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx);
4848

4949
__Z_INLINE void handle_getversion(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
50+
UNUSED(flags);
51+
UNUSED(rx);
5052
#ifdef DEBUG
5153
G_io_apdu_buffer[0] = 0xFF;
5254
#else

app/src/crypto.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ zxerr_t crypto_extractPublicKey(const uint32_t path[HDPATH_LEN_DEFAULT], uint8_t
7272
cx_ecfp_init_public_key(CX_CURVE_256K1, NULL, 0, &cx_publicKey);
7373
cx_ecfp_generate_pair(CX_CURVE_256K1, &cx_publicKey, &cx_privateKey, 1);
7474
}
75+
CATCH_OTHER(e) {
76+
return zxerr_ledger_api_error;
77+
}
7578
FINALLY {
7679
MEMZERO(&cx_privateKey, sizeof(cx_privateKey));
7780
MEMZERO(privateKeyData, 32);
@@ -88,8 +91,8 @@ typedef struct {
8891
uint8_t s[32];
8992
uint8_t v;
9093

91-
// // DER signature max size should be 73
92-
// // https://bitcoin.stackexchange.com/questions/77191/what-is-the-maximum-size-of-a-der-encoded-ecdsa-signature#77192
94+
// DER signature max size should be 73
95+
// https://bitcoin.stackexchange.com/questions/77191/what-is-the-maximum-size-of-a-der-encoded-ecdsa-signature#77192
9396
uint8_t der_signature[73];
9497

9598
} __attribute__((packed)) signature_t;
@@ -189,8 +192,6 @@ zxerr_t crypto_getDigest(uint8_t *digest, txtype_e txtype){
189192

190193
zxerr_t crypto_sign(uint8_t *signatureBuffer,
191194
uint16_t signatureMaxlen,
192-
const uint8_t *message,
193-
uint16_t messageLen,
194195
uint16_t *sigSize) {
195196
if (signatureMaxlen < SIGN_PREHASH_SIZE + sizeof(signature_t)){
196197
return zxerr_buffer_too_small;

0 commit comments

Comments
 (0)