pqc-scan 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE ADDED
@@ -0,0 +1,23 @@
1
+ pqc-scan
2
+ Copyright 2026 Giddywiddit
3
+ Licensed under the Apache License, Version 2.0 (see LICENSE).
4
+
5
+ This product includes the following third-party files, each under its own licence:
6
+
7
+ - tree-sitter grammars for C, C++, Rust and Go (the .wasm files in grammars/, copied from the npm packages
8
+ tree-sitter-c 0.24.1, tree-sitter-cpp 0.23.4, tree-sitter-rust 0.24.0 and tree-sitter-go 0.25.0).
9
+ MIT License; copyright Max Brunsfeld (C, C++, Go) and Maxim Sokolov (Rust). The full licence texts are in
10
+ grammars/LICENSE-tree-sitter-*.
11
+
12
+ - schema/cyclonedx/cryptography-defs.json, the CycloneDX cryptography registry from the CycloneDX specification
13
+ 1.7.2 (https://github.com/CycloneDX/specification), unchanged. Apache License, Version 2.0.
14
+
15
+ The source repository also contains, for tests only and not in the npm package:
16
+
17
+ - test/schemas/bom-1.7.schema.json, spdx.schema.json, jsf-0.82.schema.json and cryptography-defs.schema.json, from
18
+ the CycloneDX specification 1.7.2, unchanged. Apache License, Version 2.0.
19
+ - test/schemas/sarif-schema-2.1.0.json, the SARIF 2.1.0 JSON Schema (errata 01), © OASIS Open, unchanged, from
20
+ https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json.
21
+
22
+ pqc-scan installs, and does not include, these packages: TypeScript (Apache License 2.0), web-tree-sitter (MIT)
23
+ and yaml (ISC).
package/README.md CHANGED
@@ -1,118 +1,63 @@
1
- # pqc-scan
1
+ # pqc-scan
2
2
 
3
3
  ```
4
4
  /\_/\
5
5
  ( 0.1 ) [ pqc-scan • Post-Quantum Cryptography Scanner ]
6
- > ^ < Finds the cryptography in your JavaScript, TypeScript, C, C++, Rust and Go
6
+ > ^ < Scans your JavaScript, TypeScript, C, C++, Rust, Go and Python
7
7
  ---------------------------------------------------------
8
- Looks for what quantum computers will break (NIST FIPS 203/204/205)
8
+ Flags the cryptography a quantum computer could break
9
9
  ```
10
10
 
11
- **pqc-scan reads your source code, lists the places it uses cryptography, and tells you which of those uses a future quantum computer could break.**
11
+ pqc-scan reads your source code, lists where it uses cryptography, and flags each use a quantum computer could break.
12
12
 
13
- *Cryptography* is the mathematics that keeps data secret (encryption), proves who sent something (digital signatures) and fingerprints data (hashing). Each use relies on a specific method, called an *algorithm*, such as RSA or SHA-256. This tool finds the calls to cryptography libraries and reports which algorithm each one uses, or says that it cannot tell.
13
+ A cryptanalytically relevant quantum computer (CRQC), one able to attack real cryptographic systems, would break RSA and elliptic-curve cryptography, which protect most signatures and encrypted connections today. None exists yet; a 2025 estimate is that one with fewer than a million noisy qubits could break 2048-bit RSA in under a week ([Gidney](https://arxiv.org/abs/2505.15917)). Two reasons to act before then, both set out in [NIST IR 8547](https://csrc.nist.gov/pubs/ir/8547/final):
14
14
 
15
- ## In short
15
+ - **Harvest now, decrypt later:** encrypted data recorded today can be decrypted once a CRQC exists.
16
+ - **Mosca's theorem:** if data must stay secret for X years, moving to new cryptography takes Y years, and a CRQC is Z years away, then when X + Y > Z that data will be exposed. The move has to start before that point.
16
17
 
17
- - **The problem:** RSA and elliptic-curve cryptography are the most widely used methods for digital signatures and for setting up encrypted connections. A large enough quantum computer could break both. None exists yet.
18
- - **Why act now:** an attacker can record encrypted data today and decrypt it once such a computer exists. NIST calls this "harvest now, decrypt later".
19
- - **What this tool does:** it finds the uses of cryptography it can recognise in your code (see [Languages](#languages)) and labels each one ❌ breakable by a quantum computer, ✅ believed safe, 🔍 needs a human decision, or ⚠️ could not be determined.
20
- - **What it does not do:** it never says your code is "quantum safe". It reports only what it can read in the code, and says so when it cannot tell.
21
- - **Safe to run:** it does not change your code, run it, or send anything over the internet. The only file it writes is the cache, and only if you ask for one with `--cache`.
22
-
23
- ## Why quantum computers matter
24
-
25
- Against ordinary computers, a 2048-bit RSA key is rated by NIST at 112 bits of security: the best known attack needs on the order of 2^112 operations, which is out of reach. In 1994 Peter Shor published a method (Shor's algorithm) that would let a large enough quantum computer break RSA and elliptic-curve cryptography.
26
-
27
- - Today's quantum computers are small. Google's [Willow chip](https://blog.google/technology/research/google-willow-quantum-chip/) (December 2024) has 105 qubits (quantum bits), and they still make errors.
28
- - A [2025 paper](https://arxiv.org/abs/2505.15917) by Craig Gidney of Google estimated that a 2048-bit RSA key could be broken in under a week by fewer than one million qubits, assuming each operation fails about 1 time in 1,000.
29
- - The US standards body NIST will deprecate RSA, elliptic-curve and Diffie-Hellman methods after 2030 and disallow them after 2035, at every key size ([NIST IR 8547](https://csrc.nist.gov/pubs/ir/8547/final), October 2026).
30
-
31
- NIST has published replacements believed to resist quantum computers: ML-KEM (FIPS 203, for agreeing on secret keys), and ML-DSA (FIPS 204) and SLH-DSA (FIPS 205) for signatures. NIST notes that past moves to new algorithms took 10 to 20 years, and recommends beginning with an inventory of the cryptography in use. pqc-scan builds the part of that inventory found in your source code.
18
+ NIST's transition plan begins phasing out quantum-vulnerable public-key algorithms after 2030, with broader disallowance milestones by 2035. The exact date depends on the algorithm and security strength. Replacing them starts with knowing where they are.
32
19
 
33
20
  ## Try it
34
21
 
35
- You need [Node.js](https://nodejs.org) 22 or newer. `npm install` downloads about 150 MB: the C, C++, Rust and Go parsers (72 MB), TypeScript (23 MB, used to read JavaScript and TypeScript), and the tools that run the tests.
36
-
37
22
  ```sh
38
- git clone https://github.com/Giddywiddit/pqc-scan.git
39
- cd pqc-scan
40
- npm install
41
- npm run scan -- path/to/your/project
23
+ npx pqc-scan .
42
24
  ```
43
25
 
44
- Example result:
26
+ Needs Node.js 22 or newer. It reads your code without running, changing or uploading it, and needs no build.
45
27
 
46
28
  ```
47
- Cryptography found:
48
- ------------------------------------------------------------------------
49
- ✅ index.ts:3 SHA-256 observed-resistant
50
- ❌ keys.js:3 RSA vulnerable
51
- ℹ️ A quantum computer could work out the private key from the public key (using Shor's algorithm). Plan to replace this key type.
52
- ------------------------------------------------------------------------
53
- 2 finding(s): 1 vulnerable, 0 needs-review, 0 unresolved, 1 observed-resistant.
54
-
55
- 🚨 Quantum risk found: the ❌ items use cryptography a quantum computer could break. Plan their migration.
29
+ RESISTANT index.ts:3 SHA-256
30
+ VULNERABLE keys.js:3 RSA
31
+ A quantum computer could work out the private key from the public key (using Shor's algorithm). Plan to replace this key type.
56
32
  ```
57
33
 
58
- | Option | What it does |
59
- |---|---|
60
- | `--json` | Prints the results as JSON for other programs. The format is described by [`schema/report-v1.schema.json`](schema/report-v1.schema.json); its `schemaVersion` changes only when a change could break a program that reads it. |
61
- | `--quiet` | Hides the cat banner. |
62
- | `--sarif <file>` | Also writes the ❌, 🔍 and ⚠️ findings to `<file>` in SARIF 2.1.0, the format GitHub code scanning reads, so they appear as alerts on pull requests. ✅ findings are left out, since they need no action. |
63
- | `--cbom <file>` | Also writes the full inventory to `<file>` as a cryptography bill of materials (CBOM) in CycloneDX 1.7, the format standardised as ECMA-424: one entry per algorithm, with every file and line where it is used, its CycloneDX family and type, and its NIST quantum security category where a NIST standard states one (0 for methods a quantum computer could break). |
64
- | `--write-baseline <file>` | Also writes every finding to `<file>`, to accept the current findings for now. |
65
- | `--baseline <file>` | Leaves out the findings listed in `<file>`, so the exit status is 1 only for new ones. A finding is recognised by its rule, file and the text of its line, so it still matches after code above it moves. |
66
- | `--cache <file>` | Saves each file's results in `<file>` and reuses them on the next run while the file is unchanged. The saved results are discarded whenever the scanner or its rules change. Anyone who can change the cache file can change the results, so keep it outside the folder you scan (the tool refuses a cache inside it), or set the environment variable `PQC_SCAN_CACHE_KEY` to a secret: the cache is then signed, and a cache that was changed or signed with another key is not used. |
67
- | `--max-file-size <MB>` | Files larger than this (default 20 MB) are not read, and are reported as ⚠️ not scanned. |
68
-
69
- Exit status: 0 when every finding is ✅ or nothing was found, 1 when any finding is ❌, 🔍 or ⚠️, and 2 when the scan could not run (for example, the path does not exist).
70
-
71
- ## What the labels mean
72
-
73
- | Label | Meaning | What you should do |
74
- |---|---|---|
75
- | ❌ `vulnerable` | RSA, DSA, elliptic-curve methods (such as ECDSA, Ed25519, ECDH and X25519) or Diffie-Hellman. Shor's algorithm breaks these. | Plan to replace it with a NIST post-quantum method. |
76
- | ✅ `observed-resistant` | A method believed to withstand quantum computers, such as SHA-256, 256-bit AES or ML-KEM. | Nothing. This describes that one line, not your whole program. |
77
- | 🔍 `needs-review` | Known exactly, but acceptable only by judgement. Examples: 128-bit AES, which NIST still accepts but some organisations replace with 256-bit AES for a larger safety margin against quantum attacks; SHA-224, whose 112-bit collision strength is a security level NIST plans to disallow in 2030; and MD5 and SHA-1, which are broken even by ordinary computers. | A person decides. |
78
- | ⚠️ `unresolved` | The code picks the method in a way the tool cannot read, such as a setting read at run time or a value passed into a function. | Look at that line by hand. |
79
-
80
- ## Languages
81
-
82
- | Language | Libraries | Details |
83
- |---|---|---|
84
- | JavaScript / TypeScript | Node.js crypto, WebCrypto, jsonwebtoken, jws | [rules/javascript](rules/javascript/README.md) |
85
- | C | OpenSSL, libsodium, Mbed TLS, PSA Crypto, wolfSSL, GnuTLS, Botan | [rules/c](rules/c/README.md) |
86
- | C++ | Crypto++, Botan, and every C library above | [rules/cpp](rules/cpp/README.md) |
87
- | Rust | RustCrypto, ring, aws-lc-rs, the openssl crate, rustls, jsonwebtoken | [rules/rust](rules/rust/README.md) |
88
- | Go | The standard library (including TLS), golang.org/x/crypto (including SSH), CIRCL, golang-jwt, and every C library above through cgo | [rules/go](rules/go/README.md) |
89
-
90
- Python and Java are planned. Each language page lists what is matched, its limits, and the real projects it was tested on.
34
+ Each finding is one of:
91
35
 
92
- ## What it cannot see
93
-
94
- The tool reads code without running it, so it has blind spots. Read these before trusting a result.
95
-
96
- - **A clean result does not mean "no cryptography".** Cryptography reached in a way the tool cannot follow is missed. Each language page lists those ways.
97
- - **Only the languages and libraries listed above are covered.** Cryptography inside a package you installed is scanned only if you scan that package's code.
98
- - **Cryptography a project writes itself**, under its own function names, is not recognised.
99
- - **It does not inspect** server settings, certificate files or compiled programs. In C, C++, Rust (the openssl crate and rustls) and Go (crypto/tls and x/crypto/ssh), it flags where TLS (the encryption behind HTTPS) or SSH is set up, so you can check the settings yourself.
100
-
101
- The limits listed on each language page are pinned by automated tests, so they cannot change without anyone noticing.
102
-
103
- ## How we know it is reliable
104
-
105
- - **Over 3,000 automated tests** run on every change, including a generated test for every function and algorithm the tool recognises.
106
- - **Names are checked against the real thing:** the JavaScript names against Node.js itself and the JWT standards (RFC 7518 and RFC 8037) in automated tests, the C and C++ names against each library's header files, the Rust names against each crate's source code, and the Go names against Go's list of every exported name and each library's source code, when the rules were written.
107
- - **Real projects:** it was run on well-known open-source projects in each language, and its results were compared with a separate text search of the same code. The language pages list the projects and the numbers.
108
- - **Every fixed bug becomes a permanent test.**
36
+ | Label | Meaning |
37
+ |---|---|
38
+ | Vulnerable | RSA, DSA, elliptic curves or Diffie-Hellman. Plan to replace it. |
39
+ | Observed-resistant | The algorithm on this line is believed to withstand quantum computers, such as SHA-256, AES-256 or ML-KEM. This does not prove that the whole program is safe. |
40
+ | Review | Known exactly, but acceptable only by judgement, such as AES-128, SHA-1 or MD5. |
41
+ | Unresolved | The algorithm is chosen in a way the code does not show. Check that line by hand. |
109
42
 
110
- Which algorithms count as risky is a judgement call. The decisions are written openly in the [`rules/`](rules/) folder so you can read them and disagree with them.
43
+ ## Output and CI
111
44
 
112
- ## Contributing
45
+ | Option | Writes |
46
+ |---|---|
47
+ | `--json` | The findings as JSON ([report schema](schema/report-v1.schema.json)). |
48
+ | `--sarif <file>` | SARIF for GitHub code scanning. |
49
+ | `--cbom <file>` | A CycloneDX 1.7 cryptography bill of materials. |
50
+ | `--write-baseline <file>`, `--baseline <file>` | Accepts the current findings, so CI fails only on new ones. |
113
51
 
114
- See [CONTRIBUTING.md](CONTRIBUTING.md) for how the code is organised, how to add a library or a language, and how the tests work.
52
+ The exit status is 1 when anything is vulnerable, needs review or is unresolved. There is a [GitHub Action](docs/github-action.md).
115
53
 
116
- ## Licence
54
+ ## Languages
117
55
 
118
- Released under the [Apache License 2.0](LICENSE).
56
+ | Language | Libraries |
57
+ |---|---|
58
+ | [JavaScript / TypeScript](rules/javascript/README.md) | Node.js crypto, WebCrypto, jsonwebtoken, jws |
59
+ | [C](rules/c/README.md) | OpenSSL, libsodium, Mbed TLS, PSA Crypto, wolfSSL, GnuTLS, Botan |
60
+ | [C++](rules/cpp/README.md) | Crypto++, Botan, and the C libraries |
61
+ | [Rust](rules/rust/README.md) | RustCrypto, ring, aws-lc-rs, openssl, rustls, jsonwebtoken |
62
+ | [Go](rules/go/README.md) | Standard library, golang.org/x/crypto, CIRCL, golang-jwt |
63
+ | [Python](rules/python/README.md) | cryptography, PyJWT, PyCryptodome, ecdsa, hashlib, Paramiko, PyNaCl |
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { existsSync, statSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
3
3
  import { parseArgs } from 'node:util';
4
4
  import { dirname, isAbsolute, relative, resolve } from 'node:path';
5
5
  import { loadRules } from "./core/rules.js";
@@ -32,6 +32,28 @@ for (const [option, example] of [['cache', '~/.cache/pqc-scan.json'], ['sarif',
32
32
  process.exit(2);
33
33
  }
34
34
  }
35
+ // An output option may only replace a file that an earlier pqc-scan run wrote (a baseline, SARIF, CBOM or cache), so a
36
+ // mistyped path such as --sarif src/index.ts cannot overwrite someone's source code.
37
+ function isEarlierOutput(file) {
38
+ try {
39
+ const parsed = JSON.parse(readFileSync(file, 'utf8'));
40
+ return parsed.baselineVersion === 1 || parsed.runs?.[0]?.tool?.driver?.name === 'pqc-scan' || parsed.metadata?.tools?.components?.[0]?.name === 'pqc-scan' || (typeof parsed.body === 'string' && parsed.body.includes('"files"'));
41
+ }
42
+ catch {
43
+ return false;
44
+ }
45
+ }
46
+ for (const option of ['cache', 'sarif', 'cbom', 'write-baseline']) {
47
+ const file = values[option];
48
+ if (typeof file === 'string' && !existsSync(dirname(resolve(file)))) {
49
+ console.error(`pqc-scan: --${option} ${file}: the folder ${dirname(resolve(file))} does not exist. Create it first.`);
50
+ process.exit(2);
51
+ }
52
+ if (typeof file === 'string' && existsSync(resolve(file)) && !isEarlierOutput(resolve(file))) {
53
+ console.error(`pqc-scan: --${option} ${file} would overwrite a file that pqc-scan did not write. Choose a new file name, or delete that file first.`);
54
+ process.exit(2);
55
+ }
56
+ }
35
57
  const maxFileSize = values['max-file-size'] === undefined ? undefined : Number(values['max-file-size']);
36
58
  if (maxFileSize !== undefined && !(maxFileSize > 0)) {
37
59
  console.error('pqc-scan: --max-file-size needs a size in MB greater than 0, for example --max-file-size 50');
@@ -1,12 +1,34 @@
1
1
  import { createHash, createHmac, timingSafeEqual } from 'node:crypto';
2
2
  import { existsSync, readFileSync, readdirSync, renameSync, writeFileSync } from 'node:fs';
3
3
  import { createRequire } from 'node:module';
4
- import { join } from 'node:path';
4
+ import { dirname, join } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  const projectRoot = fileURLToPath(new URL('../../', import.meta.url));
7
7
  /** The scanner's own code: `src` when working on it, `dist` in the published package. */
8
8
  const codeFolder = fileURLToPath(new URL('../', import.meta.url)).slice(projectRoot.length).replace(/[\\/]$/, '');
9
9
  const require = createRequire(import.meta.url);
10
+ /**
11
+ * The installed version of a package, found from the package's own entry point, since some packages (web-tree-sitter)
12
+ * do not let their package.json be loaded by name. Undefined when the package is not installed.
13
+ */
14
+ export function installedVersion(name) {
15
+ let folder;
16
+ try {
17
+ folder = dirname(require.resolve(name));
18
+ }
19
+ catch {
20
+ return undefined;
21
+ }
22
+ for (; folder !== dirname(folder); folder = dirname(folder)) {
23
+ const file = join(folder, 'package.json');
24
+ if (!existsSync(file))
25
+ continue;
26
+ const manifest = JSON.parse(readFileSync(file, 'utf8'));
27
+ if (manifest.name === name)
28
+ return manifest.version;
29
+ }
30
+ return undefined;
31
+ }
10
32
  /**
11
33
  * A fingerprint of everything that decides what a scan finds: the scanner's own code, its rules, the grammars and the
12
34
  * exact versions of the packages it reads code with. When any of them changes, every cached result is thrown away.
@@ -27,13 +49,9 @@ function toolVersion() {
27
49
  if (existsSync(join(projectRoot, 'grammars')))
28
50
  add('grammars');
29
51
  hash.update(readFileSync(join(projectRoot, 'package.json')));
52
+ // The grammar packages are not installed with the published package, which carries their files in grammars/.
30
53
  for (const name of ['typescript', 'web-tree-sitter', 'yaml', 'tree-sitter-c', 'tree-sitter-cpp', 'tree-sitter-rust', 'tree-sitter-go']) {
31
- try {
32
- hash.update(`${name}@${JSON.parse(readFileSync(require.resolve(`${name}/package.json`), 'utf8')).version}`);
33
- }
34
- catch {
35
- // The grammar packages are not installed with the published package, which carries their files in grammars/.
36
- }
54
+ hash.update(`${name}@${installedVersion(name) ?? 'not installed'}\n`);
37
55
  }
38
56
  return hash.digest('hex');
39
57
  }
@@ -9,7 +9,7 @@ import { languages } from "../languages/index.js";
9
9
  * code to repay starting them. Results are put back in the same order, so the output is identical to `scan`.
10
10
  */
11
11
  export async function scanInParallel(target, rules, options = {}) {
12
- const { root, files } = planScan(target, languages);
12
+ const { root, files, unreadable } = planScan(target, languages);
13
13
  const findings = new Array(files.length);
14
14
  const { cache } = options;
15
15
  const maxBytes = options.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;
@@ -35,7 +35,7 @@ export async function scanInParallel(target, rules, options = {}) {
35
35
  if (cache)
36
36
  for (const index of pending)
37
37
  cache.set(keys[index], findings[index]);
38
- return finishScan(root, files, findings, rules);
38
+ return finishScan(root, files, findings, rules, undefined, unreadable);
39
39
  }
40
40
  const pool = new Pool(threads, rules);
41
41
  try {
@@ -48,7 +48,7 @@ export async function scanInParallel(target, rules, options = {}) {
48
48
  const sites = new Map();
49
49
  await pool.run(wrapperCallerFiles(files, findings, rules), sizes, (index) => ({ kind: 'calls', index, path: files[index].path, name: files[index].name, language: files[index].adapter.id, maxBytes }), (reply) => { if ('sites' in reply)
50
50
  sites.set(files[reply.index].path, reply.sites); });
51
- return finishScan(root, files, findings, rules, sites);
51
+ return finishScan(root, files, findings, rules, sites, unreadable);
52
52
  }
53
53
  finally {
54
54
  await pool.close();
@@ -1,6 +1,7 @@
1
1
  import { readFileSync, readdirSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { parse } from 'yaml';
4
+ import { fileURLToPath } from 'node:url';
4
5
  function validateRules(value, file) {
5
6
  if (!value || typeof value !== 'object')
6
7
  throw new Error(`${file}: rule file must contain an object.`);
@@ -46,7 +47,7 @@ export function loadRules(rulesDir = new URL('../../rules/', import.meta.url)) {
46
47
  .filter((name) => name.endsWith('.yaml'))
47
48
  .sort()
48
49
  .map((name) => {
49
- const value = parse(readFileSync(join(new URL(`${folder.name}/`, root).pathname, name), 'utf8'));
50
+ const value = parse(readFileSync(join(fileURLToPath(new URL(`${folder.name}/`, root)), name), 'utf8'));
50
51
  validateRules(value, `${folder.name}/${name}`);
51
52
  return { ...value, language: folder.name };
52
53
  }));
package/dist/core/scan.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFileSync, statSync } from 'node:fs';
2
- import { basename, extname, relative } from 'node:path';
2
+ import { basename, extname, relative, sep } from 'node:path';
3
3
  import { ESCAPING_REFERENCE_RULE_ID, UNRESOLVED_ALGORITHM_NOTE, finding } from "./finding.js";
4
4
  import { sourceFiles } from "./walk.js";
5
5
  import { escape } from "./syntax.js";
@@ -13,9 +13,12 @@ export async function loadLanguages(adapters = languages) {
13
13
  export function planScan(target, adapters = languages) {
14
14
  const root = statSync(target).isDirectory() ? target : undefined;
15
15
  const byExtension = new Map(adapters.flatMap((adapter) => adapter.extensions.map((extension) => [extension, adapter])));
16
- const files = sourceFiles(target, new Set(byExtension.keys()))
17
- .map((path) => ({ path, name: root ? relative(root, path) : basename(path), adapter: byExtension.get(extname(path)) }));
18
- return { root, files };
16
+ const skipped = [];
17
+ // Reported file names use `/` on every system, so reports and baselines are the same on Windows.
18
+ const nameOf = (path) => (root ? relative(root, path) : basename(path)).split(sep).join('/');
19
+ const files = sourceFiles(target, new Set(byExtension.keys()), skipped)
20
+ .map((path) => ({ path, name: nameOf(path), adapter: byExtension.get(extname(path)) }));
21
+ return { root, files, unreadable: skipped.map((path) => unreadableFinding(nameOf(path) || '.')) };
19
22
  }
20
23
  /** One rules array per language for the whole scan, so adapters can build their lookup tables once and reuse them. */
21
24
  export function rulesByAdapter(rules, adapters = languages) {
@@ -31,6 +34,10 @@ export function tooLargeFinding(name, bytes, maxBytes) {
31
34
  const mb = (size) => `${Number((size / 1024 / 1024).toFixed(1))} MB`;
32
35
  return finding(name, 1, 'file-too-large', 'unknown', null, 'unresolved', `Not scanned: the file is ${mb(bytes)}, over the ${mb(maxBytes)} limit. Check it by hand, or scan it with a higher --max-file-size.`);
33
36
  }
37
+ /** The finding for a file or folder that could not be read: reported, not skipped, so it cannot hide anything. */
38
+ export function unreadableFinding(name) {
39
+ return finding(name, 1, 'path-unreadable', 'unknown', null, 'unresolved', 'Not scanned: pqc-scan could not read this file or folder (no permission). Check it by hand, or scan it with access.');
40
+ }
34
41
  /** The findings in one file. */
35
42
  export function scanFile(file, rulesFor, maxBytes = DEFAULT_MAX_FILE_BYTES) {
36
43
  const bytes = statSync(file.path).size;
@@ -39,13 +46,13 @@ export function scanFile(file, rulesFor, maxBytes = DEFAULT_MAX_FILE_BYTES) {
39
46
  return file.adapter.scanSource(readFileSync(file.path, 'utf8'), file.name, rulesFor.get(file.adapter));
40
47
  }
41
48
  /** Adds the cross-file findings to the per-file findings (in plan order) and returns them all. */
42
- export function finishScan(root, files, findings, rules, prefetched) {
49
+ export function finishScan(root, files, findings, rules, prefetched, unreadable = []) {
43
50
  const scanned = files.map((file, index) => ({ ...file, findings: findings[index], text: '' }));
44
51
  if (root)
45
52
  addWrapperFindings(scanned);
46
53
  addCallsToWrappers(scanned, rules, prefetched);
47
54
  // The wrapper marks are only for the step above; they are not part of a finding as reported.
48
- return scanned.flatMap((item) => item.findings.map(({ wrapper: _wrapper, ...finding }) => finding));
55
+ return [...scanned.flatMap((item) => item.findings.map(({ wrapper: _wrapper, ...finding }) => finding)), ...unreadable];
49
56
  }
50
57
  /**
51
58
  * Follows functions whose crypto algorithm is one of their parameters to where they are called (see wrappers.ts), in
@@ -133,9 +140,9 @@ function addCallsToWrappers(files, rules, prefetched) {
133
140
  }
134
141
  /** Scan a file or folder with every registered language, giving each adapter only the rules for its own language. */
135
142
  export function scan(target, rules, adapters = languages) {
136
- const { root, files } = planScan(target, adapters);
143
+ const { root, files, unreadable } = planScan(target, adapters);
137
144
  const rulesFor = rulesByAdapter(rules, adapters);
138
- return finishScan(root, files, files.map((file) => scanFile(file, rulesFor)), rules);
145
+ return finishScan(root, files, files.map((file) => scanFile(file, rulesFor)), rules, undefined, unreadable);
139
146
  }
140
147
  // A module whose algorithm comes from a parameter (or that lets a crypto reference escape) is a wrapper: its importers
141
148
  // may be choosing the algorithm, and that flow is not tracked across files.
@@ -4,13 +4,14 @@ import { fileURLToPath } from 'node:url';
4
4
  import { Language, Parser } from 'web-tree-sitter';
5
5
  // Each grammar comes from its official `tree-sitter-<language>` package, which ships a ready-built `.wasm` file. Only
6
6
  // that file is used: the packages' native Node bindings (and their install scripts) are not needed. Versions are pinned
7
- // exactly in package.json so a grammar update cannot silently change what the scanner finds. The published package
7
+ // exactly in package.json, as are TypeScript (which reads JavaScript and TypeScript) and yaml (which reads the rules),
8
+ // so an update to any of them cannot silently change what the scanner finds. The published package
8
9
  // carries the `.wasm` files themselves in `grammars/` (copied by scripts/copy-grammars.mjs), so users do not install the
9
10
  // grammar packages at all; when working on the scanner, they are read from node_modules.
10
11
  const require = createRequire(import.meta.url);
11
12
  const bundled = (grammar) => fileURLToPath(new URL(`../../grammars/tree-sitter-${grammar}.wasm`, import.meta.url));
12
13
  let initialised;
13
- /** Loads one tree-sitter grammar (`c`, `cpp`, `go`, ...) and returns a parser for it. */
14
+ /** Loads one tree-sitter grammar (`c`, `cpp`, `go`, `python`, ...) and returns a parser for it. */
14
15
  export async function createParser(grammar) {
15
16
  initialised ??= Parser.init();
16
17
  await initialised;
package/dist/core/walk.js CHANGED
@@ -1,13 +1,39 @@
1
- import { existsSync, readdirSync, statSync } from 'node:fs';
1
+ import { accessSync, constants, existsSync, readdirSync, statSync } from 'node:fs';
2
2
  import { extname, join } from 'node:path';
3
3
  const skipped = new Set(['.git', 'dist', 'node_modules']);
4
- /** Source files under `target` (a file or a folder) whose extension is in `extensions`. */
5
- export function sourceFiles(target, extensions) {
6
- if (!statSync(target).isDirectory())
7
- return extensions.has(extname(target)) ? [target] : [];
4
+ const readable = (path) => {
5
+ try {
6
+ accessSync(path, constants.R_OK);
7
+ return true;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ };
13
+ /**
14
+ * Source files under `target` (a file or a folder) whose extension is in `extensions`. A source file or folder that
15
+ * cannot be read is added to `unreadable` instead, so the scan can report it rather than stop.
16
+ */
17
+ export function sourceFiles(target, extensions, unreadable = []) {
18
+ if (!statSync(target).isDirectory()) {
19
+ if (!extensions.has(extname(target)))
20
+ return [];
21
+ if (readable(target))
22
+ return [target];
23
+ unreadable.push(target);
24
+ return [];
25
+ }
8
26
  const found = [];
9
27
  const walk = (directory) => {
10
- for (const entry of readdirSync(directory, { withFileTypes: true })) {
28
+ let entries;
29
+ try {
30
+ entries = readdirSync(directory, { withFileTypes: true });
31
+ }
32
+ catch {
33
+ unreadable.push(directory);
34
+ return;
35
+ }
36
+ for (const entry of entries) {
11
37
  if (skipped.has(entry.name))
12
38
  continue;
13
39
  // Cargo's build output (generated code and copies of packaged crates), and Go's copies of dependencies made by
@@ -20,7 +46,7 @@ export function sourceFiles(target, extensions) {
20
46
  if (entry.isDirectory())
21
47
  walk(path);
22
48
  else if (entry.isFile() && extensions.has(extname(entry.name)))
23
- found.push(path);
49
+ (readable(path) ? found : unreadable).push(path);
24
50
  }
25
51
  };
26
52
  walk(target);
@@ -3,5 +3,6 @@ import { cpp } from "./cpp/adapter.js";
3
3
  import { go } from "./go/adapter.js";
4
4
  import { javascript } from "./javascript/adapter.js";
5
5
  import { rust } from "./rust/adapter.js";
6
+ import { python } from "./python/adapter.js";
6
7
  /** Every language the scanner can read. Adding a language means adding one adapter here plus its rules/<id>/ folder. */
7
- export const languages = [javascript, c, cpp, rust, go];
8
+ export const languages = [javascript, c, cpp, rust, go, python];
@@ -0,0 +1,150 @@
1
+ import { ruleFindings } from "../../core/match.js";
2
+ import { LineReporter, indexRules } from "../../core/matcher.js";
3
+ import { createParser } from "../../core/tree-sitter.js";
4
+ let parser;
5
+ function dotted(node) {
6
+ return node?.text ?? '';
7
+ }
8
+ function imports(root) {
9
+ const result = new Map();
10
+ const walk = (node) => {
11
+ if (node.type === 'import_statement') {
12
+ for (const item of node.namedChildren) {
13
+ const path = item.type === 'aliased_import' ? item.childForFieldName('name')?.text ?? '' : dotted(item);
14
+ const alias = item.type === 'aliased_import' ? item.childForFieldName('alias')?.text : path.split('.')[0];
15
+ if (path && alias)
16
+ result.set(alias, { path });
17
+ }
18
+ }
19
+ else if (node.type === 'import_from_statement') {
20
+ const module = node.namedChildren.find((child) => child.type === 'dotted_name')?.text ?? '';
21
+ for (const item of node.namedChildren.filter((child) => child.type === 'dotted_name' || child.type === 'aliased_import').slice(1)) {
22
+ const name = item.type === 'aliased_import' ? item.childForFieldName('name')?.text ?? '' : item.text;
23
+ const alias = item.type === 'aliased_import' ? item.childForFieldName('alias')?.text : name;
24
+ if (name && alias)
25
+ result.set(alias, { path: `${module}.${name}` });
26
+ }
27
+ }
28
+ for (const child of node.namedChildren)
29
+ walk(child);
30
+ };
31
+ walk(root);
32
+ return result;
33
+ }
34
+ function callPath(node) {
35
+ const functionNode = node.childForFieldName('function');
36
+ if (!functionNode)
37
+ return null;
38
+ const parts = [];
39
+ let current = functionNode;
40
+ while (current) {
41
+ if (current.type === 'identifier')
42
+ parts.unshift(current.text);
43
+ else if (current.type === 'attribute') {
44
+ const attr = current.childForFieldName('attribute');
45
+ if (attr)
46
+ parts.unshift(attr.text);
47
+ current = current.childForFieldName('object');
48
+ continue;
49
+ }
50
+ else
51
+ return null;
52
+ break;
53
+ }
54
+ return parts.join('.');
55
+ }
56
+ function argumentsOf(node) {
57
+ return node.childForFieldName('arguments')?.namedChildren ?? [];
58
+ }
59
+ function argumentNames(node) {
60
+ if (!node)
61
+ return null;
62
+ if (node.type === 'string')
63
+ return [node.text.slice(1, -1)];
64
+ if (node.type === 'integer')
65
+ return [node.text];
66
+ if (node.type === 'keyword_argument')
67
+ return argumentNames(node.childForFieldName('value'));
68
+ return null;
69
+ }
70
+ function ruleFor(path, lookup) {
71
+ return lookup.functions.get(path) ?? lookup.names.get(path);
72
+ }
73
+ function shadowedNames(root) {
74
+ const ranges = [];
75
+ const walk = (node) => {
76
+ if (node.type === 'function_definition') {
77
+ const names = new Set();
78
+ const parameters = node.childForFieldName('parameters');
79
+ for (const parameter of parameters?.namedChildren ?? []) {
80
+ const name = parameter.type === 'identifier' ? parameter.text : parameter.childForFieldName('name')?.text;
81
+ if (name)
82
+ names.add(name);
83
+ }
84
+ const collectAssignments = (child) => {
85
+ if (child.type === 'assignment') {
86
+ const left = child.childForFieldName('left');
87
+ if (left?.type === 'identifier')
88
+ names.add(left.text);
89
+ }
90
+ for (const nested of child.namedChildren)
91
+ collectAssignments(nested);
92
+ };
93
+ const body = node.childForFieldName('body');
94
+ if (body)
95
+ collectAssignments(body);
96
+ ranges.push({ start: node.startIndex, end: node.endIndex, names });
97
+ }
98
+ for (const child of node.namedChildren)
99
+ walk(child);
100
+ };
101
+ walk(root);
102
+ return ranges;
103
+ }
104
+ function scanSource(text, file, rules) {
105
+ if (!parser)
106
+ throw new Error('The Python grammar is not loaded: call loadLanguages() before scanning.');
107
+ const tree = parser.parse(text);
108
+ if (!tree)
109
+ throw new Error(`${file}: the Python parser returned no tree.`);
110
+ const bindings = imports(tree.rootNode);
111
+ const shadows = shadowedNames(tree.rootNode);
112
+ const lookup = indexRules(rules.filter((group) => group.language === 'python'));
113
+ const findings = [];
114
+ const reporter = new LineReporter(file, findings);
115
+ const errors = [];
116
+ const walk = (node) => {
117
+ if (node.type === 'ERROR')
118
+ errors.push(node);
119
+ if (node.type === 'call') {
120
+ const path = callPath(node);
121
+ if (path) {
122
+ const [head, ...rest] = path.split('.');
123
+ const binding = bindings.get(head);
124
+ const shadow = shadows.some((range) => node.startIndex >= range.start && node.endIndex <= range.end && range.names.has(head));
125
+ const full = binding ? [binding.path, ...rest].join('.') : null;
126
+ const rule = full ? ruleFor(full, lookup) : undefined;
127
+ if (rule && !shadow) {
128
+ const args = argumentsOf(node);
129
+ const value = rule.algorithmFrom ? argumentNames(args[rule.algorithmFrom.arg]) : null;
130
+ const result = ruleFindings(rule, file, node.startPosition.row + 1, [{ note: `matched ${full}` }], () => ({ names: value, qualifiers: [] }));
131
+ reporter.call(rule, node.startPosition.row + 1, result);
132
+ }
133
+ }
134
+ }
135
+ for (const child of node.namedChildren)
136
+ walk(child);
137
+ };
138
+ walk(tree.rootNode);
139
+ if (errors.length > 0)
140
+ findings.push({ ruleId: 'parse-error', file, line: errors[0].startPosition.row + 1, algorithm: null, category: 'unknown', status: 'unresolved', trace: [], note: 'Source could not be parsed completely.' });
141
+ tree.delete();
142
+ return findings.sort((a, b) => a.line - b.line);
143
+ }
144
+ export async function loadPython() { parser ??= await createParser('python'); }
145
+ export const python = {
146
+ id: 'python',
147
+ extensions: ['.py', '.pyw'],
148
+ load: loadPython,
149
+ scanSource,
150
+ };
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
- // SARIF 2.1.0 (OASIS), the format GitHub code scanning reads. Only findings that need action are included: a ✅
3
- // finding is part of the inventory (see --json and --cbom), not an alert.
2
+ // SARIF 2.1.0 (OASIS), the format GitHub code scanning reads. Only findings that need action are included: a
3
+ // resistant finding is part of the inventory (see --json and --cbom), not an alert.
4
4
  const version = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
5
5
  /** One SARIF rule per status, so alert titles and help stay the same whichever library a finding comes from. */
6
6
  const RULES = {
@@ -1,37 +1,48 @@
1
- const ICONS = { vulnerable: '❌', 'observed-resistant': '✅', 'needs-review': '🔍', unresolved: '⚠️ ' };
1
+ /** Each status as a word at the start of its row, and its colour when the output is a terminal. */
2
+ const LABELS = {
3
+ vulnerable: { word: 'VULNERABLE', colour: 31 },
4
+ 'needs-review': { word: 'REVIEW', colour: 33 },
5
+ unresolved: { word: 'UNRESOLVED', colour: 35 },
6
+ 'observed-resistant': { word: 'RESISTANT', colour: 32 },
7
+ };
8
+ // Colour only on a terminal, and never when NO_COLOR is set (https://no-color.org).
9
+ const useColour = () => Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
10
+ const paint = (text, colour) => (useColour() ? `\x1b[${colour}m${text}\x1b[0m` : text);
11
+ const dim = (text) => (useColour() ? `\x1b[2m${text}\x1b[0m` : text);
2
12
  export const MASCOT_BANNER = [
3
13
  ' /\\_/\\',
4
14
  '( 0.1 ) [ pqc-scan • Post-Quantum Cryptography Scanner ]',
5
- ' > ^ < Finds the cryptography in your JavaScript, TypeScript, C, C++, Rust and Go',
15
+ ' > ^ < Scans your JavaScript, TypeScript, C, C++, Rust and Go',
6
16
  ' ---------------------------------------------------------',
7
- ' Looks for what quantum computers will break (NIST FIPS 203/204/205)\n',
17
+ ' Flags the cryptography a quantum computer could break\n',
8
18
  ].join('\n');
9
19
  export function printTable(findings, known = 0) {
10
20
  if (known > 0)
11
21
  console.log(`${known} finding(s) already in the baseline are not shown.\n`);
12
22
  if (findings.length === 0 && known > 0) {
13
- console.log('✅ No new findings since the baseline.\n');
23
+ console.log('No new findings since the baseline.\n');
14
24
  return;
15
25
  }
16
26
  if (findings.length === 0) {
17
- console.log('⚠️ No recognized cryptography found. This is not a security conclusion.\n');
27
+ console.log('No recognised cryptography found. This is not a security conclusion.\n');
18
28
  return;
19
29
  }
20
30
  console.log('Cryptography found:');
21
- console.log(''.padEnd(72, '-'));
31
+ console.log(''.padEnd(76, '-'));
22
32
  for (const item of findings) {
23
- console.log(`${ICONS[item.status]} ${`${item.file}:${item.line}`.padEnd(36)} ${(item.algorithm ?? 'unknown algorithm').padEnd(18)} ${item.status}`);
33
+ const { word, colour } = LABELS[item.status];
34
+ console.log(`${paint(word.padEnd(10), colour)} ${`${item.file}:${item.line}`.padEnd(40)} ${item.algorithm ?? 'unknown algorithm'}`);
24
35
  if (item.note)
25
- console.log(` ℹ️ ${item.note}`);
36
+ console.log(dim(` ${item.note}`));
26
37
  }
27
- console.log(''.padEnd(72, '-'));
38
+ console.log(''.padEnd(76, '-'));
28
39
  const count = (status) => findings.filter((item) => item.status === status).length;
29
- console.log(`${findings.length} finding(s): ${count('vulnerable')} vulnerable, ${count('needs-review')} needs-review, ${count('unresolved')} unresolved, ${count('observed-resistant')} observed-resistant.\n`);
40
+ console.log(`${findings.length} finding(s): ${count('vulnerable')} vulnerable, ${count('needs-review')} needs review, ${count('unresolved')} unresolved, ${count('observed-resistant')} resistant.\n`);
30
41
  if (count('vulnerable') > 0)
31
- console.log('🚨 Quantum risk found: the ❌ items use cryptography a quantum computer could break. Plan their migration.');
42
+ console.log('Quantum risk found: the VULNERABLE items use cryptography a quantum computer could break. Plan their migration.');
32
43
  else if (count('needs-review') + count('unresolved') > 0)
33
- console.log('⚠️ Review needed: some items need a human decision. This scan cannot prove readiness.');
44
+ console.log('Review needed: some items need a human decision. This scan cannot prove readiness.');
34
45
  else
35
- console.log('ℹ️ Nothing risky found in the code we could read. This is not a guarantee of quantum readiness.');
46
+ console.log('Nothing risky found in the code that could be read. This is not a guarantee of quantum readiness.');
36
47
  console.log();
37
48
  }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Max Brunsfeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pqc-scan",
3
- "version": "0.1.0",
4
- "description": "Conservative post-quantum cryptography inventory for JavaScript, TypeScript, C, C++, Rust and Go",
3
+ "version": "0.1.2",
4
+ "description": "Conservative post-quantum cryptography inventory for JavaScript, TypeScript, C, C++, Rust, Go and Python",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -32,19 +32,21 @@
32
32
  "dist",
33
33
  "rules",
34
34
  "schema",
35
- "grammars"
35
+ "grammars",
36
+ "NOTICE"
36
37
  ],
37
38
  "scripts": {
38
39
  "scan": "tsx src/cli.ts",
39
40
  "test": "vitest run",
40
- "typecheck": "tsc --noEmit",
41
- "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json && node scripts/copy-grammars.mjs",
41
+ "typecheck": "tsc -p test/tsconfig.json",
42
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json && node scripts/copy-grammars.mjs",
42
43
  "prepack": "npm run build"
43
44
  },
44
45
  "dependencies": {
45
- "typescript": "^5.8.0",
46
+ "tree-sitter-python": "0.25.0",
47
+ "typescript": "5.9.3",
46
48
  "web-tree-sitter": "0.27.2",
47
- "yaml": "^2.9.1"
49
+ "yaml": "2.9.1"
48
50
  },
49
51
  "devDependencies": {
50
52
  "@types/node": "^24.0.0",
package/rules/c/README.md CHANGED
@@ -25,10 +25,10 @@ C code is full of `#if`, `#ifdef` and `#define`. The tool does not run the prepr
25
25
 
26
26
  - Both sides of every `#if` are read, because the tool cannot know which one your build uses.
27
27
  - The code inside `#define` macros is read separately. A crypto call inside a macro is reported on the line where the macro is defined, even if the macro is never used.
28
- - Where the parser cannot make sense of part of a file (common in code full of macros), any known crypto function name found there is still reported, as ⚠️ `unresolved`, instead of being dropped.
28
+ - Where the parser cannot make sense of part of a file (common in code full of macros), any known crypto function name found there is still reported, as `unresolved`, instead of being dropped.
29
29
  ## Functions that choose the algorithm
30
30
 
31
- A function of the project's own that passes one of its parameters on as the algorithm (`pick(name)` calling `EVP_get_digestbyname(name)`) is followed to where it is called, and a call that passes a written value (`pick("sha1")`) is reported with that algorithm. See [Functions that choose the algorithm from a parameter](../wrappers.md).
31
+ A function of the project's own that passes one of its parameters on as the algorithm (`pick(name)` calling `EVP_get_digestbyname(name)`) is followed to where it is called, and a call that passes a written value (`pick("sha1")`) is reported with that algorithm. See [Functions that choose the algorithm from a parameter](../../docs/wrappers.md).
32
32
 
33
33
  ## Limits specific to C
34
34
 
@@ -13,9 +13,9 @@ C++ code also calls C libraries directly, so every library on the [C page](../c/
13
13
 
14
14
  Every class, function and namespace name in these rule files was checked against the library's header files when the rules were written: Crypto++ 8 from its October 2026 source, and Botan 3.14. Botan's algorithm-name strings were checked against its source and tests.
15
15
 
16
- Two Botan details are reported as 🔍 rather than ✅:
16
+ Two Botan details are reported as `needs-review` rather than `observed-resistant`:
17
17
 
18
- - In Botan, `ML_KEM_PrivateKey` is another name for `Kyber_PrivateKey`, and the class holds either ML-KEM or the older pre-standard Kyber, depending on a mode value. The same is true of `Dilithium_PrivateKey` (ML-DSA or Dilithium) and `SphincsPlus_PrivateKey` (SLH-DSA or SPHINCS+). Code that names the ML-KEM, ML-DSA or SLH-DSA class is reported ✅; code that names the older class is reported 🔍 so the mode can be checked.
18
+ - In Botan, `ML_KEM_PrivateKey` is another name for `Kyber_PrivateKey`, and the class holds either ML-KEM or the older pre-standard Kyber, depending on a mode value. The same is true of `Dilithium_PrivateKey` (ML-DSA or Dilithium) and `SphincsPlus_PrivateKey` (SLH-DSA or SPHINCS+). Code that names the ML-KEM, ML-DSA or SLH-DSA class is reported as resistant; code that names the older class is reported as needs review, so the mode can be checked.
19
19
  - FrodoKEM and Classic McEliece are believed to resist quantum computers but are not NIST standards.
20
20
 
21
21
  ## How C++ is read
@@ -25,7 +25,7 @@ Two Botan details are reported as 🔍 rather than ✅:
25
25
  - **One use per line.** A type named twice on one line (`std::unique_ptr<CryptoPP::SHA256> p(new CryptoPP::SHA256)`) is reported once.
26
26
  - **Calls inside a declaration.** C++ reads `Wrapper w(EVP_PKEY_CTX_new_id(EVP_PKEY_DH, NULL));` as declaring a function (the "most vexing parse"). Inside a function body, the tool treats it as the call it almost always is.
27
27
  - **Export macros.** A macro between `class` and the class name (`class BOTAN_PUBLIC_API(3, 6) RSA_PublicKey`) is blanked before parsing, so the rest of the class header, including its base classes, can be read.
28
- - **The preprocessor** is handled as for C: both sides of every `#if` are read, code inside `#define` macros is read separately and reported on the line where the macro is defined, and a known name inside code the parser cannot read is reported as ⚠️ `unresolved`.
28
+ - **The preprocessor** is handled as for C: both sides of every `#if` are read, code inside `#define` macros is read separately and reported on the line where the macro is defined, and a known name inside code the parser cannot read is reported as `unresolved`.
29
29
 
30
30
  ## `.h` files
31
31
 
@@ -33,7 +33,7 @@ A `.h` file can hold C or C++, so it is read by the C++ adapter and checked agai
33
33
 
34
34
  ## Functions that choose the algorithm
35
35
 
36
- A function of the project's own that passes one of its parameters on as the algorithm is followed to where it is called, as in C. `Class::f` is matched only when called as `Class::f(...)` or from its own file, and a method called on an object (`h.pick("sha1")`) is not followed, because the object's type is not known. See [Functions that choose the algorithm from a parameter](../wrappers.md).
36
+ A function of the project's own that passes one of its parameters on as the algorithm is followed to where it is called, as in C. `Class::f` is matched only when called as `Class::f(...)` or from its own file, and a method called on an object (`h.pick("sha1")`) is not followed, because the object's type is not known. See [Functions that choose the algorithm from a parameter](../../docs/wrappers.md).
37
37
 
38
38
  ## Limits specific to C++
39
39
 
@@ -19,8 +19,8 @@ Choices worth knowing:
19
19
 
20
20
  - **A package with one algorithm is matched by its import path.** Any use of `crypto/rsa`, `crypto/ecdsa`, `crypto/md5`, `golang.org/x/crypto/curve25519` and the others listed by import path counts, including types such as `*rsa.PrivateKey` in a struct field or a type switch.
21
21
  - **HMAC, HKDF and PBKDF2** take the hash as an argument (`hmac.New(sha256.New, key)`), and only the hash is reported.
22
- - **AES** is reported as ⚠️ `unresolved`, because Go chooses AES-128, -192 or -256 by the length of the key passed to `aes.NewCipher`.
23
- - **TLS and SSH set-up** is reported as ⚠️ `unresolved` where a `tls.Config`, `ssh.ClientConfig`, `ssh.ServerConfig` or `ssh.Config` is built, with what the defaults are. Go 1.24 and later offer the hybrid post-quantum key exchange X25519MLKEM768 first when `CurvePreferences` is not set (unless `GODEBUG=tlsmlkem=0`); Go 1.26 added SecP256r1MLKEM768 and SecP384r1MLKEM1024 to the defaults. golang.org/x/crypto v0.42.0 and later, with Go 1.24 or later, offer `mlkem768x25519-sha256` first for SSH when `KeyExchanges` is not set. A `tls.Config` named only as a type (`func f(c *tls.Config)`) is not reported.
22
+ - **AES** is reported as `unresolved`, because Go chooses AES-128, -192 or -256 by the length of the key passed to `aes.NewCipher`.
23
+ - **TLS and SSH set-up** is reported as `unresolved` where a `tls.Config`, `ssh.ClientConfig`, `ssh.ServerConfig` or `ssh.Config` is built, with what the defaults are. Go 1.24 and later offer the hybrid post-quantum key exchange X25519MLKEM768 first when `CurvePreferences` is not set (unless `GODEBUG=tlsmlkem=0`); Go 1.26 added SecP256r1MLKEM768 and SecP384r1MLKEM1024 to the defaults. golang.org/x/crypto v0.42.0 and later, with Go 1.24 or later, offer `mlkem768x25519-sha256` first for SSH when `KeyExchanges` is not set. A `tls.Config` named only as a type (`func f(c *tls.Config)`) is not reported.
24
24
  - **The `crypto/hpke` and CIRCL `hpke` key exchanges** are reported by what they are made of: `hpke.MLKEM768X25519()` as the hybrid X25519MLKEM768, `hpke.DHKEM(...)` as a classical elliptic-curve key exchange.
25
25
 
26
26
  ## How Go is read
@@ -30,11 +30,11 @@ Choices worth knowing:
30
30
  - **What counts.** A name counts wherever it is used: a call (`rsa.GenerateKey(...)`), a type (`*rsa.PrivateKey`), a constant (`crypto.SHA256`), or a function passed as a value (`sha256.New`). A struct listed as built (`tls.Config`) counts where it is built: `tls.Config{...}` or `&tls.Config{...}`.
31
31
  - **One use per line.** A name used twice on one line is reported once.
32
32
  - **Versions of one library.** golang-jwt v4 and v3 and dgrijalva/jwt-go have the same names as golang-jwt v5 and are read as v5.
33
- - **Code the parser cannot read** that uses a rule package by its name in the file (`rsa.`) is reported as ⚠️ `unresolved`.
33
+ - **Code the parser cannot read** that uses a rule package by its name in the file (`rsa.`) is reported as `unresolved`.
34
34
 
35
35
  ## Functions that choose the algorithm
36
36
 
37
- A function of the project's own that passes one of its parameters on as the algorithm (`func method(name string)` calling `jwt.GetSigningMethod(name)`) is followed to where it is called, across packages, and a call that passes a written value (`sign.Method("ES256")`) is reported with that algorithm. An unexported function is matched only in its own package, and a method called on a value is not followed. See [Functions that choose the algorithm from a parameter](../wrappers.md).
37
+ A function of the project's own that passes one of its parameters on as the algorithm (`func method(name string)` calling `jwt.GetSigningMethod(name)`) is followed to where it is called, across packages, and a call that passes a written value (`sign.Method("ES256")`) is reported with that algorithm. An unexported function is matched only in its own package, and a method called on a value is not followed. See [Functions that choose the algorithm from a parameter](../../docs/wrappers.md).
38
38
 
39
39
  ## Limits specific to Go
40
40
 
@@ -20,13 +20,13 @@ Every cipher, hash and key type name is checked against Node.js itself, and the
20
20
  - `require('crypto')`, `await import('node:crypto')`, and a `require` whose name is a constant.
21
21
  - The algorithm stored in a constant: `const name = 'sha256'; createHash(name)`.
22
22
  - A function or object copied into another variable before it is called, `.call()` and `.apply()`.
23
- - Helper files: if a file passes an algorithm it received as an argument, every local file that imports it gets an ⚠️ note saying the caller chooses the algorithm.
23
+ - Helper files: if a file passes an algorithm it received as an argument, every local file that imports it gets an unresolved note saying the caller chooses the algorithm.
24
24
 
25
25
  ## Limits specific to JavaScript
26
26
 
27
27
  - A library loaded by a name built while the program runs (`require(someVariable)`) and code run from text (`eval`) are not followed.
28
- - The algorithm is reported as ⚠️ when it comes from a `let` variable, a function result, a setting, a template string with a substitution, or an object property.
29
- - Across files, the tool says that a helper's callers choose the algorithm, but does not trace which value each caller passes. Only files that import the helper directly get the ⚠️ note; a file that imports them does not.
28
+ - The algorithm is reported as unresolved when it comes from a `let` variable, a function result, a setting, a template string with a substitution, or an object property.
29
+ - Across files, the tool says that a helper's callers choose the algorithm, but does not trace which value each caller passes. Only files that import the helper directly get the unresolved note; a file that imports them does not.
30
30
 
31
31
  These limits are pinned by `test/unsupported.test.ts`.
32
32
 
@@ -0,0 +1,17 @@
1
+ # Python rules
2
+
3
+ Python rules match imported module paths and qualified call paths. An adapter only reports a call when the import can be resolved to a rule module. Dynamic values remain unresolved.
4
+
5
+ The initial rules cover `cryptography`, PyJWT, PyCryptodome, `ecdsa`, Python's `hashlib`, Paramiko, and PyNaCl. Add a fixture under `test/fixtures/python/` for every new rule and for ambiguous or unsupported forms.
6
+
7
+ Current limits are explicit: Python calls are resolved within one file only. Cross-file wrappers, dynamic imports, wildcard imports, and values selected through runtime state remain unresolved or unreported. Add a rule and fixture before claiming support for another library.
8
+
9
+ Rule files:
10
+
11
+ - `cryptography.yaml`
12
+ - `ecdsa.yaml`
13
+ - `paramiko.yaml`
14
+ - `pyjwt.yaml`
15
+ - `pycryptodome.yaml`
16
+ - `pynacl.yaml`
17
+ - `stdlib.yaml`
@@ -0,0 +1,39 @@
1
+ module: [cryptography]
2
+ rules:
3
+ - id: python-cryptography-rsa
4
+ functions: [cryptography.hazmat.primitives.asymmetric.rsa.generate_private_key]
5
+ category: keygen
6
+ algorithm: RSA
7
+ status: vulnerable
8
+ note: "A quantum computer could derive the private key from the public key using Shor's algorithm."
9
+ - id: python-cryptography-ec
10
+ functions: [cryptography.hazmat.primitives.asymmetric.ec.generate_private_key]
11
+ category: keygen
12
+ algorithm: EC
13
+ status: vulnerable
14
+ - id: python-cryptography-dh
15
+ functions: [cryptography.hazmat.primitives.asymmetric.dh.generate_parameters, cryptography.hazmat.primitives.asymmetric.dh.generate_private_key]
16
+ category: key-exchange
17
+ algorithm: DH
18
+ status: vulnerable
19
+ - id: python-cryptography-ed25519
20
+ functions: [cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey.generate, cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey.from_public_bytes]
21
+ category: signature
22
+ algorithm: Ed25519
23
+ status: vulnerable
24
+ - id: python-cryptography-x25519
25
+ functions: [cryptography.hazmat.primitives.asymmetric.x25519.X25519PrivateKey.generate, cryptography.hazmat.primitives.asymmetric.x25519.X25519PublicKey.from_public_bytes]
26
+ category: key-exchange
27
+ algorithm: X25519
28
+ status: vulnerable
29
+ - id: python-cryptography-sha256
30
+ functions: [cryptography.hazmat.primitives.hashes.SHA256]
31
+ category: hash
32
+ algorithm: SHA-256
33
+ status: observed-resistant
34
+ - id: python-cryptography-sha1
35
+ functions: [cryptography.hazmat.primitives.hashes.SHA1]
36
+ category: hash
37
+ algorithm: SHA-1
38
+ status: needs-review
39
+ note: "Classically weak. Migrate regardless of quantum risk."
@@ -0,0 +1,14 @@
1
+ module: [ecdsa]
2
+ rules:
3
+ - id: python-ecdsa-signing-key
4
+ functions: [ecdsa.SigningKey.generate, ecdsa.SigningKey.from_string, ecdsa.SigningKey.from_pem]
5
+ category: signature
6
+ algorithm: ECDSA
7
+ status: vulnerable
8
+ note: "Classical elliptic-curve signatures are vulnerable to Shor's algorithm."
9
+ - id: python-ecdsa-verifying-key
10
+ functions: [ecdsa.VerifyingKey.from_string, ecdsa.VerifyingKey.from_pem]
11
+ category: signature
12
+ algorithm: ECDSA
13
+ status: vulnerable
14
+ note: "Classical elliptic-curve signatures are vulnerable to Shor's algorithm."
@@ -0,0 +1,23 @@
1
+ module: [paramiko]
2
+ rules:
3
+ - id: python-paramiko-rsa
4
+ functions: [paramiko.RSAKey.generate, paramiko.RSAKey.from_private_key, paramiko.RSAKey.from_private_key_file]
5
+ category: keygen
6
+ algorithm: RSA
7
+ status: vulnerable
8
+ note: "RSA host and user keys are vulnerable to Shor's algorithm."
9
+ - id: python-paramiko-ecdsa
10
+ functions: [paramiko.ECDSAKey.generate, paramiko.ECDSAKey.from_private_key, paramiko.ECDSAKey.from_private_key_file]
11
+ category: signature
12
+ algorithm: ECDSA
13
+ status: vulnerable
14
+ - id: python-paramiko-ed25519
15
+ functions: [paramiko.Ed25519Key.from_private_key, paramiko.Ed25519Key.from_private_key_file]
16
+ category: signature
17
+ algorithm: Ed25519
18
+ status: vulnerable
19
+ - id: python-paramiko-dss
20
+ functions: [paramiko.DSSKey.from_private_key, paramiko.DSSKey.from_private_key_file]
21
+ category: signature
22
+ algorithm: DSA
23
+ status: vulnerable
@@ -0,0 +1,20 @@
1
+ module: [Crypto.PublicKey, Crypto.Cipher]
2
+ rules:
3
+ - id: python-pycryptodome-rsa
4
+ functions: [Crypto.PublicKey.RSA.generate, Crypto.PublicKey.RSA.import_key]
5
+ category: keygen
6
+ algorithm: RSA
7
+ status: vulnerable
8
+ note: "A quantum computer could derive or forge RSA keys using Shor's algorithm."
9
+ - id: python-pycryptodome-ecc
10
+ functions: [Crypto.PublicKey.ECC.generate, Crypto.PublicKey.ECC.import_key]
11
+ category: keygen
12
+ algorithm: ECC
13
+ status: vulnerable
14
+ note: "Classical elliptic-curve cryptography is vulnerable to Shor's algorithm."
15
+ - id: python-pycryptodome-aes
16
+ functions: [Crypto.Cipher.AES.new]
17
+ category: symmetric
18
+ algorithm: AES
19
+ status: needs-review
20
+ note: "Review the key length and mode. AES-128 has a reduced quantum security margin, and unauthenticated modes may be unsafe."
@@ -0,0 +1,13 @@
1
+ module: [jwt]
2
+ rules:
3
+ - id: python-pyjwt-encode
4
+ functions: [jwt.encode]
5
+ category: signature
6
+ algorithmFrom: { arg: 2 }
7
+ values:
8
+ RS256: { algorithm: RSA, status: vulnerable }
9
+ RS384: { algorithm: RSA, status: vulnerable }
10
+ RS512: { algorithm: RSA, status: vulnerable }
11
+ ES256: { algorithm: ECDSA, status: vulnerable }
12
+ ES384: { algorithm: ECDSA, status: vulnerable }
13
+ HS256: { algorithm: HMAC-SHA256, status: observed-resistant }
@@ -0,0 +1,12 @@
1
+ module: [nacl.public, nacl.signing]
2
+ rules:
3
+ - id: python-pynacl-x25519
4
+ functions: [nacl.public.PrivateKey.generate, nacl.public.PrivateKey.from_private_bytes]
5
+ category: key-exchange
6
+ algorithm: X25519
7
+ status: vulnerable
8
+ - id: python-pynacl-ed25519
9
+ functions: [nacl.signing.SigningKey.generate, nacl.signing.SigningKey.from_seed]
10
+ category: signature
11
+ algorithm: Ed25519
12
+ status: vulnerable
@@ -0,0 +1,45 @@
1
+ module: [hashlib]
2
+ rules:
3
+ - id: python-hashlib-md5
4
+ functions: [hashlib.md5]
5
+ category: hash
6
+ algorithm: MD5
7
+ status: needs-review
8
+ note: "MD5 is broken against ordinary computers. Replace it."
9
+ - id: python-hashlib-sha1
10
+ functions: [hashlib.sha1]
11
+ category: hash
12
+ algorithm: SHA-1
13
+ status: needs-review
14
+ note: "SHA-1 is classically weak. Migrate regardless of quantum risk."
15
+ - id: python-hashlib-sha224
16
+ functions: [hashlib.sha224]
17
+ category: hash
18
+ algorithm: SHA-224
19
+ status: needs-review
20
+ note: "SHA-224 has 112-bit collision strength. Review it against policy."
21
+ - id: python-hashlib-sha256
22
+ functions: [hashlib.sha256]
23
+ category: hash
24
+ algorithm: SHA-256
25
+ status: observed-resistant
26
+ - id: python-hashlib-sha384
27
+ functions: [hashlib.sha384]
28
+ category: hash
29
+ algorithm: SHA-384
30
+ status: observed-resistant
31
+ - id: python-hashlib-sha512
32
+ functions: [hashlib.sha512]
33
+ category: hash
34
+ algorithm: SHA-512
35
+ status: observed-resistant
36
+ - id: python-hashlib-sha3-256
37
+ functions: [hashlib.sha3_256]
38
+ category: hash
39
+ algorithm: SHA3-256
40
+ status: observed-resistant
41
+ - id: python-hashlib-sha3-512
42
+ functions: [hashlib.sha3_512]
43
+ category: hash
44
+ algorithm: SHA3-512
45
+ status: observed-resistant
@@ -9,7 +9,7 @@ Files: `.rs`. A `target` folder next to a `Cargo.toml` is skipped, because it ho
9
9
  | RustCrypto crates, and the dalek crates for Ed25519 and X25519 | `rustcrypto.yaml` | Hashes (`sha2`, `sha3`, `sha1`, `md5`, `md4`, `blake2`, `ripemd`), ciphers (`aes`, `aes-gcm`, `aes-gcm-siv`, `chacha20poly1305`, `chacha20`, `des`, `rc4`), RSA, DSA, ECDSA and the curves `p256`, `p384`, `p521`, `k256` and `sm2`, `ed25519-dalek`, `x25519-dalek`, Ed448 and X448, the post-quantum `ml-kem`, `ml-dsa`, `slh-dsa` and `x-wing`, and the password hashes `argon2` and `scrypt`. |
10
10
  | ring and aws-lc-rs | `ring.yaml` | The algorithm constants passed to their functions (`&digest::SHA256`, `&agreement::X25519`, `&signature::ECDSA_P256_SHA256_ASN1_SIGNING`), the key-pair types and `SystemRandom`. aws-lc-rs copies ring's interface, so each name is written once for ring; what only aws-lc-rs has is listed under its own name: ML-KEM (`kem::ML_KEM_768`), ML-DSA (`signature::ML_DSA_65`), SHA-3, P-521 and secp256k1. |
11
11
  | openssl crate (rust-openssl) | `openssl.yaml` | Digests (`MessageDigest::sha256()`, `Md::sha256()`, `openssl::sha::sha256`), a digest chosen by name (`MessageDigest::from_name("sha256")`), ciphers (`Cipher::aes_256_gcm()`), key types (`Rsa`, `EcKey`, `Dsa`, `Dh`, `PKey::generate_ed25519()`, `pkey::Id::X25519`, ...), `rand_bytes` and where TLS is set up (`SslConnector`, `SslAcceptor`, `SslContext`). |
12
- | rustls (TLS) | `rustls.yaml` | Which key exchange TLS offers: the crypto provider (`rustls::crypto::aws_lc_rs::default_provider()` in rustls 0.23, `rustls_aws_lc_rs::DEFAULT_PROVIDER` in 0.24, and the same for ring), each key-exchange group named in code (`kx_group::X25519MLKEM768`, `kx_group::X25519`), and where a configuration is built (`ClientConfig::builder()`, `ServerConfig::builder()`). The aws-lc-rs provider offers the hybrid post-quantum group X25519MLKEM768 first by default and is reported ✅; the ring provider offers only classical groups and is reported ❌. |
12
+ | rustls (TLS) | `rustls.yaml` | Which key exchange TLS offers: the crypto provider (`rustls::crypto::aws_lc_rs::default_provider()` in rustls 0.23, `rustls_aws_lc_rs::DEFAULT_PROVIDER` in 0.24, and the same for ring), each key-exchange group named in code (`kx_group::X25519MLKEM768`, `kx_group::X25519`), and where a configuration is built (`ClientConfig::builder()`, `ServerConfig::builder()`). The aws-lc-rs provider offers the hybrid post-quantum group X25519MLKEM768 first by default and is reported as resistant; the ring provider offers only classical groups and is reported as vulnerable. |
13
13
  | jsonwebtoken crate (JWT) | `jsonwebtoken.yaml` | The signing algorithm, a variant of its `Algorithm` enum (`Header::new(Algorithm::RS256)`, `Validation::new(Algorithm::ES256)`), wherever it is named. |
14
14
  | getrandom, rand, rand_core | `random.yaml` | Random numbers read straight from the operating system: `getrandom`, `OsRng` and `SysRng`. |
15
15
 
@@ -28,11 +28,11 @@ Choices worth knowing:
28
28
  - **Generic arguments.** Each is matched on its own, so `Hmac::<Sha256>::new_from_slice(key)` reports SHA-256.
29
29
  - **One use per line.** A name used twice on one line (`let k: SigningKey = SigningKey::random(rng)`) is reported once.
30
30
  - **Macros.** Rust does not parse a macro's arguments until the macro is expanded, so the arguments (`assert_eq!(Sha256::digest(data), ...)`) and the code inside a `macro_rules!` definition are searched as text for the same paths, with strings and comments left out. A finding inside a `macro_rules!` is reported on the line where it is written. A digest name inside a macro is read only when it is written directly as a string (`from_name("sha256")`).
31
- - **Code the parser cannot read** that names a rule crate (`ring::digest::SHA256`) is reported as ⚠️ `unresolved`.
31
+ - **Code the parser cannot read** that names a rule crate (`ring::digest::SHA256`) is reported as `unresolved`.
32
32
 
33
33
  ## Functions that choose the algorithm
34
34
 
35
- A function of the project's own that passes one of its parameters on as the algorithm (`fn digest(name: &str)` calling `MessageDigest::from_name(name)`) is followed to where it is called, and a call that passes a written value (`digest("sha256")`) is reported with that algorithm. A private function is matched only in its own file, and a method called on a value (`self.digest(...)`) is not followed. See [Functions that choose the algorithm from a parameter](../wrappers.md).
35
+ A function of the project's own that passes one of its parameters on as the algorithm (`fn digest(name: &str)` calling `MessageDigest::from_name(name)`) is followed to where it is called, and a call that passes a written value (`digest("sha256")`) is reported with that algorithm. A private function is matched only in its own file, and a method called on a value (`self.digest(...)`) is not followed. See [Functions that choose the algorithm from a parameter](../../docs/wrappers.md).
36
36
 
37
37
  ## Limits specific to Rust
38
38
 
package/rules/wrappers.md DELETED
@@ -1,46 +0,0 @@
1
- # Functions that choose the algorithm from a parameter
2
-
3
- This applies to C, C++, Rust and Go.
4
-
5
- A project often wraps a crypto call in a function of its own, and lets the caller choose the algorithm:
6
-
7
- ```c
8
- const EVP_MD *pick(const char *name) {
9
- return EVP_get_digestbyname(name); // ⚠️ the algorithm is whatever the caller passes
10
- }
11
- ```
12
-
13
- Read on its own, that line cannot say which algorithm is used, so it is reported as ⚠️ `unresolved`. The scanner then follows the function to where it is called, anywhere in the folder scanned:
14
-
15
- - **A call that passes a value written in the code** is reported where it is, with the algorithm: `pick("sha1")` is reported as SHA-1, 🔍 `needs-review`, on the line of the call.
16
- - **A call that passes its own parameter on** (`void f(const char *alg) { pick(alg); }`) makes that function a wrapper too, and its callers are followed in the same way, up to five functions deep.
17
- - **Calls that pass a value that cannot be read**, such as a setting read at run time, are listed on the wrapper's own ⚠️ finding instead of being reported one by one: "The algorithm is parameter 1 ("name") of pick(), so its callers choose it. 2 call(s) pass a value that cannot be read here, such as main.c:4, api.c:31; check those by hand." When no call is found at all, the finding says so.
18
-
19
- ## Which calls count
20
-
21
- A call is matched to a function only where the language allows that call, so a function is not confused with another of the same name:
22
-
23
- - **C and C++:** a `static` function only in its own file; `Class::f` only as `Class::f(...)` or from its own file; a C function also from C++, and from Go through cgo (`C.f(...)`).
24
- - **Rust:** a private function (no `pub`) only in its own file; `Type::f` only as `Type::f(...)` or from its own file.
25
- - **Go:** an unexported function (lower-case name) only in its own package (folder); an exported one as `pkg.F(...)` from other packages.
26
- - **Not followed:** a method called on a value (`h.pick("sha1")`, `self.pick(...)`), because the value's type is not known here; and a function the rules already name, such as a crypto library's own source defining `wc_AesGcmSetKey`, since calls to it are reported directly.
27
-
28
- When two functions of the same name could be meant and they choose the algorithm differently, nothing is guessed: the call is listed on both.
29
-
30
- ## Tested on
31
-
32
- On the 34 projects the scanner is tested on, following wrappers added findings only in C and C++ code, each a call that passes a value written in the code. A sample from each project was checked by hand.
33
-
34
- | Code | Findings added | Wrappers found |
35
- |---|---|---|
36
- | wolfSSL | 496 (322 ✅, 95 🔍, 79 ⚠️) | 134 |
37
- | GnuTLS | 66 (21 ✅, 25 🔍, 20 ❌) | 57 |
38
- | Mbed TLS | 30 (21 ✅, 8 🔍, 1 ❌) | 34 |
39
- | TF-PSA-Crypto | 24 (14 ✅, 8 🔍, 2 ❌) | 26 |
40
- | Botan | 15 (6 ✅, 3 🔍, 6 ⚠️) | 29 |
41
- | RNP | 4 ❌ | 4 |
42
- | cpp-httplib | 3 (2 ✅, 1 🔍) | 1 |
43
-
44
- The ⚠️ findings added are calls that pass a value the rule does not know, such as `0` for "no key yet" in wolfSSL's tests, or names Botan's tests pass on purpose to check they are refused (`"Blake2b(9)"`).
45
-
46
- Following wrappers reads again the files that call one, so it adds time where there are many: wolfSSL took 7.8 seconds instead of 5.0, GnuTLS 3.1 instead of 2.2, and Mbed TLS 2.4 instead of 1.8. HashiCorp Vault, which has none, took 3.9 seconds instead of 3.6.