Skip to content
Crypto Advisory Advanced CVE-2021-41117

GHSL-2021-1012: Poor random number generation in keypair - CVE-2021-41117

The keypair library generated RSA keys with a weak random number generator, causing many bytes of the seed to be zero. An attacker could guess the keys and decrypt messages or gain unauthorised access.

ghsecuritylab Follow

Originally disclosed on GitHub Security Lab

keypair implements a lot of cryptographic primitives on its own or by borrowing from other libraries where possible, including node-forge. An issue was discovered where this library was generating identical RSA keys used in SSH.

ghsecuritylab, on GitHub Security Lab

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a double String.fromCharCode call in the fallback random number generator caused most seed bytes to become zero, and the library also failed to use Node's secure random generator due to a variable shadowing bug.

Impact

Attackers could decrypt confidential messages or gain authorised access to a victim's account.

What the attacker needed

Use of keypair library in Node.js

The fix

The library was fixed by the maintainer.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

RSA keys are used to protect data; they must be random so nobody can guess them. This library made keys with a broken random generator, so many keys were almost the same and could be guessed. That let attackers read secret messages or log in as someone else.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by ghsecuritylab

View all

132 more disclosed reports, best first.

More from GitHub Security Lab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.