1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00
trezor-firmware/embed/firmware/bootloader_hashes.py

21 lines
788 B
Python
Executable File

#!/usr/bin/env python3
import glob
import pyblake2
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 = pyblake2.blake2s(data=data_00).digest()
h_ff = pyblake2.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))