Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
xmr: code reduction diet
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Jul 27, 2018
1 parent c6261bc commit 7e14253
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/apps/monero/key_image_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def layout_key_image_sync(state, ctx, msg):

log.debug(
__name__,
"### KI sync importedd. Free: {} Allocated: {}".format(
"### KI sync imported. Free: {} Allocated: {}".format(
gc.mem_free(), gc.mem_alloc()
),
)
Expand Down
42 changes: 0 additions & 42 deletions src/apps/monero/xmr/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,48 +96,6 @@ def defval_empty(val, default=None):
return val if not is_empty(val) else default


def defvalkey(js, key, default=None, take_none=True):
"""
Returns js[key] if set, otherwise default. Note js[key] can be None.
:param js:
:param key:
:param default:
:param take_none:
:return:
"""
if js is None:
return default
if key not in js:
return default
if js[key] is None and not take_none:
return default
return js[key]


def defvalkeys(js, key, default=None):
"""
Returns js[key] if set, otherwise default. Note js[key] can be None.
Key is array of keys. js[k1][k2][k3]...
:param js:
:param key:
:param default:
:return:
"""
if js is None:
return default
if not isinstance(key, (tuple, list)):
key = key.split(".")
try:
cur = js
for ckey in key:
cur = cur[ckey]
return cur
except Exception:
pass
return default


def chunk(arr, size=1):
res = []
idx = 0
Expand Down
17 changes: 1 addition & 16 deletions src/apps/monero/xmr/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,7 @@
from trezor.crypto import hmac, monero as tcry, pbkdf2 as tpbkdf2, random
from trezor.crypto.hashlib import sha3_256

# py constants
# b = const(256)
# q = const(2**255 - 19)
# l = const(2**252 + 27742317777372353535851937790883648493)
# d = const(-0x98412dfc9311d490018c7338bf8688861767ff8ff5b2bebe27548a14b235ec8feda4) # -121665 * inv(121666) % q

# py constants
# b = 256
# q = 2 ** 255 - 19
# l = 2 ** 252 + 27742317777372353535851937790883648493
# d = -0x98412dfc9311d490018c7338bf8688861767ff8ff5b2bebe27548a14b235ec8feda4 # -121665 * inv(121666) % q

# py_b = b
# py_q = q
# py_l = l
# py_d = d

NULL_KEY_ENC = [0] * 32


Expand Down
57 changes: 0 additions & 57 deletions src/apps/monero/xmr/sub/mlsag_hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from apps.monero.xmr.serialize_messages.ct_keys import KeyV
from apps.monero.xmr.serialize_messages.tx_ecdh import EcdhInfo
from apps.monero.xmr.serialize_messages.tx_full import RctSigBase
from apps.monero.xmr.serialize_messages.tx_rsig import RctType


class PreMlsagHasher(object):
Expand Down Expand Up @@ -138,59 +137,3 @@ async def get_digest(self):

self.kc_master.update(c_hash)
return self.kc_master.digest()


async def get_pre_mlsag_hash(rv):
"""
Generates final message for the Ring CT signature
:param rv:
:type rv: RctSig
:return:
"""
from apps.monero.xmr.sub.keccak_hasher import get_keccak_writer, HashWrapper
from apps.monero.xmr.serialize import xmrserialize

kc_master = HashWrapper(crypto.get_keccak())
kc_master.update(rv.message)

is_simple = rv.type in [RctType.Simple, RctType.SimpleBulletproof]
inputs = len(rv.pseudoOuts) if is_simple else 0
outputs = len(rv.ecdhInfo)

kwriter = get_keccak_writer()
ar = xmrserialize.Archive(kwriter, True)
await rv.serialize_rctsig_base(ar, inputs, outputs)
c_hash = kwriter.get_digest()
kc_master.update(c_hash)

kc = crypto.get_keccak()
if rv.type in [RctType.FullBulletproof, RctType.SimpleBulletproof]:
for p in rv.p.bulletproofs:
kc.update(p.A)
kc.update(p.S)
kc.update(p.T1)
kc.update(p.T2)
kc.update(p.taux)
kc.update(p.mu)
for i in range(len(p.L)):
kc.update(p.L[i])
for i in range(len(p.R)):
kc.update(p.R[i])
kc.update(p.a)
kc.update(p.b)
kc.update(p.t)

else:
for r in rv.p.rangeSigs:
for i in range(64):
kc.update(r.asig.s0[i])
for i in range(64):
kc.update(r.asig.s1[i])
kc.update(r.asig.ee)
for i in range(64):
kc.update(r.Ci[i])

c_hash = kc.digest()
kc_master.update(c_hash)
return kc_master.digest()

0 comments on commit 7e14253

Please sign in to comment.