Fix deprecated warnings
This commit is contained in:
@@ -52,6 +52,7 @@ static const uint8_t *field_hash_prepare(const void *const field_ptr,
|
||||
const uint8_t *data,
|
||||
uint8_t *data_length) {
|
||||
e_type field_type;
|
||||
cx_err_t error = CX_INTERNAL_ERROR;
|
||||
|
||||
field_type = struct_field_type(field_ptr);
|
||||
fh->remaining_size = __builtin_bswap16(*(uint16_t *) &data[0]); // network byte order
|
||||
@@ -59,10 +60,12 @@ static const uint8_t *field_hash_prepare(const void *const field_ptr,
|
||||
*data_length -= sizeof(uint16_t);
|
||||
fh->state = FHS_WAITING_FOR_MORE;
|
||||
if (IS_DYN(field_type)) {
|
||||
cx_keccak_init(&global_sha3, 256); // init hash
|
||||
CX_CHECK(cx_keccak_init_no_throw(&global_sha3, 256));
|
||||
ui_712_new_field(field_ptr, data, *data_length);
|
||||
}
|
||||
return data;
|
||||
end:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,14 +123,22 @@ static const uint8_t *field_hash_finalize_static(const void *const field_ptr,
|
||||
*/
|
||||
static uint8_t *field_hash_finalize_dynamic(void) {
|
||||
uint8_t *value;
|
||||
cx_err_t error = CX_INTERNAL_ERROR;
|
||||
|
||||
if ((value = mem_alloc(KECCAK256_HASH_BYTESIZE)) == NULL) {
|
||||
apdu_response_code = APDU_RESPONSE_INSUFFICIENT_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
// copy hash into memory
|
||||
cx_hash((cx_hash_t *) &global_sha3, CX_LAST, NULL, 0, value, KECCAK256_HASH_BYTESIZE);
|
||||
CX_CHECK(cx_hash_no_throw((cx_hash_t *) &global_sha3,
|
||||
CX_LAST,
|
||||
NULL,
|
||||
0,
|
||||
value,
|
||||
KECCAK256_HASH_BYTESIZE));
|
||||
return value;
|
||||
end:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,6 +63,7 @@ static bool verify_filtering_signature(uint8_t dname_length,
|
||||
cx_ecfp_public_key_t verifying_key;
|
||||
cx_sha256_t hash_ctx;
|
||||
uint64_t chain_id;
|
||||
cx_err_t error = CX_INTERNAL_ERROR;
|
||||
|
||||
cx_sha256_init(&hash_ctx);
|
||||
|
||||
@@ -105,13 +106,13 @@ static bool verify_filtering_signature(uint8_t dname_length,
|
||||
hash_nbytes((uint8_t *) dname, sizeof(char) * dname_length, (cx_hash_t *) &hash_ctx);
|
||||
|
||||
// Finalize hash
|
||||
cx_hash((cx_hash_t *) &hash_ctx, CX_LAST, NULL, 0, hash, INT256_LENGTH);
|
||||
CX_CHECK(cx_hash_no_throw((cx_hash_t *) &hash_ctx, CX_LAST, NULL, 0, hash, INT256_LENGTH));
|
||||
|
||||
cx_ecfp_init_public_key(CX_CURVE_256K1,
|
||||
LEDGER_SIGNATURE_PUBLIC_KEY,
|
||||
sizeof(LEDGER_SIGNATURE_PUBLIC_KEY),
|
||||
&verifying_key);
|
||||
if (!cx_ecdsa_verify(&verifying_key, CX_LAST, CX_SHA256, hash, sizeof(hash), sig, sig_length)) {
|
||||
CX_CHECK(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1,
|
||||
LEDGER_SIGNATURE_PUBLIC_KEY,
|
||||
sizeof(LEDGER_SIGNATURE_PUBLIC_KEY),
|
||||
&verifying_key));
|
||||
if (!cx_ecdsa_verify_no_throw(&verifying_key, hash, sizeof(hash), sig, sig_length)) {
|
||||
#ifndef HAVE_BYPASS_SIGNATURES
|
||||
PRINTF("Invalid EIP-712 filtering signature\n");
|
||||
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
|
||||
@@ -119,6 +120,8 @@ static bool verify_filtering_signature(uint8_t dname_length,
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
end:
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -147,13 +147,17 @@ static cx_sha3_t *get_last_hash_ctx(void) {
|
||||
static bool finalize_hash_depth(uint8_t *hash) {
|
||||
const cx_sha3_t *hash_ctx;
|
||||
size_t hashed_bytes;
|
||||
cx_err_t error = CX_INTERNAL_ERROR;
|
||||
|
||||
hash_ctx = get_last_hash_ctx();
|
||||
hashed_bytes = hash_ctx->blen;
|
||||
// finalize hash
|
||||
cx_hash((cx_hash_t *) hash_ctx, CX_LAST, NULL, 0, hash, KECCAK256_HASH_BYTESIZE);
|
||||
CX_CHECK(
|
||||
cx_hash_no_throw((cx_hash_t *) hash_ctx, CX_LAST, NULL, 0, hash, KECCAK256_HASH_BYTESIZE));
|
||||
mem_dealloc(sizeof(*hash_ctx)); // remove hash context
|
||||
return hashed_bytes > 0;
|
||||
end:
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +170,7 @@ static void feed_last_hash_depth(const uint8_t *const hash) {
|
||||
|
||||
hash_ctx = get_last_hash_ctx();
|
||||
// continue progressive hash with the array hash
|
||||
cx_hash((cx_hash_t *) hash_ctx, 0, hash, KECCAK256_HASH_BYTESIZE, NULL, 0);
|
||||
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) hash_ctx, 0, hash, KECCAK256_HASH_BYTESIZE, NULL, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,15 +181,18 @@ static void feed_last_hash_depth(const uint8_t *const hash) {
|
||||
*/
|
||||
static bool push_new_hash_depth(bool init) {
|
||||
cx_sha3_t *hash_ctx;
|
||||
cx_err_t error = CX_INTERNAL_ERROR;
|
||||
|
||||
// allocate new hash context
|
||||
if ((hash_ctx = MEM_ALLOC_AND_ALIGN_TYPE(*hash_ctx)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (init) {
|
||||
cx_keccak_init(hash_ctx, 256); // initialize it
|
||||
CX_CHECK(cx_keccak_init_no_throw(hash_ctx, 256));
|
||||
}
|
||||
return true;
|
||||
end:
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,7 +301,6 @@ static bool path_update(void) {
|
||||
if ((field_ptr = get_field(NULL)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
struct_ptr = path_struct->root_struct;
|
||||
while (struct_field_type(field_ptr) == TYPE_CUSTOM) {
|
||||
typename = get_struct_field_typename(field_ptr, &typename_len);
|
||||
if ((struct_ptr = get_structn(typename, typename_len)) == NULL) {
|
||||
@@ -432,6 +438,7 @@ bool path_new_array_depth(const uint8_t *const data, uint8_t length) {
|
||||
bool is_custom;
|
||||
uint8_t array_size;
|
||||
uint8_t array_depth_count_bak;
|
||||
cx_err_t error = CX_INTERNAL_ERROR;
|
||||
|
||||
if (path_struct == NULL) {
|
||||
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
|
||||
@@ -479,9 +486,9 @@ bool path_new_array_depth(const uint8_t *const data, uint8_t length) {
|
||||
if (array_size > 0) {
|
||||
memcpy(hash_ctx, old_ctx, sizeof(*old_ctx));
|
||||
} else {
|
||||
cx_keccak_init(hash_ctx, 256);
|
||||
CX_CHECK(cx_keccak_init_no_throw(hash_ctx, 256));
|
||||
}
|
||||
cx_keccak_init(old_ctx, 256); // init hash
|
||||
CX_CHECK(cx_keccak_init_no_throw(old_ctx, 256));
|
||||
}
|
||||
if (array_size == 0) {
|
||||
do {
|
||||
@@ -490,6 +497,8 @@ bool path_new_array_depth(const uint8_t *const data, uint8_t length) {
|
||||
}
|
||||
|
||||
return true;
|
||||
end:
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ bool compute_schema_hash(void) {
|
||||
const char *name;
|
||||
uint8_t name_length;
|
||||
cx_sha224_t hash_ctx;
|
||||
cx_err_t error = CX_INTERNAL_ERROR;
|
||||
|
||||
cx_sha224_init(&hash_ctx);
|
||||
|
||||
@@ -61,13 +62,15 @@ bool compute_schema_hash(void) {
|
||||
hash_byte('}', (cx_hash_t *) &hash_ctx);
|
||||
|
||||
// copy hash into context struct
|
||||
cx_hash((cx_hash_t *) &hash_ctx,
|
||||
CX_LAST,
|
||||
NULL,
|
||||
0,
|
||||
eip712_context->schema_hash,
|
||||
sizeof(eip712_context->schema_hash));
|
||||
CX_CHECK(cx_hash_no_throw((cx_hash_t *) &hash_ctx,
|
||||
CX_LAST,
|
||||
NULL,
|
||||
0,
|
||||
eip712_context->schema_hash,
|
||||
sizeof(eip712_context->schema_hash)));
|
||||
return true;
|
||||
end:
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
@@ -171,8 +171,9 @@ bool type_hash(const char *const struct_name, const uint8_t struct_name_length,
|
||||
uint8_t deps_count = 0;
|
||||
const void **deps;
|
||||
void *mem_loc_bak = mem_alloc(0);
|
||||
cx_err_t error = CX_INTERNAL_ERROR;
|
||||
|
||||
cx_keccak_init(&global_sha3, 256); // init hash
|
||||
CX_CHECK(cx_keccak_init_no_throw(&global_sha3, 256));
|
||||
deps = get_struct_dependencies(&deps_count, NULL, struct_ptr);
|
||||
if ((deps_count > 0) && (deps == NULL)) {
|
||||
return false;
|
||||
@@ -191,8 +192,15 @@ bool type_hash(const char *const struct_name, const uint8_t struct_name_length,
|
||||
mem_dealloc(mem_alloc(0) - mem_loc_bak);
|
||||
|
||||
// copy hash into memory
|
||||
cx_hash((cx_hash_t *) &global_sha3, CX_LAST, NULL, 0, hash_buf, KECCAK256_HASH_BYTESIZE);
|
||||
CX_CHECK(cx_hash_no_throw((cx_hash_t *) &global_sha3,
|
||||
CX_LAST,
|
||||
NULL,
|
||||
0,
|
||||
hash_buf,
|
||||
KECCAK256_HASH_BYTESIZE));
|
||||
return true;
|
||||
end:
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // HAVE_EIP712_FULL_SUPPORT
|
||||
|
||||
@@ -58,7 +58,7 @@ static const uint8_t *field_skip_typedesc(const uint8_t *field_ptr, const uint8_
|
||||
* @return pointer to the data right after
|
||||
*/
|
||||
static const uint8_t *field_skip_typename(const uint8_t *field_ptr, const uint8_t *ptr) {
|
||||
uint8_t size;
|
||||
uint8_t size = 0;
|
||||
|
||||
if (struct_field_type(field_ptr) == TYPE_CUSTOM) {
|
||||
get_string_in_mem(ptr, &size);
|
||||
@@ -89,7 +89,7 @@ static const uint8_t *field_skip_typesize(const uint8_t *field_ptr, const uint8_
|
||||
* @return pointer to the data right after
|
||||
*/
|
||||
static const uint8_t *field_skip_array_levels(const uint8_t *field_ptr, const uint8_t *ptr) {
|
||||
uint8_t size;
|
||||
uint8_t size = 0;
|
||||
|
||||
if (struct_field_is_array(field_ptr)) {
|
||||
ptr = get_array_in_mem(ptr, &size);
|
||||
@@ -108,11 +108,12 @@ static const uint8_t *field_skip_array_levels(const uint8_t *field_ptr, const ui
|
||||
* @return pointer to the data right after
|
||||
*/
|
||||
static const uint8_t *field_skip_keyname(const uint8_t *field_ptr, const uint8_t *ptr) {
|
||||
uint8_t size;
|
||||
uint8_t size = 0;
|
||||
uint8_t *new_ptr;
|
||||
|
||||
(void) field_ptr;
|
||||
ptr = get_array_in_mem(ptr, &size);
|
||||
return ptr + size;
|
||||
new_ptr = (uint8_t *) get_array_in_mem(ptr, &size);
|
||||
return (const uint8_t *) (new_ptr + size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +417,7 @@ const uint8_t *get_structs_array(uint8_t *const length) {
|
||||
* @return pointer to struct
|
||||
*/
|
||||
const uint8_t *get_structn(const char *const name, const uint8_t length) {
|
||||
uint8_t structs_count;
|
||||
uint8_t structs_count = 0;
|
||||
const uint8_t *struct_ptr;
|
||||
const char *struct_name;
|
||||
uint8_t name_length;
|
||||
|
||||
@@ -247,7 +247,6 @@ static bool ui_712_format_addr(const uint8_t *const data, uint8_t length) {
|
||||
if (!getEthDisplayableAddress((uint8_t *) data,
|
||||
strings.tmp.tmp,
|
||||
sizeof(strings.tmp.tmp),
|
||||
&global_sha3,
|
||||
chainConfig->chainId)) {
|
||||
THROW(APDU_RESPONSE_ERROR_NO_INFO);
|
||||
}
|
||||
@@ -292,7 +291,7 @@ static void ui_712_format_bytes(const uint8_t *const data, uint8_t length) {
|
||||
// x2 for each byte value is represented by 2 ASCII characters
|
||||
if ((2 + (length * 2)) > (sizeof(strings.tmp.tmp) - 1)) {
|
||||
strings.tmp.tmp[sizeof(strings.tmp.tmp) - 1 - 3] = '\0';
|
||||
strcat(strings.tmp.tmp, "...");
|
||||
strlcat(strings.tmp.tmp, "...", sizeof(strings.tmp.tmp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user