Skip to content

Commit

Permalink
xmr: get rid of xmr.common module
Browse files Browse the repository at this point in the history
  • Loading branch information
jpochyla committed Oct 18, 2018
1 parent 3531a42 commit adf119a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/apps/monero/key_image_sync.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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
from trezor.messages.MoneroKeyImageExportInitAck import MoneroKeyImageExportInitAck
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()
Expand Down
4 changes: 2 additions & 2 deletions src/apps/monero/layout/confirms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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
from trezor.utils import chunks

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):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/apps/monero/protocol/signing/step_04_input_vini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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")

"""
Expand All @@ -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)
4 changes: 2 additions & 2 deletions src/apps/monero/protocol/signing/step_06_set_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/apps/monero/protocol/signing/step_09_sign_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
13 changes: 0 additions & 13 deletions src/apps/monero/xmr/common.py

This file was deleted.

1 change: 1 addition & 0 deletions src/apps/monero/xmr/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


random_bytes = random.bytes
ct_equals = tcry.ct_equals


def keccak_factory(data=None):
Expand Down
11 changes: 7 additions & 4 deletions src/apps/monero/xmr/monero.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand All @@ -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):
Expand Down

0 comments on commit adf119a

Please sign in to comment.