mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-17 19:00:58 +00:00
feat(tools): Add firmware_hash.py.
This commit is contained in:
parent
e9828a5b59
commit
1b43b2190a
29
tools/firmware_hash.py
Executable file
29
tools/firmware_hash.py
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from hashlib import blake2s
|
||||||
|
|
||||||
|
FILE_T1 = "legacy/firmware/trezor.bin"
|
||||||
|
FILE_T2 = "core/build/firmware/firmware.bin"
|
||||||
|
|
||||||
|
SIZE_T1 = (7 * 128 + 64) * 1024
|
||||||
|
SIZE_T2 = 13 * 128 * 1024
|
||||||
|
|
||||||
|
for filename, size in ((FILE_T1, SIZE_T1), (FILE_T2, SIZE_T2)):
|
||||||
|
try:
|
||||||
|
data = open(filename, "rb").read()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"{filename} not found")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if len(data) > size:
|
||||||
|
raise ValueError(filename, "too big")
|
||||||
|
data = data + b"\xff" * (size - len(data))
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
challenge = bytes.fromhex(sys.argv[1])
|
||||||
|
firmware_hash = blake2s(data, key=challenge).hexdigest()
|
||||||
|
else:
|
||||||
|
firmware_hash = blake2s(data).hexdigest()
|
||||||
|
|
||||||
|
print(f"{filename}: {firmware_hash}")
|
Loading…
Reference in New Issue
Block a user