mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-09 10:28:46 +00:00
python: use stdlib blake2s on python 3.6+
commit 6d407c84d7
did not replace everything
This commit is contained in:
parent
1e58c86a9a
commit
5536fbb98a
@ -1,6 +1,9 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import glob
|
import glob
|
||||||
import pyblake2
|
try:
|
||||||
|
from hashlib import blake2s
|
||||||
|
except ImportError:
|
||||||
|
from pyblake2 import blake2s
|
||||||
|
|
||||||
ALIGNED_SIZE = 128 * 1024
|
ALIGNED_SIZE = 128 * 1024
|
||||||
|
|
||||||
@ -12,8 +15,8 @@ for fn in sorted(files):
|
|||||||
raise ValueError(fn, "too big")
|
raise ValueError(fn, "too big")
|
||||||
data_00 = data + b"\x00" * (ALIGNED_SIZE - len(data))
|
data_00 = data + b"\x00" * (ALIGNED_SIZE - len(data))
|
||||||
data_ff = data + b"\xff" * (ALIGNED_SIZE - len(data))
|
data_ff = data + b"\xff" * (ALIGNED_SIZE - len(data))
|
||||||
h_00 = pyblake2.blake2s(data=data_00).digest()
|
h_00 = blake2s(data=data_00).digest()
|
||||||
h_ff = pyblake2.blake2s(data=data_ff).digest()
|
h_ff = blake2s(data=data_ff).digest()
|
||||||
h_00 = "".join(["\\x%02x" % i for i in h_00])
|
h_00 = "".join(["\\x%02x" % i for i in h_00])
|
||||||
h_ff = "".join(["\\x%02x" % i for i in h_ff])
|
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 0x00)\n if (0 == memcmp(hash, \"%s\", 32)) return sectrue;" % (fn, h_00))
|
||||||
|
@ -4,10 +4,15 @@ from typing import Any, List, Optional
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
import construct as c
|
import construct as c
|
||||||
import pyblake2
|
|
||||||
|
|
||||||
from trezorlib import cosi, firmware
|
from trezorlib import cosi, firmware
|
||||||
|
|
||||||
|
try:
|
||||||
|
from hashlib import blake2s
|
||||||
|
except ImportError:
|
||||||
|
from pyblake2 import blake2s
|
||||||
|
|
||||||
|
|
||||||
SYM_OK = click.style("\u2714", fg="green")
|
SYM_OK = click.style("\u2714", fg="green")
|
||||||
SYM_FAIL = click.style("\u274c", fg="red")
|
SYM_FAIL = click.style("\u274c", fg="red")
|
||||||
|
|
||||||
@ -47,7 +52,7 @@ def compute_vhash(vendor_header):
|
|||||||
m = vendor_header.sig_m
|
m = vendor_header.sig_m
|
||||||
n = vendor_header.sig_n
|
n = vendor_header.sig_n
|
||||||
pubkeys = vendor_header.pubkeys
|
pubkeys = vendor_header.pubkeys
|
||||||
h = pyblake2.blake2s()
|
h = blake2s()
|
||||||
h.update(struct.pack("<BB", m, n))
|
h.update(struct.pack("<BB", m, n))
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
if i < n:
|
if i < n:
|
||||||
|
Loading…
Reference in New Issue
Block a user