-
-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(legacy): check size of integers when hashing #4556
base: main
Are you sure you want to change the base?
Conversation
[no changelog]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall great improvement imho
there are some places where we hash int values and macro is not used - i think we should use it everywhere (even for local variables)
crypto/hasher.h
Outdated
// expected size. | ||
#define HASHER_UPDATE_INT(ctx, val, expected_type) \ | ||
do { \ | ||
hasher_Update(ctx, (const uint8_t *)&val, sizeof(val)); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to be safe
hasher_Update(ctx, (const uint8_t *)&val, sizeof(val)); \ | |
hasher_Update(ctx, (const uint8_t *)&(val), sizeof(val)); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point ... haven't done any preprocessor crimes for a long time
79bb074
legacy/firmware/signing.c
Outdated
@@ -1825,13 +1825,13 @@ static void txinfo_fill_zip244_header_hash(TxInfo *tx_info) { | |||
uint32_t ver = tx_info->version | TX_OVERWINTERED; | |||
hasher_Update(&hasher, (const uint8_t *)&ver, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also update this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
legacy/firmware/signing.c
Outdated
// nSequence | ||
tx_sequence_hash(&hasher_preimage, txinput); | ||
// hashOutputs | ||
hasher_Update(&hasher_preimage, tx_info->hash_outputs143, 32); | ||
// nLockTime | ||
hasher_Update(&hasher_preimage, (const uint8_t *)&tx_info->lock_time, 4); | ||
HASHER_UPDATE_INT(&hasher_preimage, tx_info->lock_time, uint32_t); | ||
// nHashType | ||
hasher_Update(&hasher_preimage, (const uint8_t *)&hash_type, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also update this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
legacy/firmware/signing.c
Outdated
@@ -2737,8 +2737,7 @@ static void signing_hash_zip243(const TxInfo *tx_info, | |||
uint32_t ver = tx_info->version | TX_OVERWINTERED; | |||
hasher_Update(&hasher_preimage, (const uint8_t *)&ver, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also update this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
79bb074
also the hash_type
in this file
I think this actually uncovered issue similar to the one in #4396: ba96a42 Do I understand correctly that the resulting hash is only used internally during transaction verification and never shown or used to derive an address? Otherwise it should be converted to |
1 similar comment
I think this actually uncovered issue similar to the one in #4396: ba96a42 Do I understand correctly that the resulting hash is only used internally during transaction verification and never shown or used to derive an address? Otherwise it should be converted to |
Fixes #4547. See also #4396 (comment)