Skip to content

feat(runtime): crypto.subtle - #49

Merged
triniwiz merged 1 commit into
mainfrom
feat/crypto-subtle
Nov 8, 2026
Merged

triniwiz merged 1 commit into
mainfrom
feat/crypto-subtle

Conversation

@triniwiz

@triniwiz triniwiz commented Nov 8, 2026

Copy link
Copy Markdown
Member

Adds crypto.subtle and CryptoKey, backed by CNG (bcrypt).

Supported

  • digest: SHA-1, SHA-256, SHA-384, SHA-512
  • HMAC: generateKey, importKey/exportKey (raw, jwk), sign, verify
  • AES-GCM (128/256-bit keys, 96-bit IV, 128-bit tag): generateKey, importKey/exportKey (raw, jwk), encrypt, decrypt
  • PBKDF2 and HKDF: importKey (raw), deriveBits, deriveKey (to HMAC or AES-GCM)

Anything else rejects with NotSupportedError. Other failures reject with the WebCrypto error names. Behaviour matches the Linux runtime.

Design

  • runtime/src/subtle.rs holds all the logic: algorithm normalization, usage checks, JWK handling and errors. It works against a small Js trait that each engine implements.
  • subtle/backend.rs does the CNG work: BCryptHash (digest and HMAC), BCryptEncrypt/BCryptDecrypt with BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO (AES-GCM), BCryptDeriveKeyPBKDF2, and RFC 5869 HKDF over CNG HMAC.
  • Bindings for the classic engine (subtle_v8.rs) and the napi engine (napi_engine/subtle.rs), both exposed as __nsSubtle.
  • crypto.js forwards each method to __nsSubtle and wraps the result in a promise. Hosts that already provide crypto.subtle keep their own.
  • Adds the Win32_Security_Cryptography feature of windows.

Tests

  • Unit tests in runtime/src/subtle/tests.rs using FIPS 180, RFC 4231, NIST GCM, RFC 6070 and RFC 5869 vectors.
  • crypto_subtle in interop_test.rs runs the same vectors through JS.

digest (SHA-1/256/384/512), HMAC, AES-GCM, PBKDF2 and HKDF, with raw and
jwk import/export for secret keys, backed by CNG (bcrypt). The
implementation is native for both the classic and Node-API engines
(__nsSubtle); crypto.js only forwards each call and wraps the result in
a promise. Unsupported algorithms and operations reject with
NotSupportedError.
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c1c6176f-c3a4-4283-bbce-754d7fc4d4ca

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@triniwiz
triniwiz merged commit 89b1c97 into main Nov 8, 2026
3 checks passed
@triniwiz
triniwiz deleted the feat/crypto-subtle branch November 8, 2026 20:40
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.

1 participant