1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 21:22:10 +00:00

python: use stdlib blake2s on python 3.6+

commit 6d407c84d7 did not replace everything
This commit is contained in:
Pavol Rusnak 2020-08-09 10:40:43 +02:00
parent 1e58c86a9a
commit 5536fbb98a
2 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python3
import glob
import pyblake2
try:
from hashlib import blake2s
except ImportError:
from pyblake2 import blake2s
ALIGNED_SIZE = 128 * 1024
@ -12,8 +15,8 @@ for fn in sorted(files):
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 = 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))

View File

@ -4,10 +4,15 @@ from typing import Any, List, Optional
import click
import construct as c
import pyblake2
from trezorlib import cosi, firmware
try:
from hashlib import blake2s
except ImportError:
from pyblake2 import blake2s
SYM_OK = click.style("\u2714", fg="green")
SYM_FAIL = click.style("\u274c", fg="red")
@ -47,7 +52,7 @@ def compute_vhash(vendor_header):
m = vendor_header.sig_m
n = vendor_header.sig_n
pubkeys = vendor_header.pubkeys
h = pyblake2.blake2s()
h = blake2s()
h.update(struct.pack("<BB", m, n))
for i in range(8):
if i < n: