From 56eb351816b4b7bcf5301e9cf40142c839334b32 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 1 Nov 2016 15:23:37 +0100 Subject: [PATCH] trezor.crypto: add hashlib.HashIO --- src/trezor/crypto/hashlib.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/trezor/crypto/hashlib.py b/src/trezor/crypto/hashlib.py index 3f8708da..a9fb710d 100644 --- a/src/trezor/crypto/hashlib.py +++ b/src/trezor/crypto/hashlib.py @@ -3,3 +3,15 @@ from TrezorCrypto import Sha256 as sha256 from TrezorCrypto import Sha512 as sha512 from TrezorCrypto import Sha3_256 as sha3_256 from TrezorCrypto import Sha3_512 as sha3_512 + +class HashIO: + + def __init__(self, hashfunc=sha256): + self.hashfunc = hashfunc + self.ctx = hashfunc() + + def write(self, data): + self.ctx.update(data) + + def getvalue(self): + return self.ctx.digest()