Skip to content

script: Expand supports() validation coverage in WebCrypto - #47545

Merged
kkoyung merged 13 commits into
servo:mainfrom
kkoyung:improve-supports
Sep 1, 2026
Merged

kkoyung merged 13 commits into
servo:mainfrom
kkoyung:improve-supports

Conversation

@kkoyung

@kkoyung kkoyung commented Aug 26, 2026

Copy link
Copy Markdown
Member

WebCrypto API specification has updated some cryptography operations in order to expand supports() validation coverage. We follow the updates.

The update basically consists of moving all parameter validation to the beginning of the operations, and adding some new parameter validation which were done implicitly. Therefore, these operations should not have observable changes from user perspective.

Meanwhile, since the actually implementation of Step 8 of the check support for an algorithm algorithm is based on how these operations are written, and it follows the above changes, the supports() method, which relies on the check support for an algorithm algorithm, improves its validation coverage.

We also update our comment next to Step 8 based on the discussion in WICG/webcrypto-modern-algos#74.

Spec Update: w3c/webcrypto#558
WPT Update: web-platform-tests/wpt#62115

Testing: Pass more WPT tests.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
@kkoyung
kkoyung requested a review from gterzian as a code owner August 26, 2026 13:59
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Aug 26, 2026
// Step 2.
// Step 2. Let keyData be the key data to be imported.

// Step 3.

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.

Do you mind putting the spec text here as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

https://w3c.github.io/webcrypto/#ecdsa-operations-import-key
Step 3 consists of a long list of sub-steps, which are already included below. (However, the if-clauses of step 3 are missing, and I added them right above each match-arms.)

Comment thread components/script/dom/webcrypto/subtlecrypto/ecdh_operation.rs Outdated
Comment thread components/script/dom/webcrypto/subtlecrypto.rs Outdated
public_exponent
.iter()
.skip_while(|byte| **byte == 0)
.all(|byte| *byte == 255)

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.

Does this work for values of modulus_length isn't a multiple of 8?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice finding! It won't work when modulus_length is not a multiple of 8.

I rewrote this part. Now we don't calculate the public exponent length in bits. This implementation should be more straightforward.

TIL: we can get 255u8 by 0u8.wrapping_sub(1).

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Sep 1, 2026
@kkoyung
kkoyung added this pull request to the merge queue Sep 1, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Sep 1, 2026
Merged via the queue into servo:main with commit 47f0cd3 Sep 1, 2026
32 of 35 checks passed
@kkoyung
kkoyung deleted the improve-supports branch September 1, 2026 16:29
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Sep 1, 2026
RichardTjokroutomo pushed a commit to RichardTjokroutomo/servo that referenced this pull request Oct 6, 2026
…7545)

WebCrypto API specification has updated some cryptography operations in
order to expand `supports()` validation coverage. We follow the updates.

The update basically consists of moving all parameter validation to the
beginning of the operations, and adding some new parameter validation
which were done implicitly. Therefore, these operations should not have
observable changes from user perspective.

Meanwhile, since the actually implementation of Step 8 of the **check
support for an algorithm** algorithm is based on how these operations
are written, and it follows the above changes, the `supports()` method,
which relies on the **check support for an algorithm** algorithm,
improves its validation coverage.

We also update our comment next to Step 8 based on the discussion in
WICG/webcrypto-modern-algos#74.

Spec Update: w3c/webcrypto#558
WPT Update: web-platform-tests/wpt#62115

Testing: Pass more WPT tests.

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Psychpsyo pushed a commit to Psychpsyo/servo that referenced this pull request Oct 12, 2026
…7545)

WebCrypto API specification has updated some cryptography operations in
order to expand `supports()` validation coverage. We follow the updates.

The update basically consists of moving all parameter validation to the
beginning of the operations, and adding some new parameter validation
which were done implicitly. Therefore, these operations should not have
observable changes from user perspective.

Meanwhile, since the actually implementation of Step 8 of the **check
support for an algorithm** algorithm is based on how these operations
are written, and it follows the above changes, the `supports()` method,
which relies on the **check support for an algorithm** algorithm,
improves its validation coverage.

We also update our comment next to Step 8 based on the discussion in
WICG/webcrypto-modern-algos#74.

Spec Update: w3c/webcrypto#558
WPT Update: web-platform-tests/wpt#62115

Testing: Pass more WPT tests.

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
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.

3 participants