Skip to content

Commit

Permalink
xmr: wrappers cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Sep 13, 2018
1 parent aa86fb1 commit 5ccb2fb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 60 deletions.
58 changes: 0 additions & 58 deletions src/apps/monero/xmr/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,11 @@ class XmrException(Exception):
pass


def random_bytes(by):
"""
Generates X random bytes, returns byte-string
:param by:
:return:
"""
return random.bytes(by)


def ct_equal(a, b):
"""
Constant time a,b comparison
:param a:
:param b:
:return:
"""
return monero.ct_equals(a, b)


def memcpy(dst, dst_from, src, src_from, length):
from trezor.utils import memcpy

return memcpy(dst, dst_from, src, src_from, length)


def check_permutation(permutation):
"""
Check permutation sanity
:param permutation:
:return:
"""
for n in range(len(permutation)):
if n not in permutation:
raise ValueError("Invalid permutation")
Expand All @@ -62,41 +36,9 @@ def apply_permutation(permutation, swapper):


def is_empty(inp):
"""
True if none or empty
:param inp:
:return:
"""
return inp is None or len(inp) == 0


def defval(val, default=None):
"""
Returns val if is not None, default instead
:param val:
:param default:
:return:
"""
return val if val is not None else default


def defval_empty(val, default=None):
"""
Returns val if is not None, default instead
:param val:
:param default:
:return:
"""
return val if not is_empty(val) else default


def chunk(arr, size=1):
res = []
idx = 0
while True:
c = arr[idx : idx + size]
res.append(c)
idx += size
if len(c) != size:
break
return res
4 changes: 2 additions & 2 deletions src/apps/monero/xmr/ring_ct.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def generate_ring_signature(prefix_hash, image, pubs, sec, sec_idx, test=False):
:param test:
:return:
"""
from apps.monero.xmr.common import memcpy
from trezor.utils import memcpy

if test:
from apps.monero.xmr import monero
Expand Down Expand Up @@ -250,7 +250,7 @@ def check_ring_singature(prefix_hash, image, pubs, sig):
:param sig:
:return:
"""
from apps.monero.xmr.common import memcpy
from trezor.utils import memcpy

image_unp = crypto.ge_frombytes_vartime(image)
image_pre = crypto.ge_dsm_precomp(image_unp)
Expand Down

0 comments on commit 5ccb2fb

Please sign in to comment.