@quantakrypto/sieve 0.1.0
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/README.md +227 -0
- package/dist/categories/correctness.d.ts +13 -0
- package/dist/categories/correctness.d.ts.map +1 -0
- package/dist/categories/correctness.js +78 -0
- package/dist/categories/correctness.js.map +1 -0
- package/dist/categories/determinism.d.ts +12 -0
- package/dist/categories/determinism.d.ts.map +1 -0
- package/dist/categories/determinism.js +78 -0
- package/dist/categories/determinism.js.map +1 -0
- package/dist/categories/dsa.d.ts +17 -0
- package/dist/categories/dsa.d.ts.map +1 -0
- package/dist/categories/dsa.js +17 -0
- package/dist/categories/dsa.js.map +1 -0
- package/dist/categories/helpers.d.ts +50 -0
- package/dist/categories/helpers.d.ts.map +1 -0
- package/dist/categories/helpers.js +127 -0
- package/dist/categories/helpers.js.map +1 -0
- package/dist/categories/implicit-rejection.d.ts +29 -0
- package/dist/categories/implicit-rejection.d.ts.map +1 -0
- package/dist/categories/implicit-rejection.js +126 -0
- package/dist/categories/implicit-rejection.js.map +1 -0
- package/dist/categories/index.d.ts +30 -0
- package/dist/categories/index.d.ts.map +1 -0
- package/dist/categories/index.js +33 -0
- package/dist/categories/index.js.map +1 -0
- package/dist/categories/kat.d.ts +21 -0
- package/dist/categories/kat.d.ts.map +1 -0
- package/dist/categories/kat.js +173 -0
- package/dist/categories/kat.js.map +1 -0
- package/dist/categories/robustness.d.ts +15 -0
- package/dist/categories/robustness.d.ts.map +1 -0
- package/dist/categories/robustness.js +98 -0
- package/dist/categories/robustness.js.map +1 -0
- package/dist/categories/signature.d.ts +29 -0
- package/dist/categories/signature.d.ts.map +1 -0
- package/dist/categories/signature.js +259 -0
- package/dist/categories/signature.js.map +1 -0
- package/dist/categories/sizes.d.ts +23 -0
- package/dist/categories/sizes.d.ts.map +1 -0
- package/dist/categories/sizes.js +150 -0
- package/dist/categories/sizes.js.map +1 -0
- package/dist/categories/slh-dsa.d.ts +23 -0
- package/dist/categories/slh-dsa.d.ts.map +1 -0
- package/dist/categories/slh-dsa.js +23 -0
- package/dist/categories/slh-dsa.js.map +1 -0
- package/dist/categories/timing.d.ts +16 -0
- package/dist/categories/timing.d.ts.map +1 -0
- package/dist/categories/timing.js +98 -0
- package/dist/categories/timing.js.map +1 -0
- package/dist/categories/types.d.ts +68 -0
- package/dist/categories/types.d.ts.map +1 -0
- package/dist/categories/types.js +31 -0
- package/dist/categories/types.js.map +1 -0
- package/dist/cli.d.ts +14 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +181 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +169 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +115 -0
- package/dist/protocol.js.map +1 -0
- package/dist/report.d.ts +48 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +79 -0
- package/dist/report.js.map +1 -0
- package/dist/runner.d.ts +129 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +305 -0
- package/dist/runner.js.map +1 -0
- package/dist/sizes.d.ts +84 -0
- package/dist/sizes.d.ts.map +1 -0
- package/dist/sizes.js +214 -0
- package/dist/sizes.js.map +1 -0
- package/dist/vectors.d.ts +69 -0
- package/dist/vectors.d.ts.map +1 -0
- package/dist/vectors.js +198 -0
- package/dist/vectors.js.map +1 -0
- package/package.json +43 -0
- package/vectors/README.md +83 -0
package/dist/runner.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SUT runner: spawns a user-provided implementation as a child process and
|
|
3
|
+
* exchanges newline-delimited JSON requests/responses over stdin/stdout.
|
|
4
|
+
*
|
|
5
|
+
* Responsibilities:
|
|
6
|
+
* - spawn the command, wire up a readline interface on its stdout,
|
|
7
|
+
* - correlate responses to requests by `id`,
|
|
8
|
+
* - enforce a per-request timeout,
|
|
9
|
+
* - surface SUT crashes / stderr,
|
|
10
|
+
* - tear the process down cleanly.
|
|
11
|
+
*
|
|
12
|
+
* Uses only node:child_process and node:readline. No cryptography here.
|
|
13
|
+
*/
|
|
14
|
+
import { spawn } from "node:child_process";
|
|
15
|
+
import { createInterface } from "node:readline";
|
|
16
|
+
import { decodeResponse, encodeRequest, } from "./protocol.js";
|
|
17
|
+
/**
|
|
18
|
+
* Minimal environment variables a child process generally needs to locate its
|
|
19
|
+
* interpreter, resolve its home directory, and produce sane text output. This
|
|
20
|
+
* is the default base env handed to the SUT — secrets in the parent env
|
|
21
|
+
* (tokens, credentials) are NOT forwarded. Extend via
|
|
22
|
+
* {@link RunnerOptions.envAllowlist} or pass explicit {@link RunnerOptions.env}.
|
|
23
|
+
*/
|
|
24
|
+
export const DEFAULT_ENV_ALLOWLIST = [
|
|
25
|
+
"PATH",
|
|
26
|
+
"HOME",
|
|
27
|
+
"LANG",
|
|
28
|
+
"LC_ALL",
|
|
29
|
+
"LC_CTYPE",
|
|
30
|
+
"TMPDIR",
|
|
31
|
+
"TMP",
|
|
32
|
+
"TEMP",
|
|
33
|
+
// Windows process-spawn essentials (harmless / empty on POSIX).
|
|
34
|
+
"SystemRoot",
|
|
35
|
+
"SystemDrive",
|
|
36
|
+
"windir",
|
|
37
|
+
"PATHEXT",
|
|
38
|
+
"COMSPEC",
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Build the environment handed to the spawned SUT.
|
|
42
|
+
*
|
|
43
|
+
* By default this is a SCRUBBED, minimal env: only the names in
|
|
44
|
+
* {@link DEFAULT_ENV_ALLOWLIST} (plus any in `opts.envAllowlist`) are copied
|
|
45
|
+
* from the parent `process.env`, then `opts.env` is layered on top. This keeps
|
|
46
|
+
* harness secrets out of untrusted SUT code (security.md Q-17). When
|
|
47
|
+
* `opts.inheritEnv` is set, the full parent env is used instead (legacy /
|
|
48
|
+
* trusted-local behavior).
|
|
49
|
+
*
|
|
50
|
+
* Exported for testing; the returned object never aliases `process.env`.
|
|
51
|
+
*/
|
|
52
|
+
export function buildSutEnv(opts, parentEnv = process.env) {
|
|
53
|
+
const out = {};
|
|
54
|
+
if (opts.inheritEnv === true) {
|
|
55
|
+
for (const [k, v] of Object.entries(parentEnv)) {
|
|
56
|
+
if (typeof v === "string")
|
|
57
|
+
out[k] = v;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const names = new Set([...DEFAULT_ENV_ALLOWLIST, ...(opts.envAllowlist ?? [])]);
|
|
62
|
+
for (const name of names) {
|
|
63
|
+
const v = parentEnv[name];
|
|
64
|
+
if (typeof v === "string")
|
|
65
|
+
out[name] = v;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Explicit extra env always wins, even over an inherited value.
|
|
69
|
+
if (opts.env) {
|
|
70
|
+
for (const [k, v] of Object.entries(opts.env))
|
|
71
|
+
out[k] = v;
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
/** Thrown when a request exceeds its timeout. */
|
|
76
|
+
export class TimeoutError extends Error {
|
|
77
|
+
request;
|
|
78
|
+
timeoutMs;
|
|
79
|
+
constructor(request, timeoutMs) {
|
|
80
|
+
super(`SUT did not respond to id=${request.id} (${request.op}) within ${timeoutMs}ms`);
|
|
81
|
+
this.request = request;
|
|
82
|
+
this.timeoutMs = timeoutMs;
|
|
83
|
+
this.name = "TimeoutError";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Thrown when the SUT process dies before/while a request is in flight. */
|
|
87
|
+
export class SutCrashError extends Error {
|
|
88
|
+
stderr;
|
|
89
|
+
constructor(message, stderr) {
|
|
90
|
+
super(message);
|
|
91
|
+
this.stderr = stderr;
|
|
92
|
+
this.name = "SutCrashError";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
96
|
+
/**
|
|
97
|
+
* A long-lived handle to a spawned SUT. Construct once per test run, issue many
|
|
98
|
+
* requests, then `close()`. Requests are matched to responses by `id`, so the
|
|
99
|
+
* SUT MAY answer out of order, though in practice it answers serially.
|
|
100
|
+
*/
|
|
101
|
+
export class Runner {
|
|
102
|
+
child;
|
|
103
|
+
rl;
|
|
104
|
+
pending = new Map();
|
|
105
|
+
timeoutMs;
|
|
106
|
+
nextId = 1;
|
|
107
|
+
stderrBuf = "";
|
|
108
|
+
closed = false;
|
|
109
|
+
fatal;
|
|
110
|
+
constructor(opts) {
|
|
111
|
+
if (opts.command.length === 0) {
|
|
112
|
+
throw new Error("Runner: command must have at least one element");
|
|
113
|
+
}
|
|
114
|
+
this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
115
|
+
const [bin, ...args] = opts.command;
|
|
116
|
+
this.child = spawn(bin, args, {
|
|
117
|
+
cwd: opts.cwd,
|
|
118
|
+
// Scrubbed, minimal env by default — see buildSutEnv / security.md Q-17.
|
|
119
|
+
env: buildSutEnv(opts),
|
|
120
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
121
|
+
});
|
|
122
|
+
this.child.on("error", (err) => {
|
|
123
|
+
this.failAll(new SutCrashError(`failed to spawn SUT: ${err.message}`, this.stderrBuf));
|
|
124
|
+
});
|
|
125
|
+
this.child.on("exit", (code, signal) => {
|
|
126
|
+
if (this.closed)
|
|
127
|
+
return;
|
|
128
|
+
const why = signal !== null ? `SUT exited via signal ${signal}` : `SUT exited with code ${code}`;
|
|
129
|
+
this.failAll(new SutCrashError(why, this.stderrBuf));
|
|
130
|
+
});
|
|
131
|
+
this.child.stderr.setEncoding("utf8");
|
|
132
|
+
this.child.stderr.on("data", (chunk) => {
|
|
133
|
+
this.stderrBuf += chunk;
|
|
134
|
+
if (this.stderrBuf.length > 1 << 16) {
|
|
135
|
+
this.stderrBuf = this.stderrBuf.slice(-(1 << 16));
|
|
136
|
+
}
|
|
137
|
+
if (opts.onStderr) {
|
|
138
|
+
for (const line of chunk.split("\n")) {
|
|
139
|
+
if (line.length > 0)
|
|
140
|
+
opts.onStderr(line);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
this.rl = createInterface({ input: this.child.stdout });
|
|
145
|
+
this.rl.on("line", (line) => this.onLine(line));
|
|
146
|
+
}
|
|
147
|
+
/** Stderr captured from the SUT so far (most recent 64 KiB). */
|
|
148
|
+
get stderr() {
|
|
149
|
+
return this.stderrBuf;
|
|
150
|
+
}
|
|
151
|
+
onLine(line) {
|
|
152
|
+
if (line.trim().length === 0)
|
|
153
|
+
return;
|
|
154
|
+
let resp;
|
|
155
|
+
try {
|
|
156
|
+
resp = decodeResponse(line);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
// A protocol violation on a line we can't correlate is fatal; if we can
|
|
160
|
+
// extract an id, fail just that request, else fail everything.
|
|
161
|
+
const pe = err;
|
|
162
|
+
this.failAll(pe);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const entry = this.pending.get(resp.id);
|
|
166
|
+
if (entry === undefined) {
|
|
167
|
+
// Unsolicited / duplicate id — record but do not crash the run.
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
clearTimeout(entry.timer);
|
|
171
|
+
this.pending.delete(resp.id);
|
|
172
|
+
entry.resolve(resp);
|
|
173
|
+
}
|
|
174
|
+
failAll(err) {
|
|
175
|
+
if (this.fatal === undefined)
|
|
176
|
+
this.fatal = err;
|
|
177
|
+
for (const [, p] of this.pending) {
|
|
178
|
+
clearTimeout(p.timer);
|
|
179
|
+
p.reject(err);
|
|
180
|
+
}
|
|
181
|
+
this.pending.clear();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Send one request and await its response. The `id` field is assigned by the
|
|
185
|
+
* runner; any `id` on the passed object is overwritten.
|
|
186
|
+
*/
|
|
187
|
+
send(req) {
|
|
188
|
+
if (this.closed) {
|
|
189
|
+
return Promise.reject(new Error("Runner is closed"));
|
|
190
|
+
}
|
|
191
|
+
if (this.fatal !== undefined) {
|
|
192
|
+
return Promise.reject(this.fatal);
|
|
193
|
+
}
|
|
194
|
+
const id = this.nextId++;
|
|
195
|
+
const full = { ...req, id };
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
const timer = setTimeout(() => {
|
|
198
|
+
this.pending.delete(id);
|
|
199
|
+
reject(new TimeoutError(full, this.timeoutMs));
|
|
200
|
+
}, this.timeoutMs);
|
|
201
|
+
// Do not keep the event loop alive solely for this timer.
|
|
202
|
+
if (typeof timer.unref === "function")
|
|
203
|
+
timer.unref();
|
|
204
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
205
|
+
this.child.stdin.write(encodeRequest(full), (err) => {
|
|
206
|
+
if (err) {
|
|
207
|
+
clearTimeout(timer);
|
|
208
|
+
this.pending.delete(id);
|
|
209
|
+
reject(new SutCrashError(`write to SUT failed: ${err.message}`, this.stderrBuf));
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Issue many INDEPENDENT requests with bounded concurrency (pipelining).
|
|
216
|
+
*
|
|
217
|
+
* The protocol is id-correlated (each response carries the request's `id`),
|
|
218
|
+
* so multiple requests may be in flight against the SUT at once. This writes
|
|
219
|
+
* up to `maxInFlight` requests before awaiting any response, refilling as each
|
|
220
|
+
* completes, and returns results in the SAME ORDER as `reqs` (independent of
|
|
221
|
+
* the order the SUT answers).
|
|
222
|
+
*
|
|
223
|
+
* CORRECTNESS CONSTRAINT: every request in `reqs` MUST be independent of the
|
|
224
|
+
* others — no request may depend on another's response, and the SUT must not
|
|
225
|
+
* carry cross-request state that ordering would expose. Dependent or
|
|
226
|
+
* order-sensitive sequences (e.g. keygen→encaps→decaps for a single key, or
|
|
227
|
+
* the timing category's isolated measurements) MUST use serial `send()`
|
|
228
|
+
* instead. See docs/audits/performance.md §7.1.
|
|
229
|
+
*
|
|
230
|
+
* Setting `maxInFlight <= 1` degrades to strictly serial behavior.
|
|
231
|
+
*/
|
|
232
|
+
async sendMany(reqs, maxInFlight = 16) {
|
|
233
|
+
const limit = Math.max(1, Math.floor(maxInFlight));
|
|
234
|
+
const results = new Array(reqs.length);
|
|
235
|
+
let next = 0;
|
|
236
|
+
let firstError;
|
|
237
|
+
const worker = async () => {
|
|
238
|
+
while (firstError === undefined) {
|
|
239
|
+
const i = next++;
|
|
240
|
+
if (i >= reqs.length)
|
|
241
|
+
return;
|
|
242
|
+
try {
|
|
243
|
+
results[i] = await this.send(reqs[i]);
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
// Capture the first failure and stop launching new work; in-flight
|
|
247
|
+
// siblings settle on their own (their results are discarded).
|
|
248
|
+
if (firstError === undefined)
|
|
249
|
+
firstError = err;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const workers = [];
|
|
255
|
+
for (let w = 0; w < Math.min(limit, reqs.length); w++) {
|
|
256
|
+
workers.push(worker());
|
|
257
|
+
}
|
|
258
|
+
await Promise.all(workers);
|
|
259
|
+
if (firstError !== undefined)
|
|
260
|
+
throw firstError;
|
|
261
|
+
return results;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Gracefully shut the SUT down: end stdin, wait briefly for a clean exit,
|
|
265
|
+
* then SIGTERM, then SIGKILL. Idempotent.
|
|
266
|
+
*/
|
|
267
|
+
async close(graceMs = 500) {
|
|
268
|
+
if (this.closed)
|
|
269
|
+
return;
|
|
270
|
+
this.closed = true;
|
|
271
|
+
this.rl.close();
|
|
272
|
+
try {
|
|
273
|
+
this.child.stdin.end();
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
/* already closed */
|
|
277
|
+
}
|
|
278
|
+
const exited = new Promise((resolve) => {
|
|
279
|
+
if (this.child.exitCode !== null || this.child.signalCode !== null) {
|
|
280
|
+
resolve();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
this.child.once("exit", () => resolve());
|
|
284
|
+
});
|
|
285
|
+
const timed = await Promise.race([exited.then(() => true), delay(graceMs).then(() => false)]);
|
|
286
|
+
if (!timed && this.child.exitCode === null) {
|
|
287
|
+
this.child.kill("SIGTERM");
|
|
288
|
+
const killed = await Promise.race([
|
|
289
|
+
exited.then(() => true),
|
|
290
|
+
delay(graceMs).then(() => false),
|
|
291
|
+
]);
|
|
292
|
+
if (!killed && this.child.exitCode === null) {
|
|
293
|
+
this.child.kill("SIGKILL");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function delay(ms) {
|
|
299
|
+
return new Promise((resolve) => {
|
|
300
|
+
const t = setTimeout(resolve, ms);
|
|
301
|
+
if (typeof t.unref === "function")
|
|
302
|
+
t.unref();
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAuC,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAkB,MAAM,eAAe,CAAC;AAEhE,OAAO,EACL,cAAc,EACd,aAAa,GAKd,MAAM,eAAe,CAAC;AAoCvB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAsB;IACtD,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,KAAK;IACL,MAAM;IACN,gEAAgE;IAChE,YAAY;IACZ,aAAa;IACb,QAAQ;IACR,SAAS;IACT,SAAS;CACV,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CACzB,IAAgE,EAChE,YAA+B,OAAO,CAAC,GAAG;IAE1C,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,IAAI,IAAI,C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AC,IAAI,CAAC;gBACvB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;aACjC,CAAC,CAAC;YACH,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;gBAC5C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAClC,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,UAAU;YAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/sizes.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public parameter-size tables for ML-KEM (FIPS 203), ML-DSA (FIPS 204), and
|
|
3
|
+
* SLH-DSA (FIPS 205).
|
|
4
|
+
*
|
|
5
|
+
* These are the ONLY hard-coded cryptographic constants in Sieve. They are
|
|
6
|
+
* public, standardized byte lengths — not secret Known-Answer-Test values.
|
|
7
|
+
* Sieve uses them purely to check that a system-under-test (SUT) emits
|
|
8
|
+
* artifacts of the correct shape; it never derives or fabricates the bytes
|
|
9
|
+
* themselves.
|
|
10
|
+
*
|
|
11
|
+
* Sources:
|
|
12
|
+
* - ML-KEM: NIST FIPS 203, Table 3 (sizes of key/ciphertext byte strings).
|
|
13
|
+
* - ML-DSA: NIST FIPS 204, Table 2 (sizes of key/signature byte strings).
|
|
14
|
+
* - SLH-DSA: NIST FIPS 205, Table 2 (parameter sets) — pk = 2n, sk = 4n,
|
|
15
|
+
* signature lengths per set. The 12 standardized sets pair each of
|
|
16
|
+
* six (security level × s/f) combinations with a SHA2 or SHAKE
|
|
17
|
+
* hash; the public sizes depend only on the level×s/f, so the
|
|
18
|
+
* SHA2 and SHAKE variants share sizes.
|
|
19
|
+
*/
|
|
20
|
+
/** Algorithm families Sieve knows how to drive. */
|
|
21
|
+
export type Family = "ml-kem" | "ml-dsa" | "slh-dsa";
|
|
22
|
+
/** Canonical parameter-set identifiers accepted on the CLI / API. */
|
|
23
|
+
export type ParamSet = "ml-kem-512" | "ml-kem-768" | "ml-kem-1024" | "ml-dsa-44" | "ml-dsa-65" | "ml-dsa-87" | "slh-dsa-sha2-128s" | "slh-dsa-shake-128s" | "slh-dsa-sha2-128f" | "slh-dsa-shake-128f" | "slh-dsa-sha2-192s" | "slh-dsa-shake-192s" | "slh-dsa-sha2-192f" | "slh-dsa-shake-192f" | "slh-dsa-sha2-256s" | "slh-dsa-shake-256s" | "slh-dsa-sha2-256f" | "slh-dsa-shake-256f";
|
|
24
|
+
/** Byte sizes for an ML-KEM parameter set (FIPS 203, Table 3). */
|
|
25
|
+
export interface KemSizes {
|
|
26
|
+
readonly family: "ml-kem";
|
|
27
|
+
readonly id: ParamSet;
|
|
28
|
+
/** Encapsulation (public) key length in bytes. */
|
|
29
|
+
readonly publicKey: number;
|
|
30
|
+
/** Decapsulation (secret) key length in bytes. */
|
|
31
|
+
readonly secretKey: number;
|
|
32
|
+
/** Ciphertext length in bytes. */
|
|
33
|
+
readonly ciphertext: number;
|
|
34
|
+
/** Shared secret length in bytes (32 for every ML-KEM set). */
|
|
35
|
+
readonly sharedSecret: number;
|
|
36
|
+
}
|
|
37
|
+
/** Byte sizes for an ML-DSA parameter set (FIPS 204, Table 2). */
|
|
38
|
+
export interface DsaSizes {
|
|
39
|
+
readonly family: "ml-dsa";
|
|
40
|
+
readonly id: ParamSet;
|
|
41
|
+
/** Verification (public) key length in bytes. */
|
|
42
|
+
readonly publicKey: number;
|
|
43
|
+
/** Signing (secret) key length in bytes. */
|
|
44
|
+
readonly secretKey: number;
|
|
45
|
+
/** Signature length in bytes (fixed-length encoding). */
|
|
46
|
+
readonly signature: number;
|
|
47
|
+
}
|
|
48
|
+
/** Byte sizes for an SLH-DSA parameter set (FIPS 205, Table 2). */
|
|
49
|
+
export interface SlhDsaSizes {
|
|
50
|
+
readonly family: "slh-dsa";
|
|
51
|
+
readonly id: ParamSet;
|
|
52
|
+
/** Verification (public) key length in bytes (= 2·n). */
|
|
53
|
+
readonly publicKey: number;
|
|
54
|
+
/** Signing (secret) key length in bytes (= 4·n). */
|
|
55
|
+
readonly secretKey: number;
|
|
56
|
+
/** Signature length in bytes. */
|
|
57
|
+
readonly signature: number;
|
|
58
|
+
}
|
|
59
|
+
/** Union of the size shapes. */
|
|
60
|
+
export type Sizes = KemSizes | DsaSizes | SlhDsaSizes;
|
|
61
|
+
/** A signature-family size record (ML-DSA or SLH-DSA). */
|
|
62
|
+
export type SignatureSizes = DsaSizes | SlhDsaSizes;
|
|
63
|
+
/** All known parameter-set identifiers, in canonical order. */
|
|
64
|
+
export declare const PARAM_SETS: readonly ParamSet[];
|
|
65
|
+
/** Type guard: is `s` a recognized parameter-set identifier? */
|
|
66
|
+
export declare function isParamSet(s: string): s is ParamSet;
|
|
67
|
+
/**
|
|
68
|
+
* Look up the size record for a parameter set.
|
|
69
|
+
*
|
|
70
|
+
* @throws {RangeError} if `id` is not a recognized parameter set.
|
|
71
|
+
*/
|
|
72
|
+
export declare function sizesFor(id: ParamSet): Sizes;
|
|
73
|
+
/** Narrowing helper: KEM size record or `undefined`. */
|
|
74
|
+
export declare function asKemSizes(s: Sizes): KemSizes | undefined;
|
|
75
|
+
/** Narrowing helper: DSA size record or `undefined`. */
|
|
76
|
+
export declare function asDsaSizes(s: Sizes): DsaSizes | undefined;
|
|
77
|
+
/** Narrowing helper: SLH-DSA size record or `undefined`. */
|
|
78
|
+
export declare function asSlhDsaSizes(s: Sizes): SlhDsaSizes | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Narrowing helper: any signature-family size record (ML-DSA or SLH-DSA) or
|
|
81
|
+
* `undefined`. Both expose `publicKey`, `secretKey`, and `signature`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function asSignatureSizes(s: Sizes): SignatureSizes | undefined;
|
|
84
|
+
//# sourceMappingURL=sizes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sizes.d.ts","sourceRoot":"","sources":["../src/sizes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,mDAAmD;AACnD,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAErD,qEAAqE;AACrE,MAAM,MAAM,QAAQ,GAChB,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,WAAW,GACX,WAAW,GACX,WAAW,GACX,mBAAmB,GACnB,oBAAoB,GACpB,mBAAmB,GACnB,oBAAoB,GACpB,mBAAmB,GACnB,oBAAoB,GACpB,mBAAmB,GACnB,oBAAoB,GACpB,mBAAmB,GACnB,oBAAoB,GACpB,mBAAmB,GACnB,oBAAoB,CAAC;AAEzB,kEAAkE;AAClE,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,kCAAkC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,kEAAkE;AAClE,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,iDAAiD;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3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214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public parameter-size tables for ML-KEM (FIPS 203), ML-DSA (FIPS 204), and
|
|
3
|
+
* SLH-DSA (FIPS 205).
|
|
4
|
+
*
|
|
5
|
+
* These are the ONLY hard-coded cryptographic constants in Sieve. They are
|
|
6
|
+
* public, standardized byte lengths — not secret Known-Answer-Test values.
|
|
7
|
+
* Sieve uses them purely to check that a system-under-test (SUT) emits
|
|
8
|
+
* artifacts of the correct shape; it never derives or fabricates the bytes
|
|
9
|
+
* themselves.
|
|
10
|
+
*
|
|
11
|
+
* Sources:
|
|
12
|
+
* - ML-KEM: NIST FIPS 203, Table 3 (sizes of key/ciphertext byte strings).
|
|
13
|
+
* - ML-DSA: NIST FIPS 204, Table 2 (sizes of key/signature byte strings).
|
|
14
|
+
* - SLH-DSA: NIST FIPS 205, Table 2 (parameter sets) — pk = 2n, sk = 4n,
|
|
15
|
+
* signature lengths per set. The 12 standardized sets pair each of
|
|
16
|
+
* six (security level × s/f) combinations with a SHA2 or SHAKE
|
|
17
|
+
* hash; the public sizes depend only on the level×s/f, so the
|
|
18
|
+
* SHA2 and SHAKE variants share sizes.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* The size table. Values are public, standardized constants.
|
|
22
|
+
*
|
|
23
|
+
* ML-KEM (FIPS 203, Table 3):
|
|
24
|
+
* set pk sk ct ss
|
|
25
|
+
* 512 800 1632 768 32
|
|
26
|
+
* 768 1184 2400 1088 32
|
|
27
|
+
* 1024 1568 3168 1568 32
|
|
28
|
+
*
|
|
29
|
+
* ML-DSA (FIPS 204, Table 2):
|
|
30
|
+
* set pk sk sig
|
|
31
|
+
* 44 1312 2560 2420
|
|
32
|
+
* 65 1952 4032 3309
|
|
33
|
+
* 87 2592 4896 4627
|
|
34
|
+
*
|
|
35
|
+
* SLH-DSA (FIPS 205, Table 2): pk = 2n, sk = 4n; signature length per set.
|
|
36
|
+
* level/var n pk sk sig
|
|
37
|
+
* 128s 16 32 64 7856
|
|
38
|
+
* 128f 16 32 64 17088
|
|
39
|
+
* 192s 24 48 96 16224
|
|
40
|
+
* 192f 24 48 96 35664
|
|
41
|
+
* 256s 32 64 128 29792
|
|
42
|
+
* 256f 32 64 128 49856
|
|
43
|
+
* (SHA2 and SHAKE variants of a given level/var share these public sizes.)
|
|
44
|
+
*/
|
|
45
|
+
const TABLE = {
|
|
46
|
+
"ml-kem-512": {
|
|
47
|
+
family: "ml-kem",
|
|
48
|
+
id: "ml-kem-512",
|
|
49
|
+
publicKey: 800,
|
|
50
|
+
secretKey: 1632,
|
|
51
|
+
ciphertext: 768,
|
|
52
|
+
sharedSecret: 32,
|
|
53
|
+
},
|
|
54
|
+
"ml-kem-768": {
|
|
55
|
+
family: "ml-kem",
|
|
56
|
+
id: "ml-kem-768",
|
|
57
|
+
publicKey: 1184,
|
|
58
|
+
secretKey: 2400,
|
|
59
|
+
ciphertext: 1088,
|
|
60
|
+
sharedSecret: 32,
|
|
61
|
+
},
|
|
62
|
+
"ml-kem-1024": {
|
|
63
|
+
family: "ml-kem",
|
|
64
|
+
id: "ml-kem-1024",
|
|
65
|
+
publicKey: 1568,
|
|
66
|
+
secretKey: 3168,
|
|
67
|
+
ciphertext: 1568,
|
|
68
|
+
sharedSecret: 32,
|
|
69
|
+
},
|
|
70
|
+
"ml-dsa-44": {
|
|
71
|
+
family: "ml-dsa",
|
|
72
|
+
id: "ml-dsa-44",
|
|
73
|
+
publicKey: 1312,
|
|
74
|
+
secretKey: 2560,
|
|
75
|
+
signature: 2420,
|
|
76
|
+
},
|
|
77
|
+
"ml-dsa-65": {
|
|
78
|
+
family: "ml-dsa",
|
|
79
|
+
id: "ml-dsa-65",
|
|
80
|
+
publicKey: 1952,
|
|
81
|
+
secretKey: 4032,
|
|
82
|
+
signature: 3309,
|
|
83
|
+
},
|
|
84
|
+
"ml-dsa-87": {
|
|
85
|
+
family: "ml-dsa",
|
|
86
|
+
id: "ml-dsa-87",
|
|
87
|
+
publicKey: 2592,
|
|
88
|
+
secretKey: 4896,
|
|
89
|
+
signature: 4627,
|
|
90
|
+
},
|
|
91
|
+
// SLH-DSA (FIPS 205, Table 2). SHA2 and SHAKE share sizes per level/variant.
|
|
92
|
+
"slh-dsa-sha2-128s": {
|
|
93
|
+
family: "slh-dsa",
|
|
94
|
+
id: "slh-dsa-sha2-128s",
|
|
95
|
+
publicKey: 32,
|
|
96
|
+
secretKey: 64,
|
|
97
|
+
signature: 7856,
|
|
98
|
+
},
|
|
99
|
+
"slh-dsa-shake-128s": {
|
|
100
|
+
family: "slh-dsa",
|
|
101
|
+
id: "slh-dsa-shake-128s",
|
|
102
|
+
publicKey: 32,
|
|
103
|
+
secretKey: 64,
|
|
104
|
+
signature: 7856,
|
|
105
|
+
},
|
|
106
|
+
"slh-dsa-sha2-128f": {
|
|
107
|
+
family: "slh-dsa",
|
|
108
|
+
id: "slh-dsa-sha2-128f",
|
|
109
|
+
publicKey: 32,
|
|
110
|
+
secretKey: 64,
|
|
111
|
+
signature: 17088,
|
|
112
|
+
},
|
|
113
|
+
"slh-dsa-shake-128f": {
|
|
114
|
+
family: "slh-dsa",
|
|
115
|
+
id: "slh-dsa-shake-128f",
|
|
116
|
+
publicKey: 32,
|
|
117
|
+
secretKey: 64,
|
|
118
|
+
signature: 17088,
|
|
119
|
+
},
|
|
120
|
+
"slh-dsa-sha2-192s": {
|
|
121
|
+
family: "slh-dsa",
|
|
122
|
+
id: "slh-dsa-sha2-192s",
|
|
123
|
+
publicKey: 48,
|
|
124
|
+
secretKey: 96,
|
|
125
|
+
signature: 16224,
|
|
126
|
+
},
|
|
127
|
+
"slh-dsa-shake-192s": {
|
|
128
|
+
family: "slh-dsa",
|
|
129
|
+
id: "slh-dsa-shake-192s",
|
|
130
|
+
publicKey: 48,
|
|
131
|
+
secretKey: 96,
|
|
132
|
+
signature: 16224,
|
|
133
|
+
},
|
|
134
|
+
"slh-dsa-sha2-192f": {
|
|
135
|
+
family: "slh-dsa",
|
|
136
|
+
id: "slh-dsa-sha2-192f",
|
|
137
|
+
publicKey: 48,
|
|
138
|
+
secretKey: 96,
|
|
139
|
+
signature: 35664,
|
|
140
|
+
},
|
|
141
|
+
"slh-dsa-shake-192f": {
|
|
142
|
+
family: "slh-dsa",
|
|
143
|
+
id: "slh-dsa-shake-192f",
|
|
144
|
+
publicKey: 48,
|
|
145
|
+
secretKey: 96,
|
|
146
|
+
signature: 35664,
|
|
147
|
+
},
|
|
148
|
+
"slh-dsa-sha2-256s": {
|
|
149
|
+
family: "slh-dsa",
|
|
150
|
+
id: "slh-dsa-sha2-256s",
|
|
151
|
+
publicKey: 64,
|
|
152
|
+
secretKey: 128,
|
|
153
|
+
signature: 29792,
|
|
154
|
+
},
|
|
155
|
+
"slh-dsa-shake-256s": {
|
|
156
|
+
family: "slh-dsa",
|
|
157
|
+
id: "slh-dsa-shake-256s",
|
|
158
|
+
publicKey: 64,
|
|
159
|
+
secretKey: 128,
|
|
160
|
+
signature: 29792,
|
|
161
|
+
},
|
|
162
|
+
"slh-dsa-sha2-256f": {
|
|
163
|
+
family: "slh-dsa",
|
|
164
|
+
id: "slh-dsa-sha2-256f",
|
|
165
|
+
publicKey: 64,
|
|
166
|
+
secretKey: 128,
|
|
167
|
+
signature: 49856,
|
|
168
|
+
},
|
|
169
|
+
"slh-dsa-shake-256f": {
|
|
170
|
+
family: "slh-dsa",
|
|
171
|
+
id: "slh-dsa-shake-256f",
|
|
172
|
+
publicKey: 64,
|
|
173
|
+
secretKey: 128,
|
|
174
|
+
signature: 49856,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
/** All known parameter-set identifiers, in canonical order. */
|
|
178
|
+
export const PARAM_SETS = Object.keys(TABLE);
|
|
179
|
+
/** Type guard: is `s` a recognized parameter-set identifier? */
|
|
180
|
+
export function isParamSet(s) {
|
|
181
|
+
return Object.prototype.hasOwnProperty.call(TABLE, s);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Look up the size record for a parameter set.
|
|
185
|
+
*
|
|
186
|
+
* @throws {RangeError} if `id` is not a recognized parameter set.
|
|
187
|
+
*/
|
|
188
|
+
export function sizesFor(id) {
|
|
189
|
+
const entry = TABLE[id];
|
|
190
|
+
if (entry === undefined) {
|
|
191
|
+
throw new RangeError(`unknown parameter set: ${id}`);
|
|
192
|
+
}
|
|
193
|
+
return entry;
|
|
194
|
+
}
|
|
195
|
+
/** Narrowing helper: KEM size record or `undefined`. */
|
|
196
|
+
export function asKemSizes(s) {
|
|
197
|
+
return s.family === "ml-kem" ? s : undefined;
|
|
198
|
+
}
|
|
199
|
+
/** Narrowing helper: DSA size record or `undefined`. */
|
|
200
|
+
export function asDsaSizes(s) {
|
|
201
|
+
return s.family === "ml-dsa" ? s : undefined;
|
|
202
|
+
}
|
|
203
|
+
/** Narrowing helper: SLH-DSA size record or `undefined`. */
|
|
204
|
+
export function asSlhDsaSizes(s) {
|
|
205
|
+
return s.family === "slh-dsa" ? s : undefined;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Narrowing helper: any signature-family size record (ML-DSA or SLH-DSA) or
|
|
209
|
+
* `undefined`. Both expose `publicKey`, `secretKey`, and `signature`.
|
|
210
|
+
*/
|
|
211
|
+
export function asSignatureSizes(s) {
|
|
212
|
+
return s.family === "ml-dsa" || s.family === "slh-dsa" ? s : undefined;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=sizes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sizes.js","sourceRoot":"","sources":["../src/sizes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAsEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,KAAK,GAAsC;IAC/C,YAAY,EAAE;QACZ,MAAM,EAAE,QAAQ;QAChB,EAAE,EAAE,YAAY;QAChB,SAAS,EAAE,GAAG;QACd,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,GAAG;QACf,YAAY,EAAE,EAAE;K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