Dev.to Security 🔐 Cybersecurity 👁 0 📖 3 min read

How to find quantum-vulnerable encryption in your code

Before you can move to quantum-safe encryption, you need a list of where RSA and elliptic curves are used, and for what. Here is where to look, and how to search for it. What you're looking for A large quantu

Before you can move to quantum-safe encryption, you need a list of where RSA and elliptic curves are used, and for what. Here is where to look, and how to search for it.

What you're looking for

A large quantum computer breaks public-key algorithms built on factoring and discrete logarithms. In code, that means:

  • RSA: key generation, encryption (OAEP, PKCS#1 v1.5) and signatures (PSS, PKCS#1 v1.5).
  • Elliptic curves: ECDSA and Ed25519 signatures, ECDH and X25519 key exchange.
  • Older schemes: DSA and finite-field Diffie-Hellman.

AES and SHA-256 are not on the list. NIST's final transition plan deprecates all of the above after 2030 and disallows them after 2035. More on the dates.

Where it hides

  1. Your own calls to encryption libraries: generating keys, signing, verifying, encrypting.
  2. Tokens and sessions: JWT algorithms such as RS256, ES256 and EdDSA are RSA or elliptic-curve signatures.
  3. Keys and certificates checked into the repository: PEM files, SSH public keys, test fixtures.
  4. Configuration: TLS settings in web servers, load balancers, Kubernetes ingress and Terraform.
  5. Library defaults you never wrote down: every HTTPS call your code makes negotiates a key exchange. Usually it's elliptic-curve, unless your TLS library offers the hybrid post-quantum option.

Search patterns by language

Language Look for
Python rsa.generate_private_key, ec.generate_private_key, ec.ECDH, Ed25519PrivateKey, X25519PrivateKey, padding.OAEP, padding.PSS, RSA.generate (PyCryptodome)
JavaScript, TypeScript generateKeyPair with 'rsa', 'ec', 'ed25519' or 'x25519', createECDH, createDiffieHellman, Web Crypto names RSA-OAEP, RSA-PSS, ECDSA, ECDH, JWT algorithms: ['RS256']
Go rsa.GenerateKey, rsa.SignPSS, ecdsa.GenerateKey, ecdh.P256(), ecdh.X25519(), ed25519.GenerateKey, CurvePreferences in tls.Config
Java KeyPairGenerator.getInstance("RSA") or ("EC"), KeyAgreement.getInstance("ECDH"), Signature.getInstance("SHA256withRSA"), Cipher.getInstance("RSA/...")
Files and config BEGIN RSA PRIVATE KEY, BEGIN EC PRIVATE KEY, ssh-rsa, ecdsa-sha2-nistp256, ssl_ecdh_curve, ssl_protocols

A single ripgrep command gets you a first pass across all of them:

rg -n -i \
  -e 'generate_private_key|RSA\.generate|ECDH|Ed25519|X25519' \
  -e 'generateKeyPair|createDiffieHellman|ecdsa\.' \
  -e 'KeyPairGenerator|KeyAgreement|withRSA|withECDSA' \
  -e '\b(RS|PS|ES)(256|384|512)\b|EdDSA' \
  -e 'ssh-rsa|ecdsa-sha2|BEGIN (RSA |EC )?PRIVATE KEY' \
  -e 'CurvePreferences|ssl_ecdh_curve'

Expect noise. ES256 appears in plenty of places that aren't JWTs, and test fixtures will match. That's fine for a first pass. You're building a list to sort, not a verdict.

Turn the matches into an inventory

A list of line numbers isn't a plan. For each use, record four things:

  • Algorithm and size: RSA-2048, P-256, X25519.
  • Purpose: key exchange, encryption or signature. This decides the order you fix things in.
  • Where: file and line, or the service and config that sets it.
  • How long the data must stay private: a session cookie and a medical record are different problems.

The standard format for this is a cryptography bill of materials, or CBOM, part of CycloneDX. It gives security teams and auditors one format to read, and gives you a baseline to track change against.

Put it in order

  1. Weak today: MD5, SHA-1, DES, ECB mode, RSA-1024, TLS 1.0 and 1.1. These are a problem now. What to use instead.
  2. Key exchange protecting long-lived data: traffic recorded today can be decrypted later. Move to hybrid X25519MLKEM768 for TLS, or ML-KEM directly.
  3. Signatures: start with long-lived keys such as code signing and root certificates, then move the rest to ML-DSA as your libraries support it.

Keep it current

An inventory goes stale the week after you build it. New code adds new keys, and a dependency upgrade changes a default. The cheapest way to keep it accurate is to check every pull request, so new uses are caught when they're written, while the author still remembers why.

Sources

Originally published on hardkeel.com. Hard Keel Quantum Scan, the free and open-source scanner used here, is at hardkeel.com/quantum-scan.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.