Skip to content

imgtool: keys: fix ECDSA384 public sig_len value - #2951

Open
a6-a9-ai wants to merge 1 commit into
mcu-tools:mainfrom
a6-a9-ai:test/ecdsa-pad-sig
Open

a6-a9-ai wants to merge 1 commit into
mcu-tools:mainfrom
a6-a9-ai:test/ecdsa-pad-sig

Conversation

@a6-a9-ai

@a6-a9-ai a6-a9-ai commented Nov 8, 2026 •

Copy link
Copy Markdown

Fix ECDSA384P1Public.sig_len() returning 103 instead of 104 bytes. In ASN.1 DER encoding, each P-384 integer takes up to 51 bytes (2-byte header + 1-byte 0x00 pad + 48-byte value) plus the 2-byte sequence header (0x30 + 1-byte sequence length). It finally requires up to 104 bytes = 2 + 51 + 51.

imgtool: scripts: test: keys: add tests for unpadded ECDSA signatures

_test_sig validates ASN.1 DER length, checks signatures against cryptography oracle, and verifies both private and public keys rejects modified payloads, corrupted signatures, mismatched keys.

imgtool: scripts: test: keys: add tests for padded ECDSA signatures

_test_pad_sig exercises all three variable DER lengths up to sig_len (confirming padding), oracle rejection of unstripped bytes, and padding removal in verify() across valid and corrupted inputs.

Signed-off-by: Ben Lombard <a5a8ahaiac@proton.me>

Fix ECDSA384P1Public.sig_len() returning 103 instead of 104 bytes.
In ASN.1 DER encoding, each P-384 integer takes up to 51
bytes (2-byte header + 1-byte 0x00 pad + 48-byte value) plus the
2-byte sequence header (0x30 + 1-byte sequence length).
It finally requires up to 104 bytes = 2 + 51 + 51.

imgtool: scripts: test: keys: add tests for unpadded ECDSA signatures

_test_sig validates ASN.1 DER length, checks signatures
against cryptography oracle, and verifies both private and public keys
rejects modified payloads, corrupted signatures, mismatched keys.

imgtool: scripts: test: keys: add tests for padded ECDSA signatures

_test_pad_sig exercises all three variable DER lengths up to
sig_len (confirming padding), oracle rejection of unstripped bytes,
and padding removal in verify() across valid and corrupted inputs.

Signed-off-by: Ben Lombard <161700065+a6-a9-ai@users.noreply.github.com>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch test/ecdsa-pad-sig
# Changes to be committed:
#	modified:   scripts/imgtool/keys/ecdsa.py
#	modified:   scripts/tests/keys/test_ecdsa.py
#
# Untracked files:
#	commit_msg.txt
#	test_ecdsa_key.pem
#	test_ed25519_key.pem
#
@a6-a9-ai
a6-a9-ai requested a review from d3zd3z as a code owner November 8, 2026 23:33
@nordicjm nordicjm mentioned this pull request Nov 10, 2026
2 of 3 tasks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant