Skip to content

Adds to DER format of ECDSA signature with extended ECDSA-Sig-Value and ECDSA-Full-R#369

Open
gstarovo wants to merge 3 commits intotlsfuzzer:masterfrom
gstarovo:ecdsa-sig-extend
Open

Adds to DER format of ECDSA signature with extended ECDSA-Sig-Value and ECDSA-Full-R#369
gstarovo wants to merge 3 commits intotlsfuzzer:masterfrom
gstarovo:ecdsa-sig-extend

Conversation

@gstarovo
Copy link
Copy Markdown
Contributor

The changes expand encoding/decoding of the ECDSA signature in DER format: expanded ECDSA-Sig-Value format and ECDSA-Full-R.
The definition of the formats can be found in document section C.5, page 114.

The changes bring supporting functions like encoding and decoding of boolean according to ASN.1 standard.
Beside that, the changes add parameter and slightly modifies ECDSA signing function for enabling return of the whole point (instead of 'r').
The testing coverage of encoding/decoding with new function is also present.

Also, there are some formatting changes made with black formatter.

@gstarovo
Copy link
Copy Markdown
Contributor Author

I will provide more coverage for the newly added code, as the results of the checks indicate coverage decline.

@gstarovo gstarovo force-pushed the ecdsa-sig-extend branch 5 times, most recently from 0961801 to e17d333 Compare October 23, 2025 09:39
@gstarovo gstarovo force-pushed the ecdsa-sig-extend branch 2 times, most recently from 19ac7b2 to f173f56 Compare October 27, 2025 11:58
@gstarovo gstarovo force-pushed the ecdsa-sig-extend branch 5 times, most recently from 9c23305 to b046e1f Compare October 29, 2025 09:09
@gstarovo gstarovo requested a review from tomato42 October 29, 2025 09:53
src/ecdsa/der.py Outdated
body = string[1 + lengthlength : 1 + lengthlength + length]
rest = string[1 + lengthlength + length :]
if not body:
raise UnexpectedDER("Empty object identifier")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not an object identifier

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to "Empty BOOLEAN value"

src/ecdsa/der.py Outdated
if body == b"\x00":
return False, rest
# the workaround due to instrumental, that
# saves the binary data as UF-8 string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method shouldn't be passed Unicode strings ever...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added check to control if the body type is str, than it will be encoded to bytes

if isinstance(body, text_type):
        body = body.encode("utf-8")

point = ellipticcurve.AbstractPoint.from_bytes(
self.generator.curve(), r
)
r = point[0] % n
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change though?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When encoding is in format of r in the siganture is ECPoint (ECPoint ::= OCTET STRING) to get the r, I firstly have to get the point from bytes and then extract the x and provide the same operation that is in the sign:
r = p1.x() % n

:param accelerate: an indicator for ECDSA sign operation to return
an ECPoint instead of a number of "r" parameter.
Applicable only for ECDSA key.
:type accelerate: boolean
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we already are using the sigencode for specifying the output format...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that is not nice workaround that is being propagated to ecdsa.py PrivateKey.sign() to signalize what type of the r (if int or a ECPoint) I want to return. So after that it can directly go to the sigencode function in correct format. I did not find a way how to do it differently, or how to get the whole point out of r directly in the sigencode function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of r being just an int or ECPoint, maybe to create a new class, that will have both values all the time, so the sigencode will get all the values. I will show that change in a new commit. I will then squash it to one, if it will be accepted.

:param accelerate: an indicator for ECDSA sign operation to return
an ECPoint instead of a number of "r" parameter.
Applicable only for ECDSA key.
:type accelerate: boolean
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, sigencode should specify the format we want...

leak the key. Caller should try a better entropy source, retry with
different ``k``, or use the
:func:`~SigningKey.sign_deterministic` in such case.
:param accelerate: an indicator for ECDSA sign operation to return
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@gstarovo gstarovo force-pushed the ecdsa-sig-extend branch 5 times, most recently from 841cce2 to 9f5252e Compare March 26, 2026 10:40
@gstarovo gstarovo force-pushed the ecdsa-sig-extend branch 2 times, most recently from 2949133 to 0a9aebd Compare March 26, 2026 13:29
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.

2 participants