Commit 2c9153a2 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

imgtool: ECDSA pad signature

Until we fix the padding problem, pad the ecdsa signatures with zeros to
always be 72 bytes long.  Add a 'raw_sign' method so that the unit test
can use the real signature.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent b6e0ae69
Loading
Loading
Loading
Loading
+8 −1
Changes for scripts/imgtool/keys/ecdsa.py: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -89,7 +89,14 @@ class ECDSA256P1(ECDSA256P1Public):
        with open(path, 'wb') as f:
            f.write(pem)

    def sign(self, payload):
    def raw_sign(self, payload):
        """Return the actual signature"""
        return self.key.sign(
                data=payload,
                signature_algorithm=ec.ECDSA(SHA256()))

    def sign(self, payload):
        # To make fixed length, pad with one or two zeros.
        sig = self.raw_sign(payload)
        sig += b'\000' * (self.sig_len() - len(sig))
        return sig
+1 −1
Changes for scripts/imgtool/keys/ecdsa_test.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ class EcKeyGeneration(unittest.TestCase):
    def test_sig(self):
        k = ECDSA256P1.generate()
        buf = b'This is the message'
        sig = k.sign(buf)
        sig = k.raw_sign(buf)

        # The code doesn't have any verification, so verify this
        # manually.