crypto: support provider-only SM4 cipher modes - #65399
Open
PickBas wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
Fixes: nodejs#64866 Co-authored-by: StefanStojanovic <stefan.stojanovic@janeasystems.com> Signed-off-by: Kirill Saied <sayed.kirill@gmail.com>
PickBas
force-pushed
the
issue-64866-updated
branch
from
August 19, 2026 11:27
6cb1a8a to
491dc6d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65399 +/- ##
==========================================
- Coverage 90.30% 90.11% -0.20%
==========================================
Files 759 752 -7
Lines 247648 251864 +4216
Branches 46696 47355 +659
==========================================
+ Hits 223644 226970 +3326
- Misses 15466 16230 +764
- Partials 8538 8664 +126 🚀 New features to boost your workflow:
|
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.
crypto: support provider-only SM4 cipher modes
sm4-gcm,sm4-ccmandsm4-xtsexist only as fetchable provider algorithms in OpenSSL 3. There is no legacyEVP_CIPHERfor them, soEVP_get_cipherbyname()/EVP_get_cipherbynid()cannot resolve them andEVP_CIPHER_do_all_sorted(), which walks the legacy name table, never reports them.createCipheriv()threwUnknown cipher,getCipherInfo()returnedundefined, andgetCiphers()omitted them.Changes
Cipher::FromName()/Cipher::FromNid()fall back toEVP_CIPHER_fetch().Cipher::getNid()recovers the nid from the algorithm name, since a fetched cipher inherits its nid from the legacy implementation it does not have. Without this,getCipherInfo(name)reports no nid and cannot round-trip throughgetCipherInfo(nid).Cipher::ForEach()probes for the provider-only modes sogetCiphers()lists them.Cipheris a non-owning wrapper, so they are cached for the process lifetime. The cache key includes the library context's default property state, becausecrypto.setFips()changes it at runtime and a cipher fetched beforehand must not stay usable afterwards.Tests
test-crypto-sm4-aead.js- RFC 8998 A.1/A.2 known-answer vectors for GCM and CCM, XTS round-trip, tag tampering,getCipherInfoname/nid round-trip, case-insensitive lookup, and negative cases for unknown names and nids.test-crypto-sm4-fips.js- enabling FIPS at runtime must invalidate an already fetched SM4 cipher. Skipped unless a FIPS provider is available.Fixes: #64866