diff --git a/src_features/signMessageEIP712/entrypoint.c b/src_features/signMessageEIP712/entrypoint.c index 5aff3e2..1fddbee 100644 --- a/src_features/signMessageEIP712/entrypoint.c +++ b/src_features/signMessageEIP712/entrypoint.c @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -11,6 +10,7 @@ #include "sol_typenames.h" #include "field_hash.h" #include "path.h" +#include "shared_context.h" // lib functions @@ -374,7 +374,7 @@ bool handle_apdu(const uint8_t *const data) set_struct_field(data); break; default: - printf("Unknown P2 0x%x for APDU 0x%x\n", data[OFFSET_P2], data[OFFSET_INS]); + PRINTF("Unknown P2 0x%x for APDU 0x%x\n", data[OFFSET_P2], data[OFFSET_INS]); return false; } break; @@ -396,12 +396,12 @@ bool handle_apdu(const uint8_t *const data) path_new_array_depth(data[OFFSET_DATA]); break; default: - printf("Unknown P2 0x%x for APDU 0x%x\n", data[OFFSET_P2], data[OFFSET_INS]); + PRINTF("Unknown P2 0x%x for APDU 0x%x\n", data[OFFSET_P2], data[OFFSET_INS]); return false; } break; default: - printf("Unrecognized APDU (0x%.02x)\n", data[OFFSET_INS]); + PRINTF("Unrecognized APDU (0x%.02x)\n", data[OFFSET_INS]); return false; } return true; @@ -444,12 +444,12 @@ int main(void) else idx += 1; break; default: - printf("Unexpected APDU state!\n"); + PRINTF("Unexpected APDU state!\n"); return EXIT_FAILURE; } } #ifdef DEBUG - printf("%lu bytes used in RAM\n", (mem_max + 1)); + PRINTF("%lu bytes used in RAM\n", (mem_max + 1)); #endif return EXIT_SUCCESS; } diff --git a/src_features/signMessageEIP712/field_hash.c b/src_features/signMessageEIP712/field_hash.c index 0996118..25e7dbf 100644 --- a/src_features/signMessageEIP712/field_hash.c +++ b/src_features/signMessageEIP712/field_hash.c @@ -1,4 +1,3 @@ -#include #include #include "field_hash.h" #include "encode_field.h" @@ -74,13 +73,13 @@ const uint8_t *field_hash(const uint8_t *data, { return NULL; } - printf("==> "); + PRINTF("==> "); type = get_struct_field_typename(field_ptr, &typelen); fwrite(type, sizeof(char), typelen, stdout); - printf(" "); + PRINTF(" "); key = get_struct_field_keyname(field_ptr, &keylen); fwrite(key, sizeof(char), keylen, stdout); - printf("\n"); + PRINTF("\n"); if (!IS_DYN(field_type)) { @@ -101,7 +100,7 @@ const uint8_t *field_hash(const uint8_t *data, break; case TYPE_CUSTOM: default: - printf("Unknown solidity type!\n"); + PRINTF("Unknown solidity type!\n"); return NULL; } @@ -141,7 +140,7 @@ const uint8_t *field_hash(const uint8_t *data, 0); // deallocate it mem_dealloc(len); - printf("FEED %d\n", len); + PRINTF("FEED %d\n", len); path_advance(); fh->state = FHS_IDLE; diff --git a/src_features/signMessageEIP712/mem.c b/src_features/signMessageEIP712/mem.c index 655d84a..799be1f 100644 --- a/src_features/signMessageEIP712/mem.c +++ b/src_features/signMessageEIP712/mem.c @@ -1,8 +1,6 @@ #include -#ifdef DEBUG -#include -#endif #include "mem.h" +#include "shared_context.h" #define SIZE_MEM_BUFFER 8192 @@ -46,7 +44,7 @@ void *mem_alloc(size_t size) if ((mem_idx + size) > SIZE_MEM_BUFFER) // Buffer exceeded { #ifdef DEBUG - printf("Memory exhausted!\n"); + PRINTF("Memory exhausted!\n"); #endif return NULL; } diff --git a/src_features/signMessageEIP712/path.c b/src_features/signMessageEIP712/path.c index 9dbabfa..c681193 100644 --- a/src_features/signMessageEIP712/path.c +++ b/src_features/signMessageEIP712/path.c @@ -1,6 +1,5 @@ #include #include -#include #include "path.h" #include "mem.h" #include "context.h" @@ -123,12 +122,12 @@ static bool path_depth_list_pop(void) mem_dealloc(sizeof(cx_sha3_t)); // remove hash context #ifdef DEBUG // print computed hash - printf("SHASH POP 0x"); + PRINTF("SHASH POP 0x"); for (int idx = 0; idx < KECCAK256_HASH_BYTESIZE; ++idx) { - printf("%.02x", shash[idx]); + PRINTF("%.02x", shash[idx]); } - printf("\n"); + PRINTF("\n"); #endif if (path_struct->depth_count > 0) { @@ -143,7 +142,7 @@ static bool path_depth_list_pop(void) } else { - printf("\n"); + PRINTF("\n"); } return true; @@ -202,7 +201,7 @@ static bool array_depth_list_pop(void) KECCAK256_HASH_BYTESIZE, NULL, 0); - printf("AHASH POP\n"); + PRINTF("AHASH POP\n"); path_struct->array_depth_count -= 1; return true; @@ -262,7 +261,7 @@ static bool path_update(void) 0); // deallocate it mem_dealloc(KECCAK256_HASH_BYTESIZE); - printf("SHASH PUSH w/o deps %p\n", hash_ctx); + PRINTF("SHASH PUSH w/o deps %p\n", hash_ctx); path_depth_list_push(); } @@ -311,7 +310,7 @@ bool path_set_root(const char *const struct_name, uint8_t name_length) 0); // deallocate it mem_dealloc(KECCAK256_HASH_BYTESIZE); - printf("SHASH PUSH w/ deps %p\n", hash_ctx); + PRINTF("SHASH PUSH w/ deps %p\n", hash_ctx); // // init depth, at 0 : empty path @@ -355,7 +354,7 @@ static bool check_and_add_array_depth(const void *depth, expected_type = struct_field_array_depth(depth, &expected_size); if ((expected_type == ARRAY_FIXED_SIZE) && (expected_size != size)) { - printf("Unexpected array depth size. (expected %d, got %d)\n", + PRINTF("Unexpected array depth size. (expected %d, got %d)\n", expected_size, size); return false; } @@ -382,7 +381,7 @@ bool path_new_array_depth(uint8_t size) if (path_struct == NULL) // sanity check { - printf("NULL struct check failed\n"); + PRINTF("NULL struct check failed\n"); return false; } @@ -412,7 +411,7 @@ bool path_new_array_depth(uint8_t size) if (pidx == path_struct->depth_count) { - printf("Did not find a matching array type.\n"); + PRINTF("Did not find a matching array type.\n"); return false; } // TODO: Move elsewhere @@ -421,20 +420,20 @@ bool path_new_array_depth(uint8_t size) { return false; } - printf("AHASH PUSH %p", hash_ctx); + PRINTF("AHASH PUSH %p", hash_ctx); if (struct_field_type(field_ptr) == TYPE_CUSTOM) { cx_sha3_t *old_ctx = (void*)hash_ctx - sizeof(cx_sha3_t); memcpy(hash_ctx, old_ctx, sizeof(cx_sha3_t)); cx_keccak_init((cx_hash_t*)old_ctx, 256); // init hash - printf(" (switched)"); + PRINTF(" (switched)"); } else // solidity type { cx_keccak_init((cx_hash_t*)hash_ctx, 256); // init hash } - printf("\n"); + PRINTF("\n"); return true; } diff --git a/src_features/signMessageEIP712/type_hash.c b/src_features/signMessageEIP712/type_hash.c index eda0f75..4c6e6ec 100644 --- a/src_features/signMessageEIP712/type_hash.c +++ b/src_features/signMessageEIP712/type_hash.c @@ -1,7 +1,6 @@ #include #include #include -#include #include "mem.h" #include "mem_utils.h" #include "eip712.h" @@ -13,7 +12,7 @@ static inline void hash_nbytes(const uint8_t *b, uint8_t n) #ifdef DEBUG for (int i = 0; i < n; ++i) { - printf("%c", b[i]); + PRINTF("%c", b[i]); } #endif cx_hash((cx_hash_t*)&global_sha3, @@ -305,7 +304,7 @@ const uint8_t *type_hash(const void *const structs_array, mem_dealloc(sizeof(void*) * deps_count); } #ifdef DEBUG - printf("\n"); + PRINTF("\n"); #endif // End progressive hashing if ((hash_ptr = mem_alloc(KECCAK256_HASH_BYTESIZE)) == NULL) @@ -321,12 +320,12 @@ const uint8_t *type_hash(const void *const structs_array, KECCAK256_HASH_BYTESIZE); #ifdef DEBUG // print computed hash - printf("new -> 0x"); + PRINTF("new -> 0x"); for (int idx = 0; idx < KECCAK256_HASH_BYTESIZE; ++idx) { - printf("%.02x", hash_ptr[idx]); + PRINTF("%.02x", hash_ptr[idx]); } - printf("\n"); + PRINTF("\n"); #endif return hash_ptr; }