Commit Graph

90 Commits

Author SHA1 Message Date
Kingsley Yung
80ee60a1bf script: Resolve name referencing issue during ML-KEM export (#42918)
In the WebCrypto modern algorithm specification, the issue
(https://github.com/WICG/webcrypto-modern-algos/issues/47) on algorithm
name referencing in the export key operation of ML-KEM had been resolved
by the following commit in the specification repository:


705f8ec6ce

Our implementation actually matches the new specification. We simply
update the specification text, with some minor refactoring accordingly.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-02-28 07:27:49 +00:00
Kingsley Yung
bf5f296cfb script: New design of algorithm registration in WebCrypto (#42896)
`NormalizedAlgorithm::encrypt`, `NormalizedAlgorithm::decrypt` and other
similar functions have some catch-all `match` arms that are unreachable.
They are unreachable because we rely on the name attribute in `String`
of the subtle dictionaries and the `NormalizedAlgorithm` enum to
determine which cryptographic algorithm to use, while the algorithm
normalization mechanism guarantees that some combinations of name and
enum variants won't exist.

This patch tries to get rid of those unreachable `match` arms to make
our WebCrypto code more idiomatic so that the Rust compiler can help us
ensure the correctness in the future.

To achieve this, we break the enum `NormalizedAlgorithm` into multiple
enums: `EncryptAlgorithm`, `DecryptAlgorithm`, `SignAlgorithm`, etc.
Each one is associated to a cryptographic operation, and its variants
are the cryptographic algorithms that support the associated operation.
The inner type of each variant is the desired parameter dictionary.
Therefore, when the call `EncryptAlgorithm::encrypt`,
`DecryptAlgorithm::decrypt` and other similar functions, we can have
`match` statements that cover all patterns since those enums only
contains necessary variants.

To make this change, we also need to change the algorithm registration
mechanism. Instead of using the `SupportedAlgorithm` enum and its method
`SupportedAlgorithm::support` to register the operations of the
algorithms, the algorithm registration is now done in the function
`from_object_value` of a new trait named `NormalizedAlgorithm`, which
the new enums `EncryptAlgorithm`, `DecryptAlgorithm` and so implement.
(Note that the existing enum named `NormalizedAlgorithm` is removed.)

Some refactoring in also done in the `normalize_algorithm` function to
adapt the above changes.

This new design of algorithm registration is also closer to the
WebCrypto specification, as explained in the comment block below the
`normalize_algorithm` function.

The crate `strum` is also used to reduce some boilerplate code.

Testing: Refactoring. Existing tests suffice.
Fixes: Part of #42579

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-02-27 18:21:35 +00:00
Kingsley Yung
00a36b27b8 script: Use reflect_dom_object_with_cx in CryptoKey::new (#42738)
Use the new `reflect_dom_object_with_cx` introduced in #42725 in
`CryptoKey::new`.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-02-21 10:57:43 +00:00
Kingsley Yung
b6f714c73d script: Pass &mut JSContext to methods of SubtleCrypto (#42726)
This patch changes the methods of `SubtleCrypto` to use the new `&mut
JSContext` and `&mut CurrentRealm`, Those methods are `Encrypt`,
`Decrypt`, `Sign`, `Verify`, `GenerateKey`, `DeriveKey`, `DeriveBits`,
`Digest`, `ImportKey`, `ExportKey`, `WrapKey`, `UnwrapKey`,
`EncapsulateKey`, `EncapsulateBits`, `DecapsulateKey`,
`DecapsulateBits`.

The change also propagate to the all internal methods within the
`subtlecrypto` module.

Testing: Refactoring. Existing tests suffice.
Fixes: Part of #42638

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-02-20 11:18:29 +00:00
Sam
d5d400c7d6 script: Use CString for Error::Type and Error::Range (#42576)
Continuation of https://github.com/servo/servo/pull/42135, switch
Error::Type and Error::Range to also use CStrings internally, as they
are converted to CString for throwing JS exceptions (other get thrown as
DomException object, which uses rust string internally).

Changes in script crate are mechanical.

Testing: Should be covered by WPT tests.
Part of #42126

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2026-02-12 15:17:30 +00:00
Kingsley Yung
05d1bb60e1 script: Combine import key operations of RSA algorithms (#42422)
The import key operations of

- RSASSA-PKCS1-v1_5 (`rsassa_pkcs1_v1_5_operation::import_key`)
- RSA-PSS (`rsa_pss::import_key`)
- RSA_OAEP (`rsa_oaep::import_key`)

only differ from each other by a few steps. This patch combines them
into a single function (`rsa_common::import_key`) shared among them.

The enum variant `RsaAlgorithm::RsaSsaPkcs1v15` is also renamed as
`RsaAlgorithm::RsassaPkcs1v1_5` for clarity.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-02-07 12:20:09 +00:00
Kingsley Yung
db95883dc0 script: Move more steps of AES algorithms to aes_common module (#42323)
Move some common/similar steps of the import key operations of AES-CTR,
AES-CBC, AES-GCM, AES-KW and AES-OCB to the shared module `aes_common`.

Some comments are also added to the shared module `aes_common` to
explain the small difference in the specification of AES-OCB operations.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-02-04 07:05:27 +00:00
César Danilo Pedraza Montoya
e153020f8f script: Add error messages for cSHAKE and HKDF (#41964)
Add all the missing error messages for `hkdf_operation.rs` and
`cshake_operation.rs` (one message only). Tried to follow the style of
existing messages and used an existing message for the HKDF-expand
operation. Related to #40756.

Testing: No tests added.

Signed-off-by: César Pedraza <cpedraza@unal.edu.co>
2026-01-18 13:30:14 +00:00
PaulTreitel
1fa5fdc2f9 script: Add error messages for the ECDH cryptographic functions (#41468)
Adding error messages across
`script/dom/subtlecrypto/ecdh_operation.rs`.

Testing: No tests as this is just adding error messages
Fixes: (part of) #40756

---------

Signed-off-by: PaulTreitel <paul.treitel@gmail.com>
2026-01-17 05:50:34 +00:00
Kingsley Yung
5261e160c0 script: Move AES-KW to individual submodule (#41949)
We previously introduced new infrastructure for sharing code in
`aes_common.rs` among AES algorithms.

This patch makes AES-KW algorithm adapt the new infrastructure, by
moving the relevant code away from `aes_operation.rs` to its own
`aes_kw_operation.rs`, and calling AES common steps in the new
`aes_common.rs`.

Since all AES algorithms have been moved away from `aes_operation.rs`,
the file `aes_operation.rs` is also removed. The key handle variants
`Handle::Aes128`, `Handle::Aes192` and `Handle::Aes256` used by the old
AES infrastructure is also removed.

Testing: Refactoring. Existing tests suffice.
Fixes: Part of #41763

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-16 06:56:13 +00:00
Kingsley Yung
7f2abe4bdb script: Extend AES-GCM in WebCrypto to support more tag lengths (#41950)
We currently only support 128-bit tags for AES-GCM authenticated
decryption. This patch expands support to 96-bit, 104-bit, 112-bit, and
120-bit tags.

The specification recommends supporting 32-bit and 64-bit tags as well.
However, the `aes-gcm` crate currently does not support them. We may
need to look for a workaround or wait for updates from the upstream
project.

Testing: Pass some WPT tests that were expected to fail.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-16 06:55:35 +00:00
César Danilo Pedraza Montoya
77a1a2546c script: Add error messages in ed25519_operation.rs (#41902)
Add all the missing error messages in `ed25519_operation.rs`. Followed
the other implementations of `importKey`, `exportKey` and others to try
and follow the same style. Related to #40756.

Testing: No tests added, did some manual tests

---------

Signed-off-by: César Pedraza <cpedraza@unal.edu.co>
2026-01-14 13:15:25 +00:00
Kingsley Yung
b7d0503d60 script: Move AES-GCM to individual submodule (#41908)
We previously introduced new infrastructure for sharing code in
`aes_common.rs` among AES algorithms.

Similar to #41856 on AES-CTR and #41883 on AES-CBC, this patch makes
AES-GCM algorithm adapt the new infrastructure, by moving the relevant
code away from `aes_operation.rs` to its own `aes_gcm_operation.rs`, and
calling AES common steps in the new `aes_common.rs`.

The patch also re-wrote the encrypt and decrypt operations of AES-GCM to
properly handle different tag lengths. This helps extend our support on
more tag lengths later, in order pass more WPT tests.

Testing: Refactoring. Existing tests suffice.
Fixes: Part of #41763

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-14 13:08:10 +00:00
Kingsley Yung
91843d928e script: Move AES-CBC to individual submodule (#41883)
We previously introduced new infrastructure for sharing code in
`aes_common.rs` among AES algorithms.

Similar to #41856 on AES-CTR, this patch makes AES-CBC algorithm adapt
the new infrastructure, by moving the relevant code away from
`aes_operation.rs` to its own `aes_cbc_operation.rs`, and calling AES
common steps in the new `aes_common.rs`. The patch also does some
refactoring on the encrypt and decrypt operations to get closer to
specification.

Testing: Refactoring. Existing tests suffice.
Fixes: Part of #41763

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-14 07:03:25 +00:00
Kingsley Yung
c3fafb2f25 script: Move AES-CTR to individual submodule (#41856)
#41762 introduced new infrastructure for sharing code in `aes_common.rs`
among AES algorithms.

This patch makes AES-CTR algorithm adopt the new infrastructure, by
moving the relevant code away from `aes_operation.rs` to its own
`aes_ctr_operation.rs`, with refactoring for adaptation.

Testing: Refactoring. Existing tests suffice.
Fixes: Part of #41763

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-13 04:46:19 +00:00
Kingsley Yung
889749643f script: Implement encrypt and decrypt operations of AES-OCB (#41829)
Finish on adding AES-OCB support to WebCrypto API.

This patch implements the encrypt and decrypt operations of AES-OCB,
with the `ocb3` crate. The "get key length" operation of AES-OCB is also
implemented for internal use.

Specification:
-
<https://wicg.github.io/webcrypto-modern-algos/#aes-ocb-operations-encrypt>
-
<https://wicg.github.io/webcrypto-modern-algos/#aes-ocb-operations-decrypt>
-
<https://wicg.github.io/webcrypto-modern-algos/#aes-ocb-operations-get-key-length>

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41762

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-11 05:06:10 +00:00
Kingsley Yung
68688ac362 script: Implement generate key operation of AES-OCB (#41822)
Start adding AES-OCB support to WebCrypto API.

This patch implements the generate key operation of AES-OCB, with the
`aes` crate.

Specification:
https://wicg.github.io/webcrypto-modern-algos/#aes-ocb-operations-generate-key

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41762

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-10 10:09:49 +00:00
Kingsley Yung
2f640994d3 script: Implement export key operation of AES-OCB (#41813)
Start adding AES-OCB support to WebCrypto API.

This patch implements the export key operations of AES-OCB, with the
`aes` crate.

Specification:
https://wicg.github.io/webcrypto-modern-algos/#aes-ocb-operations-export-key

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41762

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-10 07:17:04 +00:00
Kingsley Yung
b5aa03e97a script: Implement import key operation of AES-OCB (#41791)
Start adding AES-OCB support to WebCrypto API.

This patch implements the import key operations of AES-OCB, with the
`aes` crate.

Specification:
https://wicg.github.io/webcrypto-modern-algos/#aes-ocb-operations-import-key

Testing:
- Pass some WPT tests that were expected to fail.
- Some new FAIL expectations are added. They were skipped by WPT when
the import key operation of AES-OCB had not been implemented, and
requires other not-yet-implemented operations to pass.

Fixes: Part of #41762

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-09 08:06:38 +00:00
Kingsley Yung
259b3985ee script: Implement sign and verify operations of ML-DSA (#41676)
Finish adding ML-DSA support to WebCrypto API.

This patch implements the sign and verify operations of ML-DSA, with
`ml-dsa` crate.

Specification:
https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-operations-sign
https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-operations-verify

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41626

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-05 06:12:58 +00:00
Kingsley Yung
58070dd692 script: Implement generate key operation of ML-DSA (#41659)
Continue on adding ML-DSA support to WebCrypto API.

This patch implements the generate key operation of ML-DSA, with
`ml-dsa` crate.

Specification:
https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-operations-generate-key

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41626

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-04 08:52:23 +00:00
Kingsley Yung
0c91c3bc81 script: Implement export key operation of ML-DSA (#41647)
Continue on adding ML-DSA support to WebCrypto API.

This patch implements the export key operation of ML-DSA, with `ml-dsa`
crate.

Specification:
https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-operations-export-key

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41626

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-03 07:42:55 +00:00
Kingsley Yung
df9877a94c script: Implement import key operations of ML-DSA (#41628)
Start adding ML-DSA support to WebCrypto API.

This patch implements the import key operations of ML-DSA, with `ml-dsa`
crate.

Specification:
https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-operations-import-key

Testing:
- Pass some WPT tests that were expected to fail.
- Some new FAIL expectations are added. They were skipped by WPT when
the import key operations of ML-DSA had not been implemented, and
requires other not-yet-implemented operations to pass.

Fixes: Part of #41626

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-02 09:59:00 +00:00
Kingsley Yung
00792e098e script: Fix alg field of exported ML-KEM key in JWK format (#41627)
We wrongly use the object identifier of ML-KEM for the `alg` field of
exported ML-KEM key in JWK format. We should use the values specified in
Section 8 of [draft-ietf-jose-pqc-kem-01] (Figure 1) instead.

[draft-ietf-jose-pqc-kem-01] (Figure 1):

https://www.ietf.org/archive/id/draft-ietf-jose-pqc-kem-01.html#direct-table

Testing: WPT currently does not have relevant tests for ML-KEM keys in
JWK format since The JWK format for ML-KEM is not standardized yet. We
strive to remain compliant with the current specification.

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-02 09:33:35 +00:00
Kingsley Yung
96ddb0bbf0 script: Implement WebCrypto encapsulation and decapsulation with ML-KEM (#41617)
Complete the ML-KEM support in WebCrypto API, with the implementation of
the "encapsulate" and "decapsulate" operations of ML-KEM, as well as
four new methods `encapsulateKey`, `encapsulateBits`, `decapsulateKey`
and `decapsulateBits` of `SubtleCrypto`.

Specification:

https://wicg.github.io/webcrypto-modern-algos/#ml-kem-operations-encapsulate

https://wicg.github.io/webcrypto-modern-algos/#ml-kem-operations-decapsulate

https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-encapsulateKey

https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-encapsulateBits

https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-decapsulateKey

https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-decapsulateBits

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41473

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-01 13:30:04 +00:00
Kingsley Yung
883f8b4a6c script: Implement generate key operation of ML-KEM (#41615)
Continue on adding ML-KEM support to WebCrypto API.
Specification: https://wicg.github.io/webcrypto-modern-algos/#ml-kem

This patch implements generate key operation of ML-KEM, with `ml-kem`
crate.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41473

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2026-01-01 08:46:15 +00:00
Kingsley Yung
c7cd8fcef8 script: Implement export key operation of ML-KEM (#41604)
Continue on adding ML-KEM support to WebCrypto API.
Specification: https://wicg.github.io/webcrypto-modern-algos/#ml-kem

This patch implements export key operation of ML-KEM, with `ml-kem`
crate.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41473

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-31 14:27:47 +00:00
Kingsley Yung
5d6d2c67bb script: Implement import key operation of ML-KEM (#41585)
Start adding ML-KEM support to WebCrypto API.
Specification: https://wicg.github.io/webcrypto-modern-algos/#ml-kem

This patch implements import key operation of ML-KEM, with `ml-kem`
crate.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41473

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-30 11:46:10 +00:00
Kingsley Yung
7342ee0627 script: Properly implement supportedAlgorithms of WebCrypto (#41563)
WebCrypto API has an internal object `supportedAlgorithms`
<https://w3c.github.io/webcrypto/#dfn-supportedAlgorithms> that maps the
all supported algorithms and operations to their desired IDL dictionary
types. It is mainly used by the "normalize an algorithm" algorithm
<https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm>.
We currently implement it as a large `match` block in the
`normalize_algorithm` function.

This patch properly implements the internal object `supportedAlgorithms`
as a new enum type `SupportedAlgorithm`.

By doing so, we can reduce a lot of string comparison to enum matching,
which can be done faster. This patch also separates the dictionary
conversion away from the `match` block to make our code cleaner.
Furthermore, the `exportKey()` method can now utilize the new
`SupportedAlgorithm` to properly check against the algorithm
registration, instead of hard-coding an list of unsupported algorithms
by itself.

Testing: Refactoring. Existing tests suffice.

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-29 06:22:24 +00:00
Kingsley Yung
c77cc00474 script: Add helper function for setting JsonWebKey key_ops attribute (#41544)
Add a helper function `JsonWebKey::set_key_ops` for setting JsonWebKey
key_ops attribute to a given list of key usages. This task is very
common in export key operation of different cryptographic algorithms.
Adding this helper function helps simplify our code.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-28 05:02:30 +00:00
Kingsley Yung
bb84e0dac3 script: Add helper function to handle JsonWebKey common encoding tasks (#41472)
Companion of #41428, which added helper functions to handle JsonWebKey
common decoding tasks.

This patch adds a helper function `JsonWebKey::encode_string_field` to
handle common base64url encoding tasks across multiple algorithms.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-27 17:19:30 +00:00
Kingsley Yung
007f3379c5 script: Add helper functions to handle JsonWebKey common decoding tasks (#41428)
Add several helper functions to JsonWebKey to handle common base64url
decoding tasks across multiple algorithms. Those helper functions
include:

- `JsonWebKey::decode_optional_string_field`: decode optional field
- `JsonWebKey::decode_required_string_field`: decode required field
- `JsonWebKey::decode_primes_from_oth_field`: decode oth field to primes

These help simplify our code for importing keys in JsonWebKey format.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-22 04:45:16 +00:00
PaulTreitel
008ffa6965 script: Add remaining AES error messages (#41442)
Fill in the error messages across
`script/dom/subtlecrypto/aes_operations.rs` that were still left as
`None`.

Testing: No tests added as these are just error messages.
Addressing: #40756

---------

Signed-off-by: PaulTreitel <paul.treitel@gmail.com>
2025-12-21 20:55:22 +00:00
Kingsley Yung
4539c7efde script: Store HashAlgorithmIdentifier as NormalizedAlgorithm (#41395)
For some dictionaries in SubtleCrypto interface, we store the hash field
of `HashAlgorithmIdentifier` type as a `SubtleKeyAlgorithm`. The
conversion to `SubtleKeyAlgorithm` is unnecessary. Moreover,
`SubtleKeyAlgorithm` is not supposed to be used there.

This patch fixes it by simply storing them as the normalized algorithm
given by Step 10.1.3 of normalization [1], for those hash field of
`HashAlgorithmIdentifier` type.

[1]
https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm

Testing: Refactoring. Existing tests suffice.

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-19 07:20:09 +00:00
Kingsley Yung
0261ab1ef9 script: Implement encrypt/decrypt operations of RSA-OAEP (#41316)
Finish adding RSA-OAEP support to WebCrypto API, by implementing the
encrypt and decrypt operations of RSA-OAEP.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41113

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-17 11:21:31 +00:00
César Danilo Pedraza Montoya
db8e01076a script: Add error message text to errors in aes_operation.rs (#41292)
add error messages for `encrypt_aes_ctr`, `encrypt_aes_cbc`, and
`decrypt_aes_cbc`

Related issue: #40756

For some of the messages I just used the `fmt::Display` of `UnpadError`,
but maybe these messages should be more specific?

---------

Signed-off-by: César Pedraza <cpedraza@unal.edu.co>
2025-12-16 12:56:43 +00:00
Kingsley Yung
706e06315d script: Implement sign/verify operations of RSA-PSS (#41287)
Finish adding RSA-PSS support to WebCrypto API, by implementing the sign
and verify operations of RSA-PSS.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41113

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-15 16:54:44 +00:00
Kingsley Yung
a36e3dbe19 script: Implement sign/verify operations of RSASSA-PKCS1-v1_5 (#41267)
Finish adding RSASSA-PKCS1-v1_5 support to WebCrypto API, by
implementing the sign and verify operations of RSASSA-PKCS1-v1_5.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41113

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-15 06:48:52 +00:00
Kingsley Yung
84e8194434 script: Implement generate key operations of three RSA algorithms (#41240)
This patch implements generate key operations of three RSA algorithms
(RSASSA-PKCS1-v1_5, RSA-OAEP, RSA-OAEP), with `rsa` crate.

The three operations are very similar to each other, so we can implement
them as a single function, located at the sub-module `rsa_common`,
shared among the three RSA algorithms. The enum `RsaAlgorithm` is used
differentiate the behavior of a few steps (Step 1, 5, 13 and 18) that
are slightly different among the three RSA algorithms.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41113

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2025-12-13 05:10:34 +00:00
Kingsley Yung
df8484e6a4 script: Implement export key operations of three RSA algorithms (#41225)
This patch implements export key operations of three RSA algorithms
(RSASSA-PKCS1-v1_5, RSA-OAEP, RSA-OAEP), with `rsa` crate.

The three operations are very similar to each other, so we can implement
them as a single function, located at a new sub-module `rsa_common`,
shared among the three RSA algorithms. An enum `RsaAlgorithm` is also
added to the sub-module `rsa_common`, in order to slightly differentiate
the behavior of the step (Step 3.4 of "jwk" format) that are different
among the three RSA algorithms.

Testing:
- Pass some WPT tests that were expected to fail.
- Some new FAIL expectations are added. They were skipped by WPT when
the export key operations of RSASSA-PKCS1-v1_5, RSA-PSS and RSA-OAEP had
not been implemented, and requires other not-yet-implemented operations
to pass.

Fixes: Part of #41113

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-12 14:13:18 +00:00
Kingsley Yung
ec5a6dacca script: Implement import key operation of RSA-OAEP (#41217)
Start adding RSAS-OAEP support to WebCrypto API.

This patch implements import key operation of RSA-OAEP, with `rsa`
crate.

Testing:
- Pass some WPT tests that were expected to fail.
- Some new FAIL expectations are added. They were skipped by WPT when
the import key operation of RSA-OAEP had not been implemented, and
requires other not-yet-implemented operations to pass.

Fixes: Part of #41113

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Co-authored-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
2025-12-12 06:25:05 +00:00
Kingsley Yung
0e1ab937b3 script: Update spec text of WebCrypto API (#41180)
Update a few spec texts of WebCrypto API with respect to recent changes
in the [Web Cryptography](https://w3c.github.io/webcrypto/) and [Modern
Algorithms in WICG](https://wicg.github.io/webcrypto-modern-algos/) that
refines some expressions. No behavioral changes.

Commits of the changes in the specifications:
-
0213b32f7e
-
3b9d192f52
-
0d5f58606c

Testing: No behavioral changes. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-10 14:49:19 +00:00
Kingsley Yung
64dd55ccc3 script: Implement import key operation of RSASSA-PKCS1-v1_5 (#41172)
Start adding RSASSA-PKCS1-v1_5 support to WebCrypto API.

This patch implements import key operation of RSASSA-PKCS1-v1_5, with
`rsa` crate.

Testing:
- Pass some WPT tests that were expected to fail.
- Some new FAIL expectations are added. They were skipped by WPT when
the import key operation of RSASSA-PKCS1-v1_5 had not been implemented,
and requires other not-yet-implemented operations to pass.

Fixes: Part of #41113

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-10 14:48:03 +00:00
Kingsley Yung
56d9e24bff script: Implement import key operation of RSA-PSS (#41157)
Start adding RSA-PSS support to WebCrypto API.

This patch implements import key operation of RSA-PSS, with `rsa` crate.

Testing:
- Pass some WPT tests that were expected to fail.
- Some new FAIL expectations are added. They were skipped by WPT when
the import key operation of RSA-PSS had not been implemented, and
requires other not-yet-implemented operations to pass.

Fixes: #34362, and part of #41113

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-09 15:34:01 +00:00
César Danilo Pedraza Montoya
6e8384896a script: add error messages (#41039)
script: add error messages for conditions in `encrypt_aes_ctr`

Testing: No tests needed (?) let me know if I should add tests for this
somewhere.
Fixes: #40756

Followed the
[MDN](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#aes-ctr)
and [w3c](https://w3c.github.io/webcrypto/#aes-ctr-operations-encrypt)
docs to write the messages.

I'm thinking on adding more messages, so any feedback would be
appreciated! :)

---------

Signed-off-by: César Pedraza <cpedraza@unal.edu.co>
2025-12-05 09:20:50 +00:00
Kingsley Yung
f19bffd186 script: Add error messages to operations of ChaCha20-Poly1305 (#41030)
Error messages in the import/export key operations of ChaCha20-Poly1305
are missing. This patch adds those error messages.

Testing: No behavioral change. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-03 12:59:35 +00:00
Kingsley Yung
ff8211275d script: Implement encrypt/decrypt operation of ChaCha20-Poly1305 (#41003)
Finish adding ChaCha20-Poly1305 support to WebCrypto API.

This patch implements encrypt operation and decrypt operation of
ChaCha20-Poly1305, using the crate `chacha20poly1305` to support the
cryptographic calculation. The get key length operation of
ChaCha20-Poly1305 is also included in this patch.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #40687

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-02 07:42:51 +00:00
Kingsley Yung
c30e1126d8 script: Implement generate key operation of ChaCha20-Poly1305 (#40978)
Continue on adding ChaCha20-Poly1305 support to WebCrypto API.

This patch implements generate key operation of ChaCha20-Poly1305, using
the crate `chacha20poly1305` to support the cryptographic calculation.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #40687

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-01 09:34:51 +00:00
Kingsley Yung
b5e78199a1 script: Implement import/export key operation of ChaCha20-Poly1305 (#40948)
Start adding ChaCha20-Poly1305 support to WebCrypto API.

This patch implements "import key" operation and "export key" operation
of ChaCha20-Poly1305, using the crate `chacha20poly1305` to support the
cryptographic calculation.

Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #40687

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-29 05:52:35 +00:00
Ignacio Casal Quinteiro
b00a76427a Fix various typos throughout the code base (#40934)
Signed-off-by: Ignacio Casal Quinteiro <qignacio@amazon.com>
2025-11-28 15:00:56 +00:00