Commit Graph

205 Commits

Author SHA1 Message Date
Shannon Booth
0cf991e205 LibWeb/Crypto: Move WebCrypto dictionaries into Crypto namespace
Keep the JsonWebKey dictionary types in line with other dictionary
types in the codebase by putting them in the Crypto namespace
rather than under Web::Bindings.
2026-04-23 22:12:13 +02:00
Shannon Booth
fd44da6829 LibWeb/Bindings: Emit one bindings header and cpp per IDL
Previously, the LibWeb bindings generator would output multiple per
interface files like Prototype/Constructor/Namespace/GlobalMixin
depending on the contents of that IDL file.

This complicates the build system as it means that it does not know
what files will be generated without knowledge of the contents of that
IDL file.

Instead, for each IDL file only generate a single Bindings/<IDLFile>.h
and Bindings/<IDLFile>.cpp.
2026-04-21 07:36:13 +02:00
Tete17
1af8cc471d LibWeb: Validate JWK key pair consistency for OKP importKey
For private key JWK imports, after decoding both d and x, derive
the public key from d and verify it matches x. A private key that
doesn't correspond to the provided public key doesn't "contain the
private key" as required by RFC 8037 Section 2.
2026-04-19 13:35:36 +02:00
Tete17
32af84b698 LibWeb: Validate JWK key length for OKP importKey
After base64url-decoding the x and d fields during JWK import,
verify the decoded byte length matches the expected key size for
the curve (32 for Ed25519/X25519, 57 for Ed448, 56 for X448).
A truncated value does not "contain the public/private key" as
required by RFC 8037 Section 2.
2026-04-19 13:35:36 +02:00
Tete17
00e9396cfe LibWeb: Fix Ed448 raw key length check in importKey
Ed448 public keys are 57 bytes (456 bits), not 56 bytes (448 bits).
The curve is named "Ed448" after its 448-bit prime field, but per
RFC 8032 Section 5.2.5, the parameter b=456 and both private and
public keys are 57 bytes. This caused importKey to reject valid raw
Ed448 public keys with a DataError.

Note: The spec incorrectly says "not 448" for this check.
See https://github.com/w3c/webcrypto/pull/425#discussion_r3070135408
2026-04-19 13:35:36 +02:00
Andreas Kling
52c46483d1 LibWeb: Handle raw-secret key formats in wrap_key
Refresh the imported wrapKey_unwrapKey WPT to the current upstream
version and treat the raw-secret and other raw* formats like raw
when wrap_key() and unwrap_key() serialize wrapped key bytes.

The updated test covers ChaCha20-Poly1305 wrapping with the
raw-secret format. Accepting the full set of byte-oriented raw
formats lets those keys round-trip through wrapKey and unwrapKey.
2026-03-29 13:21:36 +02:00
Andreas Kling
3726df5a9e LibWeb: Align wrapKey steps with the WebCrypto spec
Keep the existing comment wording and wrapping where it already
matched the spec, but fix the places where wrap_key() and
unwrap_key() had drifted from the current wrapKey and unwrapKey
steps.

Add the missing realm and wrappedKey steps, use the spec terms
exportedKey, bytes, and key in the touched blocks, and leave
explicit FIXME comments for the queue-a-task and conversion
steps that we still skip.
2026-03-29 13:21:36 +02:00
mikiubo
29ae949798 LibWeb: Use outputLength instead of length in KmacParams
The WebCrypto spec was updated to rename the KMAC algorithm
parameter from length to outputLength.
2026-03-25 22:07:53 +01:00
Timothy Flynn
58791db818 AK+LibWeb: Move generation of random UUIDs into AK
This will let us use this more outside of LibWeb more easily.

Stop handling tiny OOM while we are here.
2026-03-24 12:04:50 -04:00
mikiubo
63d8f6b4a9 LibWeb: Use outputLength instead of length in CShakeParams
The WebCrypto spec was updated to rename the CSHAKE algorithm
parameter from length to outputLength.
2026-03-22 14:13:21 +01:00
mikiubo
d4cf537d58 LibCrypto: Implement KMAC authentication support
Add a LibCrypto::Authentication::KMAC helper over OpenSSL.
Add keygen/import/export logic into WebCrypto.
Register KMAC128/KMAC256 operations with SubtleCrypto.
2026-03-19 10:46:49 +01:00
mikiubo
1ac12651f6 LibWeb: Update SubtleCrypto.digest() to match the spec
The WebCrypto spec was updated to normalize the algorithm before
getting a copy of the data bytes, and to queue a global task on the
crypto task source when rejecting or resolving the promise.

This fixes some WPT tests.
2026-03-17 21:05:13 +01:00
mikiubo
0e2d8ff43a LibWeb: Update SubtleCrypto.sign() and verify() to match the spec
The WebCrypto spec was updated to normalize the algorithm before
getting a copy of the input bytes, and to queue a global task on the
crypto task source when rejecting or resolving the promise.
2026-03-15 20:03:58 +01:00
mikiubo
17fe3ae00c LibWeb: Update SubtleCrypto.encrypt() and decrypt() to match the spec
The WebCrypto spec was updated to normalize the algorithm before
getting a copy of the data bytes, and to queue a global task on the
crypto task source when rejecting or resolving the promise.
2026-03-06 14:21:46 +01:00
mikiubo
0d08aa2b58 LibWeb: Fix incorrect error message in SubtleCrypto::decrypt
The error message incorrectly stated "encryption" when checking
for decrypt usage. Updated it to "decryption" for accuracy and
consistency with the operation being performed.
2026-03-06 14:21:46 +01:00
mikiubo
50ec070017 LibCrypto: Add AES-OCB support
Implement AES-OCB AEAD using OpenSSL and expose it through
the WebCrypto API, including key management and AEAD parameters.

Add WPT:
/encrypt_decrypt/aes_ocb.tentative.https.any.html
2026-02-27 12:03:19 +01:00
Shannon Booth
6a9cd0e8e0 LibWeb: Use interface_name instead of serialize_type virtual
`interface_name` is implemented for every platform object,
so we no longer need this boilerplate for every serializable
platform object.
2026-02-14 20:22:40 +01:00
Shannon Booth
76cf230bd6 LibWeb: Use Bindings::InterfaceName for serializing types
While this does cost us an extra byte to serialize as it
contains _all_ interface names instead of the set of serializable
types, doing this will allow us to remove to use the same
enum for checking whether that interface is exposed in a future
commit.
2026-02-14 20:22:40 +01:00
devgianlu
492b97f769 LibWeb/Crypto: Update spec links
Add and update spec links to more precise ones
and move X25519 and Ed25519 from WICG to W3C.
2026-02-14 17:43:34 +01:00
Psychpsyo
dab742ed84 Everywhere: Remove double // on comments 2026-02-11 13:28:01 -06:00
mikiubo
4a1a15ce66 LibWeb: Allow importing ChaCha20-Poly1305 JWK without alg
The WebCrypto specification does not require the "alg" member
to be present when importing a symmetric JWK, as long as the
key material itself is valid.

Add tests covering JWK import without an "alg" field.

This fixes the following WPT:
WebCryptoAPI/import_export/ChaCha20-Poly1305_importKey
2026-02-05 09:05:11 +01:00
mikiubo
ff2acd1d33 LibWeb: Use unchecked_append for pre-sized JWK key_ops vectors
The key_ops vector is pre-sized with ensure_capacity(), so
bounds-checked append() is unnecessary here.

Switch to unchecked_append() to avoid redundant checks.

This change was suggested in a previous pull request #7563.

Add some typo and wrong comment.
2026-02-04 19:19:09 +01:00
Andreas Kling
d89f3fc5e6 LibGC+ClangPlugins: Forbid non-trivial destructors in Cell subclasses
Add a clang plugin check that flags GC::Cell subclasses (and their
base classes within the Cell hierarchy) that have destructors with
non-trivial bodies. Such logic should use Cell::finalize() instead.

Add GC_ALLOW_CELL_DESTRUCTOR annotation macro for opting out in
exceptional cases (currently only JS::Object).

This prevents us from accidentally adding code in destructors that
runs after something we're pointing to may have been destroyed.
(This could become a problem when the garbage collector sweeps
objects in an unfortunate order.)

This new check uncovered a handful of bugs which are then also fixed
in this commit. :^)
2026-01-30 20:57:42 +01:00
mikiubo
ba75d4c014 LibCrypto: Add ChaCha20-Poly1305 support
Implement ChaCha20-Poly1305 AEAD using OpenSSL and expose it through
the WebCrypto API, including key management and AEAD parameters.

Add WPT:
/encrypt_decrypt/chacha20_poly1305.tentative.https.any.worker.html
2026-01-26 10:03:09 +01:00
Colleirose
bf7fd80140 LibCrypto+AK: Merge LibCrypto/SecureRandom into AK/Random
AK/Random is already the same as SecureRandom. See PR for more details.

ProcessPrng is used on Windows for compatibility w/ sandboxing measures
See e.g. https://crbug.com/40277768
2026-01-23 15:53:27 +01:00
mikiubo
cd8465a6b5 LibCrypto: Add SHAKE digest support
Introduce a new SHAKE hash wrapper in LibCrypto backed by OpenSSL.

Wire cSHAKE128 and cSHAKE256 into WebCrypto.

Note that cSHAKE with non-empty functionName or customization is
currently rejected due to OpenSSL EVP limitations.

This fixes WPT:
WebCryptoAPI/digest/cshake.tentative.https.any.html
2026-01-22 19:47:09 -05:00
Jelle Raaijmakers
ae20ecf857 AK+Everywhere: Add Vector::contains(predicate) and use it
No functional changes.
2026-01-08 15:27:30 +00:00
Tete17
7ac6aecef0 LibWeb: Implement decapsulation for ML-KEM algorithms 2026-01-06 01:06:06 +01:00
Tete17
140bbe50ab LibWeb: Extend decapsulate(Key|Bits) methods to pass the key
This is mandated by the spec but since no algorithm supported this
method, yet we didn't notice it was missing.
2026-01-06 01:06:06 +01:00
Tete17
08b48d5369 LibWeb: Align input argument name to the spec 2026-01-06 01:06:06 +01:00
Tete17
a739311fdc LibWeb: Support the exporting of ml-kem keys in pkcs8 format 2026-01-06 01:06:06 +01:00
Tete17
9c5cb08b63 LibWeb: Support the importing of ml-kem keys in pkcs8 format 2026-01-06 01:06:06 +01:00
Tete17
df0796bdf2 LibWeb: Support the exporting of ml-kem keys in raw-seed format 2026-01-06 01:06:06 +01:00
Tete17
ed025f5fcd LibWeb: Support the importing of ml-kem keys in raw-seed format 2026-01-06 01:06:06 +01:00
Tete17
ab74519a0b LibWeb: Support the exporting of ml-kem keys in raw-public format 2026-01-06 01:06:06 +01:00
Tete17
0fc7746b96 LibWeb: Support the importing of ml-kem keys in raw-public format 2026-01-06 01:06:06 +01:00
Tete17
56804e7930 LibWeb: Support the exporting of ml-kem keys in spki format 2026-01-06 01:06:06 +01:00
Tete17
86e9765fe7 LibWeb: Pass the correct algorithms parameters when importing shared key
During decapsulate we were passing the parameters for decapsulate
instead of the ones for the shared key.
2026-01-06 01:06:06 +01:00
Tete17
4e41cfb6c4 LibWeb: Correctly set the usage on the private key for ML-KEM
This is one lines gives us almost 1000 WPTs :)
2026-01-06 01:06:06 +01:00
Tete17
94410298f3 LibWeb: Implement Derive Bits for Argon2 algorithm 2026-01-04 15:56:54 +01:00
Tete17
7b3a97a928 LibWeb: Implement Argon2Params
This is the needed context for the Derive Bits operation of the Argon2
algorithm.
2026-01-04 15:56:54 +01:00
Tete17
2cc71e6437 LibWeb: Support the importing for Argon2 keys 2026-01-04 15:56:54 +01:00
Tete17
ebd0874fb5 LibWeb: Implement Get Key Length for Argon2 algorithm 2026-01-04 15:56:54 +01:00
Tete17
1e6b5a6f81 LibWeb: Set the extractable and usages fields of the generated key
This was a spec bug updated in
https://github.com/WICG/webcrypto-modern-algos/pull/39
2025-12-30 14:16:35 +01:00
Tete17
bbf70e320f LibWeb: Allow symmetric algorithms to be imported with RawSecret
This new format is equivalent to the old Raw.
2025-12-30 14:16:35 +01:00
Tete17
a414819dd6 LibWeb: Support the importing of ml-kem keys in spki format 2025-12-30 14:16:35 +01:00
Tete17
6350b063ab LibWeb: Implement encapsulation for ML-KEM algorithms 2025-12-30 14:16:35 +01:00
Tete17
013cf34d1b LibWeb: Implement key generation for ML-KEM algorithms 2025-12-30 14:16:35 +01:00
Tete17
336929c5a3 LibWeb: Add TemporaryExecutionContext to encapsulate/decapsulate methods
Some operations like retrieving the algorithm name require it.
2025-12-30 14:16:35 +01:00
Tete17
26a9551db2 LibWeb: Correctly transform EncapsulatedKey into an ECMAScript object
The spec prefers camel case, but we internally use snake case.
2025-12-30 14:16:35 +01:00