1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-02 21:02:34 +00:00
trezor-firmware/core/src/apps/monero/xmr/keccak_hasher.py
Dusan Klinec 33c174491f refactor(core/monero): Monero code cleanup
* remove support for HF12 and below
* remove MLSAG support
* clean up monero cryptography naming
* get rid of "optional first argument" pattern, in favor of mandatory argument that is allowed to be None
  (and fix several bugs related to this feature)

Co-authored-by: grdddj <jiri.musil06@seznam.cz>
Co-authored-by: Martin Milata <martin@martinmilata.cz>
Co-authored-by: matejcik <ja@matejcik.cz>
2022-05-16 12:37:24 +02:00

33 lines
878 B
Python

from typing import TYPE_CHECKING
from trezor.utils import HashWriter
from apps.monero.xmr import crypto_helpers
from apps.monero.xmr.serialize import int_serialize
if TYPE_CHECKING:
from trezor.utils import HashContext
class KeccakXmrArchive:
def __init__(self, ctx: HashContext | None = None) -> None:
self.kwriter = get_keccak_writer(ctx)
def get_digest(self) -> bytes:
return self.kwriter.get_digest()
def buffer(self, buf: bytes) -> None:
return self.kwriter.write(buf)
def uvarint(self, i: int) -> None:
int_serialize.dump_uvarint(self.kwriter, i)
def uint(self, i: int, width: int) -> None:
int_serialize.dump_uint(self.kwriter, i, width)
def get_keccak_writer(ctx: HashContext | None = None) -> HashWriter:
if ctx is None:
ctx = crypto_helpers.get_keccak()
return HashWriter(ctx)