Predictable Key Generation Vulnerability in sm-crypto Package

sm-crypto Updated 25 Jul 2026

Summary

24/07/2026
CRITICAL
Yes i
Critical
9.1

GHSA-vh45-f885-3848: sm-crypto: Predictable SM2 key generation in Node.js: default RNG uses Math.random + wall clock. Affects sm-crypto versions < 0.5.0. Fixed in 0.5.0. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Your last release was probably never penetration tested Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

The sm-crypto package is an npm library designed for cryptographic operations, specifically implementing the SM2 algorithm for public key cryptography. It is widely used in applications requiring secure key generation and signing. However, a critical vulnerability exists in its key generation process when used in Node.js environments, where it relies on non-cryptographic sources for randomness, making it susceptible to attacks.

Vulnerability Detail

The vulnerability arises from the sm-crypto package's use of a predictable random number generator (RNG) for generating SM2 private keys and signing ephemeral scalars. In Node.js, the library defaults to using Math.random() and the current time (Date.now()) to seed its RNG, which is non-cryptographic and can be estimated by an attacker. This predictability allows an attacker who can observe a few outputs of Math.random() and estimate the generation time to recover private keys and forge signatures, leading to severe security implications.

How To Fix

Latest published version: 0.5.7 as of 23 Oct 2026

npm install sm-crypto@0.5.7

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

0.5.0

This is the first release that contains the fix.

npm install sm-crypto@0.5.0

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a temporary workaround, you can implement your own secure RNG or use Node.js's built-in crypto module to generate secure random bytes. Replace the RNG initialization in sm-crypto with the following code:

const crypto = require('crypto');
function csrandBytes(n) {
  return crypto.randomBytes(n);
}

Conclusion

The sm-crypto package contains a critical vulnerability due to its reliance on predictable RNG for key generation in Node.js. It is essential to update to the latest version to ensure cryptographic security. Users are encouraged to utilize tools like Vulert to monitor for vulnerabilities in their applications.

See every vulnerability recorded for sm-crypto →

Share this vulnerability

FAQ

The CVSS score of this vulnerability is 9.1, indicating a critical severity level.

You can use Vulert, which monitors and alerts for open-source vulnerabilities in real-time. You can check your application using the Vulert playground without any signup.

The consequences include private key recovery and signature forgery, which can lead to unauthorized access and data breaches.

Yes, a patch is available in version 0.5.0 of the sm-crypto package. It is recommended to update to this version.

If immediate updating is not possible, consider implementing a secure RNG as a workaround to mitigate the risk until you can upgrade.

Related vulnerabilities

Recent vulnerabilities recorded for sm-crypto.

How To Fix

Latest published version: 0.5.7 as of 23 Oct 2026

npm install sm-crypto@0.5.7

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

0.5.0

This is the first release that contains the fix.

npm install sm-crypto@0.5.0

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback