# Show HN: Pqkit – scan a codebase for crypto a quantum computer will break

> Source: <https://github.com/loperdev/pqkit>
> Published: 2026-12-05 23:29:53+00:00

**Key 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

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.

pqkit invents no cryptography. It wraps the [noble](https://paulmillr.com/noble/)
implementations of published standards and always runs a classical and a
post-quantum algorithm together, so a break of one family alone does not expose
your data. [SPEC.md](https://github.com/loperdev/pqkit/blob/main/SPEC.md) states exactly what each half must still provide.

|  | Standard strength | High strength | 
|---|---|---|
| Encryption | X-Wing (ML-KEM-768 + X25519) | ML-KEM-1024 + P-384 | 
| Signatures | Ed25519 + ML-DSA-65 | Ed448 + ML-DSA-87 | 

Both halves of a signature must verify. Data is encrypted with ChaCha20-Poly1305.

```
npm install pqtoolkit
```

The npm package is called `pqtoolkit` (npm would not accept `pqkit`: too close to
another package's name). The command it installs is `pqkit`, and `npx pqtoolkit`
runs the same command without installing.

Works in Node 22.12 or later, browsers and React Native. The environment must
provide `crypto.getRandomValues`, `TextEncoder`, `TextDecoder`, `BigInt`,
`Object.hasOwn` and `DataView.prototype.setBigUint64` (Safari 15.4 or later). Load
any polyfills before importing pqkit. React Native gets `getRandomValues` from
`react-native-get-random-values` or `expo-crypto`, and may need a `TextDecoder`
polyfill that supports the `fatal` option. pqkit refuses to run if the random
number generator is missing, returns zeros or returns the same bytes twice. That
check catches a broken generator, not a predictable one.

pqkit is an ES module. Use `import`; `require('pqkit')` works on Node 22.12 or
later.

Every failure throws a `PqkitError`. Check `error.name === 'PqkitError'` rather
than `instanceof`, which fails across workers, iframes and duplicate installs.

Signing 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.

``` js
import { generateEncryptionKeys, seal, open, bytesToString } from 'pqtoolkit';

const { publicKey, secretKey } = generateEncryptionKeys();

const sealed = seal('card ending 4242', publicKey);
const text = bytesToString(open(sealed, secretKey));
```

**`open` succeeding says nothing about who sealed the data.** Anyone who has the
public key can seal. Never treat sealed data as a session, token or licence: sign
it (see below). `open` throws a `PqkitError` if the key, the context or the data
is wrong.

Generate 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.

`seal` takes text or bytes and returns bytes. Text is encoded as UTF-8; text that
is not valid Unicode is refused, so that two different strings can never produce
the same bytes. To store the result as text:

``` js
import { toBase64Url, fromBase64Url } from 'pqtoolkit';

const column = toBase64Url(sealed);
const again = open(fromBase64Url(column), secretKey);
```

Only the public key is needed to encrypt, so a server that writes data never has to hold the key that reads it.

``` js
import { generateSigningKeys, sign, verify } from 'pqtoolkit';

const { publicKey, secretKey } = generateSigningKeys();

const signature = sign('licence:pro:2027', secretKey);
verify(signature, 'licence:pro:2027', publicKey); // true
verify(signature, 'licence:pro:2099', publicKey); // false
```

**`verify` returns `false` for a signature that does not match. It does not throw**
(it throws only for arguments of the wrong kind, such as a damaged key). Always use
the return value:

```
if (!verify(signature, data, publicKey)) throw new Error('bad signature');
```

Signatures 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.

``` js
import { sealSigned, openSigned } from 'pqtoolkit';

const blob = sealSigned('wire 10 to bob', bob.publicKey, alice.secretKey);
const message = openSigned(blob, bob.secretKey, alice.publicKey); // throws unless Alice signed it for Bob
```

`sealSigned` signs the message for one named recipient and seals the signature
inside. `openSigned` returns the message only if it was sealed to your key and
signed by the sender you name; everything else is one error. Both keys must be the
same strength. It adds 4,553 bytes (6,466 at high strength).

Use it instead of calling `sign` and `seal` yourself, because doing both by hand
has two classic traps. If you sign and then seal, the recipient can seal your
signed message again for someone else, who will believe you sent it to them. If
you seal and then sign, anyone can remove your signature and add their own.
`sealSigned` closes both: the signature names the recipient, and the sealed blob
is tied to the sender's key.

What 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.

Pass a `context` to tie a result to one purpose. It must match exactly to open or
verify, which stops a value made for one place being reused in another. Options
are checked strictly: a misspelt option name, or a `context` that turns out to be
`undefined`, is an error and never silently ignored.

``` js
const context = JSON.stringify(['user', userId]);
const sealed = seal(token, publicKey, { context });
open(sealed, secretKey, { context });
```

Build a context from separate parts with `JSON.stringify([...])`, not by joining
them with a separator: `"1:2" + ":" + "3"` and `"1" + ":" + "2:3"` are the same
text. Check that every part is defined first, because `` `user:${undefined}` `` is
a valid string. A context is a label, not a password: it is not secret. Signing
contexts are limited to 255 bytes.

Standard 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.

``` js
const keys = generateEncryptionKeys({ strength: 'high' });
const signing = generateSigningKeys({ strength: 'high' });
```

A key of one strength cannot open or verify data made with the other.

High strength is not a compliance claim. CNSA 2.0 also requires AES-256 and validated implementations, and pqkit provides neither.

|  | Standard | High | 
|---|---|---|
| Encryption public key | 1,640 characters | 2,239 characters | 
| Signing public key | 2,664 characters | 3,551 characters | 
| Encryption secret key | 61 characters | 61 characters | 
| Signing secret key | 104 characters | 137 characters | 
| Sealed data | your data + 1,174 bytes | your data + 1,719 bytes | 
| Signature | 3,379 bytes | 4,747 bytes | 
| Signed and sealed data | your data + 4,553 bytes | your data + 6,466 bytes | 

Post-quantum keys and signatures are much larger than the ones they replace. Allow for that in database columns, headers and URLs.

`npm run bench` measures every operation in both strengths, the scanner, and the
classical algorithms in native code for scale. It prints the median, the 95th
percentile and the slowest run, and warns when the machine is busy. Add `--json`
after `node bench/run.mjs` for machine-readable output.

pqkit 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.

```
npx pqtoolkit keygen encryption -o alice     # alice.pub, alice.key
npx pqtoolkit encrypt -r alice.pub report.pdf
npx pqtoolkit decrypt -k alice.key report.pdf.pqk -o report.copy.pdf

npx pqtoolkit keygen signing -o release
npx pqtoolkit sign -k release.key app.zip
npx pqtoolkit verify -p release.pub app.zip

# sign and encrypt in one file; the reader must name the sender
npx pqtoolkit encrypt -r alice.pub --sign-key release.key report.pdf
npx pqtoolkit decrypt -k alice.key --from release.pub report.pdf.pqk -o report.copy.pdf
```

Add `--high` to `keygen` for high-strength keys.

Secret keys are read from a file or from `PQKIT_SECRET_KEY`, never from the
command line. Secret key files and decrypted files are created readable only by
you; a folder with an inherited access-control list, or a FAT or exFAT disk, can
override that. A run that is killed outright can leave a `.tmp` file beside the
output. Exit codes: 0 for success, 1 for an invalid signature or for scan findings at
or above `--fail-on`, 2 for any error.

Each option may be given once, and only with the commands it belongs to. In a script, check a download like this:

```
set -eu
if npx pqtoolkit verify -p ./release.pub -- "$FILE"; then
  install "$FILE"
fi
```

Use the exit code, never the printed text. Quote the file name and put `--` before
it. Keep the public key with your script; a key downloaded from the same place as
the file proves nothing. A valid signature does not say which version a file is,
so an old signed release still verifies: sign with `--context "myapp/2.0"` and
verify with the same context if that matters.

`encrypt` does not remove the original file. `keygen` without `-o` shows the keys
only on a terminal.

```
npx pqtoolkit scan .
```

Lists 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:

- **High** : encryption and key exchange. Traffic recorded today can be decrypted later.
- **Medium** : signatures, keys and certificates. At risk once a quantum computer exists.
- **Low** : 128-bit symmetric keys.

It 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.

Output formats: `--json` for tooling, `--sarif` (SARIF 2.1.0) for GitHub code
scanning and similar dashboards, and `--cbom` for a CycloneDX 1.6 cryptography
bill of materials, the inventory format many compliance programmes ask for (its
output validates against the official 1.6 schema). The
CBOM has one entry per kind of finding with every location as evidence; because
the scanner matches text, an entry names what a rule looks for, not one exact
algorithm and key size. Use `--fail-on high` to fail a CI build. Put
`pqkit-ignore` on a line, as a word of its own, to silence it; the report lists
every silenced finding, so a reviewer can see when one is added.

```
permissions:
  contents: read
  security-events: write   # to show results under Security > Code scanning

steps:
  - uses: actions/checkout@v4
  - uses: loperdev/pqkit@v0.1.0
    with:
      fail-on: high        # optional: fail the job on high findings
```

Inputs: `path` (default `.`), `fail-on` (default: never fail), `sarif-file`
(default `pqkit.sarif`) and `upload` (default `true`; set `false` to keep the
report as a file only). Code scanning on private repositories needs GitHub
Advanced Security.

The 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.

It is built to be run on code you do not trust. It never follows symbolic links
inside the folder, and it strips terminal control characters from everything it
prints. It reads every file that is not skipped by name or type, whatever its
extension or encoding, up to 20 MB each, and lists at most 1,000 findings per file. It reports what it did not read: folders
skipped by name (such as `build` and `vendor`), files skipped by type, symbolic
links, and anything it could not open. A file over 20 MB or a folder it could not
open counts as a high finding, so it cannot slip through a CI gate. Symbolic links
are listed but not followed or counted. A pqkit secret key found in a file is
reported as a finding of its own.

The 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.

It is an inventory tool, not a defence against someone deliberately hiding code
from it. Anyone who can write to the repository can place code in a skipped
folder or assemble an algorithm name at run time. Use `--fail-on` to catch
honest mistakes, not as a security boundary.

``` js
import { scan } from 'pqtoolkit/scan';

const { findings, summary } = scan('./src');
```

Every sealed blob and signature starts with a header naming the format version and
algorithm suite, so algorithms can be replaced later without breaking old data.
[SPEC.md](https://github.com/loperdev/pqkit/blob/main/SPEC.md) describes the bytes exactly.

The format is checked three ways: against the published test values for both key
exchanges, against frozen test vectors, and against a second
implementation written on OpenSSL that must agree with pqkit in both directions.
`test/reject.json` lists inputs every implementation must refuse.

`keyKind(text)` reads only the label at the front of a key. It tells you which
kind of key a string claims to be, not that the key is valid.

`npm test` runs, from the source repository:

- Project Wycheproof: 3,888 cases built from known attacks, run against each algorithm pqkit is built from.
- NIST's ACVP validation vectors for ML-KEM and ML-DSA: 460 cases.
- The test values published in the two key-exchange drafts.
- A second implementation of the format on OpenSSL, compared in both directions, including signed and sealed data.
- Property tests (fast-check): thousands of generated inputs per run checking that nothing changed, truncated, extended or of the wrong type is ever accepted.
- Regression tests for every problem found while attacking the library, the command line and the scanner.
- 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).
- 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.
- A two-key attack on the key commitment: one blob must never open under two keys, whatever body the owner of both builds.
- 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.
- A corpus of 605 one-line usages in twelve languages that the scanner must keep
finding, and 139 harmless lines it must keep leaving alone
(`test/scan-corpus.json` , which also records what it still gets wrong).

`npm run test:browser` runs the published vectors, the must-refuse vectors and a
round trip in Chrome, loading the built modules as they are.

`npm run test:coverage` reports coverage and `npm run check:package` checks the
published layout and types. None of this replaces an independent audit.

- 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.
- Both hybrid key exchanges come from Internet-Drafts that are not yet finished standards.
- 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.
- 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.
- 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.
- It does not make HTTPS quantum-safe. Your hosting provider and TLS library do that.
- It handles one message in memory at a time; there is no streaming for very large files.
- Error messages are safe to log, but do not send them to untrusted clients: they can reveal which strength of key a server uses.
- 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.
- Standard and high describe the post-quantum half. The classical half is X25519 and Ed25519 (about 128-bit) or P-384 and Ed448.
- 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.
- Do not reuse a pqkit signing key's seeds in another protocol.
- It does not do passwords or key storage. Keep secret keys in your platform's secret manager.
- 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.
- 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.
- 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.
