1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-27 18:08:15 +00:00
trezor-firmware/core/embed/firmware/bootloader_hashes.py
Pavol Rusnak 5536fbb98a python: use stdlib blake2s on python 3.6+
commit 6d407c84d7 did not replace everything
2020-08-10 23:35:38 +02:00

24 lines
844 B
Python
Executable File

#!/usr/bin/env python3
import glob
try:
from hashlib import blake2s
except ImportError:
from pyblake2 import blake2s
ALIGNED_SIZE = 128 * 1024
files = glob.glob("bootloader*.bin")
for fn in sorted(files):
data = open(fn, "rb").read()
if len(data) > ALIGNED_SIZE:
raise ValueError(fn, "too big")
data_00 = data + b"\x00" * (ALIGNED_SIZE - len(data))
data_ff = data + b"\xff" * (ALIGNED_SIZE - len(data))
h_00 = blake2s(data=data_00).digest()
h_ff = blake2s(data=data_ff).digest()
h_00 = "".join(["\\x%02x" % i for i in h_00])
h_ff = "".join(["\\x%02x" % i for i in h_ff])
print(" // %s (padded with 0x00)\n if (0 == memcmp(hash, \"%s\", 32)) return sectrue;" % (fn, h_00))
print(" // %s (padded with 0xff)\n if (0 == memcmp(hash, \"%s\", 32)) return sectrue;" % (fn, h_ff))