mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
crypto: Use Hasher for message signing
This commit is contained in:
parent
a1e911aa4c
commit
0e60ba54b7
@ -112,18 +112,22 @@ int gpgMessageSign(HDNode *node, const uint8_t *message, size_t message_len, uin
|
||||
}
|
||||
}
|
||||
|
||||
int cryptoMessageSign(const CoinInfo *coin, HDNode *node, InputScriptType script_type, const uint8_t *message, size_t message_len, uint8_t *signature)
|
||||
{
|
||||
SHA256_CTX ctx;
|
||||
sha256_Init(&ctx);
|
||||
sha256_Update(&ctx, (const uint8_t *)coin->signed_message_header, strlen(coin->signed_message_header));
|
||||
static void cryptoMessageHash(const CoinInfo *coin, const uint8_t *message, size_t message_len, uint8_t hash[HASHER_DIGEST_LENGTH]) {
|
||||
Hasher hasher;
|
||||
hasher_Init(&hasher, coin->hasher_type);
|
||||
hasher_Update(&hasher, (const uint8_t *)coin->signed_message_header, strlen(coin->signed_message_header));
|
||||
uint8_t varint[5];
|
||||
uint32_t l = ser_length(message_len, varint);
|
||||
sha256_Update(&ctx, varint, l);
|
||||
sha256_Update(&ctx, message, message_len);
|
||||
uint8_t hash[32];
|
||||
sha256_Final(&ctx, hash);
|
||||
sha256_Raw(hash, 32, hash);
|
||||
hasher_Update(&hasher, varint, l);
|
||||
hasher_Update(&hasher, message, message_len);
|
||||
hasher_Double(&hasher, hash);
|
||||
}
|
||||
|
||||
int cryptoMessageSign(const CoinInfo *coin, HDNode *node, InputScriptType script_type, const uint8_t *message, size_t message_len, uint8_t *signature)
|
||||
{
|
||||
uint8_t hash[HASHER_DIGEST_LENGTH];
|
||||
cryptoMessageHash(coin, message, message_len, hash);
|
||||
|
||||
uint8_t pby;
|
||||
int result = hdnode_sign_digest(node, hash, signature + 1, &pby, NULL);
|
||||
if (result == 0) {
|
||||
@ -152,17 +156,8 @@ int cryptoMessageVerify(const CoinInfo *coin, const uint8_t *message, size_t mes
|
||||
return 1;
|
||||
}
|
||||
|
||||
// calculate hash
|
||||
SHA256_CTX ctx;
|
||||
sha256_Init(&ctx);
|
||||
sha256_Update(&ctx, (const uint8_t *)coin->signed_message_header, strlen(coin->signed_message_header));
|
||||
uint8_t varint[5];
|
||||
uint32_t l = ser_length(message_len, varint);
|
||||
sha256_Update(&ctx, varint, l);
|
||||
sha256_Update(&ctx, message, message_len);
|
||||
uint8_t hash[32];
|
||||
sha256_Final(&ctx, hash);
|
||||
sha256_Raw(hash, 32, hash);
|
||||
uint8_t hash[HASHER_DIGEST_LENGTH];
|
||||
cryptoMessageHash(coin, message, message_len, hash);
|
||||
|
||||
uint8_t recid = (signature[0] - 27) % 4;
|
||||
bool compressed = signature[0] >= 31;
|
||||
|
2
vendor/trezor-crypto
vendored
2
vendor/trezor-crypto
vendored
@ -1 +1 @@
|
||||
Subproject commit 95a522bf1a453880050521661258d7943e966d1f
|
||||
Subproject commit 764cc4c6e8ef32e7e1a77f0496ae090f11a36def
|
Loading…
Reference in New Issue
Block a user