Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
ethereum: use original ethereum message digest
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed May 25, 2018
1 parent bccba48 commit 1f470cf
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions firmware/ethereum.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,17 @@ static void ethereum_message_hash(const uint8_t *message, size_t message_len, ui
struct SHA3_CTX ctx;
sha3_256_Init(&ctx);
sha3_Update(&ctx, (const uint8_t *)"\x19" "Ethereum Signed Message:\n", 26);
uint8_t varint[5];
uint32_t l = ser_length(message_len, varint);
sha3_Update(&ctx, varint, l);
uint8_t c;
if (message_len > 1000000000) { c = '0' + message_len / 1000000000 % 10; sha3_Update(&ctx, &c, 1); }
if (message_len > 100000000) { c = '0' + message_len / 100000000 % 10; sha3_Update(&ctx, &c, 1); }
if (message_len > 10000000) { c = '0' + message_len / 10000000 % 10; sha3_Update(&ctx, &c, 1); }
if (message_len > 1000000) { c = '0' + message_len / 1000000 % 10; sha3_Update(&ctx, &c, 1); }
if (message_len > 100000) { c = '0' + message_len / 100000 % 10; sha3_Update(&ctx, &c, 1); }
if (message_len > 10000) { c = '0' + message_len / 10000 % 10; sha3_Update(&ctx, &c, 1); }
if (message_len > 1000) { c = '0' + message_len / 1000 % 10; sha3_Update(&ctx, &c, 1); }
if (message_len > 100) { c = '0' + message_len / 100 % 10; sha3_Update(&ctx, &c, 1); }
if (message_len > 10) { c = '0' + message_len / 10 % 10; sha3_Update(&ctx, &c, 1); }
c = '0' + message_len % 10; sha3_Update(&ctx, &c, 1);
sha3_Update(&ctx, message, message_len);
keccak_Final(&ctx, hash);
}
Expand Down

0 comments on commit 1f470cf

Please sign in to comment.