1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 08:08:51 +00:00

split trezor.crypto into more modules

This commit is contained in:
Pavol Rusnak 2016-04-11 11:10:43 +02:00
parent ed39c2001e
commit 0d8112f6b4
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 29 additions and 5 deletions

View File

@ -15,7 +15,7 @@ build_unix: ## build unix port
make -C vendor/micropython/unix
run_unix: ## run unix port
./vendor/micropython/unix/micropython
cd src ; ../vendor/micropython/unix/micropython
flash: ## flash firmware using st-flash
st-flash write $(STMHAL_BUILD_DIR)/firmware0.bin 0x8000000

1
emu.sh
View File

@ -2,3 +2,4 @@
cd `dirname $0`/src
rm -f ../pipe.*
../vendor/micropython/unix/micropython $* -O0 -X heapsize=100000 main.py
rm -f ../pipe.*

View File

@ -1,4 +0,0 @@
from TrezorCrypto import Base58, Sha256
base58 = Base58()
sha256 = Sha256()

View File

View File

@ -0,0 +1,21 @@
from TrezorCrypto import Base58
from . import sha256
_base58 = Base58()
def encode(data):
return _base58.encode(data)
def decode(string):
return _base58.decode(string)
def encode_check(data, hashlen=4):
h = sha256.hash(data)
return encode(data + h[:hashlen])
def decode_check(string, hashlen=4):
data = decode(string)
d, h = data[:-hashlen], data[-hashlen:]
if sha256.hash(d) != h:
raise RuntimeError('Checksum error')
return d

View File

@ -0,0 +1,6 @@
from TrezorCrypto import Sha256
_sha256 = Sha256()
def hash(data):
return _sha256.hash(data)