{"slug": "show-hn-pqkit-scan-a-codebase-for-crypto-a-quantum-computer-will-break", "title": "Show HN: Pqkit – scan a codebase for crypto a quantum computer will break", "summary": "Developer loperdev released pqkit, an npm package published as `pqtoolkit` that wraps the noble implementations of published post-quantum standards and always runs a classical and a post-quantum algorithm together, pairing X-Wing (ML-KEM-768 + X25519) with ML-KEM-1024 + P-384 for encryption and Ed25519 + ML-DSA-65 with Ed448 + ML-DSA-87 for signatures. The package, which requires Node 22.12 or later and also runs in browsers and React Native, includes a scanner that finds old quantum-vulnerable algorithms in a codebase and a documented SPEC.md format so other tools can read what it writes. pqkit invents no cryptography of its own, encrypts data with ChaCha20-Poly1305, requires both halves of a signature to verify, and refuses to run if the random number generator is missing, returns zeros or returns the same bytes twice.", "body_md": "Quantum-safe encryption and signatures in a few lines, a scanner that finds the old algorithms in a codebase, and a documented format so other tools can read what it writes.\n\npqkit invents no cryptography. It wraps the [noble](https://paulmillr.com/noble/)\nimplementations of published standards and always runs a classical and a\npost-quantum algorithm together, so a break of one family alone does not expose\nyour data. [SPEC.md](https://github.com/loperdev/pqkit/blob/main/SPEC.md) states exactly what each half must still provide.\n\n|  | Standard strength | High strength | \n|---|---|---|\n| Encryption | X-Wing (ML-KEM-768 + X25519) | ML-KEM-1024 + P-384 | \n| Signatures | Ed25519 + ML-DSA-65 | Ed448 + ML-DSA-87 | \n\nBoth halves of a signature must verify. Data is encrypted with ChaCha20-Poly1305.\n\n```\nnpm install pqtoolkit\n```\n\nThe npm package is called `pqtoolkit` (npm would not accept `pqkit`: too close to\nanother package's name). The command it installs is `pqkit`, and `npx pqtoolkit`\nruns the same command without installing.\n\nWorks in Node 22.12 or later, browsers and React Native. The environment must\nprovide `crypto.getRandomValues`, `TextEncoder`, `TextDecoder`, `BigInt`,\n`Object.hasOwn` and `DataView.prototype.setBigUint64` (Safari 15.4 or later). Load\nany polyfills before importing pqkit. React Native gets `getRandomValues` from\n`react-native-get-random-values` or `expo-crypto`, and may need a `TextDecoder`\npolyfill that supports the `fatal` option. pqkit refuses to run if the random\nnumber generator is missing, returns zeros or returns the same bytes twice. That\ncheck catches a broken generator, not a predictable one.\n\npqkit is an ES module. Use `import`; `require('pqkit')` works on Node 22.12 or\nlater.\n\nEvery failure throws a `PqkitError`. Check `error.name === 'PqkitError'` rather\nthan `instanceof`, which fails across workers, iframes and duplicate installs.\n\nSigning takes tens of milliseconds and occasionally a few hundred, and it blocks the thread. In a browser or app, sign in a worker. Do not pass shared memory that another thread is writing: pqkit would sign or seal a mix of old and new bytes.\n\n``` js\nimport { generateEncryptionKeys, seal, open, bytesToString } from 'pqtoolkit';\n\nconst { publicKey, secretKey } = generateEncryptionKeys();\n\nconst sealed = seal('card ending 4242', publicKey);\nconst text = bytesToString(open(sealed, secretKey));\n```\n\n**`open` succeeding says nothing about who sealed the data.** Anyone who has the\npublic key can seal. Never treat sealed data as a session, token or licence: sign\nit (see below). `open` throws a `PqkitError` if the key, the context or the data\nis wrong.\n\nGenerate a key pair once and store the secret key somewhere safe. A new key pair cannot read data sealed for an old one. Logging or serialising the key pair object prints the secret key.\n\n`seal` takes text or bytes and returns bytes. Text is encoded as UTF-8; text that\nis not valid Unicode is refused, so that two different strings can never produce\nthe same bytes. To store the result as text:\n\n``` js\nimport { toBase64Url, fromBase64Url } from 'pqtoolkit';\n\nconst column = toBase64Url(sealed);\nconst again = open(fromBase64Url(column), secretKey);\n```\n\nOnly the public key is needed to encrypt, so a server that writes data never has to hold the key that reads it.\n\n``` js\nimport { generateSigningKeys, sign, verify } from 'pqtoolkit';\n\nconst { publicKey, secretKey } = generateSigningKeys();\n\nconst signature = sign('licence:pro:2027', secretKey);\nverify(signature, 'licence:pro:2027', publicKey); // true\nverify(signature, 'licence:pro:2099', publicKey); // false\n```\n\n**`verify` returns `false` for a signature that does not match. It does not throw**\n(it throws only for arguments of the wrong kind, such as a damaged key). Always use\nthe return value:\n\n```\nif (!verify(signature, data, publicKey)) throw new Error('bad signature');\n```\n\nSignatures are different every time, even for the same message, so never use one as an identifier. Verify the exact bytes you received, then parse those same bytes.\n\n``` js\nimport { sealSigned, openSigned } from 'pqtoolkit';\n\nconst blob = sealSigned('wire 10 to bob', bob.publicKey, alice.secretKey);\nconst message = openSigned(blob, bob.secretKey, alice.publicKey); // throws unless Alice signed it for Bob\n```\n\n`sealSigned` signs the message for one named recipient and seals the signature\ninside. `openSigned` returns the message only if it was sealed to your key and\nsigned by the sender you name; everything else is one error. Both keys must be the\nsame strength. It adds 4,553 bytes (6,466 at high strength).\n\nUse it instead of calling `sign` and `seal` yourself, because doing both by hand\nhas two classic traps. If you sign and then seal, the recipient can seal your\nsigned message again for someone else, who will believe you sent it to them. If\nyou seal and then sign, anyone can remove your signature and add their own.\n`sealSigned` closes both: the signature names the recipient, and the sealed blob\nis tied to the sender's key.\n\nWhat it does not give you: the recipient can still show the signed message to a third party (it is a real signature), the same blob can be delivered twice, and a stolen recipient key opens old messages. Put a date or counter in the message if replay matters.\n\nPass a `context` to tie a result to one purpose. It must match exactly to open or\nverify, which stops a value made for one place being reused in another. Options\nare checked strictly: a misspelt option name, or a `context` that turns out to be\n`undefined`, is an error and never silently ignored.\n\n``` js\nconst context = JSON.stringify(['user', userId]);\nconst sealed = seal(token, publicKey, { context });\nopen(sealed, secretKey, { context });\n```\n\nBuild a context from separate parts with `JSON.stringify([...])`, not by joining\nthem with a separator: `\"1:2\" + \":\" + \"3\"` and `\"1\" + \":\" + \"2:3\"` are the same\ntext. Check that every part is defined first, because `` `user:${undefined}` `` is\na valid string. A context is a label, not a password: it is not secret. Signing\ncontexts are limited to 255 bytes.\n\nStandard is NIST's general default (security category 3) and is the right choice for most projects. High uses the top category (5), the level that the NSA's CNSA 2.0 and Australia's post-2030 guidance name for key exchange and signatures. Choose it when generating keys; everything else follows from the key.\n\n``` js\nconst keys = generateEncryptionKeys({ strength: 'high' });\nconst signing = generateSigningKeys({ strength: 'high' });\n```\n\nA key of one strength cannot open or verify data made with the other.\n\nHigh strength is not a compliance claim. CNSA 2.0 also requires AES-256 and validated implementations, and pqkit provides neither.\n\n|  | Standard | High | \n|---|---|---|\n| Encryption public key | 1,640 characters | 2,239 characters | \n| Signing public key | 2,664 characters | 3,551 characters | \n| Encryption secret key | 61 characters | 61 characters | \n| Signing secret key | 104 characters | 137 characters | \n| Sealed data | your data + 1,174 bytes | your data + 1,719 bytes | \n| Signature | 3,379 bytes | 4,747 bytes | \n| Signed and sealed data | your data + 4,553 bytes | your data + 6,466 bytes | \n\nPost-quantum keys and signatures are much larger than the ones they replace. Allow for that in database columns, headers and URLs.\n\n`npm run bench` measures every operation in both strengths, the scanner, and the\nclassical algorithms in native code for scale. It prints the median, the 95th\npercentile and the slowest run, and warns when the machine is busy. Add `--json`\nafter `node bench/run.mjs` for machine-readable output.\n\npqkit is written in JavaScript and does a classical and a post-quantum operation every time, so it is far slower than native Ed25519 or X25519 alone. Signing is the slowest operation. Measure on the hardware you will run on.\n\n```\nnpx pqtoolkit keygen encryption -o alice     # alice.pub, alice.key\nnpx pqtoolkit encrypt -r alice.pub report.pdf\nnpx pqtoolkit decrypt -k alice.key report.pdf.pqk -o report.copy.pdf\n\nnpx pqtoolkit keygen signing -o release\nnpx pqtoolkit sign -k release.key app.zip\nnpx pqtoolkit verify -p release.pub app.zip\n\n# sign and encrypt in one file; the reader must name the sender\nnpx pqtoolkit encrypt -r alice.pub --sign-key release.key report.pdf\nnpx pqtoolkit decrypt -k alice.key --from release.pub report.pdf.pqk -o report.copy.pdf\n```\n\nAdd `--high` to `keygen` for high-strength keys.\n\nSecret keys are read from a file or from `PQKIT_SECRET_KEY`, never from the\ncommand line. Secret key files and decrypted files are created readable only by\nyou; a folder with an inherited access-control list, or a FAT or exFAT disk, can\noverride that. A run that is killed outright can leave a `.tmp` file beside the\noutput. Exit codes: 0 for success, 1 for an invalid signature or for scan findings at\nor above `--fail-on`, 2 for any error.\n\nEach option may be given once, and only with the commands it belongs to. In a script, check a download like this:\n\n```\nset -eu\nif npx pqtoolkit verify -p ./release.pub -- \"$FILE\"; then\n  install \"$FILE\"\nfi\n```\n\nUse the exit code, never the printed text. Quote the file name and put `--` before\nit. Keep the public key with your script; a key downloaded from the same place as\nthe file proves nothing. A valid signature does not say which version a file is,\nso an old signed release still verifies: sign with `--context \"myapp/2.0\"` and\nverify with the same context if that matters.\n\n`encrypt` does not remove the original file. `keygen` without `-o` shows the keys\nonly on a terminal.\n\n```\nnpx pqtoolkit scan .\n```\n\nLists where a project uses RSA, elliptic curves and Diffie-Hellman, grouped by urgency. It knows the common libraries and settings of JavaScript, Python, Go, Java, C#, Rust, C, Ruby, PHP and Swift, and of shell scripts and server configuration:\n\n- **High** : encryption and key exchange. Traffic recorded today can be decrypted later.\n- **Medium** : signatures, keys and certificates. At risk once a quantum computer exists.\n- **Low** : 128-bit symmetric keys.\n\nIt also reads dependency manifests and lockfiles (npm, PyPI, Go, crates.io, RubyGems, Packagist, Maven and NuGet) and lists, as low findings, the packages that implement RSA, elliptic curves or Diffie-Hellman. The list of packages is short and hand-picked, so it is a starting point and not a complete audit of your dependencies.\n\nOutput formats: `--json` for tooling, `--sarif` (SARIF 2.1.0) for GitHub code\nscanning and similar dashboards, and `--cbom` for a CycloneDX 1.6 cryptography\nbill of materials, the inventory format many compliance programmes ask for (its\noutput validates against the official 1.6 schema). The\nCBOM has one entry per kind of finding with every location as evidence; because\nthe scanner matches text, an entry names what a rule looks for, not one exact\nalgorithm and key size. Use `--fail-on high` to fail a CI build. Put\n`pqkit-ignore` on a line, as a word of its own, to silence it; the report lists\nevery silenced finding, so a reviewer can see when one is added.\n\n```\npermissions:\n  contents: read\n  security-events: write   # to show results under Security > Code scanning\n\nsteps:\n  - uses: actions/checkout@v4\n  - uses: loperdev/pqkit@v0.1.0\n    with:\n      fail-on: high        # optional: fail the job on high findings\n```\n\nInputs: `path` (default `.`), `fail-on` (default: never fail), `sarif-file`\n(default `pqkit.sarif`) and `upload` (default `true`; set `false` to keep the\nreport as a file only). Code scanning on private repositories needs GitHub\nAdvanced Security.\n\nThe scanner is a text search of your own source and config. Each result is a place to look, not proof of a weakness, and a clean result is not proof of safety: code that builds an algorithm name at run time will not be found. It does not look inside installed packages (only at their names in manifests and lockfiles), and it cannot see the HTTPS your hosting provider handles.\n\nIt is built to be run on code you do not trust. It never follows symbolic links\ninside the folder, and it strips terminal control characters from everything it\nprints. It reads every file that is not skipped by name or type, whatever its\nextension or encoding, up to 20 MB each, and lists at most 1,000 findings per file. It reports what it did not read: folders\nskipped by name (such as `build` and `vendor`), files skipped by type, symbolic\nlinks, and anything it could not open. A file over 20 MB or a folder it could not\nopen counts as a high finding, so it cannot slip through a CI gate. Symbolic links\nare listed but not followed or counted. A pqkit secret key found in a file is\nreported as a finding of its own.\n\nThe lines it quotes come from your code and can contain secrets. It hides private keys, long random-looking tokens and passwords inside URLs, but it cannot recognise every secret, so treat scan output like the source itself.\n\nIt is an inventory tool, not a defence against someone deliberately hiding code\nfrom it. Anyone who can write to the repository can place code in a skipped\nfolder or assemble an algorithm name at run time. Use `--fail-on` to catch\nhonest mistakes, not as a security boundary.\n\n``` js\nimport { scan } from 'pqtoolkit/scan';\n\nconst { findings, summary } = scan('./src');\n```\n\nEvery sealed blob and signature starts with a header naming the format version and\nalgorithm suite, so algorithms can be replaced later without breaking old data.\n[SPEC.md](https://github.com/loperdev/pqkit/blob/main/SPEC.md) describes the bytes exactly.\n\nThe format is checked three ways: against the published test values for both key\nexchanges, against frozen test vectors, and against a second\nimplementation written on OpenSSL that must agree with pqkit in both directions.\n`test/reject.json` lists inputs every implementation must refuse.\n\n`keyKind(text)` reads only the label at the front of a key. It tells you which\nkind of key a string claims to be, not that the key is valid.\n\n`npm test` runs, from the source repository:\n\n- Project Wycheproof: 3,888 cases built from known attacks, run against each algorithm pqkit is built from.\n- NIST's ACVP validation vectors for ML-KEM and ML-DSA: 460 cases.\n- The test values published in the two key-exchange drafts.\n- A second implementation of the format on OpenSSL, compared in both directions, including signed and sealed data.\n- Property tests (fast-check): thousands of generated inputs per run checking that nothing changed, truncated, extended or of the wrong type is ever accepted.\n- Regression tests for every problem found while attacking the library, the command line and the scanner.\n- A simulated quantum attacker: every classical private key is handed over, as Shor's algorithm would recover it, and decryption and forgery must still fail (and the same with only the lattice keys handed over).\n- Every-byte tamper tests: each byte of an ML-KEM ciphertext, a sealed message and a signature is changed in turn and must be refused. Decapsulation code that compared only part of the ciphertext caused key-recovery bugs in another library in 2026.\n- A two-key attack on the key commitment: one blob must never open under two keys, whatever body the owner of both builds.\n- A statistical check on pqkit's own signatures for the two ML-DSA signing mistakes shown to leak the key in Bernstein's \"Exploiting ML-DSA bugs\" (2026): repeated values inside one signature's secret mask, and the same mask used for two signatures.\n- A corpus of 605 one-line usages in twelve languages that the scanner must keep\nfinding, and 139 harmless lines it must keep leaving alone\n(`test/scan-corpus.json` , which also records what it still gets wrong).\n\n`npm run test:browser` runs the published vectors, the must-refuse vectors and a\nround trip in Chrome, loading the built modules as they are.\n\n`npm run test:coverage` reports coverage and `npm run check:package` checks the\npublished layout and types. None of this replaces an independent audit.\n\n- It has not had an independent security audit, and neither has `@noble/post-quantum` , which supplies the post-quantum half (its authors self-audited an earlier release). The classical half is what protects you if a flaw turns up there, which is the reason pqkit is hybrid-only.\n- Both hybrid key exchanges come from Internet-Drafts that are not yet finished standards.\n- pqkit zeroes the buffers it owns; the libraries beneath it keep copies of the shared secret and the expanded signing key that it cannot reach.\n- Timing is not constant. `node bench/timing.mjs` measures it: on the machine it was written on, opening with two different secret keys differed by a few microseconds, which is the big-number arithmetic underneath. Inputs that are invalid for reasons anyone can check, such as a point that is not on the curve, are refused early.\n- JavaScript cannot guarantee constant-time execution or wipe secret keys from memory. Do not use it where an attacker can measure timings precisely or read process memory.\n- It does not make HTTPS quantum-safe. Your hosting provider and TLS library do that.\n- It handles one message in memory at a time; there is no streaming for very large files.\n- Error messages are safe to log, but do not send them to untrusted clients: they can reveal which strength of key a server uses.\n- Its format is its own. It does not read or write HPKE, age, COSE or other tools' files, and at version 0.1 the programming interface may still change. The byte format of version 1 will not.\n- Standard and high describe the post-quantum half. The classical half is X25519 and Ed25519 (about 128-bit) or P-384 and Ed448.\n- CI runs the full suite on Linux and macOS (Node 22.12, 24 and 26), and the library tests and the GitHub Action on Windows; Chrome is covered by `npm run test:browser` . The command line's file handling is not tested on Windows, where file permissions do not work the same way. Safari, Firefox, React Native, Deno and Bun are untested. To check another browser, run`node scripts/browser-test.mjs --serve` and open the address it prints.\n- Do not reuse a pqkit signing key's seeds in another protocol.\n- It does not do passwords or key storage. Keep secret keys in your platform's secret manager.\n- There is no forward secrecy: a secret key that leaks opens everything ever sealed to it. Sealed data also shows how long the original was.\n- A public key does not prove whose it is, and nothing stops an old message or signature being sent again. Share keys over a channel you trust, and put a date or counter in the message if replay matters.\n- If code you do not control runs in the same process and replaces built-in functions, it can defeat pqkit, as it can any library.", "url": "https://wpnews.pro/news/show-hn-pqkit-scan-a-codebase-for-crypto-a-quantum-computer-will-break", "canonical_source": "https://github.com/loperdev/pqkit", "published_at": "2026-12-05 23:29:53+00:00", "updated_at": "2026-12-05 23:45:59.456296+00:00", "lang": "en", "topics": ["artificial-intelligence", "developer-tools"], "entities": ["pqkit", "pqtoolkit", "noble", "loperdev", "ML-KEM-768", "X25519", "ML-DSA-65", "Node 22.12"], "also_reported_by": [], "takeaway": "pqkit pairs a classical and a post-quantum algorithm in every operation — X-Wing (ML-KEM-768 + X25519) or ML-KEM-1024 + P-384 for encryption and Ed25519 + ML-DSA-65 or Ed448 + ML-DSA-87 for signatures — so a break of one family alone does not expose data, and signing blocks the thread for tens to a ", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-pqkit-scan-a-codebase-for-crypto-a-quantum-computer-will-break", "markdown": "https://wpnews.pro/news/show-hn-pqkit-scan-a-codebase-for-crypto-a-quantum-computer-will-break.md", "text": "https://wpnews.pro/news/show-hn-pqkit-scan-a-codebase-for-crypto-a-quantum-computer-will-break.txt", "jsonld": "https://wpnews.pro/news/show-hn-pqkit-scan-a-codebase-for-crypto-a-quantum-computer-will-break.jsonld"}}