mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-27 00:28:10 +00:00
split trezor.crypto into more modules
This commit is contained in:
parent
ed39c2001e
commit
0d8112f6b4
2
Makefile
2
Makefile
@ -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
1
emu.sh
@ -2,3 +2,4 @@
|
||||
cd `dirname $0`/src
|
||||
rm -f ../pipe.*
|
||||
../vendor/micropython/unix/micropython $* -O0 -X heapsize=100000 main.py
|
||||
rm -f ../pipe.*
|
||||
|
@ -1,4 +0,0 @@
|
||||
from TrezorCrypto import Base58, Sha256
|
||||
|
||||
base58 = Base58()
|
||||
sha256 = Sha256()
|
0
src/trezor/crypto/__init__.py
Normal file
0
src/trezor/crypto/__init__.py
Normal file
21
src/trezor/crypto/base58.py
Normal file
21
src/trezor/crypto/base58.py
Normal 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
|
6
src/trezor/crypto/sha256.py
Normal file
6
src/trezor/crypto/sha256.py
Normal file
@ -0,0 +1,6 @@
|
||||
from TrezorCrypto import Sha256
|
||||
|
||||
_sha256 = Sha256()
|
||||
|
||||
def hash(data):
|
||||
return _sha256.hash(data)
|
Loading…
Reference in New Issue
Block a user