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

Commit

Permalink
xmr: manual serialization improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Sep 13, 2018
1 parent d07cee6 commit 9e5e047
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/apps/monero/protocol/tsx_sign_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ async def set_out1(self, dst_entr, dst_entr_hmac, rsig_data=None):
# Incremental hashing of the ECDH info.
# RctSigBase allows to hash only one of the (ecdh, out_pk) as they are serialized
# as whole vectors. Hashing ECDH info saves state space.
self.full_message_hasher.set_ecdh(ecdh_info_bin, True)
self.full_message_hasher.set_ecdh(ecdh_info_bin)
self._mem_trace(13, True)

# Output_pk is stored to the state as it is used during the signature and hashed to the
Expand Down
6 changes: 3 additions & 3 deletions src/apps/monero/xmr/serialize/xmrserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ def uvarint(self, elem):
else:
return load_uvarint(self.iobj)

def uint(self, elem, elem_type, params=None):
def uint(self, elem, elem_type=None, width=None):
"""
Fixed size int
"""
if self.writing:
return dump_uint(self.iobj, elem, elem_type.WIDTH)
return dump_uint(self.iobj, elem, width if width else elem_type.WIDTH)
else:
return load_uint(self.iobj, elem_type.WIDTH)
return load_uint(self.iobj, width if width else elem_type.WIDTH)

def unicode_type(self, elem):
"""
Expand Down
8 changes: 8 additions & 0 deletions src/apps/monero/xmr/sub/keccak_hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def release(self):
def buffer(self, buf):
return self.kwriter.write(buf)

def uvarint(self, i):
ar = self._ar(None)
ar.uvarint(i)

def uint(self, i, width):
ar = self._ar(None)
ar.uint(i, width=width)

def field(self, elem=None, elem_type=None, params=None, xser=None):
ar = self._ar(xser)
return ar.field(elem, elem_type, params)
Expand Down
25 changes: 6 additions & 19 deletions src/apps/monero/xmr/sub/mlsag_hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,8 @@ def set_type_fee(self, rv_type, fee):
if self.state != 1:
raise ValueError("State error")
self.state = 2

from apps.monero.xmr.serialize_messages.tx_full import RctSigBase

rfields = RctSigBase.f_specs()
self.rtcsig_hasher.message_field(None, field=rfields[0], fvalue=rv_type)
self.rtcsig_hasher.message_field(None, field=rfields[1], fvalue=fee)
self.rtcsig_hasher.uint(rv_type, 1) # UInt8
self.rtcsig_hasher.uvarint(fee) # UVarintType

def set_pseudo_out(self, out):
if self.state != 2 and self.state != 3:
Expand All @@ -70,26 +66,17 @@ def set_pseudo_out(self, out):

self.rtcsig_hasher.field(out, KeyV.ELEM_TYPE)

def set_ecdh(self, ecdh, raw=False):
def set_ecdh(self, ecdh):
if self.state != 2 and self.state != 3 and self.state != 4:
raise ValueError("State error")
self.state = 4
self.rtcsig_hasher.buffer(ecdh)

if raw:
self.rtcsig_hasher.buffer(ecdh)
else:
from apps.monero.xmr.serialize_messages.tx_ecdh import EcdhInfo

self.rtcsig_hasher.field(ecdh, EcdhInfo.ELEM_TYPE)

def set_out_pk(self, out_pk, mask=None):
def set_out_pk(self, out_pk):
if self.state != 4 and self.state != 5:
raise ValueError("State error")
self.state = 5

from apps.monero.xmr.serialize_messages.base import ECKey

self.rtcsig_hasher.field(mask if mask else out_pk.mask, ECKey)
self.rtcsig_hasher.buffer(out_pk.mask) # ECKey

def rctsig_base_done(self):
if self.state != 5:
Expand Down

0 comments on commit 9e5e047

Please sign in to comment.