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
def set(auth_message: protobuf.MessageType) -> None: buffer = protobuf.dump_message_buffer(auth_message) # only wire-level messages can be stored as authorization # (because only wire-level messages have wire_type, which we use as identifier) ensure(auth_message.MESSAGE_WIRE_TYPE is not None) assert auth_message.MESSAGE_WIRE_TYPE is not None # so that typechecker knows too storage.cache.set( storage.cache.APP_COMMON_AUTHORIZATION_TYPE, auth_message.MESSAGE_WIRE_TYPE.to_bytes(2, "big"), ) storage.cache.set(storage.cache.APP_COMMON_AUTHORIZATION_DATA, buffer)
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
def _compute_sec_keys(state: State, tsx_data: MoneroTransactionData) -> None: """ Generate master key H( H(TsxData || tx_priv) || rand ) """ from trezor import protobuf from apps.monero.xmr.keccak_hasher import get_keccak_writer writer = get_keccak_writer() writer.write(protobuf.dump_message_buffer(tsx_data)) writer.write(crypto_helpers.encodeint(state.tx_priv)) master_key = crypto_helpers.keccak_2hash( writer.get_digest() + crypto_helpers.encodeint(crypto.random_scalar())) state.key_hmac = crypto_helpers.keccak_2hash(b"hmac" + master_key) state.key_enc = crypto_helpers.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