Commit 20462a71 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

fix: RSA: Use 32-byte salt with PSS

The verification code requires a fixed 32-byte salt, which seems is what
the old crypto library did.  Use this same value to avoid having to
modify the code.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 1d5bea1c
Loading
Loading
Loading
Loading
+3 −1
Changes for scripts/imgtool/keys/rsa.py: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -87,7 +87,9 @@ class RSA2048(RSA2048Public):
            f.write(pem)

    def sign(self, payload):
        # The verification code only allows the salt length to be the
        # same as the hash length, 32.
        return self.key.sign(
                data=payload,
                padding=PSS(mgf=MGF1(SHA256()), salt_length=PSS.MAX_LENGTH),
                padding=PSS(mgf=MGF1(SHA256()), salt_length=32),
                algorithm=SHA256())
+2 −2
Changes for scripts/imgtool/keys/rsa_test.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ class KeyGeneration(unittest.TestCase):
        k.key.public_key().verify(
                signature=sig,
                data=buf,
                padding=PSS(mgf=MGF1(SHA256()), salt_length=PSS.MAX_LENGTH),
                padding=PSS(mgf=MGF1(SHA256()), salt_length=32),
                algorithm=SHA256())

        # Modify the message to make sure the signature fails.
@@ -95,7 +95,7 @@ class KeyGeneration(unittest.TestCase):
                k.key.public_key().verify,
                signature=sig,
                data=b'This is thE message',
                padding=PSS(mgf=MGF1(SHA256()), salt_length=PSS.MAX_LENGTH),
                padding=PSS(mgf=MGF1(SHA256()), salt_length=32),
                algorithm=SHA256())

if __name__ == '__main__':