1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-31 09:50:58 +00:00

core/monero: update Monero app to use synchronous protobuf

This commit is contained in:
matejcik 2020-07-01 10:17:29 +02:00 committed by Tomas Susanka
parent 01d695283f
commit a000ea5ec8
6 changed files with 17 additions and 17 deletions

View File

@ -122,7 +122,7 @@ def det_comm_masks(key_enc, idx: int) -> Sc25519:
return crypto.decodeint(_build_key(key_enc, b"out-mask", idx)) return crypto.decodeint(_build_key(key_enc, b"out-mask", idx))
async def gen_hmac_vini( def gen_hmac_vini(
key, src_entr: MoneroTransactionSourceEntry, vini_bin: bytes, idx: int key, src_entr: MoneroTransactionSourceEntry, vini_bin: bytes, idx: int
) -> bytes: ) -> bytes:
""" """
@ -146,7 +146,7 @@ async def gen_hmac_vini(
src_entr.real_out_additional_tx_keys[src_entr.real_output_in_tx_index] src_entr.real_out_additional_tx_keys[src_entr.real_output_in_tx_index]
] ]
await protobuf.dump_message(kwriter, src_entr) protobuf.dump_message(kwriter, src_entr)
src_entr.outputs = real_outputs src_entr.outputs = real_outputs
src_entr.real_out_additional_tx_keys = real_additional src_entr.real_out_additional_tx_keys = real_additional
kwriter.write(vini_bin) kwriter.write(vini_bin)
@ -156,7 +156,7 @@ async def gen_hmac_vini(
return hmac_vini return hmac_vini
async def gen_hmac_vouti( def gen_hmac_vouti(
key, dst_entr: MoneroTransactionDestinationEntry, tx_out_bin: bytes, idx: int key, dst_entr: MoneroTransactionDestinationEntry, tx_out_bin: bytes, idx: int
) -> bytes: ) -> bytes:
""" """
@ -166,7 +166,7 @@ async def gen_hmac_vouti(
from apps.monero.xmr.keccak_hasher import get_keccak_writer from apps.monero.xmr.keccak_hasher import get_keccak_writer
kwriter = get_keccak_writer() kwriter = get_keccak_writer()
await protobuf.dump_message(kwriter, dst_entr) protobuf.dump_message(kwriter, dst_entr)
kwriter.write(tx_out_bin) kwriter.write(tx_out_bin)
hmac_key_vouti = hmac_key_txout(key, idx) hmac_key_vouti = hmac_key_txout(key, idx)
@ -174,7 +174,7 @@ async def gen_hmac_vouti(
return hmac_vouti return hmac_vouti
async def gen_hmac_tsxdest( def gen_hmac_tsxdest(
key, dst_entr: MoneroTransactionDestinationEntry, idx: int key, dst_entr: MoneroTransactionDestinationEntry, idx: int
) -> bytes: ) -> bytes:
""" """
@ -184,7 +184,7 @@ async def gen_hmac_tsxdest(
from apps.monero.xmr.keccak_hasher import get_keccak_writer from apps.monero.xmr.keccak_hasher import get_keccak_writer
kwriter = get_keccak_writer() kwriter = get_keccak_writer()
await protobuf.dump_message(kwriter, dst_entr) protobuf.dump_message(kwriter, dst_entr)
hmac_key = hmac_key_txdst(key, idx) hmac_key = hmac_key_txdst(key, idx)
hmac_tsxdest = crypto.compute_hmac(hmac_key, kwriter.get_digest()) hmac_tsxdest = crypto.compute_hmac(hmac_key, kwriter.get_digest())

View File

@ -81,7 +81,7 @@ async def init_transaction(
# Extra processing, payment id # Extra processing, payment id
_process_payment_id(state, tsx_data) _process_payment_id(state, tsx_data)
await _compute_sec_keys(state, tsx_data) _compute_sec_keys(state, tsx_data)
gc.collect() gc.collect()
# Iterative tx_prefix_hash hash computation # Iterative tx_prefix_hash hash computation
@ -104,7 +104,7 @@ async def init_transaction(
# and trezor validates it. # and trezor validates it.
hmacs = [] hmacs = []
for idx in range(state.output_count): for idx in range(state.output_count):
c_hmac = await offloading_keys.gen_hmac_tsxdest( c_hmac = offloading_keys.gen_hmac_tsxdest(
state.key_hmac, tsx_data.outputs[idx], idx state.key_hmac, tsx_data.outputs[idx], idx
) )
hmacs.append(c_hmac) hmacs.append(c_hmac)
@ -268,7 +268,7 @@ def _check_change(state: State, outputs: List[MoneroTransactionDestinationEntry]
raise signing.ChangeAddressError("Change address differs from ours") raise signing.ChangeAddressError("Change address differs from ours")
async def _compute_sec_keys(state: State, tsx_data: MoneroTransactionData): def _compute_sec_keys(state: State, tsx_data: MoneroTransactionData):
""" """
Generate master key H( H(TsxData || tx_priv) || rand ) Generate master key H( H(TsxData || tx_priv) || rand )
""" """
@ -276,7 +276,7 @@ async def _compute_sec_keys(state: State, tsx_data: MoneroTransactionData):
from apps.monero.xmr.keccak_hasher import get_keccak_writer from apps.monero.xmr.keccak_hasher import get_keccak_writer
writer = get_keccak_writer() writer = get_keccak_writer()
await protobuf.dump_message(writer, tsx_data) protobuf.dump_message(writer, tsx_data)
writer.write(crypto.encodeint(state.tx_priv)) writer.write(crypto.encodeint(state.tx_priv))
master_key = crypto.keccak_2hash( master_key = crypto.keccak_2hash(

View File

@ -95,7 +95,7 @@ async def set_input(
state.mem_trace(2, True) state.mem_trace(2, True)
# HMAC(T_in,i || vin_i) # HMAC(T_in,i || vin_i)
hmac_vini = await offloading_keys.gen_hmac_vini( hmac_vini = offloading_keys.gen_hmac_vini(
state.key_hmac, src_entr, vini_bin, state.current_input_index state.key_hmac, src_entr, vini_bin, state.current_input_index
) )
state.mem_trace(3, True) state.mem_trace(3, True)

View File

@ -44,7 +44,7 @@ async def input_vini(
state.current_input_index += 1 state.current_input_index += 1
# HMAC(T_in,i || vin_i) # HMAC(T_in,i || vin_i)
hmac_vini_comp = await offloading_keys.gen_hmac_vini( hmac_vini_comp = offloading_keys.gen_hmac_vini(
state.key_hmac, state.key_hmac,
src_entr, src_entr,
vini_bin, vini_bin,

View File

@ -79,7 +79,7 @@ async def set_output(
return MoneroTransactionSetOutputAck() return MoneroTransactionSetOutputAck()
# Tx header prefix hashing, hmac dst_entr # Tx header prefix hashing, hmac dst_entr
tx_out_bin, hmac_vouti = await _set_out_tx_out(state, dst_entr, tx_out_key) tx_out_bin, hmac_vouti = _set_out_tx_out(state, dst_entr, tx_out_key)
state.mem_trace(11, True) state.mem_trace(11, True)
out_pk_dest, out_pk_commitment, ecdh_info_bin = _get_ecdh_info_and_out_pk( out_pk_dest, out_pk_commitment, ecdh_info_bin = _get_ecdh_info_and_out_pk(
@ -157,7 +157,7 @@ async def _validate(
if not state.is_processing_offloaded: if not state.is_processing_offloaded:
# HMAC check of the destination # HMAC check of the destination
dst_entr_hmac_computed = await offloading_keys.gen_hmac_tsxdest( dst_entr_hmac_computed = offloading_keys.gen_hmac_tsxdest(
state.key_hmac, dst_entr, state.current_output_index state.key_hmac, dst_entr, state.current_output_index
) )
@ -204,7 +204,7 @@ def _compute_tx_keys(
return tx_out_key, amount_key return tx_out_key, amount_key
async def _set_out_tx_out( def _set_out_tx_out(
state: State, dst_entr: MoneroTransactionDestinationEntry, tx_out_key: Ge25519 state: State, dst_entr: MoneroTransactionDestinationEntry, tx_out_key: Ge25519
) -> Tuple[bytes, bytes]: ) -> Tuple[bytes, bytes]:
""" """
@ -221,7 +221,7 @@ async def _set_out_tx_out(
state.mem_trace(9, True) state.mem_trace(9, True)
# Hmac dst_entr # Hmac dst_entr
hmac_vouti = await offloading_keys.gen_hmac_vouti( hmac_vouti = offloading_keys.gen_hmac_vouti(
state.key_hmac, dst_entr, tx_out_bin, state.current_output_index state.key_hmac, dst_entr, tx_out_bin, state.current_output_index
) )
state.mem_trace(10, True) state.mem_trace(10, True)

View File

@ -77,7 +77,7 @@ async def sign_input(
# Check input's HMAC # Check input's HMAC
from apps.monero.signing import offloading_keys from apps.monero.signing import offloading_keys
vini_hmac_comp = await offloading_keys.gen_hmac_vini( vini_hmac_comp = offloading_keys.gen_hmac_vini(
state.key_hmac, src_entr, vini_bin, input_position state.key_hmac, src_entr, vini_bin, input_position
) )
if not crypto.ct_equals(vini_hmac_comp, vini_hmac): if not crypto.ct_equals(vini_hmac_comp, vini_hmac):