imgtool: Allow --key to be optional when signing
If the --key is not specified, only the SHA256 hash is added to the TLV.
This is useful for testing configurations, where the crypto has not been
fully configured. Note that this configuration is not secure, and this
only verifies that the image has not been corrupted.
diff --git a/scripts/imgtool/image.py b/scripts/imgtool/image.py
index c4bedfe..f270268 100644
--- a/scripts/imgtool/image.py
+++ b/scripts/imgtool/image.py
@@ -101,8 +101,9 @@
tlv.add('SHA256', digest)
- sig = key.sign(self.payload)
- tlv.add(key.sig_tlv(), sig)
+ if key is not None:
+ sig = key.sign(self.payload)
+ tlv.add(key.sig_tlv(), sig)
self.payload += tlv.get()
@@ -112,9 +113,11 @@
The key is needed to know the type of signature, and
approximate the size of the signature."""
- flags = IMAGE_F[key.sig_type()]
+ flags = 0
tlvsz = 0
- tlvsz += TLV_HEADER_SIZE + key.sig_len()
+ if key is not None:
+ flags |= IMAGE_F[key.sig_type()]
+ tlvsz += TLV_HEADER_SIZE + key.sig_len()
flags |= IMAGE_F['SHA256']
tlvsz += 4 + hashlib.sha256().digest_size