Skip to content

Commit edc4023

Browse files
michalek-nonvlsianpu
authored andcommitted
scripts: bootloader: provision: key validity check fix
uses proper hash to verify validity of signature keys. Signed-off-by: Mateusz Michalek <[email protected]>
1 parent 6756485 commit edc4023

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

scripts/bootloader/provision.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import argparse
77
import os
88
import struct
9-
from hashlib import sha256
9+
from hashlib import sha256, sha512
1010

1111
from cryptography.hazmat.primitives import serialization
1212
from cryptography.hazmat.primitives.asymmetric import ec, ed25519
@@ -174,7 +174,11 @@ def get_hashes(public_key_files, verify_hashes):
174174
hashes = list()
175175
for fn in public_key_files:
176176
with open(fn, 'rb') as f:
177-
digest = sha256(public_key_to_string(load_pem_public_key(f.read()))).digest()[:16]
177+
key_data = load_pem_public_key(f.read())
178+
if isinstance(key_data, ed25519.Ed25519PublicKey):
179+
digest = sha512(public_key_to_string(key_data)).digest()[:16]
180+
else:
181+
digest = sha256(public_key_to_string(key_data)).digest()[:16]
178182
if verify_hashes and any([digest[n:n + 2] == b'\xff\xff' for n in range(0, len(digest), 2)]):
179183
raise RuntimeError(f"Hash of key in '{os.path.abspath(f.name)}' contains 0xffff. Please regenerate the key.")
180184
hashes.append(digest)

0 commit comments

Comments
 (0)