Skip to content

Commit 2b6d093

Browse files
committed
sign.py: Fixed parsing size of public key when in 'manual-sign' or 'sha-only'
mode.
1 parent f2ba779 commit 2b6d093

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

tools/keytools/sign.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,27 @@
135135
kf = open(key_file, "rb")
136136
wolfboot_key_buffer = kf.read(4096)
137137
wolfboot_key_buffer_len = len(wolfboot_key_buffer)
138-
if wolfboot_key_buffer_len == 64:
139-
if (sign == 'ecc256'):
140-
print("Error: key size does not match the cipher selected")
138+
if wolfboot_key_buffer_len == 32:
139+
if (sign != 'ed25519' and not manual_sign and not sha_only):
140+
print("Error: key too short for cipher")
141141
sys.exit(1)
142-
if sign == 'auto':
142+
elif sign == 'auto' and (manual_sign or sha_only):
143143
sign = 'ed25519'
144-
print("'ed25519' key autodetected.")
144+
print("'ed25519' public key autodetected.")
145+
elif wolfboot_key_buffer_len == 64:
146+
if (sign == 'ecc256'):
147+
if not manual_sign and not sha_only:
148+
print("Error: key size does not match the cipher selected")
149+
sys.exit(1)
150+
else:
151+
print("Ecc256 public key detected")
152+
if sign == 'auto':
153+
if (manual_sign or sha_only):
154+
sign = 'ecc256'
155+
print("'ecc256' public key autodetected.")
156+
else:
157+
sign = 'ed25519'
158+
print("'ed25519' key autodetected.")
145159
elif wolfboot_key_buffer_len == 96:
146160
if (sign == 'ed25519'):
147161
print("Error: key size does not match the cipher selected")

0 commit comments

Comments
 (0)