def gen_hmac_vini(key: bytes, src_entr: MoneroTransactionSourceEntry, vini_bin: bytes, idx: int) -> bytes: """ Computes hmac (TxSourceEntry[i] || tx.vin[i]) In src_entr.outputs only src_entr.outputs[src_entr.real_output] is HMACed as it is used across the protocol. Consistency of other values across the protocol is not required as they are used only once and hard to check. I.e., indices in step 2 are uncheckable, decoy keys in step 9 are just random keys. """ from trezor import protobuf from apps.monero.xmr.keccak_hasher import get_keccak_writer kwriter = get_keccak_writer() real_outputs = src_entr.outputs real_additional = src_entr.real_out_additional_tx_keys src_entr.outputs = [src_entr.outputs[src_entr.real_output]] if real_additional and len(real_additional) > 1: src_entr.real_out_additional_tx_keys = [ src_entr.real_out_additional_tx_keys[ src_entr.real_output_in_tx_index] ] kwriter.write(protobuf.dump_message_buffer(src_entr)) src_entr.outputs = real_outputs src_entr.real_out_additional_tx_keys = real_additional kwriter.write(vini_bin) hmac_key_vini = hmac_key_txin(key, idx) hmac_vini = crypto_helpers.compute_hmac(hmac_key_vini, kwriter.get_digest()) return hmac_vini
async def gen_hmac_tsxdest(key, dst_entr, idx: int) -> bytes: """ Generates HMAC for TxDestinationEntry[i] """ import protobuf from apps.monero.xmr.keccak_hasher import get_keccak_writer kwriter = get_keccak_writer() await protobuf.dump_message(kwriter, dst_entr) hmac_key = hmac_key_txdst(key, idx) hmac_tsxdest = crypto.compute_hmac(hmac_key, kwriter.get_digest()) return hmac_tsxdest
def gen_hmac_tsxdest(key: bytes, dst_entr: MoneroTransactionDestinationEntry, idx: int) -> bytes: """ Generates HMAC for TxDestinationEntry[i] """ from trezor import protobuf from apps.monero.xmr.keccak_hasher import get_keccak_writer kwriter = get_keccak_writer() kwriter.write(protobuf.dump_message_buffer(dst_entr)) hmac_key = hmac_key_txdst(key, idx) hmac_tsxdest = crypto_helpers.compute_hmac(hmac_key, kwriter.get_digest()) return hmac_tsxdest
async def gen_hmac_vouti(key, dst_entr, tx_out_bin, idx: int) -> bytes: """ Generates HMAC for (TxDestinationEntry[i] || tx.vout[i]) """ import protobuf from apps.monero.xmr.keccak_hasher import get_keccak_writer kwriter = get_keccak_writer() await protobuf.dump_message(kwriter, dst_entr) kwriter.write(tx_out_bin) hmac_key_vouti = hmac_key_txout(key, idx) hmac_vouti = crypto.compute_hmac(hmac_key_vouti, kwriter.get_digest()) return hmac_vouti
async def gen_hmac_vini(key, src_entr, vini_bin, idx: int) -> bytes: """ Computes hmac (TxSourceEntry[i] || tx.vin[i]) """ import protobuf from apps.monero.xmr.keccak_hasher import get_keccak_writer kwriter = get_keccak_writer() await protobuf.dump_message(kwriter, src_entr) kwriter.write(vini_bin) hmac_key_vini = hmac_key_txin(key, idx) hmac_vini = crypto.compute_hmac(hmac_key_vini, kwriter.get_digest()) return hmac_vini
async def _compute_sec_keys(state: State, tsx_data: MoneroTransactionData): """ Generate master key H( H(TsxData || tx_priv) || rand ) """ import protobuf from apps.monero.xmr.keccak_hasher import get_keccak_writer writer = get_keccak_writer() await protobuf.dump_message(writer, tsx_data) writer.write(crypto.encodeint(state.tx_priv)) master_key = crypto.keccak_2hash(writer.get_digest() + crypto.encodeint(crypto.random_scalar())) state.key_hmac = crypto.keccak_2hash(b"hmac" + master_key) state.key_enc = crypto.keccak_2hash(b"enc" + master_key)
def gen_hmac_vouti(key, dst_entr: MoneroTransactionDestinationEntry, tx_out_bin: bytes, idx: int) -> bytes: """ Generates HMAC for (TxDestinationEntry[i] || tx.vout[i]) """ from trezor import protobuf from apps.monero.xmr.keccak_hasher import get_keccak_writer kwriter = get_keccak_writer() kwriter.write(protobuf.dump_message_buffer(dst_entr)) kwriter.write(tx_out_bin) hmac_key_vouti = hmac_key_txout(key, idx) hmac_vouti = crypto.compute_hmac(hmac_key_vouti, kwriter.get_digest()) return hmac_vouti