mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 23:48:12 +00:00
Compute hash before checking signatures. (#158)
This fixes the problem where an invalid hash is shown, if the firmware contains no signing key indices.
This commit is contained in:
parent
d7d3d0490e
commit
49645ba277
@ -47,6 +47,12 @@ int signatures_ok(uint8_t *store_hash)
|
||||
sigindex2 = *((uint8_t *)FLASH_META_SIGINDEX2);
|
||||
sigindex3 = *((uint8_t *)FLASH_META_SIGINDEX3);
|
||||
|
||||
uint8_t hash[32];
|
||||
sha256_Raw((uint8_t *)FLASH_APP_START, codelen, hash);
|
||||
if (store_hash) {
|
||||
memcpy(store_hash, hash, 32);
|
||||
}
|
||||
|
||||
if (sigindex1 < 1 || sigindex1 > PUBKEYS) return 0; // invalid index
|
||||
if (sigindex2 < 1 || sigindex2 > PUBKEYS) return 0; // invalid index
|
||||
if (sigindex3 < 1 || sigindex3 > PUBKEYS) return 0; // invalid index
|
||||
@ -55,12 +61,6 @@ int signatures_ok(uint8_t *store_hash)
|
||||
if (sigindex1 == sigindex3) return 0; // duplicate use
|
||||
if (sigindex2 == sigindex3) return 0; // duplicate use
|
||||
|
||||
uint8_t hash[32];
|
||||
sha256_Raw((uint8_t *)FLASH_APP_START, codelen, hash);
|
||||
if (store_hash) {
|
||||
memcpy(store_hash, hash, 32);
|
||||
}
|
||||
|
||||
if (ecdsa_verify_digest(&secp256k1, pubkey[sigindex1 - 1], (uint8_t *)FLASH_META_SIG1, hash) != 0) { // failure
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user