From adf119acba550bff230f6ea34227420a68e9f7e8 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Thu, 18 Oct 2018 14:38:35 +0200 Subject: [PATCH] xmr: get rid of xmr.common module --- src/apps/monero/key_image_sync.py | 10 +++++----- src/apps/monero/layout/confirms.py | 4 ++-- .../protocol/signing/step_01_init_transaction.py | 2 +- .../monero/protocol/signing/step_04_input_vini.py | 6 +++--- .../monero/protocol/signing/step_06_set_output.py | 4 ++-- .../monero/protocol/signing/step_09_sign_input.py | 6 +++--- src/apps/monero/xmr/common.py | 13 ------------- src/apps/monero/xmr/crypto.py | 1 + src/apps/monero/xmr/monero.py | 11 +++++++---- 9 files changed, 24 insertions(+), 33 deletions(-) delete mode 100644 src/apps/monero/xmr/common.py diff --git a/src/apps/monero/key_image_sync.py b/src/apps/monero/key_image_sync.py index 8bf2439e8..eee06c0ff 100644 --- a/src/apps/monero/key_image_sync.py +++ b/src/apps/monero/key_image_sync.py @@ -1,10 +1,5 @@ import gc -from apps.monero.controller import misc -from apps.monero.layout import confirms -from apps.monero.xmr import crypto, key_image, monero -from apps.monero.xmr.enc import chacha_poly - from trezor import log, wire from trezor.messages import MessageType from trezor.messages.MoneroExportedKeyImage import MoneroExportedKeyImage @@ -12,6 +7,11 @@ from trezor.messages.MoneroKeyImageSyncFinalAck import MoneroKeyImageSyncFinalAck from trezor.messages.MoneroKeyImageSyncStepAck import MoneroKeyImageSyncStepAck +from apps.monero.controller import misc +from apps.monero.layout import confirms +from apps.monero.xmr import crypto, key_image, monero +from apps.monero.xmr.enc import chacha_poly + async def key_image_sync(ctx, msg): state = KeyImageSync() diff --git a/src/apps/monero/layout/confirms.py b/src/apps/monero/layout/confirms.py index bedb63f84..8ad1524e0 100644 --- a/src/apps/monero/layout/confirms.py +++ b/src/apps/monero/layout/confirms.py @@ -1,5 +1,3 @@ -from apps.common.confirm import require_confirm, require_hold_to_confirm - from trezor import ui from trezor.messages import ButtonRequestType from trezor.ui.text import Text @@ -7,6 +5,8 @@ from . import common +from apps.common.confirm import require_confirm, require_hold_to_confirm + async def confirm_out(ctx, dst, is_change=False, creds=None, int_payment=None): """ diff --git a/src/apps/monero/protocol/signing/step_01_init_transaction.py b/src/apps/monero/protocol/signing/step_01_init_transaction.py index 9257bb8f7..602c805e0 100644 --- a/src/apps/monero/protocol/signing/step_01_init_transaction.py +++ b/src/apps/monero/protocol/signing/step_01_init_transaction.py @@ -288,7 +288,7 @@ def _process_payment_id(state: State, tsx_data: MoneroTransactionData): See: - https://github.com/monero-project/monero/blob/ff7dc087ae5f7de162131cea9dbcf8eac7c126a1/src/cryptonote_basic/tx_extra.h """ - if common.is_empty(tsx_data.payment_id): + if not tsx_data.payment_id: return # encrypted payment id diff --git a/src/apps/monero/protocol/signing/step_04_input_vini.py b/src/apps/monero/protocol/signing/step_04_input_vini.py index 6ed7dca27..38536391d 100644 --- a/src/apps/monero/protocol/signing/step_04_input_vini.py +++ b/src/apps/monero/protocol/signing/step_04_input_vini.py @@ -10,7 +10,7 @@ from apps.monero.protocol import hmac_encryption_keys from apps.monero.protocol.signing.rct_type import RctType from apps.monero.protocol.signing.rsig_type import RsigType -from apps.monero.xmr import common, crypto +from apps.monero.xmr import crypto if False: from trezor.messages.MoneroTransactionSourceEntry import ( @@ -45,7 +45,7 @@ async def input_vini( vini_bin, state.source_permutation[state.current_input_index], ) - if not common.ct_equal(hmac_vini_comp, vini_hmac): + if not crypto.ct_equals(hmac_vini_comp, vini_hmac): raise ValueError("HMAC is not correct") """ @@ -69,7 +69,7 @@ def _hash_vini_pseudo_out(state: State, pseudo_out: bytes, pseudo_out_hmac: byte pseudo_out_hmac_comp = crypto.compute_hmac( hmac_encryption_keys.hmac_key_txin_comm(state.key_hmac, idx), pseudo_out ) - if not common.ct_equal(pseudo_out_hmac, pseudo_out_hmac_comp): + if not crypto.ct_equals(pseudo_out_hmac, pseudo_out_hmac_comp): raise ValueError("HMAC invalid for pseudo outs") state.full_message_hasher.set_pseudo_out(pseudo_out) diff --git a/src/apps/monero/protocol/signing/step_06_set_output.py b/src/apps/monero/protocol/signing/step_06_set_output.py index ac892bb00..175324363 100644 --- a/src/apps/monero/protocol/signing/step_06_set_output.py +++ b/src/apps/monero/protocol/signing/step_06_set_output.py @@ -12,7 +12,7 @@ from apps.monero.layout import confirms from apps.monero.protocol import hmac_encryption_keys from apps.monero.protocol.signing.rsig_type import RsigType -from apps.monero.xmr import common, crypto +from apps.monero.xmr import crypto async def set_output(state: State, dst_entr, dst_entr_hmac, rsig_data): @@ -112,7 +112,7 @@ async def _validate(state: State, dst_entr, dst_entr_hmac): dst_entr_hmac_computed = await hmac_encryption_keys.gen_hmac_tsxdest( state.key_hmac, dst_entr, state.current_output_index ) - if not common.ct_equal(dst_entr_hmac, dst_entr_hmac_computed): + if not crypto.ct_equals(dst_entr_hmac, dst_entr_hmac_computed): raise ValueError("HMAC invalid") del (dst_entr_hmac, dst_entr_hmac_computed) state.mem_trace(3, True) diff --git a/src/apps/monero/protocol/signing/step_09_sign_input.py b/src/apps/monero/protocol/signing/step_09_sign_input.py index 2e6725f79..e0791423b 100644 --- a/src/apps/monero/protocol/signing/step_09_sign_input.py +++ b/src/apps/monero/protocol/signing/step_09_sign_input.py @@ -9,7 +9,7 @@ from apps.monero.controller import misc from apps.monero.layout import confirms from apps.monero.protocol.signing.rct_type import RctType -from apps.monero.xmr import common, crypto +from apps.monero.xmr import crypto if False: from trezor.messages.MoneroTransactionSourceEntry import ( @@ -61,7 +61,7 @@ async def sign_input( vini_hmac_comp = await hmac_encryption_keys.gen_hmac_vini( state.key_hmac, src_entr, vini_bin, input_position ) - if not common.ct_equal(vini_hmac_comp, vini_hmac): + if not crypto.ct_equals(vini_hmac_comp, vini_hmac): raise ValueError("HMAC is not correct") gc.collect() @@ -74,7 +74,7 @@ async def sign_input( hmac_encryption_keys.hmac_key_txin_comm(state.key_hmac, input_position), pseudo_out, ) - if not common.ct_equal(pseudo_out_hmac_comp, pseudo_out_hmac): + if not crypto.ct_equals(pseudo_out_hmac_comp, pseudo_out_hmac): raise ValueError("HMAC is not correct") gc.collect() diff --git a/src/apps/monero/xmr/common.py b/src/apps/monero/xmr/common.py deleted file mode 100644 index 154fdc801..000000000 --- a/src/apps/monero/xmr/common.py +++ /dev/null @@ -1,13 +0,0 @@ -from trezor.crypto import monero - - -class XmrException(Exception): - pass - - -def ct_equal(a, b): - return monero.ct_equals(a, b) - - -def is_empty(inp): - return inp is None or len(inp) == 0 diff --git a/src/apps/monero/xmr/crypto.py b/src/apps/monero/xmr/crypto.py index 9db4cc163..54f241fa9 100644 --- a/src/apps/monero/xmr/crypto.py +++ b/src/apps/monero/xmr/crypto.py @@ -14,6 +14,7 @@ random_bytes = random.bytes +ct_equals = tcry.ct_equals def keccak_factory(data=None): diff --git a/src/apps/monero/xmr/monero.py b/src/apps/monero/xmr/monero.py index 52d28098f..0d22a9fc4 100644 --- a/src/apps/monero/xmr/monero.py +++ b/src/apps/monero/xmr/monero.py @@ -1,6 +1,6 @@ from micropython import const -from apps.monero.xmr import common, crypto +from apps.monero.xmr import crypto if False: from apps.monero.xmr.types import * @@ -9,9 +9,12 @@ DISPLAY_DECIMAL_POINT = const(12) -class XmrNoSuchAddressException(common.XmrException): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) +class XmrException(Exception): + pass + + +class XmrNoSuchAddressException(XmrException): + pass def get_subaddress_secret_key(secret_key, index=None, major=None, minor=None):