Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EC signatures deterministic #1623

Closed
sw opened this issue Feb 22, 2023 · 3 comments
Closed

Make EC signatures deterministic #1623

sw opened this issue Feb 22, 2023 · 3 comments
Labels

Comments

@sw
Copy link

sw commented Feb 22, 2023

The ECDSA signatures created by imgtool are not deterministic, because a random value is used as an input to the signature scheme.

This means that the signed images are not reproducible, which is generally a bad thing for builds. It may lead to unnecessary firmware updates if the signature (instead of just the hash) is used for deciding if an update is necessary. It may also complicate automated tests. This problem already came up in zephyrproject-rtos/zephyr#52271

RFC6979 defines how to do deterministic signature generation. Unfortunately it seems that the cryptography module does not support this. However PyCryptodome does support it and produces valid, deterministic signatures.

The following line:

sig = key.sign(bytes(self.payload))

could be replaced by this:

from Crypto.Hash import SHA256
from Crypto.PublicKey import ECC
from Crypto.Signature import DSS
from cryptography.hazmat.primitives.serialization import PrivateFormat, NoEncryption

k = ECC.import_key(key.key.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption()))
signer = DSS.new(k, 'deterministic-rfc6979', encoding='der')
sig = signer.sign(SHA256.new(bytes(self.payload)))

This obviously is rather hackish, but maybe someone can find a clean way to do this using the cryptography module?

Note that I'm no cryptography expert and make no claims on the security ramifications of doing this.

@Laczen
Copy link

Laczen commented Feb 23, 2023

@sw, maybe this will solve the problem for the signatures, but as soon as you start using encrypted images the same problem will arise because the key derivation method starts from a random value that is different for each image generation.

@utzig
Copy link
Member

utzig commented Feb 24, 2023

OpenSSL merged support for determistic ECDSA two months ago: openssl/openssl#18809. This probably means that soon enough cryptography will also support it.

@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants