Join our Newsletter — 33% off our NHI Course
Home› Guides› Weak Key Generation Incidents Guide: Debian OpenSSL, ROCA…
Guide Data Security

Weak Key Generation Incidents Guide: Debian OpenSSL, ROCA and Detecting Weak Keys in Your Estate

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 14 min read
On this page

A key that was generated badly is broken from the day it was made, no matter how strong the algorithm, how long the key or how well it is stored afterwards. The Debian OpenSSL bug of 2008, the ROCA flaw in Infineon's RSA library in 2017, the shared-prime keys found across embedded devices in 2012 and the Fermat-factorable printer keys of 2022 all show the same pattern: keys look normal, pass every format check and then fall to an attacker who knows the generator's flaw. This guide uses those incidents to explain how key generation fails, how to find weak keys already in your estate and why fixing the generator is only half the job. It is for PKI, cryptography and platform security engineers. It describes detection and remediation only, not factoring methods. For the underlying theory of randomness, see the Random Number Generation and Entropy in Security Guide.

Key takeaways

  • Patching the generator does not fix the keys. Every key made by a flawed generator stays weak until it is regenerated on a fixed system and the old key is revoked and removed from every trust store.
  • Failures fall into a few classes. Too little entropy, entropy thrown away by a code change, structured key generation that leaks a fingerprint, and flawed randomness in hardware after power-up account for the incidents on this page.
  • Weak keys are detectable from the public key alone. Known weak sets (Debian, ROCA, Fermat, shared primes) can be tested from certificates, CSRs and SSH public keys without touching the private key.
  • Hardware is not immune. ROCA hit TPMs and smart cards and the YubiKey FIPS advisory hit tokens, so firmware updates and device replacement belong in the plan alongside software updates.
  • Inventory makes response possible. Without a list of keys, their algorithm, length, generating device and owner, you cannot answer "which of ours are affected?" when the next advisory lands.

Why key generation fails

Key generation needs unpredictable input and a correct algorithm. NIST splits the randomness side into entropy sources (SP 800-90B, which sets design requirements and validation tests for them) and deterministic random bit generators (SP 800-90A), combined into complete generators in SP 800-90C. When either the input or the algorithm is wrong, the output is a key that looks valid but sits in a small or structured space an attacker can search.

Failure classWhat goes wrongExample incidentWhat it lets an attacker do
Entropy removed by a code changeA patch stops real entropy reaching the generator, leaving a tiny set of possible statesDebian OpenSSL, CVE-2008-0166Enumerate every possible key in advance and match public keys against the list
Boot-time entropy holeHeadless devices generate keys on first boot before the kernel pool has gathered enough entropyShared RSA primes and repeated keys across the internet, 2012Find shared factors between public keys, or reuse known default keys
Structured prime generationA library builds primes with a special structure to save time, leaving a detectable fingerprint and a reduced search spaceROCA, CVE-2017-15361Recover private keys of affected lengths at a computational cost that falls far short of the key's nominal strength
Primes too close togetherBoth RSA primes are chosen close to each otherRambus SafeZone in printers, CVE-2022-26320Recover the private key efficiently from the public key
Predictable output after power-upHardware random buffer starts with leftover, predictable contentYubiKey FIPS, YSA-2019-02Weaken keys and, for ECDSA, biased nonces may allow key recovery from signatures
Nonce reuse in signaturesDSA or ECDSA signature randomness repeats or is predictableDSA keys recovered from SSH hosts, 2012Recover the private key from two or more signatures, even if the key itself was generated well

Debian OpenSSL 2008

CVE-2008-0166, published on 13 May 2008, records that OpenSSL 0.9.8c-1 up to versions before 0.9.8g-9 on Debian-based operating systems used a random number generator that generated predictable numbers. A Debian-specific change had removed the code that mixed real entropy into OpenSSL's pool, leaving the process ID as the main source of variation. The result was a small, enumerable set of possible keys for each key type and size.

  • Blast radius: any key generated with the affected OpenSSL on Debian, Ubuntu and derivatives: SSH host and user keys, X.509 keys and CSRs, OpenVPN keys and anything else that used the library. Debian issued DSA-1571 for OpenSSL and DSA-1576 for OpenSSH.
  • The DSA twist: DSA signatures need fresh randomness for every signature. A DSA key generated perfectly elsewhere but used for signing on an affected system could be exposed through its predictable signatures, so Debian's guidance covered keys used on affected hosts, not only keys made there.
  • Long tail: because the weak key set is finite and published, any affected key that survived (on an appliance, an old jump host, a forgotten authorized_keys file) can still be matched today.

The lesson for engineering teams is about change control as much as cryptography: a downstream patch to silence a Valgrind warning about uninitialised memory touched a security-critical path. Treat changes to random number generation code as high-risk changes that need cryptographic review.

ROCA 2017

ROCA (CVE-2017-15361) was a flaw in RSA key generation in the Infineon RSA library 1.02.013, used in Infineon TPM firmware and in smart cards and tokens. The researchers at Masaryk University stress that it was not a weak random number generator: the library built primes with a structure that made affected keys both fingerprintable and practical to factor at certain lengths. The CVE record names BitLocker with TPM 1.2, YubiKey 4 (before 4.3.5) PGP key generation and Chrome OS Cached User Data encryption among affected technologies, and the research team reported electronic identity documents, authentication tokens, code signing, TLS and PGP keys among the affected uses.

  • Timeline: found at the end of January 2017, disclosed to Infineon on 1 February 2017, made public on 16 October 2017 together with a detection tool, and presented at ACM CCS in November 2017.
  • Scale: the researchers confirmed about 760,000 vulnerable keys and estimated the real number could be two to three orders of magnitude higher.
  • Affected lengths: the team listed 512 to 704, 992 to 1216 and 1984 to 2144 bit ranges as practically factorable, with 2048-bit keys costly but feasible. Longer keys were not practically affected at the time, but they recommended them only as a last resort.
  • What not to do: FIDO U2F tokens were not affected because U2F uses elliptic curve keys only. Do not waste response effort on algorithms the flaw cannot touch.

The researchers' mitigation list is the template for any hardware key generation flaw: apply the vendor firmware update, replace the device if no update exists, or generate keys outside the device and import them, use elliptic curve keys where the device supports them, and add compensating risk controls for keys that cannot be replaced at once.

Other weak key incidents

IncidentYearCVE or advisoryCauseAffected keys
Debian OpenSSL2008CVE-2008-0166; DSA-1571, DSA-1576Entropy removed by a distribution patchRSA and DSA keys generated or used on affected Debian-based systems
Shared primes and repeated keys ("Mining Your Ps and Qs")2012Research by UC San Diego and University of MichiganBoot-time entropy hole on headless and embedded devicesPrivate keys recovered for 0.50% of TLS hosts and 0.03% of SSH hosts; DSA keys for 1.03% of SSH hosts
ROCA2017CVE-2017-15361Structured prime generation in Infineon RSA libraryRSA keys from Infineon TPMs, smart cards and tokens
YubiKey FIPS reduced initial randomness2019Yubico YSA-2019-02Predictable leftover content in the random buffer after power-up self-testsYubiKey FIPS series on firmware 4.4.2 and 4.4.4; ECDSA signatures highest risk
Fermat-factorable keys2022CVE-2022-26320Rambus SafeZone Basic Crypto Module before 10.4.0 chose primes too close togetherRSA keys in TLS certificates on certain Fujifilm and Canon devices, and potentially others

The 2012 study found that most affected hosts were routers, firewalls and server management cards that generated keys on first boot, and the team notified 54 manufacturers. Yubico replaced affected YubiKey FIPS devices, the FIPS certification of the affected firmware was revoked, and firmware 4.4.5 fixed the issue. The pattern repeats: the affected keys usually live in devices nobody thinks of as cryptographic infrastructure.

Detecting weak keys in your estate

Where to look

  • TLS certificates: internal CA databases, certificate discovery scans of internal ranges and Certificate Transparency logs for your public domains. See How to build a TLS certificate inventory.
  • SSH keys: host keys collected by network scans and known_hosts files, and user keys in authorized_keys files, Git hosting platforms and bastion hosts. See How to find unused GitHub deploy keys and SSH keys.
  • Hardware-generated keys: TPM-backed keys (BitLocker, Windows Hello for Business, virtual smart cards, device certificates), smart cards and security tokens, HSM-generated keys. Record the device model and firmware version that generated each key.
  • Code signing, PGP and S/MIME keys: often long-lived and owned by individuals, so easy to miss.
  • Appliances and embedded devices: printers, management controllers, network devices and OT equipment that make their own keys on first boot.

How to test

CheckWhat it findsInput neededNotes
Known weak key setsDebian 2008 keys, ROCA fingerprint, Fermat-close primes, published compromised keysPublic keys from certificates, CSRs or SSH public keysTools such as the open-source badkeys checker by Hanno Böck and the ROCA detector published by the researchers work from public keys only
Shared factors across your corpusRSA keys that share a prime with another key you holdAll RSA public keys you can collectWorks best at scale; one hit means both keys are broken
Duplicate keysDefault or cloned keys reused across devices or imagesPublic key fingerprintsCommon in golden images and appliances; each copy needs regeneration
Algorithm and length inventoryDSA keys, RSA below your minimum, unusual exponents, legacy curvesCertificate and key metadataFeeds the Cryptographic Inventory and CBOM Guide
Generator provenanceKeys generated by a device, firmware or library version named in an advisoryKey inventory with generating device and firmwareThe only way to find affected keys when no public key test exists

Never upload production private keys to online checkers. Public key tests are sufficient for the known weak classes, and they can run inside your environment.

Metrics

  • Percentage of certificates and SSH keys in inventory with algorithm, length and generating source recorded.
  • Number of keys matching a known weak set, and median days from detection to regeneration and revocation.
  • Percentage of TPMs, tokens and HSMs on firmware versions that are fixed for all published key generation advisories.
  • Number of duplicate public keys across devices and images.
  • Time to produce an affected-key list after a new key generation advisory.

Prevention

Regeneration, not just revocation

When a weak key is found, the order matters. Revoking a certificate without replacing its key leaves the service down or, worse, re-issued on the same weak key.

  1. Fix the generator first: update the library, apply the TPM, token or HSM firmware update, or move key generation off the affected device. Regenerating on an unfixed system produces another weak key.
  2. Clear and reinitialise hardware where the vendor requires it: some TPM remediations require clearing the TPM after the firmware update before keys can be regenerated, which affects BitLocker, Windows Hello and device certificates. Follow the device vendor's documented order and test on a pilot group.
  3. Generate new key pairs: never re-use the old private key for a new certificate request.
  4. Re-issue and deploy: new certificates, new SSH host keys (warn users about host key changes in advance), new authorized_keys entries.
  5. Revoke and remove the old keys: revoke certificates at the CA, delete old public keys from authorized_keys, known_hosts and trust stores, and rotate any secret that was protected by the weak key.
  6. Re-scan: confirm the weak key no longer appears anywhere. Keep the old key's fingerprint on a blocklist so it cannot return from a backup or image.
  7. Assess past exposure: data encrypted to, or signatures made with, a weak key may already be compromised. Decide whether to re-encrypt data and re-sign artefacts.

Rollback for a failed rotation means restoring service on a temporary key from a known good generator, never reinstating the weak key.

Building it in

  • Use validated generators: prefer modules validated under FIPS 140-3 for key generation where your sector expects it, while remembering that YSA-2019-02 hit a FIPS-validated product. See the FIPS 140-3 and Cryptographic Module Validation Guide.
  • Delay first-boot key generation: generate device and host keys only after the operating system reports its random pool is initialised, and do not bake host keys into images.
  • Test keys at issuance: run weak key checks in the CA or certificate lifecycle tooling on every CSR, so weak keys are refused before they are certified.
  • Prefer deterministic nonces or modern signature schemes: signature schemes that do not depend on a fresh random nonce per signature remove the nonce reuse class.
  • Track firmware: treat TPM, token and HSM firmware as patchable assets with owners. The HSM Deployment and Operations Guide covers operating models.

Decision guidance

  • Device-generated versus imported keys: on-device generation keeps the private key from ever leaving hardware, but you inherit the device's generator flaws. Importing keys generated on a validated host avoids a known flawed generator at the cost of handling the private key in transit. ROCA guidance favoured import for affected devices.
  • Small organisations: start with public key scanning of TLS and SSH plus an inventory of TPMs and tokens by model and firmware. That covers most of the incident classes on this page.
  • Large organisations: integrate weak key tests into CA issuance, CBOM tooling and SSH key management, and run corpus-wide shared factor checks periodically.

Where identity fits

Most of the keys at risk belong to machines: TLS server certificates, SSH host keys, service account keys and device certificates. A weak key on a machine identity means an attacker can impersonate that workload or decrypt its traffic. Track owners for these keys through the Machine Identity, PKI and Certificate Lifecycle Guide so regeneration has someone to act on it.

Framework mapping

FrameworkReferenceHow it applies
NIST SP 800-53 Rev 5SC-12 Cryptographic Key Establishment and Management; SC-13 Cryptographic Protection; IA-5 Authenticator Management; SI-2 Flaw Remediation; CM-8 System Component InventoryKey generation and replacement, approved cryptography, key-based authenticators, firmware and library patching, device inventory
NIST SP 800-90B and 800-90AEntropy sources and deterministic random bit generatorsRequirements for the generators behind key creation
NIST SP 800-57 Part 1 Rev 5Key management guidanceKey lifecycle, compromise handling and inventory
NIST CSF 2.0ID.RA-01; PR.PS-02Identify vulnerable keys and generators; maintain and replace software and firmware by risk

Common failure patterns

  • Revoke and re-issue on the same key: the certificate changes, the weak key stays.
  • Regenerate before patching: new keys made on the unfixed library or firmware are just as weak.
  • Forgetting the images: host keys baked into templates come back with every new instance.
  • Ignoring signature-only use: treating DSA or ECDSA keys as safe because they were generated elsewhere, when the flawed system made the signatures.
  • No generator provenance: when an advisory names a device and firmware version, teams without that field in their inventory cannot find affected keys.

Practitioner checklist

  • Collect public keys from internal CA records, certificate scans, CT logs, SSH host scans and authorized_keys files.
  • Test them against known weak sets (Debian 2008, ROCA, Fermat, published compromised keys) and for shared factors and duplicates.
  • Record algorithm, length, generating device or library, firmware version and owner for every key.
  • Inventory TPMs, smart cards, tokens and HSMs by model and firmware, and apply vendor key generation fixes.
  • For every weak key: fix the generator, regenerate, re-issue, revoke, remove and blocklist the old fingerprint.
  • Add weak key checks to certificate issuance so weak CSRs are refused.
  • Remove baked-in host keys from images and generate keys after the random pool is initialised.
  • Assess whether data or signatures protected by a weak key need re-encryption or re-signing.

Standards and references

Related NHI Mgmt Group resources: Random Number Generation and Entropy in Security Guide · Cryptographic Key Management Guide · Cryptographic Protocol Failures and Misuse Guide · HSM vs TPM vs Secure Enclave

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.