diff --git a/crypto/hasher.h b/crypto/hasher.h index e58e74bae2..b70f630653 100644 --- a/crypto/hasher.h +++ b/crypto/hasher.h @@ -80,4 +80,20 @@ void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]); void hasher_Raw(HasherType type, const uint8_t *data, size_t length, uint8_t hash[HASHER_DIGEST_LENGTH]); +// Update the hash with an integer and also (statically) check that it has the +// expected size. +#define HASHER_UPDATE_INT(ctx, val, expected_type) \ + do { \ + hasher_Update((ctx), (const uint8_t *)&(val), sizeof(val)); \ + _Static_assert(sizeof(val) == sizeof(expected_type), "invalid int size"); \ + } while (0) + +// Byte array version of the macro above. +#define HASHER_UPDATE_BYTES(ctx, val, expected_size) \ + do { \ + hasher_Update((ctx), (val), sizeof(val)); \ + _Static_assert(sizeof(val) == expected_size, "invalid value size"); \ + _Static_assert(sizeof((val)[0]) == 1, "not a byte array"); \ + } while (0) + #endif diff --git a/crypto/sha2.h b/crypto/sha2.h index 5149b8dae6..ee98302b39 100644 --- a/crypto/sha2.h +++ b/crypto/sha2.h @@ -82,6 +82,22 @@ char* sha256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]); void sha256_Raw(const uint8_t*, size_t, uint8_t[SHA256_DIGEST_LENGTH]); char* sha256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]); +// Update the hash with an integer and also (statically) check that it has the +// expected size. +#define SHA256_UPDATE_INT(ctx, val, expected_type) \ + do { \ + sha256_Update((ctx), (const uint8_t *)&(val), sizeof(val)); \ + _Static_assert(sizeof(val) == sizeof(expected_type), "invalid int size"); \ + } while (0) + +// Byte array version of the macro above. +#define SHA256_UPDATE_BYTES(ctx, val, expected_size) \ + do { \ + sha256_Update((ctx), (val), sizeof(val)); \ + _Static_assert(sizeof(val) == expected_size, "invalid value size"); \ + _Static_assert(sizeof((val)[0]) == 1, "not a byte array"); \ + } while (0) + void sha384_Raw(const uint8_t*, size_t, uint8_t[SHA384_DIGEST_LENGTH]); void sha512_Transform(const uint64_t* state_in, const uint64_t* data, uint64_t* state_out); diff --git a/legacy/firmware/crypto.c b/legacy/firmware/crypto.c index 7cad755e27..19b5a9fdbf 100644 --- a/legacy/firmware/crypto.c +++ b/legacy/firmware/crypto.c @@ -471,19 +471,16 @@ int cryptoMultisigFingerprint(const MultisigRedeemScriptType *multisig, SHA256_CTX ctx = {0}; sha256_Init(&ctx); - sha256_Update(&ctx, (const uint8_t *)&(multisig->m), sizeof(uint32_t)); - sha256_Update(&ctx, (const uint8_t *)&(pubkeys_order), sizeof(uint32_t)); + SHA256_UPDATE_INT(&ctx, multisig->m, uint32_t); + SHA256_UPDATE_INT(&ctx, pubkeys_order, uint32_t); for (uint32_t i = 0; i < n; i++) { - sha256_Update(&ctx, (const uint8_t *)&(pubnodes[i]->depth), - sizeof(uint32_t)); - sha256_Update(&ctx, (const uint8_t *)&(pubnodes[i]->fingerprint), - sizeof(uint32_t)); - sha256_Update(&ctx, (const uint8_t *)&(pubnodes[i]->child_num), - sizeof(uint32_t)); - sha256_Update(&ctx, pubnodes[i]->chain_code.bytes, 32); - sha256_Update(&ctx, pubnodes[i]->public_key.bytes, 33); + SHA256_UPDATE_INT(&ctx, pubnodes[i]->depth, uint32_t); + SHA256_UPDATE_INT(&ctx, pubnodes[i]->fingerprint, uint32_t); + SHA256_UPDATE_INT(&ctx, pubnodes[i]->child_num, uint32_t); + SHA256_UPDATE_BYTES(&ctx, pubnodes[i]->chain_code.bytes, 32); + SHA256_UPDATE_BYTES(&ctx, pubnodes[i]->public_key.bytes, 33); } - sha256_Update(&ctx, (const uint8_t *)&n, sizeof(uint32_t)); + SHA256_UPDATE_INT(&ctx, n, uint32_t); sha256_Final(&ctx, hash); layoutProgressUpdate(true); return 1; @@ -492,7 +489,7 @@ int cryptoMultisigFingerprint(const MultisigRedeemScriptType *multisig, int cryptoIdentityFingerprint(const IdentityType *identity, uint8_t *hash) { SHA256_CTX ctx = {0}; sha256_Init(&ctx); - sha256_Update(&ctx, (const uint8_t *)&(identity->index), sizeof(uint32_t)); + SHA256_UPDATE_INT(&ctx, identity->index, uint32_t); if (identity->has_proto && identity->proto[0]) { sha256_Update(&ctx, (const uint8_t *)(identity->proto), strlen(identity->proto)); diff --git a/legacy/firmware/reset.c b/legacy/firmware/reset.c index cefffb075c..928465f53a 100644 --- a/legacy/firmware/reset.c +++ b/legacy/firmware/reset.c @@ -84,7 +84,7 @@ void reset_entropy(const uint8_t *ext_entropy, uint32_t len) { SHA256_CTX ctx = {0}; sha256_Init(&ctx); - sha256_Update(&ctx, int_entropy, 32); + SHA256_UPDATE_BYTES(&ctx, int_entropy, 32); sha256_Update(&ctx, ext_entropy, len); sha256_Final(&ctx, int_entropy); const char *mnemonic = mnemonic_from_data(int_entropy, strength / 8); diff --git a/legacy/firmware/signing.c b/legacy/firmware/signing.c index 917c1abfd6..9646a827ed 100644 --- a/legacy/firmware/signing.c +++ b/legacy/firmware/signing.c @@ -1823,15 +1823,15 @@ static void txinfo_fill_zip244_header_hash(TxInfo *tx_info) { // T.1a: version (4-byte little-endian version identifier including // overwintered flag) uint32_t ver = tx_info->version | TX_OVERWINTERED; - hasher_Update(&hasher, (const uint8_t *)&ver, 4); + HASHER_UPDATE_INT(&hasher, ver, uint32_t); // T.1b: version_group_id (4-byte little-endian version group identifier) - hasher_Update(&hasher, (const uint8_t *)&tx_info->version_group_id, 4); + HASHER_UPDATE_INT(&hasher, tx_info->version_group_id, uint32_t); // T.1c: consensus_branch_id (4-byte little-endian consensus branch id) - hasher_Update(&hasher, (const uint8_t *)&tx_info->branch_id, 4); + HASHER_UPDATE_INT(&hasher, tx_info->branch_id, uint32_t); // T.1d: lock_time (4-byte little-endian nLockTime value) - hasher_Update(&hasher, (const uint8_t *)&tx_info->lock_time, 4); + HASHER_UPDATE_INT(&hasher, tx_info->lock_time, uint32_t); // T.1e: expiry_height (4-byte little-endian block height) - hasher_Update(&hasher, (const uint8_t *)&tx_info->expiry, 4); + HASHER_UPDATE_INT(&hasher, tx_info->expiry, uint32_t); hasher_Final(&hasher, tx_info->hash_header); } #endif @@ -2666,26 +2666,26 @@ static void signing_hash_bip143(const TxInfo *tx_info, hasher_Init(&hasher_preimage, coin->curve->hasher_sign); // nVersion - hasher_Update(&hasher_preimage, (const uint8_t *)&tx_info->version, 4); + HASHER_UPDATE_INT(&hasher_preimage, tx_info->version, uint32_t); // hashPrevouts - hasher_Update(&hasher_preimage, tx_info->hash_prevouts143, 32); + HASHER_UPDATE_BYTES(&hasher_preimage, tx_info->hash_prevouts143, 32); // hashSequence - hasher_Update(&hasher_preimage, tx_info->hash_sequence143, 32); + HASHER_UPDATE_BYTES(&hasher_preimage, tx_info->hash_sequence143, 32); // outpoint tx_prevout_hash(&hasher_preimage, txinput); // scriptCode tx_script_hash(&hasher_preimage, txinput->script_sig.size, txinput->script_sig.bytes); // amount - hasher_Update(&hasher_preimage, (const uint8_t *)&txinput->amount, 8); + HASHER_UPDATE_INT(&hasher_preimage, txinput->amount, uint64_t); // nSequence tx_sequence_hash(&hasher_preimage, txinput); // hashOutputs - hasher_Update(&hasher_preimage, tx_info->hash_outputs143, 32); + HASHER_UPDATE_BYTES(&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); + HASHER_UPDATE_INT(&hasher_preimage, hash_type, uint32_t); hasher_Final(&hasher_preimage, hash); } @@ -2700,23 +2700,23 @@ static void signing_hash_bip341(const TxInfo *tx_info, uint32_t i, // nHashType hasher_Update(&sigmsg_hasher, &sighash_type, 1); // nVersion - hasher_Update(&sigmsg_hasher, (const uint8_t *)&tx_info->version, 4); + HASHER_UPDATE_INT(&sigmsg_hasher, tx_info->version, uint32_t); // nLockTime - hasher_Update(&sigmsg_hasher, (const uint8_t *)&tx_info->lock_time, 4); + HASHER_UPDATE_INT(&sigmsg_hasher, tx_info->lock_time, uint32_t); // sha_prevouts - hasher_Update(&sigmsg_hasher, tx_info->hash_prevouts, 32); + HASHER_UPDATE_BYTES(&sigmsg_hasher, tx_info->hash_prevouts, 32); // sha_amounts - hasher_Update(&sigmsg_hasher, tx_info->hash_amounts, 32); + HASHER_UPDATE_BYTES(&sigmsg_hasher, tx_info->hash_amounts, 32); // sha_scriptpubkeys - hasher_Update(&sigmsg_hasher, tx_info->hash_scriptpubkeys, 32); + HASHER_UPDATE_BYTES(&sigmsg_hasher, tx_info->hash_scriptpubkeys, 32); // sha_sequences - hasher_Update(&sigmsg_hasher, tx_info->hash_sequences, 32); + HASHER_UPDATE_BYTES(&sigmsg_hasher, tx_info->hash_sequences, 32); // sha_outputs - hasher_Update(&sigmsg_hasher, tx_info->hash_outputs, 32); + HASHER_UPDATE_BYTES(&sigmsg_hasher, tx_info->hash_outputs, 32); // spend_type 0 (no tapscript message extension, no annex) hasher_Update(&sigmsg_hasher, &zero, 1); // input_index - hasher_Update(&sigmsg_hasher, (const uint8_t *)&i, 4); + HASHER_UPDATE_INT(&sigmsg_hasher, i, uint32_t); hasher_Final(&sigmsg_hasher, hash); } @@ -2735,16 +2735,15 @@ static void signing_hash_zip243(const TxInfo *tx_info, // 1. nVersion | fOverwintered uint32_t ver = tx_info->version | TX_OVERWINTERED; - hasher_Update(&hasher_preimage, (const uint8_t *)&ver, 4); + HASHER_UPDATE_INT(&hasher_preimage, ver, uint32_t); // 2. nVersionGroupId - hasher_Update(&hasher_preimage, (const uint8_t *)&tx_info->version_group_id, - 4); + HASHER_UPDATE_INT(&hasher_preimage, tx_info->version_group_id, uint32_t); // 3. hashPrevouts - hasher_Update(&hasher_preimage, tx_info->hash_prevouts, 32); + HASHER_UPDATE_BYTES(&hasher_preimage, tx_info->hash_prevouts, 32); // 4. hashSequence - hasher_Update(&hasher_preimage, tx_info->hash_sequences, 32); + HASHER_UPDATE_BYTES(&hasher_preimage, tx_info->hash_sequences, 32); // 5. hashOutputs - hasher_Update(&hasher_preimage, tx_info->hash_outputs, 32); + HASHER_UPDATE_BYTES(&hasher_preimage, tx_info->hash_outputs, 32); // 6. hashJoinSplits hasher_Update(&hasher_preimage, null_bytes, 32); // 7. hashShieldedSpends @@ -2752,20 +2751,20 @@ static void signing_hash_zip243(const TxInfo *tx_info, // 8. hashShieldedOutputs hasher_Update(&hasher_preimage, null_bytes, 32); // 9. nLockTime - hasher_Update(&hasher_preimage, (const uint8_t *)&tx_info->lock_time, 4); + HASHER_UPDATE_INT(&hasher_preimage, tx_info->lock_time, uint32_t); // 10. expiryHeight - hasher_Update(&hasher_preimage, (const uint8_t *)&tx_info->expiry, 4); + HASHER_UPDATE_INT(&hasher_preimage, tx_info->expiry, uint32_t); // 11. valueBalance hasher_Update(&hasher_preimage, null_bytes, 8); // 12. nHashType - hasher_Update(&hasher_preimage, (const uint8_t *)&hash_type, 4); + HASHER_UPDATE_INT(&hasher_preimage, hash_type, uint32_t); // 13a. outpoint tx_prevout_hash(&hasher_preimage, txinput); // 13b. scriptCode tx_script_hash(&hasher_preimage, txinput->script_sig.size, txinput->script_sig.bytes); // 13c. value - hasher_Update(&hasher_preimage, (const uint8_t *)&txinput->amount, 8); + HASHER_UPDATE_INT(&hasher_preimage, txinput->amount, uint64_t); // 13d. nSequence tx_sequence_hash(&hasher_preimage, txinput); @@ -2785,12 +2784,12 @@ static void signing_hash_zip244(const TxInfo *tx_info, // S.2g.i: prevout (field encoding) tx_prevout_hash(&hasher, txinput); // S.2g.ii: value (8-byte signed little-endian) - hasher_Update(&hasher, (const uint8_t *)&txinput->amount, 8); + HASHER_UPDATE_INT(&hasher, txinput->amount, uint64_t); // S.2g.iii: scriptPubKey (field encoding) tx_script_hash(&hasher, txinput->script_pubkey.size, txinput->script_pubkey.bytes); // S.2g.iv: nSequence (4-byte unsigned little-endian) - hasher_Update(&hasher, (const uint8_t *)&txinput->sequence, 4); + HASHER_UPDATE_INT(&hasher, txinput->sequence, uint32_t); hasher_Final(&hasher, txin_sig_digest); // `S.2: transparent_sig_digest` field for signature digest computation. @@ -2801,20 +2800,17 @@ static void signing_hash_zip244(const TxInfo *tx_info, // S.2a: hash_type (1 byte) hasher_Update(&hasher, (const uint8_t *)&hash_type, 1); // S.2b: prevouts_sig_digest (32-byte hash) - hasher_Update(&hasher, tx_info->hash_prevouts, - sizeof(tx_info->hash_prevouts)); + HASHER_UPDATE_BYTES(&hasher, tx_info->hash_prevouts, 32); // S.2c: amounts_sig_digest (32-byte hash) - hasher_Update(&hasher, tx_info->hash_amounts, sizeof(tx_info->hash_amounts)); + HASHER_UPDATE_BYTES(&hasher, tx_info->hash_amounts, 32); // S.2d: scriptpubkeys_sig_digest (32-byte hash) - hasher_Update(&hasher, tx_info->hash_scriptpubkeys, - sizeof(tx_info->hash_scriptpubkeys)); + HASHER_UPDATE_BYTES(&hasher, tx_info->hash_scriptpubkeys, 32); // S.2e: sequence_sig_digest (32-byte hash) - hasher_Update(&hasher, tx_info->hash_sequences, - sizeof(tx_info->hash_sequences)); + HASHER_UPDATE_BYTES(&hasher, tx_info->hash_sequences, 32); // S.2f: outputs_sig_digest (32-byte hash) - hasher_Update(&hasher, tx_info->hash_outputs, sizeof(tx_info->hash_outputs)); + HASHER_UPDATE_BYTES(&hasher, tx_info->hash_outputs, 32); // S.2g: txin_sig_digest (32-byte hash) - hasher_Update(&hasher, txin_sig_digest, sizeof(txin_sig_digest)); + HASHER_UPDATE_BYTES(&hasher, txin_sig_digest, 32); hasher_Final(&hasher, transparent_sig_digest); // `S.3: sapling_digest` field. Empty Sapling bundle. @@ -2835,14 +2831,13 @@ static void signing_hash_zip244(const TxInfo *tx_info, hasher_InitParam(&hasher, HASHER_BLAKE2B_PERSONAL, personal, sizeof(personal)); // S.1: header_digest (32-byte hash output) - hasher_Update(&hasher, tx_info->hash_header, sizeof(tx_info->hash_header)); + HASHER_UPDATE_BYTES(&hasher, tx_info->hash_header, 32); // S.2: transparent_sig_digest (32-byte hash output) - hasher_Update(&hasher, transparent_sig_digest, - sizeof(transparent_sig_digest)); + HASHER_UPDATE_BYTES(&hasher, transparent_sig_digest, 32); // S.3: sapling_digest (32-byte hash output) - hasher_Update(&hasher, sapling_digest, sizeof(sapling_digest)); + HASHER_UPDATE_BYTES(&hasher, sapling_digest, 32); // S.4: orchard_digest (32-byte hash output) - hasher_Update(&hasher, orchard_digest, sizeof(orchard_digest)); + HASHER_UPDATE_BYTES(&hasher, orchard_digest, 32); hasher_Final(&hasher, hash); } #endif @@ -2900,7 +2895,7 @@ static bool signing_verify_orig_nonlegacy_input(TxInputType *orig_input) { static bool signing_verify_orig_legacy_input(void) { // Finalize legacy digest computation. uint32_t hash_type = signing_hash_type(&input); - hasher_Update(&ti.hasher, (const uint8_t *)&hash_type, 4); + HASHER_UPDATE_INT(&ti.hasher, hash_type, uint32_t); // Compute the signed digest and verify signature. uint8_t hash[32] = {0}; @@ -3131,12 +3126,12 @@ static void phase1_request_orig_output(void) { #if !BITCOIN_ONLY static void signing_hash_decred(const TxInputType *txinput, - const uint8_t *hash_witness, uint8_t *hash) { + const uint8_t hash_witness[32], uint8_t *hash) { uint32_t hash_type = signing_hash_type(txinput); Hasher hasher_preimage = {0}; hasher_Init(&hasher_preimage, coin->curve->hasher_sign); - hasher_Update(&hasher_preimage, (const uint8_t *)&hash_type, 4); - hasher_Update(&hasher_preimage, decred_hash_prefix, 32); + HASHER_UPDATE_INT(&hasher_preimage, hash_type, uint32_t); + HASHER_UPDATE_BYTES(&hasher_preimage, decred_hash_prefix, 32); hasher_Update(&hasher_preimage, hash_witness, 32); hasher_Final(&hasher_preimage, hash); } @@ -3208,7 +3203,7 @@ static bool signing_sign_bip340(const uint8_t *private_key, static bool signing_sign_legacy_input(void) { // Finalize legacy digest computation. uint32_t hash_type = signing_hash_type(&input); - hasher_Update(&ti.hasher, (const uint8_t *)&hash_type, 4); + HASHER_UPDATE_INT(&ti.hasher, hash_type, uint32_t); // Compute the digest and generate signature. uint8_t hash[32] = {0}; diff --git a/legacy/firmware/transaction.c b/legacy/firmware/transaction.c index 19dc54cf05..9b7bd4317d 100644 --- a/legacy/firmware/transaction.c +++ b/legacy/firmware/transaction.c @@ -544,19 +544,16 @@ bool tx_sign_bip340(const uint8_t *private_key, const uint8_t *hash, // tx methods bool tx_input_check_hash(Hasher *hasher, const TxInputType *input) { - hasher_Update(hasher, (const uint8_t *)&input->address_n_count, - sizeof(input->address_n_count)); - for (int i = 0; i < input->address_n_count; ++i) - hasher_Update(hasher, (const uint8_t *)&input->address_n[i], - sizeof(input->address_n[0])); - hasher_Update(hasher, input->prev_hash.bytes, sizeof(input->prev_hash.bytes)); - hasher_Update(hasher, (const uint8_t *)&input->prev_index, - sizeof(input->prev_index)); + HASHER_UPDATE_INT(hasher, input->address_n_count, uint16_t); + for (int i = 0; i < input->address_n_count; ++i) { + HASHER_UPDATE_INT(hasher, input->address_n[i], uint32_t); + } + HASHER_UPDATE_BYTES(hasher, input->prev_hash.bytes, 32); + HASHER_UPDATE_INT(hasher, input->prev_index, uint32_t); tx_script_hash(hasher, input->script_sig.size, input->script_sig.bytes); - hasher_Update(hasher, (const uint8_t *)&input->sequence, - sizeof(input->sequence)); - hasher_Update(hasher, (const uint8_t *)&input->script_type, - sizeof(input->script_type)); + HASHER_UPDATE_INT(hasher, input->sequence, uint32_t); + uint32_t script_type = input->script_type; + HASHER_UPDATE_INT(hasher, script_type, uint32_t); uint8_t multisig_fp[32] = {0}; if (input->has_multisig) { if (cryptoMultisigFingerprint(&input->multisig, multisig_fp) == 0) { @@ -564,14 +561,12 @@ bool tx_input_check_hash(Hasher *hasher, const TxInputType *input) { return false; } } - hasher_Update(hasher, multisig_fp, sizeof(multisig_fp)); - hasher_Update(hasher, (const uint8_t *)&input->amount, sizeof(input->amount)); + HASHER_UPDATE_BYTES(hasher, multisig_fp, 32); + HASHER_UPDATE_INT(hasher, input->amount, uint64_t); tx_script_hash(hasher, input->witness.size, input->witness.bytes); - hasher_Update(hasher, (const uint8_t *)&input->has_orig_hash, - sizeof(input->has_orig_hash)); - hasher_Update(hasher, input->orig_hash.bytes, sizeof(input->orig_hash.bytes)); - hasher_Update(hasher, (const uint8_t *)&input->orig_index, - sizeof(input->orig_index)); + HASHER_UPDATE_INT(hasher, input->has_orig_hash, uint8_t); + HASHER_UPDATE_BYTES(hasher, input->orig_hash.bytes, 32); + HASHER_UPDATE_INT(hasher, input->orig_index, uint32_t); tx_script_hash(hasher, input->script_pubkey.size, input->script_pubkey.bytes); return true; } @@ -580,12 +575,12 @@ uint32_t tx_prevout_hash(Hasher *hasher, const TxInputType *input) { for (int i = 0; i < 32; i++) { hasher_Update(hasher, &(input->prev_hash.bytes[31 - i]), 1); } - hasher_Update(hasher, (const uint8_t *)&input->prev_index, 4); + HASHER_UPDATE_INT(hasher, input->prev_index, uint32_t); return 36; } uint32_t tx_amount_hash(Hasher *hasher, const TxInputType *input) { - hasher_Update(hasher, (const uint8_t *)&input->amount, 8); + HASHER_UPDATE_INT(hasher, input->amount, uint64_t); return 8; } @@ -596,18 +591,18 @@ uint32_t tx_script_hash(Hasher *hasher, uint32_t size, const uint8_t *data) { } uint32_t tx_sequence_hash(Hasher *hasher, const TxInputType *input) { - hasher_Update(hasher, (const uint8_t *)&input->sequence, 4); + HASHER_UPDATE_INT(hasher, input->sequence, uint32_t); return 4; } uint32_t tx_output_hash(Hasher *hasher, const TxOutputBinType *output, bool decred) { uint32_t r = 0; - hasher_Update(hasher, (const uint8_t *)&output->amount, 8); + HASHER_UPDATE_INT(hasher, output->amount, uint64_t); r += 8; if (decred) { uint16_t script_version = output->decred_script_version & 0xFFFF; - hasher_Update(hasher, (const uint8_t *)&script_version, 2); + HASHER_UPDATE_INT(hasher, script_version, uint16_t); r += 2; } r += tx_script_hash(hasher, output->script_pubkey.size, @@ -662,20 +657,20 @@ uint32_t tx_serialize_header_hash(TxStruct *tx) { #if !BITCOIN_ONLY if (tx->is_zcashlike && tx->version >= 3) { uint32_t ver = tx->version | TX_OVERWINTERED; - hasher_Update(&(tx->hasher), (const uint8_t *)&ver, 4); - hasher_Update(&(tx->hasher), (const uint8_t *)&(tx->version_group_id), 4); + HASHER_UPDATE_INT(&(tx->hasher), ver, uint32_t); + HASHER_UPDATE_INT(&(tx->hasher), tx->version_group_id, uint32_t); r += 4; } else #endif { - hasher_Update(&(tx->hasher), (const uint8_t *)&(tx->version), 4); + HASHER_UPDATE_INT(&(tx->hasher), tx->version, uint32_t); #if !BITCOIN_ONLY if (tx->timestamp) { - hasher_Update(&(tx->hasher), (const uint8_t *)&(tx->timestamp), 4); + HASHER_UPDATE_INT(&(tx->hasher), tx->timestamp, uint32_t); } #endif if (tx->is_segwit) { - hasher_Update(&(tx->hasher), segwit_header, 2); + HASHER_UPDATE_BYTES(&(tx->hasher), segwit_header, 2); r += 2; } } @@ -852,14 +847,14 @@ uint32_t tx_serialize_footer(TxStruct *tx, uint8_t *out) { } uint32_t tx_serialize_footer_hash(TxStruct *tx) { - hasher_Update(&(tx->hasher), (const uint8_t *)&(tx->lock_time), 4); + HASHER_UPDATE_INT(&(tx->hasher), tx->lock_time, uint32_t); #if !BITCOIN_ONLY if (tx->is_zcashlike && tx->version >= 3) { - hasher_Update(&(tx->hasher), (const uint8_t *)&(tx->expiry), 4); + HASHER_UPDATE_INT(&(tx->hasher), tx->expiry, uint32_t); return 8; } if (tx->is_decred) { - hasher_Update(&(tx->hasher), (const uint8_t *)&(tx->expiry), 4); + HASHER_UPDATE_INT(&(tx->hasher), tx->expiry, uint32_t); return 8; } #endif