Skip to content

Commit

Permalink
scripts: Fix extracted ECDSA signature padding
Browse files Browse the repository at this point in the history
Ensure that ECDSA key components that are too short are properly
left-padded with 0s.

Signed-off-by: Kendall Goto <[email protected]>
  • Loading branch information
kendallgoto committed Jan 22, 2025
1 parent c9251c2 commit a388b30
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/bootloader/asn1parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_ecdsa_signature(der, clength):
# Disable pylint error as 'input' keyword has specific handling in 'check_output'
# pylint: disable=unexpected-keyword-arg
stdout = check_output(['openssl', 'asn1parse', '-inform', 'der'], input=der)
sig = b''.join([bytes.fromhex(re.search(r'(?<=\:)([0-9A-F]+)', num)[0]).ljust(clength, b'\0') \
sig = b''.join([bytes.fromhex(re.search(r'(?<=\:)([0-9A-F]+)', num)[0]).rjust(clength, b'\0') \
for num in re.findall(r'INTEGER *\:[0-9A-F]+', stdout.decode())])

assert len(sig) == 2*clength
Expand Down

0 comments on commit a388b30

Please sign in to comment.