Complete the WebCrypto API implementation to cover the full specification#1045
Complete the WebCrypto API implementation to cover the full specification#1045xeioex merged 5 commits intonginx:masterfrom
Conversation
Removed the incorrect "alg":"RS256" field from RSA JWK test data files. The field is optional per RFC 7517, and the value RS256 (RSASSA-PKCS1-v1_5) was wrong for tests that use RSA-OAEP and RSA-PSS algorithms. Node.js correctly rejects JWK imports when the "alg" field does not match the requested algorithm. The hash mismatch negative test was updated to use an inline JWK with an explicit "alg" field instead of the shared file. This ensures: `test/test262 --binary=node test/webcrypto` pass.
Supports 128, 192, and 256-bit key sizes with generateKey, importKey, and exportKey operations in raw and JWK formats. Also fixed deriveKey to accept 192-bit AES key lengths.
|
It seems X25519 should have its own feature probe instead of piggybacking on NJS_HAVE_ED25519. Right now auto/openssl checks only EVP_PKEY_ED25519, but the algorithm table enables both Ed25519 and X25519 under #if (NJS_HAVE_ED25519). This works if both are always present together in all supported crypto backends, but that assumption is not encoded in the build checks. Would you mind adding a separate EVP_PKEY_X25519 probe / macro, or at least documenting why the shared gate is guaranteed safe? |
Implemented Ed25519 sign/verify/generateKey/importKey/exportKey Supports raw, PKCS8, SPKI, and JWK (OKP) key formats. Implemented X25519 deriveBits/deriveKey/generateKey/importKey/ exportKey.
Added JWK format support to unwrapKey: decrypted data is parsed as JSON and imported through the shared import path.
Both Ed25519 and X25519 share the same Curve25519 implementation and were introduced together in all supported crypto backends: OpenSSL 1.1.1, LibreSSL 3.7.0, BoringSSL (rolling-release mode), and AWS-LC (forked from BoringSSL after 2019 with both *25519 already supported). No known build configuration in any of these libraries enables one without the other. Added a comment in auto/openssl documenting this. |
This complete the WebCrypto API implementation to cover the full W3C specification.
This branch adds the remaining algorithms and operations that were missing:
With these changes, njs implements all 12 SubtleCrypto methods, all 13 algorithms (RSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEP, ECDSA, ECDH, Ed25519, X25519, AES-CTR, AES-CBC, AES-GCM, AES-KW, HMAC, HKDF, PBKDF2), all 4 digest algorithms, all 4 key formats (raw, pkcs8, spki, jwk), crypto.getRandomValues(), and crypto.randomUUID(). Both the njs and QuickJS engine backends are updated.
Ed25519/X25519 and AES-KW are conditionally compiled based on OpenSSL feature detection (
auto/openssl), so builds against older OpenSSL versions remain functional.Test plan