Commit 76528c44 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

imgtool: Add rust language support to ECDSA

Generate rust code for ECDSA signatures, when requested (rather than
raising an exception)

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent d36e91ac
Loading
Loading
Loading
Loading
+13
Changes for scripts/imgtool/keys.py: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -115,6 +115,19 @@ class ECDSA256P1():
        print("\n};")
        print("const unsigned int ecdsa_pub_key_len = {};".format(len(encoded)))

    def emit_rust(self):
        vk = self.key.get_verifying_key()
        print(AUTOGEN_MESSAGE)
        print("static ECDSA_PUB_KEY: &'static [u8] = &[", end='')
        encoded = bytes(vk.to_der())
        for count, b in enumerate(encoded):
            if count % 8 == 0:
                print("\n    ", end='')
            else:
                print(" ", end='')
            print("0x{:02x},".format(b), end='')
        print("\n];")

    def sign(self, payload):
        # To make this fixed length, possibly pad with zeros.
        sig = self.key.sign(payload, hashfunc=hashlib.sha256, sigencode=util.sigencode_der)