Repository navigation
feat(runtime): crypto.subtle - #49
Merged
Merged
Conversation
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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
crypto.subtleandCryptoKey, backed by CNG (bcrypt).Supported
digest: SHA-1, SHA-256, SHA-384, SHA-512generateKey,importKey/exportKey(raw,jwk),sign,verifygenerateKey,importKey/exportKey(raw,jwk),encrypt,decryptimportKey(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.rsholds all the logic: algorithm normalization, usage checks, JWK handling and errors. It works against a smallJstrait that each engine implements.subtle/backend.rsdoes the CNG work:BCryptHash(digest and HMAC),BCryptEncrypt/BCryptDecryptwithBCRYPT_AUTHENTICATED_CIPHER_MODE_INFO(AES-GCM),BCryptDeriveKeyPBKDF2, and RFC 5869 HKDF over CNG HMAC.subtle_v8.rs) and the napi engine (napi_engine/subtle.rs), both exposed as__nsSubtle.crypto.jsforwards each method to__nsSubtleand wraps the result in a promise. Hosts that already providecrypto.subtlekeep their own.Win32_Security_Cryptographyfeature ofwindows.Tests
runtime/src/subtle/tests.rsusing FIPS 180, RFC 4231, NIST GCM, RFC 6070 and RFC 5869 vectors.crypto_subtleininterop_test.rsruns the same vectors through JS.