Skip to content

Relax the permitted-algorithm policy for ECDSA#312

Merged
athoelke merged 3 commits intoARM-software:mainfrom
athoelke:crypto-relax-ecdsa-policy
Oct 20, 2025
Merged

Relax the permitted-algorithm policy for ECDSA#312
athoelke merged 3 commits intoARM-software:mainfrom
athoelke:crypto-relax-ecdsa-policy

Conversation

@athoelke
Copy link
Copy Markdown
Contributor

Fixes #278

@athoelke athoelke added this to the Crypto API 1.4 milestone Oct 15, 2025
@athoelke athoelke self-assigned this Oct 15, 2025
@athoelke athoelke added bug Something is incorrect or inconsistent in the documentation Crypto API Issue or PR related to the Cryptography API labels Oct 15, 2025
@athoelke athoelke moved this to In Progress in PSA Certified API development Oct 15, 2025
@athoelke athoelke changed the title Relex the permitted-algorithm policy for ECDSA Relax the permitted-algorithm policy for ECDSA Oct 15, 2025
Comment thread doc/crypto/api/ops/signature.rst Outdated
The ECDSA signature scheme is defined by :cite-title:`SEC1`, and also by :cite-title:`X9-62`, with a random per-message secret number :math:`k`.

When based on the same hash algorithm, the verification operations for `PSA_ALG_ECDSA` and `PSA_ALG_DETERMINISTIC_ECDSA` are identical. A signature created using `PSA_ALG_ECDSA` can be verified with the same key using either `PSA_ALG_ECDSA` or `PSA_ALG_DETERMINISTIC_ECDSA`. Similarly, a signature created using `PSA_ALG_DETERMINISTIC_ECDSA` can be verified with the same key using either `PSA_ALG_ECDSA` or `PSA_ALG_DETERMINISTIC_ECDSA`.
The representation of the signature as a byte string consists of the concatenation of the signature values :math:`r` and :math:`s`. Each of :math:`r` and :math:`s` is encoded as an :math:`N`-octet string, where :math:`N` is the length of the base point of the curve in octets. Each value is represented in big-endian order, with the most significant octet first.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pre-existing: I don't think "the length of the base point" is correct. I believe you mean the length of the order of the base point.

Copy link
Copy Markdown
Contributor Author

@athoelke athoelke Oct 16, 2025

Choose a reason for hiding this comment

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

Correct. How to fix though - the 'bit size' or 'octet size' of an integer is an odd concept and I'd quite like to not use that.

I might use the same style as I used for the WPA3 password token keys (but adjusted to refer to the group order):

$N$ is the integer for which $2^{8(N-1)} \leq r < 2^{8N}$, where $r$ is the order [of the base point]* of the curve.

* This is not strictly necessary as 'order of the curve' typically menas the same thing?

Or I could go with the SEC1 style, which has equivalent results (as $p$ is not a power of 2):

Where $N = \lceil{\log_2{r}/8}\rceil$, where $r$ is the order of the elliptic curve.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the 'bit size' or 'octet size' of an integer is an odd concept

Agreed, writing this felt weird.

I think I like the first option a bit better, but both are fine IMO.

Unless I'm mistaken all of the curves standardised for use with ECDSA have cofactor 1, so indeed the order of the curve and the order of its base point are the same thing.

Comment thread doc/crypto/api/ops/signature.rst Outdated
.. note::

The representation of the signature as a byte string consists of the concatenation of the signature values :math:`r` and :math:`s`. Each of :math:`r` and :math:`s` is encoded as an :math:`N`-octet string, where :math:`N` is the length of the base point of the curve in octets. Each value is represented in big-endian order, with the most significant octet first.
It is impossible to determine whether a signature was produced with deterministic ECDSA or with randomized ECDSA: it is only possible to verify that a signature was made with ECDSA with the private key corresponding to the public key used for the verification.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: it is impossible unless you have access to the private key ;)

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.

Also pre-existing. But do I really need to qualify this with 'Without the private key, it is impossible ...'?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Honestly that's probably just me being too picky here, and I'm not insisting on fixing this. But perhaps we could avoid the word "impossible" and just say "Signature verification can't determine ..."?

Copy link
Copy Markdown
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

LGTM for the new text, but I think the section on policies also needs to be adapted.

Relaxations
~~~~~~~~~~~

* Relaxed the permitted-key policy requirements for ECDSA verification, to be consistent with those for ML-DSA and SLH-DSA.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think these exceptions should be mentioned in the “Permitted algorithms” section of the chapter on policies. Not necessarily the full list, but at least the general ideas that some algorithms are considered partially equivalent. Maybe just say that it's the case for some signature algorithms, which are only considered equivalent for verification? According to the current text, “A specific algorithm value permits exactly that particular algorithm” (plus NONE and various wildcard cases), which rules out the ML-DSA, SLH-DSA and now ECDSA verification relaxation.

Copy link
Copy Markdown
Contributor Author

@athoelke athoelke Oct 16, 2025

Choose a reason for hiding this comment

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

Good point - the PQC extension didn't actually modify that text, because it is outside the main spec for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That text should also make it clear that the policy enforcement there depends not only on the key metadata and the requested algorithm for the operation, but also on the nature of the operation.

When a key is used in a cryptographic operation, the application must supply the algorithm to use for the operation. This algorithm is checked against the key's permitted-algorithm policy.

That doesn't completely rule out the fact that a policy of PSA_ALG_ECDSA(PSA_ALG_SHA_256) allows PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256) for verification but not for signature, but it strongly hints that only the algorithm matters.

This is reflected architecturally, for example, in Mbed TLS/TF-PSA-Crypto, where the policy check is implemented as a function

static psa_status_t psa_key_policy_permits(const psa_key_policy_t *policy,
                                           psa_key_type_t key_type,
                                           psa_algorithm_t alg)

which will need to take an extra argument that allows distinguishing signature from verification. (The key type is not enough since a key pair can be used to verify a signature.)

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.

This approaches what we have described for psa_check_key_usage - where the role the key takes in the algorithm matters, not just the algorithm itself.

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.

I've tried to capture this in a rewording of the permitted algorithm policy introduction.

Copy link
Copy Markdown
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@MarcusJGStreets MarcusJGStreets left a comment

Choose a reason for hiding this comment

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

I am happy the intro includes the relaxation - which I also think is sensible.
So I think this answers Giles point.
Therefore, I am happy

@athoelke athoelke merged commit 6d4356b into ARM-software:main Oct 20, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in PSA Certified API development Oct 20, 2025
@athoelke athoelke deleted the crypto-relax-ecdsa-policy branch October 20, 2025 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something is incorrect or inconsistent in the documentation Crypto API Issue or PR related to the Cryptography API

Projects

Development

Successfully merging this pull request may close these issues.

Deterministic ML-DSA/SLH-DSA key policies not consistent with ECDSA

4 participants