Skip to main content
Press slash or control plus K to focus the search. Use the arrow keys to navigate results and press enter to open a threat.
Reconnecting to live updates…

sm-crypto: Predictable SM2 key generation in Node.js: default RNG uses Math.random + wall clock

0
Critical
Published: 07/24/2026 (07/24/2026, 21:50:45 UTC)
Source: GCVE Database
Product: sm-crypto

Description

The npm package sm-crypto version 0.4.0 and earlier generates SM2 private keys and signing ephemeral scalars using a predictable random number generator in Node.js environments. The library relies on jsbn's SecureRandom, which attempts to seed from window.crypto.getRandomValues in browsers but falls back to non-cryptographic sources (Math.random and wall clock time) in Node.js because window is undefined. This fallback results in keys and ephemeral values that are predictable by attackers who can observe some outputs of Math.random and estimate the generation time. This vulnerability affects the default key generation path without requiring special configuration.

CVSS v3.1

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
None
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N

Affected software

npmghsa
sm-crypto
Affected versions
<0.5.0

Run on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.

AI-Powered Analysis

Machine-generated threat intelligence

AILast updated: 07/25/2026, 23:51:39 UTC

Technical Analysis

[email protected] uses jsbn's SecureRandom for SM2 key generation. In browsers, SecureRandom seeds an ARC4 stream from window.crypto.getRandomValues, providing cryptographically secure randomness. However, in Node.js, window is undefined, so the secure seeding branch is skipped. Instead, the RNG pool is seeded from Math.random (a recoverable xorshift128+ PRNG) and Date.getTime(), both of which are non-cryptographic and attacker-estimable. Consequently, SM2 private keys and signing ephemeral scalars generated by the default no-argument call path are predictable. A proof-of-concept demonstrates that pinning Math.random and the clock before loading sm-crypto results in deterministic key generation, confirming the vulnerability. This issue affects sm-crypto versions before 0.5.0 and is not mitigated by any existing fixes or configuration options.

Potential Impact

An attacker who can observe some outputs of Math.random and estimate the approximate time of key generation can predict SM2 private keys and signing ephemeral scalars generated by sm-crypto in Node.js. This compromises the confidentiality and integrity of cryptographic operations relying on these keys, enabling key recovery and signature forgery. The vulnerability affects all users of the default key generation path in sm-crypto versions prior to 0.5.0 running in Node.js environments.

Mitigation Recommendations

No official fix or patch is currently available for this vulnerability in [email protected]. Users should avoid using the default key generation in Node.js environments until a patched version is released. Monitor the vendor or repository for updates addressing this issue. Since the vulnerability arises from the fallback to non-cryptographic RNG sources, a potential mitigation is to patch or override the RNG initialization to use Node.js's globalThis.crypto.getRandomValues or another cryptographically secure RNG before loading sm-crypto, but this requires custom intervention. Patch status is not yet confirmed — check the vendor advisory for current remediation guidance.

Pro Console: star threats, build custom feeds, automate alerts via Slack, email & webhooks.Upgrade to Pro

Technical Details

Gcve Source
db.gcve.eu
Osv Id
GHSA-vh45-f885-3848
Osv Schema Version
1.4.0
Aliases
[]
Ecosystems
["npm"]
Database Specific Severity
CRITICAL
Cvss Version
3.1

Threat ID: 6a65421f9c2644c7f808819c

Added to database: 07/25/2026, 23:09:19 UTC

Last enriched: 07/25/2026, 23:51:39 UTC

Last updated: 07/26/2026, 03:46:02 UTC

Views: 4

Community Reviews

0 reviews

Crowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.

Sort by
Loading community insights…

Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.

Actions

PRO

Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.

Please log in to the Console to use AI analysis features.

Need more coverage?

Upgrade to Pro Console for AI refresh and higher limits.

For incident response and remediation, OffSeq services can help resolve threats faster.

Latest Threats

Breach by OffSeqOFFSEQFRIENDS — 25% OFF

Check if your credentials are on the dark web

Instant breach scanning across billions of leaked records. Free tier available.

Scan now
OffSeq TrainingCredly Certified

Lead Pen Test Professional

Technical5-day eLearningPECB Accredited
View courses