Now prefixes the type hash with a marker
This commit is contained in:
@@ -57,6 +57,13 @@ typedef enum
|
||||
#define TYPESIZE_MASK (1 << 6)
|
||||
#define TYPENAME_ENUM (0xF)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EIP712_TYPE_HASH,
|
||||
EIP712_FIELD_HASH,
|
||||
EIP712_STRUCT_HASH
|
||||
} e_eip712_hash_type;
|
||||
|
||||
#define KECCAK256_HASH_BYTESIZE 32
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
@@ -37,23 +37,27 @@ const uint8_t *type_hash(const void *const structs_array,
|
||||
// restore the memory location
|
||||
mem_dealloc(mem_alloc(0) - mem_loc_bak);
|
||||
|
||||
// copy hash into memory
|
||||
if ((hash_ptr = mem_alloc(KECCAK256_HASH_BYTESIZE)) == NULL)
|
||||
if ((hash_ptr = mem_alloc(KECCAK256_HASH_BYTESIZE + 1)) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// set TypeHash marker
|
||||
*hash_ptr = EIP712_TYPE_HASH;
|
||||
|
||||
// copy hash into memory
|
||||
cx_hash((cx_hash_t*)&global_sha3,
|
||||
CX_LAST,
|
||||
NULL,
|
||||
0,
|
||||
hash_ptr,
|
||||
hash_ptr + 1,
|
||||
KECCAK256_HASH_BYTESIZE);
|
||||
#ifdef DEBUG
|
||||
// print computed hash
|
||||
printf("-> 0x");
|
||||
for (int idx = 0; idx < KECCAK256_HASH_BYTESIZE; ++idx)
|
||||
{
|
||||
printf("%.02x", hash_ptr[idx]);
|
||||
printf("%.02x", (hash_ptr + 1)[idx]);
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user