diff --git a/src/apdu-pubkey.c b/src/apdu-pubkey.c index 1d1c6d9..9db0467 100644 --- a/src/apdu-pubkey.c +++ b/src/apdu-pubkey.c @@ -121,11 +121,11 @@ encode_xpub( return b58enc(b58, b58_sz, data, sizeof(data)); } -uint8_t +uint16_t hns_apdu_get_public_key( uint8_t p1, uint8_t p2, - uint8_t len, + uint16_t len, volatile uint8_t *buf, volatile uint8_t *out, volatile uint8_t *flags diff --git a/src/apdu-signature.c b/src/apdu-signature.c index e013f51..9e233fe 100644 --- a/src/apdu-signature.c +++ b/src/apdu-signature.c @@ -158,7 +158,7 @@ static ledger_blake2b_ctx blake2; static inline bool parse_item( volatile uint8_t **buf, - uint8_t *len, + uint16_t *len, uint8_t *item, size_t item_sz, ledger_blake2b_ctx *hash @@ -193,7 +193,7 @@ parse_item( static inline bool parse_addr( volatile uint8_t **buf, - uint8_t *len, + uint16_t *len, uint8_t *addr_hash, uint8_t *addr_len, ledger_blake2b_ctx *hash @@ -228,7 +228,7 @@ parse_addr( static inline bool parse_name( volatile uint8_t **buf, - uint8_t *len, + uint16_t *len, char *name, uint8_t *name_len, ledger_blake2b_ctx *hash @@ -269,7 +269,7 @@ parse_name( static inline bool cmp_name( volatile uint8_t **buf, - uint8_t *len, + uint16_t *len, uint8_t *name_hash, char *name, uint8_t *name_len @@ -313,7 +313,7 @@ cmp_name( static inline bool parse_resource_len( volatile uint8_t **buf, - uint8_t *len, + uint16_t *len, hns_varint_t *ctr, ledger_blake2b_ctx *hash ) { @@ -346,7 +346,7 @@ parse_resource_len( static inline bool parse_resource( volatile uint8_t **buf, - uint8_t *len, + uint16_t *len, hns_varint_t *ctr, ledger_blake2b_ctx *hash ) { @@ -365,6 +365,7 @@ parse_resource( if (*ctr > 0) { if (*len != 0) THROW(HNS_INCORRECT_PARSER_STATE); + return false; } } @@ -391,7 +392,7 @@ parse_resource( static inline uint8_t parse( uint8_t p1, - uint8_t *len, + uint16_t *len, volatile uint8_t *buf, volatile uint8_t *res, volatile uint8_t *flags @@ -987,7 +988,7 @@ parse( static inline uint8_t sign( uint8_t p1, - uint8_t *len, + uint16_t *len, volatile uint8_t *buf, volatile uint8_t *sig, volatile uint8_t *flags @@ -1239,11 +1240,11 @@ sign( return 65; } -uint8_t +uint16_t hns_apdu_get_input_signature( uint8_t p1, uint8_t p2, - uint8_t len, + uint16_t len, volatile uint8_t *in, volatile uint8_t *out, volatile uint8_t *flags diff --git a/src/apdu.h b/src/apdu.h index bdf60fd..42ddeca 100644 --- a/src/apdu.h +++ b/src/apdu.h @@ -295,11 +295,11 @@ hns_apdu_get_app_version( * @return the status word */ -uint8_t +uint16_t hns_apdu_get_public_key( uint8_t p1, uint8_t p2, - uint8_t len, + uint16_t len, volatile uint8_t *in, volatile uint8_t *out, volatile uint8_t *flags @@ -320,11 +320,11 @@ hns_apdu_get_public_key( * @return the status word */ -uint8_t +uint16_t hns_apdu_get_input_signature( uint8_t p1, uint8_t p2, - uint8_t len, + uint16_t len, volatile uint8_t *in, volatile uint8_t *out, volatile uint8_t *flags diff --git a/src/ledger.c b/src/ledger.c index a09b3bc..3cb6051 100644 --- a/src/ledger.c +++ b/src/ledger.c @@ -119,11 +119,11 @@ ledger_apdu_cache_write(volatile uint8_t *src, uint8_t src_len) { } uint8_t -ledger_apdu_cache_flush(uint8_t *len) { +ledger_apdu_cache_flush(uint16_t *len) { uint8_t *cache = g_ledger_apdu_cache; uint8_t *buffer = g_ledger_apdu_buffer; uint8_t cache_len = g_ledger_apdu_cache_len; - uint8_t buffer_len = 0; + uint16_t buffer_len = 0; if (cache_len == 0) return 0; diff --git a/src/ledger.h b/src/ledger.h index df36fcc..7818c03 100644 --- a/src/ledger.h +++ b/src/ledger.h @@ -168,7 +168,7 @@ ledger_apdu_cache_write(volatile uint8_t *src, uint8_t src_len); * @return the amount of data added to the exchange buffer from the cache. */ uint8_t -ledger_apdu_cache_flush(uint8_t *len); +ledger_apdu_cache_flush(uint16_t *len); /** * Checks the apdu cache buffer for stored data. diff --git a/src/utils.h b/src/utils.h index 1588afc..3b4c48e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -239,7 +239,7 @@ size_varsize(size_t val) { } static inline bool -read_u8(volatile uint8_t **buf, uint8_t *len, uint8_t *u8) { +read_u8(volatile uint8_t **buf, uint16_t *len, uint8_t *u8) { if (*len < 1) return false; @@ -251,7 +251,7 @@ read_u8(volatile uint8_t **buf, uint8_t *len, uint8_t *u8) { } static inline bool -read_u16(volatile uint8_t **buf, uint8_t *len, uint16_t *u16, bool be) { +read_u16(volatile uint8_t **buf, uint16_t *len, uint16_t *u16, bool be) { if (*len < 2) return false; @@ -270,7 +270,7 @@ read_u16(volatile uint8_t **buf, uint8_t *len, uint16_t *u16, bool be) { } static inline bool -read_u32(volatile uint8_t **buf, uint8_t *len, uint32_t *u32, bool be) { +read_u32(volatile uint8_t **buf, uint16_t *len, uint32_t *u32, bool be) { if (*len < 4) return false; @@ -291,7 +291,7 @@ read_u32(volatile uint8_t **buf, uint8_t *len, uint32_t *u32, bool be) { } static inline bool -read_varint(volatile uint8_t **buf, uint8_t *len, hns_varint_t *varint) { +read_varint(volatile uint8_t **buf, uint16_t *len, hns_varint_t *varint) { if (*len < 1) return false; @@ -350,7 +350,7 @@ read_varint(volatile uint8_t **buf, uint8_t *len, hns_varint_t *varint) { } static inline bool -peek_varint(volatile uint8_t **buf, uint8_t *len, hns_varint_t *varint) { +peek_varint(volatile uint8_t **buf, uint16_t *len, hns_varint_t *varint) { if (!read_varint(buf, len, varint)) return false; @@ -363,7 +363,7 @@ peek_varint(volatile uint8_t **buf, uint8_t *len, hns_varint_t *varint) { } static inline bool -read_varsize(volatile uint8_t **buf, uint8_t *len, size_t *val) { +read_varsize(volatile uint8_t **buf, uint16_t *len, size_t *val) { hns_varint_t v; if (!read_varint(buf, len, &v)) @@ -375,7 +375,7 @@ read_varsize(volatile uint8_t **buf, uint8_t *len, size_t *val) { } static inline bool -read_bytes(volatile uint8_t **buf, uint8_t *len, volatile uint8_t *out, size_t sz) { +read_bytes(volatile uint8_t **buf, uint16_t *len, volatile uint8_t *out, size_t sz) { if (*len < sz) return false; @@ -390,7 +390,7 @@ read_bytes(volatile uint8_t **buf, uint8_t *len, volatile uint8_t *out, size_t s static inline bool read_varbytes( volatile uint8_t **buf, - uint8_t *len, + uint16_t *len, uint8_t *out, size_t out_sz, size_t *out_len @@ -412,6 +412,7 @@ read_varbytes( if (!read_bytes(buf, len, out, sz)) { *buf -= offset; *len += offset; + return false; } @@ -423,7 +424,7 @@ read_varbytes( static inline bool read_bip44_path( volatile uint8_t **buf, - uint8_t *len, + uint16_t *len, uint8_t *depth, uint32_t *path, uint8_t *info