starknet 11.3.0 → 11.4.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/CHANGELOG.md +6 -0
- package/dist/falcon/index.d.ts +352 -0
- package/dist/falcon/index.js +3736 -0
- package/dist/falcon/index.js.map +1 -0
- package/dist/falcon/index.mjs +3723 -0
- package/dist/falcon/index.mjs.map +1 -0
- package/package.json +10 -1
|
@@ -0,0 +1,3736 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/falcon/index.ts
|
|
31
|
+
var falcon_exports = {};
|
|
32
|
+
__export(falcon_exports, {
|
|
33
|
+
Falcon512Signer: () => Falcon512Signer,
|
|
34
|
+
falcon512: () => falcon512_exports
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(falcon_exports);
|
|
37
|
+
|
|
38
|
+
// src/falcon/Falcon512Signer.ts
|
|
39
|
+
var starknet6 = __toESM(require("starknet"));
|
|
40
|
+
|
|
41
|
+
// src/falcon/s2morrow/keys.ts
|
|
42
|
+
var import_utils6 = require("@noble/hashes/utils.js");
|
|
43
|
+
var starknet3 = __toESM(require("starknet"));
|
|
44
|
+
|
|
45
|
+
// src/falcon/engine/noble/falcon.ts
|
|
46
|
+
var import_aes = require("@noble/ciphers/aes.js");
|
|
47
|
+
var import_chacha = require("@noble/ciphers/chacha.js");
|
|
48
|
+
var import_fft2 = require("@noble/curves/abstract/fft.js");
|
|
49
|
+
var import_modular = require("@noble/curves/abstract/modular.js");
|
|
50
|
+
var import_utils3 = require("@noble/curves/utils.js");
|
|
51
|
+
var import_sha32 = require("@noble/hashes/sha3.js");
|
|
52
|
+
var import_utils4 = require("@noble/hashes/utils.js");
|
|
53
|
+
|
|
54
|
+
// src/falcon/engine/noble/_crystals.ts
|
|
55
|
+
var import_fft = require("@noble/curves/abstract/fft.js");
|
|
56
|
+
var import_sha3 = require("@noble/hashes/sha3.js");
|
|
57
|
+
|
|
58
|
+
// src/falcon/engine/noble/utils.ts
|
|
59
|
+
var import_utils = require("@noble/hashes/utils.js");
|
|
60
|
+
function aobject(value, title = "object") {
|
|
61
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
62
|
+
throw new TypeError(
|
|
63
|
+
title === "object" ? "expected valid options object" : `"${title}" expected object, got type=${typeof value}`
|
|
64
|
+
);
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
function copyBytes(bytes) {
|
|
68
|
+
return new Uint8Array((0, import_utils.abytes)(bytes));
|
|
69
|
+
}
|
|
70
|
+
function byteSwap64(arr) {
|
|
71
|
+
const bytes = new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
72
|
+
for (let i = 0; i < bytes.length; i += 8) {
|
|
73
|
+
const a0 = bytes[i + 0];
|
|
74
|
+
const a1 = bytes[i + 1];
|
|
75
|
+
const a2 = bytes[i + 2];
|
|
76
|
+
const a3 = bytes[i + 3];
|
|
77
|
+
bytes[i + 0] = bytes[i + 7];
|
|
78
|
+
bytes[i + 1] = bytes[i + 6];
|
|
79
|
+
bytes[i + 2] = bytes[i + 5];
|
|
80
|
+
bytes[i + 3] = bytes[i + 4];
|
|
81
|
+
bytes[i + 4] = a3;
|
|
82
|
+
bytes[i + 5] = a2;
|
|
83
|
+
bytes[i + 6] = a1;
|
|
84
|
+
bytes[i + 7] = a0;
|
|
85
|
+
}
|
|
86
|
+
return arr;
|
|
87
|
+
}
|
|
88
|
+
var baswap64If = import_utils.isLE ? (arr) => arr : byteSwap64;
|
|
89
|
+
function validateOpts(opts) {
|
|
90
|
+
if ((0, import_utils.isBytes)(opts)) throw new TypeError('"opts" expected object, got Uint8Array');
|
|
91
|
+
aobject(opts, "opts");
|
|
92
|
+
const proto = Object.getPrototypeOf(opts);
|
|
93
|
+
if (proto !== null && proto !== Object.prototype)
|
|
94
|
+
throw new TypeError('"opts" expected a plain object');
|
|
95
|
+
}
|
|
96
|
+
var VER_OPT_KEYS = /* @__PURE__ */ Object.freeze([
|
|
97
|
+
"context"
|
|
98
|
+
]);
|
|
99
|
+
var SIG_OPT_KEYS = /* @__PURE__ */ Object.freeze([
|
|
100
|
+
"context",
|
|
101
|
+
"extraEntropy"
|
|
102
|
+
]);
|
|
103
|
+
function checkOptKeys(opts, allowed) {
|
|
104
|
+
validateOpts(opts);
|
|
105
|
+
const normalized = Object.assign(/* @__PURE__ */ Object.create(null), opts);
|
|
106
|
+
for (const [k, v] of Object.entries(normalized)) {
|
|
107
|
+
if (v === void 0) continue;
|
|
108
|
+
if (!allowed.includes(k))
|
|
109
|
+
throw new TypeError(
|
|
110
|
+
'unexpected option "' + String(k) + '"; expected one of: ' + allowed.join(", ")
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return Object.freeze(normalized);
|
|
114
|
+
}
|
|
115
|
+
function validateVerOpts(opts, allowed = VER_OPT_KEYS) {
|
|
116
|
+
const normalized = checkOptKeys(opts, allowed);
|
|
117
|
+
if (normalized.context !== void 0) (0, import_utils.abytes)(normalized.context, void 0, "opts.context");
|
|
118
|
+
return normalized;
|
|
119
|
+
}
|
|
120
|
+
function validateSigOpts(opts, allowed = SIG_OPT_KEYS) {
|
|
121
|
+
const normalized = checkOptKeys(opts, allowed);
|
|
122
|
+
if (normalized.context !== void 0) (0, import_utils.abytes)(normalized.context, void 0, "opts.context");
|
|
123
|
+
if (normalized.extraEntropy !== false && normalized.extraEntropy !== void 0)
|
|
124
|
+
(0, import_utils.abytes)(normalized.extraEntropy, void 0, "opts.extraEntropy");
|
|
125
|
+
return normalized;
|
|
126
|
+
}
|
|
127
|
+
function splitCoder(label, ...lengths) {
|
|
128
|
+
const getLength = (c) => typeof c === "number" ? c : c.bytesLen;
|
|
129
|
+
const bytesLen = lengths.reduce((sum, a) => sum + getLength(a), 0);
|
|
130
|
+
return {
|
|
131
|
+
bytesLen,
|
|
132
|
+
encode: (bufs) => {
|
|
133
|
+
const res = new Uint8Array(bytesLen);
|
|
134
|
+
for (let i = 0, pos = 0; i < lengths.length; i++) {
|
|
135
|
+
const c = lengths[i];
|
|
136
|
+
const l = getLength(c);
|
|
137
|
+
const b = typeof c === "number" ? bufs[i] : c.encode(bufs[i]);
|
|
138
|
+
(0, import_utils.abytes)(b, l, label);
|
|
139
|
+
res.set(b, pos);
|
|
140
|
+
if (typeof c !== "number") b.fill(0);
|
|
141
|
+
pos += l;
|
|
142
|
+
}
|
|
143
|
+
return res;
|
|
144
|
+
},
|
|
145
|
+
decode: (buf) => {
|
|
146
|
+
(0, import_utils.abytes)(buf, bytesLen, label);
|
|
147
|
+
const res = [];
|
|
148
|
+
for (const c of lengths) {
|
|
149
|
+
const l = getLength(c);
|
|
150
|
+
const b = buf.subarray(0, l);
|
|
151
|
+
res.push(typeof c === "number" ? b : c.decode(b));
|
|
152
|
+
buf = buf.subarray(l);
|
|
153
|
+
}
|
|
154
|
+
return res;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function cleanBytes(...list) {
|
|
159
|
+
for (const t of list) {
|
|
160
|
+
if (Array.isArray(t)) for (const b of t) b.fill(0);
|
|
161
|
+
else t.fill(0);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function getMask(bits) {
|
|
165
|
+
(0, import_utils.anumber)(bits, "bits");
|
|
166
|
+
if (bits > 32) throw new RangeError('"bits" expected <= 32, got ' + bits);
|
|
167
|
+
return bits === 32 ? 4294967295 : ~(-1 << bits) >>> 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/falcon/engine/noble/_crystals.ts
|
|
171
|
+
var genCrystals = (opts) => {
|
|
172
|
+
const { newPoly, N: N2, Q: Q3, F, ROOT_OF_UNITY, brvBits, isKyber } = opts;
|
|
173
|
+
const mod = (a, modulo = Q3) => {
|
|
174
|
+
const result = a % modulo | 0;
|
|
175
|
+
return (result >= 0 ? result | 0 : modulo + result | 0) | 0;
|
|
176
|
+
};
|
|
177
|
+
const smod = (a, modulo = Q3) => {
|
|
178
|
+
const r = mod(a, modulo) | 0;
|
|
179
|
+
return (r > modulo >> 1 ? r - modulo | 0 : r) | 0;
|
|
180
|
+
};
|
|
181
|
+
function getZettas() {
|
|
182
|
+
const out = newPoly(N2);
|
|
183
|
+
for (let i = 0; i < N2; i++) {
|
|
184
|
+
const b = (0, import_fft.reverseBits)(i, brvBits);
|
|
185
|
+
const p = BigInt(ROOT_OF_UNITY) ** BigInt(b) % BigInt(Q3);
|
|
186
|
+
out[i] = Number(p) | 0;
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
const nttZetas = getZettas();
|
|
191
|
+
const inv = (_a) => {
|
|
192
|
+
throw new Error("not implemented");
|
|
193
|
+
};
|
|
194
|
+
const field = isKyber ? {
|
|
195
|
+
add: (a, b) => {
|
|
196
|
+
const r = a + b | 0;
|
|
197
|
+
return r >= Q3 ? r - Q3 | 0 : r;
|
|
198
|
+
},
|
|
199
|
+
sub: (a, b) => {
|
|
200
|
+
const r = a - b | 0;
|
|
201
|
+
return r < 0 ? r + Q3 | 0 : r;
|
|
202
|
+
},
|
|
203
|
+
mul: (a, b) => mod((a | 0) * (b | 0)) | 0,
|
|
204
|
+
inv
|
|
205
|
+
} : {
|
|
206
|
+
add: (a, b) => mod((a | 0) + (b | 0)) | 0,
|
|
207
|
+
sub: (a, b) => mod((a | 0) - (b | 0)) | 0,
|
|
208
|
+
mul: (a, b) => mod((a | 0) * (b | 0)) | 0,
|
|
209
|
+
inv
|
|
210
|
+
};
|
|
211
|
+
const nttOpts = {
|
|
212
|
+
N: N2,
|
|
213
|
+
roots: nttZetas,
|
|
214
|
+
invertButterflies: true,
|
|
215
|
+
skipStages: isKyber ? 1 : 0,
|
|
216
|
+
brp: false
|
|
217
|
+
};
|
|
218
|
+
const dif = (0, import_fft.FFTCore)(field, { dit: false, ...nttOpts });
|
|
219
|
+
const dit = (0, import_fft.FFTCore)(field, { dit: true, ...nttOpts });
|
|
220
|
+
const NTT = {
|
|
221
|
+
encode: (r) => {
|
|
222
|
+
return dif(r);
|
|
223
|
+
},
|
|
224
|
+
decode: (r) => {
|
|
225
|
+
dit(r);
|
|
226
|
+
for (let i = 0; i < r.length; i++) r[i] = mod(F * r[i]);
|
|
227
|
+
return r;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const bitsCoder = (d, c) => {
|
|
231
|
+
for (let i = 0, bufLen = 0; i < N2; i++) {
|
|
232
|
+
bufLen += d;
|
|
233
|
+
if (bufLen > 32) getMask(bufLen);
|
|
234
|
+
bufLen %= 8;
|
|
235
|
+
}
|
|
236
|
+
const mask = getMask(d);
|
|
237
|
+
const bytesLen = d * (N2 / 8);
|
|
238
|
+
return {
|
|
239
|
+
bytesLen,
|
|
240
|
+
encode: (poly_) => {
|
|
241
|
+
const poly = poly_;
|
|
242
|
+
const r = new Uint8Array(bytesLen);
|
|
243
|
+
for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < poly.length; i++) {
|
|
244
|
+
buf |= (c.encode(poly[i]) & mask) << bufLen;
|
|
245
|
+
bufLen += d;
|
|
246
|
+
for (; bufLen >= 8; bufLen -= 8, buf >>= 8) r[pos++] = buf & 255;
|
|
247
|
+
}
|
|
248
|
+
return r;
|
|
249
|
+
},
|
|
250
|
+
decode: (bytes) => {
|
|
251
|
+
const r = newPoly(N2);
|
|
252
|
+
for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < bytes.length; i++) {
|
|
253
|
+
buf |= bytes[i] << bufLen;
|
|
254
|
+
bufLen += 8;
|
|
255
|
+
for (; bufLen >= d; bufLen -= d, buf >>= d) r[pos++] = c.decode(buf & mask);
|
|
256
|
+
}
|
|
257
|
+
return r;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
return {
|
|
262
|
+
mod,
|
|
263
|
+
smod,
|
|
264
|
+
nttZetas,
|
|
265
|
+
NTT: {
|
|
266
|
+
encode: (r) => NTT.encode(r),
|
|
267
|
+
decode: (r) => NTT.decode(r)
|
|
268
|
+
},
|
|
269
|
+
bitsCoder
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/falcon/engine/noble/falcon.ts
|
|
274
|
+
var bitsCoderMSB = (newPoly, N2, d, c) => {
|
|
275
|
+
const mask = getMask(d);
|
|
276
|
+
const bytesLen = d * (N2 / 8);
|
|
277
|
+
return {
|
|
278
|
+
bytesLen,
|
|
279
|
+
encode: (poly) => {
|
|
280
|
+
if (poly.length !== N2) throw new Error(`wrong length: expected ${N2}, got ${poly.length}`);
|
|
281
|
+
const r = new Uint8Array(bytesLen);
|
|
282
|
+
for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < poly.length; i++) {
|
|
283
|
+
buf = buf << d | c.encode(poly[i]) & mask;
|
|
284
|
+
bufLen += d;
|
|
285
|
+
for (; bufLen >= 8; bufLen -= 8) r[pos++] = buf >>> bufLen - 8 & 255;
|
|
286
|
+
}
|
|
287
|
+
return r;
|
|
288
|
+
},
|
|
289
|
+
decode: (bytes) => {
|
|
290
|
+
const r = newPoly(N2);
|
|
291
|
+
for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < bytes.length; i++) {
|
|
292
|
+
buf = buf << 8 | bytes[i];
|
|
293
|
+
bufLen += 8;
|
|
294
|
+
for (; bufLen >= d; bufLen -= d) r[pos++] = c.decode(buf >>> bufLen - d & mask);
|
|
295
|
+
}
|
|
296
|
+
return r;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
var headerCoder = (tag, restCoder) => {
|
|
301
|
+
const coder = restCoder;
|
|
302
|
+
return {
|
|
303
|
+
bytesLen: 1 + coder.bytesLen,
|
|
304
|
+
encode(value) {
|
|
305
|
+
const body = coder.encode(value);
|
|
306
|
+
const out = new Uint8Array(1 + body.length);
|
|
307
|
+
out[0] = tag;
|
|
308
|
+
out.set(body, 1);
|
|
309
|
+
cleanBytes(body);
|
|
310
|
+
return out;
|
|
311
|
+
},
|
|
312
|
+
decode(data) {
|
|
313
|
+
if (data[0] !== tag) throw new Error(`wrong tag: expected ${tag}, got 0x${data[0]}`);
|
|
314
|
+
return coder.decode(data.subarray(1));
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
var compCoder = (n) => {
|
|
319
|
+
const LIMIT = 2047;
|
|
320
|
+
return {
|
|
321
|
+
encode(data) {
|
|
322
|
+
if (data.length !== n) throw new Error("wrong length");
|
|
323
|
+
const res = [];
|
|
324
|
+
let buf = 0;
|
|
325
|
+
let bufLen = 0;
|
|
326
|
+
const writeBits = (n2, v) => {
|
|
327
|
+
bufLen += n2;
|
|
328
|
+
buf = buf << n2 | v;
|
|
329
|
+
for (; bufLen >= 8; buf &= getMask(bufLen)) {
|
|
330
|
+
bufLen -= 8;
|
|
331
|
+
res.push(buf >>> bufLen & 255);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
for (let i = 0; i < n; i++) {
|
|
335
|
+
let v = data[i];
|
|
336
|
+
if (!Number.isInteger(v) || v < -LIMIT || v > LIMIT)
|
|
337
|
+
throw new Error(`data[${i}]=${v} out of range`);
|
|
338
|
+
const sign = v < 0 ? 1 : 0;
|
|
339
|
+
v = Math.abs(v);
|
|
340
|
+
writeBits(1, sign);
|
|
341
|
+
writeBits(7, v & 127);
|
|
342
|
+
writeBits((v >>> 7) + 1, 1);
|
|
343
|
+
}
|
|
344
|
+
if (bufLen > 0) res.push(buf << 8 - bufLen & 255);
|
|
345
|
+
return new Uint8Array(res);
|
|
346
|
+
},
|
|
347
|
+
decode(data) {
|
|
348
|
+
const res = new Int16Array(n);
|
|
349
|
+
let buf = 0;
|
|
350
|
+
let bufLen = 0;
|
|
351
|
+
let pos = 0;
|
|
352
|
+
const readBits = (n2) => {
|
|
353
|
+
for (; bufLen < n2 && pos < data.length; bufLen += 8) buf = buf << 8 | data[pos++];
|
|
354
|
+
if (bufLen < n2)
|
|
355
|
+
throw new Error(`end of buffer: len=${bufLen} buf=${buf} lastByte=${data[pos]}`);
|
|
356
|
+
bufLen -= n2;
|
|
357
|
+
const val = buf >>> bufLen;
|
|
358
|
+
buf &= getMask(bufLen);
|
|
359
|
+
return val;
|
|
360
|
+
};
|
|
361
|
+
for (let resPos = 0; resPos < n; resPos++) {
|
|
362
|
+
const sign = readBits(1);
|
|
363
|
+
const low = readBits(7);
|
|
364
|
+
let high = 0;
|
|
365
|
+
while (!readBits(1)) {
|
|
366
|
+
high++;
|
|
367
|
+
if (high > LIMIT >>> 7) throw new Error(`limit: ${low | high << 7} > ${LIMIT}`);
|
|
368
|
+
}
|
|
369
|
+
const v = low | high << 7;
|
|
370
|
+
if (sign && v === 0) throw new Error("negative zero encoding");
|
|
371
|
+
if (v > LIMIT) throw new Error(`limit: ${v} > ${LIMIT}`);
|
|
372
|
+
res[resPos] = sign ? -v : v;
|
|
373
|
+
}
|
|
374
|
+
if (buf) throw new Error("non-empty accumulator");
|
|
375
|
+
return res;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
var pad = (len) => ({
|
|
380
|
+
encode(data) {
|
|
381
|
+
const res = new Uint8Array(len);
|
|
382
|
+
res.set(data);
|
|
383
|
+
return res;
|
|
384
|
+
},
|
|
385
|
+
decode(data) {
|
|
386
|
+
let end = data.length;
|
|
387
|
+
while (end > 0 && data[end - 1] === 0) end--;
|
|
388
|
+
return data.subarray(0, end);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
var cleanCPoly = (...list) => {
|
|
392
|
+
for (const p of list) {
|
|
393
|
+
for (let i = 0; i < p.length; i++) {
|
|
394
|
+
p[i].re = 0;
|
|
395
|
+
p[i].im = 0;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
function getComplex(field) {
|
|
400
|
+
const F = field;
|
|
401
|
+
return {
|
|
402
|
+
lift: (x) => {
|
|
403
|
+
if (x.re !== void 0 && x.im !== void 0) return x;
|
|
404
|
+
return { re: x, im: F.ZERO };
|
|
405
|
+
},
|
|
406
|
+
add: (a, b) => ({
|
|
407
|
+
re: F.add(a.re, b.re),
|
|
408
|
+
im: F.add(a.im, b.im)
|
|
409
|
+
}),
|
|
410
|
+
sub: (a, b) => ({
|
|
411
|
+
re: F.sub(a.re, b.re),
|
|
412
|
+
im: F.sub(a.im, b.im)
|
|
413
|
+
}),
|
|
414
|
+
mul: (a, b) => ({
|
|
415
|
+
re: F.sub(F.mul(a.re, b.re), F.mul(a.im, b.im)),
|
|
416
|
+
im: F.add(F.mul(a.re, b.im), F.mul(a.im, b.re))
|
|
417
|
+
}),
|
|
418
|
+
div: (a, b) => {
|
|
419
|
+
const denom = F.add(F.mul(b.re, b.re), F.mul(b.im, b.im));
|
|
420
|
+
return {
|
|
421
|
+
re: F.div(F.add(F.mul(a.re, b.re), F.mul(a.im, b.im)), denom),
|
|
422
|
+
im: F.div(F.sub(F.mul(a.im, b.re), F.mul(a.re, b.im)), denom)
|
|
423
|
+
};
|
|
424
|
+
},
|
|
425
|
+
neg: (a) => ({ re: F.neg(a.re), im: F.neg(a.im) }),
|
|
426
|
+
conj: (a) => ({ re: a.re, im: F.neg(a.im) }),
|
|
427
|
+
scale: (a, x) => ({
|
|
428
|
+
re: F.mul(a.re, x),
|
|
429
|
+
im: F.mul(a.im, x)
|
|
430
|
+
}),
|
|
431
|
+
// a.re * a.re + a.im * a.im + b.re * b.re + b.im * b.im;
|
|
432
|
+
magSqSum: (a, b) => F.add(
|
|
433
|
+
F.add(F.add(F.mul(a.re, a.re), F.mul(a.im, a.im)), F.mul(b.re, b.re)),
|
|
434
|
+
F.mul(b.im, b.im)
|
|
435
|
+
),
|
|
436
|
+
eql: (a, b) => F.eql(a.re, b.re) && F.eql(a.im, b.im),
|
|
437
|
+
clone: (a) => ({ re: a.re, im: a.im }),
|
|
438
|
+
inv: () => {
|
|
439
|
+
throw new Error("not implemented");
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
var ComplexArr = {
|
|
444
|
+
decode(lst) {
|
|
445
|
+
const N2 = lst.length;
|
|
446
|
+
const hn = N2 >> 1;
|
|
447
|
+
const len = lst.length;
|
|
448
|
+
if (len === 0) return [];
|
|
449
|
+
if (len % 2 !== 0)
|
|
450
|
+
throw new Error("Array length must be even to pair real and imaginary parts.");
|
|
451
|
+
const res = [];
|
|
452
|
+
for (let i = 0; i < hn; i++) {
|
|
453
|
+
res.push({ re: lst[i], im: lst[i + hn] });
|
|
454
|
+
}
|
|
455
|
+
return res;
|
|
456
|
+
},
|
|
457
|
+
encode(lst) {
|
|
458
|
+
const re = [];
|
|
459
|
+
const im = [];
|
|
460
|
+
for (const i of lst) {
|
|
461
|
+
re.push(i.re);
|
|
462
|
+
im.push(i.im);
|
|
463
|
+
}
|
|
464
|
+
return [...re, ...im];
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
var ComplexArrInterleaved = {
|
|
468
|
+
decode(lst) {
|
|
469
|
+
const len = lst.length;
|
|
470
|
+
if (len === 0) return [];
|
|
471
|
+
if (len % 2 !== 0)
|
|
472
|
+
throw new Error("Array length must be even to pair real and imaginary parts.");
|
|
473
|
+
const res = [];
|
|
474
|
+
for (let i = 0; i < len; i += 2) {
|
|
475
|
+
res.push({ re: lst[i], im: lst[i + 1] });
|
|
476
|
+
}
|
|
477
|
+
return res;
|
|
478
|
+
},
|
|
479
|
+
encode(lst) {
|
|
480
|
+
const res = [];
|
|
481
|
+
for (const complexNum of lst) {
|
|
482
|
+
res.push(complexNum.re);
|
|
483
|
+
res.push(complexNum.im);
|
|
484
|
+
}
|
|
485
|
+
return res;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
var u8f = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
489
|
+
var f64a = (arr) => new Float64Array(
|
|
490
|
+
baswap64If(Uint8Array.from(arr.subarray(0, Math.floor(arr.byteLength / 8) * 8))).buffer
|
|
491
|
+
);
|
|
492
|
+
var Float = /* @__PURE__ */ Object.freeze({
|
|
493
|
+
encode(n) {
|
|
494
|
+
const bytes = new Uint8Array(8);
|
|
495
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
496
|
+
view.setFloat64(0, n, false);
|
|
497
|
+
return (0, import_utils4.bytesToHex)(bytes);
|
|
498
|
+
},
|
|
499
|
+
decode(s) {
|
|
500
|
+
const bytes = (0, import_utils4.hexToBytes)(s);
|
|
501
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
502
|
+
return view.getFloat64(0, false);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
var f64b = (n) => Float.decode((0, import_utils3.numberToHexUnpadded)(n));
|
|
506
|
+
var EMPTY_CHACHA20_BLOCK = /* @__PURE__ */ new Uint8Array(64);
|
|
507
|
+
var NONCELEN = 40;
|
|
508
|
+
var Q = 12289;
|
|
509
|
+
var Qhalf = Q >> 1;
|
|
510
|
+
var QBig = BigInt(Q);
|
|
511
|
+
var _0n = /* @__PURE__ */ BigInt(0);
|
|
512
|
+
var _1n = /* @__PURE__ */ BigInt(1);
|
|
513
|
+
var _10n = /* @__PURE__ */ BigInt(10);
|
|
514
|
+
var _25n = /* @__PURE__ */ BigInt(25);
|
|
515
|
+
var _31n = /* @__PURE__ */ BigInt(31);
|
|
516
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
517
|
+
var _63n = /* @__PURE__ */ BigInt(63);
|
|
518
|
+
var _64n = /* @__PURE__ */ BigInt(64);
|
|
519
|
+
var MASK_32n = /* @__PURE__ */ BigInt("0xffffffff");
|
|
520
|
+
var MASK_63n = /* @__PURE__ */ BigInt("0x7fffffffffffffff");
|
|
521
|
+
var R2 = 10952;
|
|
522
|
+
var Q0I = 12287;
|
|
523
|
+
var F_INV_Q = 1 / Q;
|
|
524
|
+
var F_MINUS_INV_Q = -F_INV_Q;
|
|
525
|
+
var MAX_BL_SMALL = [1, 1, 2, 2, 4, 7, 14, 27, 53, 106, 209];
|
|
526
|
+
var MAX_BL_LARGE = [2, 2, 5, 7, 12, 21, 40, 78, 157, 308];
|
|
527
|
+
var BNORM_MAX = f64b(BigInt("4670353323383631276"));
|
|
528
|
+
var BITLENGTH = [
|
|
529
|
+
{ avg: 4, std: 0 },
|
|
530
|
+
{ avg: 11, std: 1 },
|
|
531
|
+
{ avg: 24, std: 1 },
|
|
532
|
+
{ avg: 50, std: 1 },
|
|
533
|
+
{ avg: 102, std: 1 },
|
|
534
|
+
{ avg: 202, std: 2 },
|
|
535
|
+
{ avg: 401, std: 4 },
|
|
536
|
+
{ avg: 794, std: 5 },
|
|
537
|
+
{ avg: 1577, std: 8 },
|
|
538
|
+
{ avg: 3138, std: 13 },
|
|
539
|
+
{ avg: 6308, std: 25 }
|
|
540
|
+
];
|
|
541
|
+
var gauss_1024_12289 = /* @__PURE__ */ [
|
|
542
|
+
"1283868770400643928",
|
|
543
|
+
"6416574995475331444",
|
|
544
|
+
"4078260278032692663",
|
|
545
|
+
"2353523259288686585",
|
|
546
|
+
"1227179971273316331",
|
|
547
|
+
"575931623374121527",
|
|
548
|
+
"242543240509105209",
|
|
549
|
+
"91437049221049666",
|
|
550
|
+
"30799446349977173",
|
|
551
|
+
"9255276791179340",
|
|
552
|
+
"2478152334826140",
|
|
553
|
+
"590642893610164",
|
|
554
|
+
"125206034929641",
|
|
555
|
+
"23590435911403",
|
|
556
|
+
"3948334035941",
|
|
557
|
+
"586753615614",
|
|
558
|
+
"77391054539",
|
|
559
|
+
"9056793210",
|
|
560
|
+
"940121950",
|
|
561
|
+
"86539696",
|
|
562
|
+
"7062824",
|
|
563
|
+
"510971",
|
|
564
|
+
"32764",
|
|
565
|
+
"1862",
|
|
566
|
+
"94",
|
|
567
|
+
"4",
|
|
568
|
+
"0"
|
|
569
|
+
].map(BigInt);
|
|
570
|
+
var INV_SIGMA = /* @__PURE__ */ Object.freeze([
|
|
571
|
+
0,
|
|
572
|
+
// unused
|
|
573
|
+
f64b(BigInt("4574611497772390042")),
|
|
574
|
+
f64b(BigInt("4574501679055810265")),
|
|
575
|
+
f64b(BigInt("4574396282908341804")),
|
|
576
|
+
f64b(BigInt("4574245855758572086")),
|
|
577
|
+
f64b(BigInt("4574103865040221165")),
|
|
578
|
+
f64b(BigInt("4573969550563515544")),
|
|
579
|
+
f64b(BigInt("4573842244705920822")),
|
|
580
|
+
f64b(BigInt("4573721358406441454")),
|
|
581
|
+
f64b(BigInt("4573606369665796042")),
|
|
582
|
+
f64b(BigInt("4573496814039276259"))
|
|
583
|
+
]);
|
|
584
|
+
var SIGMA_MIN = /* @__PURE__ */ Object.freeze([
|
|
585
|
+
0,
|
|
586
|
+
// unused
|
|
587
|
+
f64b(BigInt("4607707126469777035")),
|
|
588
|
+
f64b(BigInt("4607777455861499430")),
|
|
589
|
+
f64b(BigInt("4607846828256951418")),
|
|
590
|
+
f64b(BigInt("4607949175006100261")),
|
|
591
|
+
f64b(BigInt("4608049571757433526")),
|
|
592
|
+
f64b(BigInt("4608148125896792003")),
|
|
593
|
+
f64b(BigInt("4608244935301382692")),
|
|
594
|
+
f64b(BigInt("4608340089478362016")),
|
|
595
|
+
f64b(BigInt("4608433670533905013")),
|
|
596
|
+
f64b(BigInt("4608525754002622308"))
|
|
597
|
+
]);
|
|
598
|
+
var SIGMA_MAX = 1.8205;
|
|
599
|
+
var GAUSS0 = new Uint32Array([
|
|
600
|
+
10745844,
|
|
601
|
+
3068844,
|
|
602
|
+
3741698,
|
|
603
|
+
5559083,
|
|
604
|
+
1580863,
|
|
605
|
+
8248194,
|
|
606
|
+
2260429,
|
|
607
|
+
13669192,
|
|
608
|
+
2736639,
|
|
609
|
+
708981,
|
|
610
|
+
4421575,
|
|
611
|
+
10046180,
|
|
612
|
+
169348,
|
|
613
|
+
7122675,
|
|
614
|
+
4136815,
|
|
615
|
+
30538,
|
|
616
|
+
13063405,
|
|
617
|
+
7650655,
|
|
618
|
+
4132,
|
|
619
|
+
14505003,
|
|
620
|
+
7826148,
|
|
621
|
+
417,
|
|
622
|
+
16768101,
|
|
623
|
+
11363290,
|
|
624
|
+
31,
|
|
625
|
+
8444042,
|
|
626
|
+
8086568,
|
|
627
|
+
1,
|
|
628
|
+
12844466,
|
|
629
|
+
265321,
|
|
630
|
+
0,
|
|
631
|
+
1232676,
|
|
632
|
+
13644283,
|
|
633
|
+
0,
|
|
634
|
+
38047,
|
|
635
|
+
9111839,
|
|
636
|
+
0,
|
|
637
|
+
870,
|
|
638
|
+
6138264,
|
|
639
|
+
0,
|
|
640
|
+
14,
|
|
641
|
+
12545723,
|
|
642
|
+
0,
|
|
643
|
+
0,
|
|
644
|
+
3104126,
|
|
645
|
+
0,
|
|
646
|
+
0,
|
|
647
|
+
28824,
|
|
648
|
+
0,
|
|
649
|
+
0,
|
|
650
|
+
198,
|
|
651
|
+
0,
|
|
652
|
+
0,
|
|
653
|
+
1
|
|
654
|
+
]);
|
|
655
|
+
var L2BOUND = [
|
|
656
|
+
0,
|
|
657
|
+
// unused
|
|
658
|
+
101498,
|
|
659
|
+
208714,
|
|
660
|
+
428865,
|
|
661
|
+
892039,
|
|
662
|
+
1852696,
|
|
663
|
+
3842630,
|
|
664
|
+
7959734,
|
|
665
|
+
16468416,
|
|
666
|
+
34034726,
|
|
667
|
+
70265242
|
|
668
|
+
];
|
|
669
|
+
var COMPLEX_ROOTS = /* @__PURE__ */ (() => {
|
|
670
|
+
const roots = f64a(
|
|
671
|
+
(0, import_utils4.hexToBytes)(
|
|
672
|
+
"000000000000000000000000000000000000000000000080000000000000f03fcd3b7f669ea0e63fcd3b7f669ea0e63fcd3b7f669ea0e6bfcd3b7f669ea0e63f468d32cf6b90ed3f63a9aea6e27dd83f63a9aea6e27dd8bf468d32cf6b90ed3f63a9aea6e27dd83f468d32cf6b90ed3f468d32cf6b90edbf63a9aea6e27dd83fb05cf7cf9762ef3f0ba6693cb8f8c83f0ba6693cb8f8c8bfb05cf7cf9762ef3fc868ae393bc7e13fa3a10e29669bea3fa3a10e29669beabfc868ae393bc7e13fa3a10e29669bea3fc868ae393bc7e13fc868ae393bc7e1bfa3a10e29669bea3f0ba6693cb8f8c83fb05cf7cf9762ef3fb05cf7cf9762efbf0ba6693cb8f8c83f2625d1a38dd8ef3f2cb429bca617b93f2cb429bca617b9bf2625d1a38dd8ef3fd61d0925f34ce43f4117156b80bce83f4117156b80bce8bfd61d0925f34ce43fb1bd80f1b238ec3f3bf606385d2bde3f3bf606385d2bdebfb1bd80f1b238ec3f069fd52e0694d23fda2dc656419fee3fda2dc656419feebf069fd52e0694d23fda2dc656419fee3f069fd52e0694d23f069fd52e0694d2bfda2dc656419fee3f3bf606385d2bde3fb1bd80f1b238ec3fb1bd80f1b238ecbf3bf606385d2bde3f4117156b80bce83fd61d0925f34ce43fd61d0925f34ce4bf4117156b80bce83f2cb429bca617b93f2625d1a38dd8ef3f2625d1a38dd8efbf2cb429bca617b93f7e6d79e321f6ef3f14d80df1651fa93f14d80df1651fa9bf7e6d79e321f6ef3fa0ec8c34697de53fafaf6a22dfb5e73fafaf6a22dfb5e7bfa0ec8c34697de53f73c73cf47aedec3fc05ce109105ddb3fc05ce109105ddbbf73c73cf47aedec3fdd1fab759a8fd53fe586f6042121ee3fe586f6042121eebfdd1fab759a8fd53fd73092fb7e0aef3f1b5f217bf919cf3f1b5f217bf919cfbfd73092fb7e0aef3feeff22998773e03f3e6e19458372eb3f3e6e19458372ebbfeeff22998773e03f4187f347e0b3e93f3570e1fcf70fe33f3570e1fcf70fe3bf4187f347e0b3e93f3a618e6e10c8c23f17a5087f55a7ef3f17a5087f55a7efbf3a618e6e10c8c23f17a5087f55a7ef3f3a618e6e10c8c23f3a618e6e10c8c2bf17a5087f55a7ef3f3570e1fcf70fe33f4187f347e0b3e93f4187f347e0b3e9bf3570e1fcf70fe33f3e6e19458372eb3feeff22998773e03feeff22998773e0bf3e6e19458372eb3f1b5f217bf919cf3fd73092fb7e0aef3fd73092fb7e0aefbf1b5f217bf919cf3fe586f6042121ee3fdd1fab759a8fd53fdd1fab759a8fd5bfe586f6042121ee3fc05ce109105ddb3f73c73cf47aedec3f73c73cf47aedecbfc05ce109105ddb3fafaf6a22dfb5e73fa0ec8c34697de53fa0ec8c34697de5bfafaf6a22dfb5e73f14d80df1651fa93f7e6d79e321f6ef3f7e6d79e321f6efbf14d80df1651fa93f0dcd846088fdef3f7e66a3f75521993f7e66a3f7552199bf0dcd846088fdef3fdf2c1d55b710e63f96ffef37082de73f96ffef37082de7bfdf2c1d55b710e63f3ac94dd13441ed3f8aeda84379efd93f8aeda84379efd9bf3ac94dd13441ed3f9f45fa308508d73f3cc2ccb613dbed3f3cc2ccb613dbedbf9f45fa308508d73f89e564acf338ef3f634f7e6a820bcc3f634f7e6a820bccbf89e564acf338ef3f234b1b54b31ee13f000215580a09eb3f000215580a09ebbf234b1b54b31ee13f822746a0a729ea3fdf12dd4c056de23fdf12dd4c056de2bf822746a0a729ea3fc63f8b4414e2c53fa94b71fa6487ef3fa94b71fa6487efbfc63f8b4414e2c53fd39fe17064c2ef3f0e73a9564e56bf3f0e73a9564e56bfbfd39fe17064c2ef3fb9502029faafe33ffb639249223ae93ffb639249223ae9bfb9502029faafe33f2a956facc0d7eb3fba9af8dba48bdf3fba9af8dba48bdfbf2a956facc0d7eb3f77f6b162d211d13f634968e740d7ee3f634968e740d7eebf77f6b162d211d13f12e148ec8862ee3f016617945c13d43f016617945c13d4bf12e148ec8862ee3f5ec431996ec6dc3ff51134214b95ec3ff51134214b95ecbf5ec431996ec6dc3f6e97ff0b0e3be83fe9e5e3bbcae6e43fe9e5e3bbcae6e4bf6e97ff0b0e3be83ff619ce9220d5b23f3a8801adcde9ef3f3a8801adcde9efbff619ce9220d5b23f3a8801adcde9ef3ff619ce9220d5b23ff619ce9220d5b2bf3a8801adcde9ef3fe9e5e3bbcae6e43f6e97ff0b0e3be83f6e97ff0b0e3be8bfe9e5e3bbcae6e43ff51134214b95ec3f5ec431996ec6dc3f5ec431996ec6dcbff51134214b95ec3f016617945c13d43f12e148ec8862ee3f12e148ec8862eebf016617945c13d43f634968e740d7ee3f77f6b162d211d13f77f6b162d211d1bf634968e740d7ee3fba9af8dba48bdf3f2a956facc0d7eb3f2a956facc0d7ebbfba9af8dba48bdf3ffb639249223ae93fb9502029faafe33fb9502029faafe3bffb639249223ae93f0e73a9564e56bf3fd39fe17064c2ef3fd39fe17064c2efbf0e73a9564e56bf3fa94b71fa6487ef3fc63f8b4414e2c53fc63f8b4414e2c5bfa94b71fa6487ef3fdf12dd4c056de23f822746a0a729ea3f822746a0a729eabfdf12dd4c056de23f000215580a09eb3f234b1b54b31ee13f234b1b54b31ee1bf000215580a09eb3f634f7e6a820bcc3f89e564acf338ef3f89e564acf338efbf634f7e6a820bcc3f3cc2ccb613dbed3f9f45fa308508d73f9f45fa308508d7bf3cc2ccb613dbed3f8aeda84379efd93f3ac94dd13441ed3f3ac94dd13441edbf8aeda84379efd93f96ffef37082de73fdf2c1d55b710e63fdf2c1d55b710e6bf96ffef37082de73f7e66a3f75521993f0dcd846088fdef3f0dcd846088fdefbf7e66a3f75521993fdb929b1662ffef3f84c7defcd121893f84c7defcd12189bfdb929b1662ffef3f3d78f0251959e63fafa8ea5444e7e63fafa8ea5444e7e6bf3d78f0251959e63f8be6c9736169ed3fd793bc632a37d93fd793bc632a37d9bf8be6c9736169ed3fe7cc1d31a9c3d73f9ba0386252b6ed3f9ba0386252b6edbfe7cc1d31a9c3d73f2d2f0b3b604eef3f5104b025a082ca3f5104b025a082cabf2d2f0b3b604eef3f49dbde634d73e13f11d5219ebcd2ea3f11d5219ebcd2eabf49dbde634d73e13fe2fa021b0963ea3f59eb3399791ae23f59eb3399791ae2bfe2fa021b0963ea3f31bf50ded96dc73f7720a1a39975ef3f7720a1a39975efbf31bf50ded96dc73f7ba66dfd15ceef3fd5c29ec78537bc3fd5c29ec78537bcbf7ba66dfd15ceef3fd4564553d9fee33f0d94efa3ccfbe83f0d94efa3ccfbe8bfd4564553d9fee33f49557226c408ec3fd678ef5219dcde3fd678ef5219dcdebf49557226c408ec3f3edb4c3f44d3d13f740bdfc8d8bbee3f740bdfc8d8bbeebf3edb4c3f44d3d13f0dd14cab7b81ee3f5281e1c21054d33f5281e1c21054d3bf0dd14cab7b81ee3f89e3865b7779dd3f9b7388348b67ec3f9b7388348b67ecbf89e3865b7779dd3fbf2eba0f407ce83f39099b9b449ae43f39099b9b449ae4bfbf2eba0f407ce83f19a49a0ad0f6b53f095bbdfccae1ef3f095bbdfccae1efbf19a49a0ad0f6b53fad718e6595f0ef3fe020f8796e65af3fe020f8796e65afbfad718e6595f0ef3f9655a3928232e53f711757e3ecf8e73f711757e3ecf8e7bf9655a3928232e53f5cfcfcf3f0c1ec3fe71e01d84912dc3fe71e01d84912dcbf5cfcfcf3f0c1ec3f6ae77842e2d1d43f7ec12b4b6a42ee3f7ec12b4b6a42eebf6ae77842e2d1d43fc273e4a378f1ee3faefd370eb84fd03faefd370eb84fd0bfc273e4a378f1ee3fb73e4c87fc1ce03fd2903567aaa5eb3fd2903567aaa5ebbfb73e4c87fc1ce03f42d7c7f47e77e93ff35906b15860e33ff35906b15860e3bf42d7c7f47e77e93f77f5dacef039c13f41d7957179b5ef3f41d7957179b5efbf77f5dacef039c13f9b09c924f997ef3f5a3e29b17655c43f5a3e29b17655c4bf9b09c924f997ef3feaf3fa25dbbee23f94af29ef43efe93f94af29ef43efe9bfeaf3fa25dbbee23f1257f53e4d3eeb3f8f895d4d70c9e03f8f895d4d70c9e0bf1257f53e4d3eeb3f114345e54f93cd3fda3a76f75222ef3fda3a76f75222efbf114345e54f93cd3f2bbe2d62aefeed3fc6273fdd7d4cd63fc6273fdd7d4cd6bf2bbe2d62aefeed3fca3f6d2bc8a6da3fdc353e74e717ed3fdc353e74e717edbfca3f6d2bc8a6da3f6172035fe771e73f8c0165be7bc7e53f8c0165be7bc7e5bf6172035fe771e73fcd55947565d8a23f5df7feef72faef3f5df7feef72faefbfcd55947565d8a23f5df7feef72faef3fcd55947565d8a23fcd55947565d8a2bf5df7feef72faef3f8c0165be7bc7e53f6172035fe771e73f6172035fe771e7bf8c0165be7bc7e53fdc353e74e717ed3fca3f6d2bc8a6da3fca3f6d2bc8a6dabfdc353e74e717ed3fc6273fdd7d4cd63f2bbe2d62aefeed3f2bbe2d62aefeedbfc6273fdd7d4cd63fda3a76f75222ef3f114345e54f93cd3f114345e54f93cdbfda3a76f75222ef3f8f895d4d70c9e03f1257f53e4d3eeb3f1257f53e4d3eebbf8f895d4d70c9e03f94af29ef43efe93feaf3fa25dbbee23feaf3fa25dbbee2bf94af29ef43efe93f5a3e29b17655c43f9b09c924f997ef3f9b09c924f997efbf5a3e29b17655c43f41d7957179b5ef3f77f5dacef039c13f77f5dacef039c1bf41d7957179b5ef3ff35906b15860e33f42d7c7f47e77e93f42d7c7f47e77e9bff35906b15860e33fd2903567aaa5eb3fb73e4c87fc1ce03fb73e4c87fc1ce0bfd2903567aaa5eb3faefd370eb84fd03fc273e4a378f1ee3fc273e4a378f1eebfaefd370eb84fd03f7ec12b4b6a42ee3f6ae77842e2d1d43f6ae77842e2d1d4bf7ec12b4b6a42ee3fe71e01d84912dc3f5cfcfcf3f0c1ec3f5cfcfcf3f0c1ecbfe71e01d84912dc3f711757e3ecf8e73f9655a3928232e53f9655a3928232e5bf711757e3ecf8e73fe020f8796e65af3fad718e6595f0ef3fad718e6595f0efbfe020f8796e65af3f095bbdfccae1ef3f19a49a0ad0f6b53f19a49a0ad0f6b5bf095bbdfccae1ef3f39099b9b449ae43fbf2eba0f407ce83fbf2eba0f407ce8bf39099b9b449ae43f9b7388348b67ec3f89e3865b7779dd3f89e3865b7779ddbf9b7388348b67ec3f5281e1c21054d33f0dd14cab7b81ee3f0dd14cab7b81eebf5281e1c21054d33f740bdfc8d8bbee3f3edb4c3f44d3d13f3edb4c3f44d3d1bf740bdfc8d8bbee3fd678ef5219dcde3f49557226c408ec3f49557226c408ecbfd678ef5219dcde3f0d94efa3ccfbe83fd4564553d9fee33fd4564553d9fee3bf0d94efa3ccfbe83fd5c29ec78537bc3f7ba66dfd15ceef3f7ba66dfd15ceefbfd5c29ec78537bc3f7720a1a39975ef3f31bf50ded96dc73f31bf50ded96dc7bf7720a1a39975ef3f59eb3399791ae23fe2fa021b0963ea3fe2fa021b0963eabf59eb3399791ae23f11d5219ebcd2ea3f49dbde634d73e13f49dbde634d73e1bf11d5219ebcd2ea3f5104b025a082ca3f2d2f0b3b604eef3f2d2f0b3b604eefbf5104b025a082ca3f9ba0386252b6ed3fe7cc1d31a9c3d73fe7cc1d31a9c3d7bf9ba0386252b6ed3fd793bc632a37d93f8be6c9736169ed3f8be6c9736169edbfd793bc632a37d93fafa8ea5444e7e63f3d78f0251959e63f3d78f0251959e6bfafa8ea5444e7e63f84c7defcd121893fdb929b1662ffef3fdb929b1662ffefbf84c7defcd121893f928a8e85d8ffef3f710067fef021793f710067fef02179bf928a8e85d8ffef3f10af9184f77ce63f7582c1730dc4e63f7582c1730dc4e6bf10af9184f77ce63ff9ecb8020b7ded3fb0a4c82ea5dad83fb0a4c82ea5dad8bff9ecb8020b7ded3fc4aa4eb0e320d83f888966a983a3ed3f888966a983a3edbfc4aa4eb0e320d83f849e78b1a258ef3f6643dcf2cbbdc93f6643dcf2cbbdc9bf849e78b1a258ef3fb8b9f2095a9de13fd4c0165932b7ea3fd4c0165932b7eabfb8b9f2095a9de13f9de69f52587fea3f1b86bc8bf0f0e13f1b86bc8bf0f0e1bf9de69f52587fea3fc6649ce86633c83fb7bbf57d3f6cef3fb7bbf57d3f6cefbfc6649ce86633c83f840b221479d3ef3f035c4924b7a7ba3f035c4924b7a7babf840b221479d3ef3fb16b8e17ff25e43fcc98163345dce83fcc98163345dce8bfb16b8e17ff25e43fb071a93fde20ec3f1451f8eae083de3f1451f8eae083debfb071a93fde20ec3f71bbc3abbb33d23f8ea8e7e8b2adee3f8ea8e7e8b2adeebf71bbc3abbb33d23ff2f71d368490ee3f8703ecda22f4d23f8703ecda22f4d2bff2f71d368490ee3f58cc81148fd2dd3f07692b014250ec3f07692b014250ecbf58cc81148fd2dd3faad44d9a7e9ce83f4773981bb573e43f4773981bb573e4bfaad44d9a7e9ce83f215b5d6a5887b73f56f4f19f53ddef3f56f4f19f53ddefbf215b5d6a5887b73f5c578d0f83f3ef3fe3d7c0128d42ac3fe3d7c0128d42acbf5c578d0f83f3ef3f375197381058e53fb23dc36c83d7e73fb23dc36c83d7e7bf375197381058e53ff6328b89d9d7ec3f01bd0423cfb7db3f01bd0423cfb7dbbff6328b89d9d7ec3f243caf80d830d53f25ce70e8ea31ee3f25ce70e8ea31eebf243caf80d830d53fec950b0c22feee3ff9eddf1adcdccf3ff9eddf1adcdccfbfec950b0c22feee3f1a22ae265648e03fe90475d2388ceb3fe90475d2388cebbf1a22ae265648e03f220dd82ecf95e93f578e0c0d4038e33f578e0c0d4038e3bf220dd82ecf95e93fcf7becd41601c23fbbcf468e8eaeef3fbbcf468e8eaeefbfcf7becd41601c23fc8b2ad55ce9fef3f148dcdb0db8ec33f148dcdb0db8ec3bfc8b2ad55ce9fef3f17eae8e380e7e23fd580eaf5b1d1e93fd580eaf5b1d1e9bf17eae8e380e7e23f051492fe8958eb3fe1c51774909ee03fe1c51774909ee0bf051492fe8958eb3f1b1a101eca56ce3f5d20f7538f16ef3f5d20f7538f16efbf1b1a101eca56ce3fac8029ca0c10ee3f93a69e3727eed53f93a69e3727eed5bfac8029ca0c10ee3f09407f6c0d02db3f92bdb2fed402ed3f92bdb2fed402edbf09407f6c0d02db3fe5554f570094e73f50725d2a8da2e53f50725d2a8da2e5bfe5554f570094e73f43cd90d200fca53fdf81dbda71f8ef3fdf81dbda71f8efbf43cd90d200fca53ff8d3f11d25fcef3f01cfd13137699f3f01cfd13137699fbff8d3f11d25fcef3f7470839534ece53f8dd2a88d944fe73f8dd2a88d944fe7bf7470839534ece53f9fefe020b22ced3fe5a1de27414bda3fe5a1de27414bdabf9fefe020b22ced3f177ec77d9daad63fda47def705eded3fda47def705ededbf177ec77d9daad63f9d9a08c9c92def3f86b212b38ccfcc3f86b212b38ccfccbf9d9a08c9c92def3f7e8e2abb26f4e03fb4130047cd23eb3fb4130047cd23ebbf7e8e2abb26f4e03f37f9baea950cea3fa89c62270796e23fa89c62270796e2bf37f9baea950cea3ff2c59785df1bc53fdb41aeffd58fef3fdb41aeffd58fefbff2c59785df1bc53f8641e41716bcef3f1d83ba47a072c03f1d83ba47a072c0bf8641e41716bcef3f22ebdf854188e33fd76d8ee4ef58e93fd76d8ee4ef58e9bf22ebdf854188e33fea8093c4d7beeb3f1012e74bf6e2df3f1012e74bf6e2dfbfea8093c4d7beeb3f90dbdbcfd9b0d03fbc9d5ae282e4ee3fbc9d5ae282e4eebf90dbdbcfd9b0d03ffc9f72049f52ee3f541057a5b872d43f541057a5b872d4bffc9f72049f52ee3f0b0097497f6cdc3f00b9a069c1abec3f00b9a069c1abecbf0b0097497f6cdc3fcc7ab5331b1ae83f9ba0599fc00ce53f9ba0599fc00ce5bfcc7ab5331b1ae83fb309d7340144b13fc473b6ec58edef3fc473b6ec58edefbfb309d7340144b13f40392eaff3e5ef3f962027791166b43f962027791166b4bf40392eaff3e5ef3f0400ec45a1c0e43fcc58e91ac55be83fcc58e91ac55be8bf0400ec45a1c0e43ff33c23528e7eec3f5bdbe9e81620dd3f5bdbe9e81620ddbff33c23528e7eec3fb71404faceb3d33f44976adb2772ee3f44976adb2772eebfb71404faceb3d33f84bfc3d3b2c9ee3f775176d7a072d13f775176d7a072d1bf84bfc3d3b2c9ee3f67d03f960534df3fdd7753e164f0eb3fdd7753e164f0ebbf67d03f960534df3fa29dd46f161be93f4483c53882d7e33f4483c53882d7e3bfa29dd46f161be93fc99faecb0ec7bd3f21b7fe6c64c8ef3f21b7fe6c64c8efbfc99faecb0ec7bd3f6e3de629a67eef3fb24af60413a8c63fb24af60413a8c6bf6e3de629a67eef3f1fac98fbd543e23fc89a11c87846ea3fc89a11c87846eabf1fac98fbd543e23f74143cb404eeea3feb6c33af1549e13feb6c33af1549e1bf74143cb404eeea3f22673def3247cb3fdd92ff85d043ef3fdd92ff85d043efbf22673def3247cb3f600241cbd7c8ed3ff618240f3466d73ff618240f3466d7bf600241cbd7c8ed3fffbd41617193d93fb13ee9526f55ed3fb13ee9526f55edbfffbd41617193d93f7a6d17b3420ae73fe91b1ca30335e63fe91b1ca30335e6bf7a6d17b3420ae73ffd0ee3bb36d9923fa1514bb49cfeef3fa1514bb49cfeefbffd0ee3bb36d9923fa1514bb49cfeef3ffd0ee3bb36d9923ffd0ee3bb36d992bfa1514bb49cfeef3fe91b1ca30335e63f7a6d17b3420ae73f7a6d17b3420ae7bfe91b1ca30335e63fb13ee9526f55ed3fffbd41617193d93fffbd41617193d9bfb13ee9526f55ed3ff618240f3466d73f600241cbd7c8ed3f600241cbd7c8edbff618240f3466d73fdd92ff85d043ef3f22673def3247cb3f22673def3247cbbfdd92ff85d043ef3feb6c33af1549e13f74143cb404eeea3f74143cb404eeeabfeb6c33af1549e13fc89a11c87846ea3f1fac98fbd543e23f1fac98fbd543e2bfc89a11c87846ea3fb24af60413a8c63f6e3de629a67eef3f6e3de629a67eefbfb24af60413a8c63f21b7fe6c64c8ef3fc99faecb0ec7bd3fc99faecb0ec7bdbf21b7fe6c64c8ef3f4483c53882d7e33fa29dd46f161be93fa29dd46f161be9bf4483c53882d7e33fdd7753e164f0eb3f67d03f960534df3f67d03f960534dfbfdd7753e164f0eb3f775176d7a072d13f84bfc3d3b2c9ee3f84bfc3d3b2c9eebf775176d7a072d13f44976adb2772ee3fb71404faceb3d33fb71404faceb3d3bf44976adb2772ee3f5bdbe9e81620dd3ff33c23528e7eec3ff33c23528e7eecbf5bdbe9e81620dd3fcc58e91ac55be83f0400ec45a1c0e43f0400ec45a1c0e4bfcc58e91ac55be83f962027791166b43f40392eaff3e5ef3f40392eaff3e5efbf962027791166b43fc473b6ec58edef3fb309d7340144b13fb309d7340144b1bfc473b6ec58edef3f9ba0599fc00ce53fcc7ab5331b1ae83fcc7ab5331b1ae8bf9ba0599fc00ce53f00b9a069c1abec3f0b0097497f6cdc3f0b0097497f6cdcbf00b9a069c1abec3f541057a5b872d43ffc9f72049f52ee3ffc9f72049f52eebf541057a5b872d43fbc9d5ae282e4ee3f90dbdbcfd9b0d03f90dbdbcfd9b0d0bfbc9d5ae282e4ee3f1012e74bf6e2df3fea8093c4d7beeb3fea8093c4d7beebbf1012e74bf6e2df3fd76d8ee4ef58e93f22ebdf854188e33f22ebdf854188e3bfd76d8ee4ef58e93f1d83ba47a072c03f8641e41716bcef3f8641e41716bcefbf1d83ba47a072c03fdb41aeffd58fef3ff2c59785df1bc53ff2c59785df1bc5bfdb41aeffd58fef3fa89c62270796e23f37f9baea950cea3f37f9baea950ceabfa89c62270796e23fb4130047cd23eb3f7e8e2abb26f4e03f7e8e2abb26f4e0bfb4130047cd23eb3f86b212b38ccfcc3f9d9a08c9c92def3f9d9a08c9c92defbf86b212b38ccfcc3fda47def705eded3f177ec77d9daad63f177ec77d9daad6bfda47def705eded3fe5a1de27414bda3f9fefe020b22ced3f9fefe020b22cedbfe5a1de27414bda3f8dd2a88d944fe73f7470839534ece53f7470839534ece5bf8dd2a88d944fe73f01cfd13137699f3ff8d3f11d25fcef3ff8d3f11d25fcefbf01cfd13137699f3fdf81dbda71f8ef3f43cd90d200fca53f43cd90d200fca5bfdf81dbda71f8ef3f50725d2a8da2e53fe5554f570094e73fe5554f570094e7bf50725d2a8da2e53f92bdb2fed402ed3f09407f6c0d02db3f09407f6c0d02dbbf92bdb2fed402ed3f93a69e3727eed53fac8029ca0c10ee3fac8029ca0c10eebf93a69e3727eed53f5d20f7538f16ef3f1b1a101eca56ce3f1b1a101eca56cebf5d20f7538f16ef3fe1c51774909ee03f051492fe8958eb3f051492fe8958ebbfe1c51774909ee03fd580eaf5b1d1e93f17eae8e380e7e23f17eae8e380e7e2bfd580eaf5b1d1e93f148dcdb0db8ec33fc8b2ad55ce9fef3fc8b2ad55ce9fefbf148dcdb0db8ec33fbbcf468e8eaeef3fcf7becd41601c23fcf7becd41601c2bfbbcf468e8eaeef3f578e0c0d4038e33f220dd82ecf95e93f220dd82ecf95e9bf578e0c0d4038e33fe90475d2388ceb3f1a22ae265648e03f1a22ae265648e0bfe90475d2388ceb3ff9eddf1adcdccf3fec950b0c22feee3fec950b0c22feeebff9eddf1adcdccf3f25ce70e8ea31ee3f243caf80d830d53f243caf80d830d5bf25ce70e8ea31ee3f01bd0423cfb7db3ff6328b89d9d7ec3ff6328b89d9d7ecbf01bd0423cfb7db3fb23dc36c83d7e73f375197381058e53f375197381058e5bfb23dc36c83d7e73fe3d7c0128d42ac3f5c578d0f83f3ef3f5c578d0f83f3efbfe3d7c0128d42ac3f56f4f19f53ddef3f215b5d6a5887b73f215b5d6a5887b7bf56f4f19f53ddef3f4773981bb573e43faad44d9a7e9ce83faad44d9a7e9ce8bf4773981bb573e43f07692b014250ec3f58cc81148fd2dd3f58cc81148fd2ddbf07692b014250ec3f8703ecda22f4d23ff2f71d368490ee3ff2f71d368490eebf8703ecda22f4d23f8ea8e7e8b2adee3f71bbc3abbb33d23f71bbc3abbb33d2bf8ea8e7e8b2adee3f1451f8eae083de3fb071a93fde20ec3fb071a93fde20ecbf1451f8eae083de3fcc98163345dce83fb16b8e17ff25e43fb16b8e17ff25e4bfcc98163345dce83f035c4924b7a7ba3f840b221479d3ef3f840b221479d3efbf035c4924b7a7ba3fb7bbf57d3f6cef3fc6649ce86633c83fc6649ce86633c8bfb7bbf57d3f6cef3f1b86bc8bf0f0e13f9de69f52587fea3f9de69f52587feabf1b86bc8bf0f0e13fd4c0165932b7ea3fb8b9f2095a9de13fb8b9f2095a9de1bfd4c0165932b7ea3f6643dcf2cbbdc93f849e78b1a258ef3f849e78b1a258efbf6643dcf2cbbdc93f888966a983a3ed3fc4aa4eb0e320d83fc4aa4eb0e320d8bf888966a983a3ed3fb0a4c82ea5dad83ff9ecb8020b7ded3ff9ecb8020b7dedbfb0a4c82ea5dad83f7582c1730dc4e63f10af9184f77ce63f10af9184f77ce6bf7582c1730dc4e63f710067fef021793f928a8e85d8ffef3f928a8e85d8ffefbf710067fef021793f021d6221f6ffef3fbaa4ccbef821693fbaa4ccbef82169bf021d6221f6ffef3f719ca1ead18ee63f9ce22fed5cb2e63f9ce22fed5cb2e6bf719ca1ead18ee63f4fa44584c486ed3f44edd5864bacd83f44edd5864bacd8bf4fa44584c486ed3f3f90f3aa6a4fd83f463d8bdd009aed3f463d8bdd009aedbf3f90f3aa6a4fd83f5d6843eda65def3ffa2ab6e9495bc93ffa2ab6e9495bc9bf5d6843eda65def3fbf73131750b2e13f8eb92c7a54a9ea3f8eb92c7a54a9eabfbf73131750b2e13fd25a546e678dea3f7248dc641bdce13f7248dc641bdce1bfd25a546e678dea3f0418c4271796c83fee3c88567567ef3fee3c88567567efbf0418c4271796c83f9e5ca72d0dd6ef3f5ca824ebb6dfb93f5ca824ebb6dfb9bf9e5ca72d0dd6ef3f80432a5b7f39e43f554618756acce83f554618756acce8bf80432a5b7f39e43ff1e33149d12cec3f25d83c6da857de3f25d83c6da857debff1e33149d12cec3fba545599e663d23f0058e69383a6ee3f0058e69383a6eebfba545599e663d23f306b0136ec97ee3f2045954e1ac4d23f2045954e1ac4d2bf306b0136ec97ee3fde41a966fffedd3f04c041318344ec3f04c041318344ecbfde41a966fffedd3f881dde1e87ace83fa2322b695a60e43fa2322b695a60e4bf881dde1e87ace83fa130c112874fb83f8c531475fadaef3f8c531475fadaefbfa130c112874fb83fd3beb154dcf4ef3f17835fbd01b1aa3f17835fbd01b1aabfd3beb154dcf4ef3f9f649751c36ae53f33d3e29cb8c6e73f33d3e29cb8c6e7bf9f649751c36ae53f60a09927b3e2ec3f9356fd14788adb3f9356fd14788adbbf60a09927b3e2ec3fb467f4124060d53f7a1939448f29ee3f7a1939448f29eebfb467f4124060d53f8c73cf145a04ef3f0238bd80747bcf3f0238bd80747bcfbf8c73cf145a04ef3fb7b831ecf35de03fe992e786667feb3fe992e786667febbfb7b831ecf35de03fb2062ba4dfa4e93f1fa649ec2124e33f1fa649ec2124e3bfb2062ba4dfa4e93f0934fd4d9964c23fdcfd0ccbfbaaef3fdcfd0ccbfbaaefbf0934fd4d9964c23f91177aac9ba3ef3fa71645f97b2bc33fa71645f97b2bc3bf91177aac9ba3ef3f1510444bc2fbe23fc275f010d1c2e93fc275f010d1c2e9bf1510444bc2fbe23f47bcfd148f65eb3f8cb032201189e03f8cb032201189e0bf47bcfd148f65eb3f48e32d466bb8ce3f5f8f89bc9010ef3f5f8f89bc9010efbf48e32d466bb8ce3fd966dc2fa018ee3fb6b39d8be7bed53fb6b39d8be7bed5bfd966dc2fa018ee3f7219b31d972fdb3f7b46cee830f8ec3f7b46cee830f8ecbf7219b31d972fdb3fd297bf07f7a4e73fdf23f7d50190e53fdf23f7d50190e5bfd297bf07f7a4e73f864687a5ba8da73f64911bbb53f7ef3f64911bbb53f7efbf864687a5ba8da73f79a6e29ce0fcef3f1d3be54c4f459c3f1d3be54c4f459cbf79a6e29ce0fcef3f106ae5bd7cfee53f4299078e553ee73f4299078e553ee7bf106ae5bd7cfee53fdcfbcb7bfc36ed3fc00ab543651dda3fc00ab543651ddabfdcfbcb7bfc36ed3fb60c8a6398d9d63f818d6d0f16e4ed3f818d6d0f16e4edbfb60c8a6398d9d63ff0ae3a5a6833ef3fdd745d53906dcc3fdd745d53906dccbff0ae3a5a6833ef3f57a9d0487209e13ff5a24c2a7416eb3ff5a24c2a7416ebbf57a9d0487209e13f5ea7c0d2261bea3fba3c4def8b81e23fba3c4def8b81e2bf5ea7c0d2261bea3fdecb5486007fc53f784bcb37a78bef3f784bcb37a78befbfdecb5486007fc53f888d0a0f47bfef3f5bb86fade80ec03f5bb86fade80ec0bf888d0a0f47bfef3f2930d6e3239ce33f6c4aace39049e93f6c4aace39049e9bf2930d6e3239ce33f27230dcb54cbeb3fded2245c57b7df3fded2245c57b7dfbf27230dcb54cbeb3fce49174e5be1d03f5186076aebddee3f5186076aebddeebfce49174e5be1d03fd36704559d5aee3ff03689dc1043d43ff03689dc1043d4bfd36704559d5aee3f895386c37f99dc3f49c4b9198fa0ec3f49c4b9198fa0ecbf895386c37f99dc3fff45f5139c2ae83f86a4cc25ccf9e43f86a4cc25ccf9e4bfff45f5139c2ae83f4d44ed74960cb23f0f4130259debef3f0f4130259debefbf4d44ed74960cb23f602d4885eae7ef3f99a2c5129f9db33f99a2c5129f9db3bf602d4885eae7ef3f7f9f586dbcd3e43ffa83af11714be83ffa83af11714be8bf7f9f586dbcd3e43f139c0287f589ec3f21cde1ae4bf3dc3f21cde1ae4bf3dcbf139c0287f589ec3f71c26ee99be3d33fa7535dc5616aee3fa7535dc5616aeebf71c26ee99be3d33f0990995e83d0ee3f7893c6ef3e42d13f7893c6ef3e42d1bf0990995e83d0ee3fa3cd56e6de5fdf3fc15411611be4eb3fc15411611be4ebbfa3cd56e6de5fdf3f15a8c51fa42ae93f18c58149c4c3e33f18c58149c4c3e3bf15a8c51fa42ae93f3faae4fdb78ebe3ff69a7d3b6ec5ef3ff69a7d3b6ec5efbf3faae4fdb78ebe3f0cc6404a0f83ef3f0d831d831a45c63f0d831d831a45c6bf0cc6404a0f83ef3f1071bb4c7358e23fc63b594a1838ea3fc63b594a1838eabf1071bb4c7358e23fb6579fd88ffbea3f4f25eecfe933e13f4f25eecfe933e1bfb6579fd88ffbea3fad5df13463a9cb3f65bc1bbc6b3eef3f65bc1bbc6b3eefbfad5df13463a9cb3f5a918af3fed1ed3f921026c96337d73f921026c96337d7bf5a918af3fed1ed3ff2f90d447dc1d93f2475181b5b4bed3f2475181b5b4bedbff2f90d447dc1d93fbf410e96ac1be73fff22ec4fe422e63fff22ec4fe422e6bfbf410e96ac1be73f26b2fa214dfd953f77cb70681cfeef3f77cb70681cfeefbf26b2fa214dfd953fd13bc54309ffef3fcb97b96a296a8f3fcb97b96a296a8fbfd13bc54309ffef3f5b537f431547e63f755bc999caf8e63f755bc999caf8e6bf5b537f431547e63f7f8a8872715fed3f8f94abb75565d93f8f94abb75565d9bf7f8a8872715fed3faedf13e6f594d73f9a7595439ebfed3f9a7595439ebfedbfaedf13e6f594d73fb4abbc062249ef3fabb9f3d5f1e4ca3fabb9f3d5f1e4cabfb4abbc062249ef3fbce2dbe4365ee13fefec45f368e0ea3fefec45f368e0eabfbce2dbe4365ee13f23f59010c954ea3fe2132c662d2fe23fe2132c662d2fe2bf23f59010c954ea3fffc4088dfd0ac73f2a321a9c297aef3f2a321a9c297aefbfffc4088dfd0ac73f5443910347cbef3fc17d303b53ffbc3fc17d303b53ffbcbf5443910347cbef3f8006beea33ebe33ffe5e5743790be93ffe5e5743790be9bf8006beea33ebe33f47b1a1259dfceb3ffef7bf061908df3ffef7bf061908dfbf47b1a1259dfceb3f43f2e8fbf7a2d13fb2f61a4bcfc2ee3fb2f61a4bcfc2eebf43f2e8fbf7a2d13f5a16a529db79ee3fabb653e3f583d33fabb653e3f583d3bf5a16a529db79ee3f9d60a82bd04cdd3fd7aa9e891573ec3fd7aa9e891573ecbf9d60a82bd04cdd3f95a19a1d0a6ce83ff122675179ade43ff122675179ade4bf95a19a1d0a6ce83f0a4d4d4a772eb53f86d8e92be9e3ef3f86d8e92be9e3efbf0a4d4d4a772eb53f9161820201efef3f6430464e617bb03f6430464e617bb0bf9161820201efef3fa69ad91ca81fe53ffa526e758b09e83ffa526e758b09e8bfa69ad91ca81fe53f99da000ae2b6ec3f293126476d3fdc3f293126476d3fdcbf99da000ae2b6ec3ff3821bd153a2d43f5ece81ff8d4aee3f5ece81ff8d4aeebff3821bd153a2d43f44a5504c07ebee3f1e66eb054e80d03f1e66eb054e80d0bf44a5504c07ebee3fe1822bc84007e03f0dc4b6a049b2eb3f0dc4b6a049b2ebbfe1822bc84007e03fe17fbd423f68e93f8d7f811b5374e33f8d7f811b5374e3bfe17fbd423f68e93f8667b2bc4dd6c03fb7ad668dd1b8ef3fb7ad668dd1b8efbf8667b2bc4dd6c03f08ac854ff193ef3f88fa797fb1b8c43f88fa797fb1b8c4bf08ac854ff193ef3f58eb7ae876aae23fde4931f1f4fde93fde4931f1f4fde9bf58eb7ae876aae23ff37bf3a51531eb3fb6c44bb8d0dee03fb6c44bb8d0dee0bff37bf3a51531eb3feebd2c4d7731cd3fce0946fc1728ef3fce0946fc1728efbfeebd2c4d7731cd3f9ca59b6ae3f5ed3fcb63ad9c947bd63fcb63ad9c947bd6bf9ca59b6ae3f5ed3f1bf3dbd30c79da3fe1a4e5c65522ed3fe1a4e5c65522edbf1bf3dbd30c79da3f6447302cc560e73f5c343ee7ded9e53f5c343ee7ded9e5bf6447302cc560e73f7fc142db8546a13faefd25e455fbef3faefd25e455fbefbf7fc142db8546a13f14c008427cf9ef3f7961f86f396aa43f7961f86f396aa4bf14c008427cf9ef3f48744f260bb5e53f5bb3901bfb82e73f5bb3901bfb82e7bf48744f260bb5e53fb9d2592f670ded3f09dc5c1273d4da3f09dc5c1273d4dabfb9d2592f670ded3f02c2885c591dd63f540f28d96607ee3f540f28d96607eebf02c2885c591dd63f084728be7a1cef3f9a09013f16f5cd3f9a09013f16f5cdbf084728be7a1cef3fec858f8705b4e03f2579de09744beb3f2579de09744bebbfec858f8705b4e03f7224b4ed82e0e93fb89b4ed333d3e23fb89b4ed333d3e2bf7224b4ed82e0e93f9348db572ff2c33f29defb7ced9bef3f29defb7ced9befbf9348db572ff2c33f4dd581c60db2ef3fe724be40899dc13fe724be40899dc1bf4dd581c60db2ef3fe14dc152524ce33f947545f1ae86e93f947545f1ae86e9bfe14dc152524ce33f5e15d91ffa98eb3f96bded55ae32e03f96bded55ae32e0bf5e15d91ffa98eb3fd2fdb906181fd03fc0a31ce5d6f7ee3fc0a31ce5d6f7eebfd2fdb906181fd03f85ce75ec333aee3f487019dc6301d53f487019dc6301d5bf85ce75ec333aee3fd9c0ff1715e5db3fa0dec220eeccec3fa0dec220eeccecbfd9c0ff1715e5db3f8636b0873fe8e73ffc9d15f54f45e53ffc9d15f54f45e5bf8636b0873fe8e73fc98e80f906d4ad3fed31e11416f2ef3fed31e11416f2efbfc98e80f906d4ad3f0733f72299dfef3f29b1793e1bbfb63f29b1793e1bbfb6bf0733f72299dfef3fff9160300387e43fa11b48e7668ce83fa11b48e7668ce8bfff9160300387e43f5af8fe59ef5bec3fd910fa5c0ca6dd3fd910fa5c0ca6ddbf5af8fe59ef5bec3fafba38b61f24d33f2560ad5b0989ee3f2560ad5b0989eebfafba38b61f24d33f11885b51cfb4ee3fbe27d7838503d23fbe27d7838503d2bf11885b51cfb4ee3f2056f29506b0de3f575e46dcd914ec3f575e46dcd914ecbf2056f29506b0de3f496c489b10ece83f8c103d667212e43f8c103d667212e4bf496c489b10ece83f4cf638eca66fbb3f8760d858d1d0ef3f8760d858d1d0efbf4cf638eca66fbb3fb77e4b43f670ef3f1ccbd2bba7d0c73f1ccbd2bba7d0c7bfb77e4b43f670ef3fd66075a1ba05e23ff5609dde3871ea3ff5609dde3871eabfd66075a1ba05e23fc8fa3ebdffc4ea3fe5463a1f5988e13fe5463a1f5988e1bfc8fa3ebdffc4ea3fda31181b3e20ca3f072daf1f8b53ef3f072daf1f8b53efbfda31181b3e20ca3fb98ae62cf4aced3fe44173d34df2d73fe44173d34df2d7bfb98ae62cf4aced3fd17bef81ef08d93fff0d8c503f73ed3fff0d8c503f73edbfd17bef81ef08d93fcdaf4aefafd5e63f86b3523f0f6be63f86b3523f0f6be6bfcdaf4aefafd5e63f0397500e6bd9823f4f8c972ca7ffef3f4f8c972ca7ffefbf0397500e6bd9823f4f8c972ca7ffef3f0397500e6bd9823f0397500e6bd982bf4f8c972ca7ffef3f86b3523f0f6be63fcdaf4aefafd5e63fcdaf4aefafd5e6bf86b3523f0f6be63fff0d8c503f73ed3fd17bef81ef08d93fd17bef81ef08d9bfff0d8c503f73ed3fe44173d34df2d73fb98ae62cf4aced3fb98ae62cf4acedbfe44173d34df2d73f072daf1f8b53ef3fda31181b3e20ca3fda31181b3e20cabf072daf1f8b53ef3fe5463a1f5988e13fc8fa3ebdffc4ea3fc8fa3ebdffc4eabfe5463a1f5988e13ff5609dde3871ea3fd66075a1ba05e23fd66075a1ba05e2bff5609dde3871ea3f1ccbd2bba7d0c73fb77e4b43f670ef3fb77e4b43f670efbf1ccbd2bba7d0c73f8760d858d1d0ef3f4cf638eca66fbb3f4cf638eca66fbbbf8760d858d1d0ef3f8c103d667212e43f496c489b10ece83f496c489b10ece8bf8c103d667212e43f575e46dcd914ec3f2056f29506b0de3f2056f29506b0debf575e46dcd914ec3fbe27d7838503d23f11885b51cfb4ee3f11885b51cfb4eebfbe27d7838503d23f2560ad5b0989ee3fafba38b61f24d33fafba38b61f24d3bf2560ad5b0989ee3fd910fa5c0ca6dd3f5af8fe59ef5bec3f5af8fe59ef5becbfd910fa5c0ca6dd3fa11b48e7668ce83fff9160300387e43fff9160300387e4bfa11b48e7668ce83f29b1793e1bbfb63f0733f72299dfef3f0733f72299dfefbf29b1793e1bbfb63fed31e11416f2ef3fc98e80f906d4ad3fc98e80f906d4adbfed31e11416f2ef3ffc9d15f54f45e53f8636b0873fe8e73f8636b0873fe8e7bffc9d15f54f45e53fa0dec220eeccec3fd9c0ff1715e5db3fd9c0ff1715e5dbbfa0dec220eeccec3f487019dc6301d53f85ce75ec333aee3f85ce75ec333aeebf487019dc6301d53fc0a31ce5d6f7ee3fd2fdb906181fd03fd2fdb906181fd0bfc0a31ce5d6f7ee3f96bded55ae32e03f5e15d91ffa98eb3f5e15d91ffa98ebbf96bded55ae32e03f947545f1ae86e93fe14dc152524ce33fe14dc152524ce3bf947545f1ae86e93fe724be40899dc13f4dd581c60db2ef3f4dd581c60db2efbfe724be40899dc13f29defb7ced9bef3f9348db572ff2c33f9348db572ff2c3bf29defb7ced9bef3fb89b4ed333d3e23f7224b4ed82e0e93f7224b4ed82e0e9bfb89b4ed333d3e23f2579de09744beb3fec858f8705b4e03fec858f8705b4e0bf2579de09744beb3f9a09013f16f5cd3f084728be7a1cef3f084728be7a1cefbf9a09013f16f5cd3f540f28d96607ee3f02c2885c591dd63f02c2885c591dd6bf540f28d96607ee3f09dc5c1273d4da3fb9d2592f670ded3fb9d2592f670dedbf09dc5c1273d4da3f5bb3901bfb82e73f48744f260bb5e53f48744f260bb5e5bf5bb3901bfb82e73f7961f86f396aa43f14c008427cf9ef3f14c008427cf9efbf7961f86f396aa43faefd25e455fbef3f7fc142db8546a13f7fc142db8546a1bfaefd25e455fbef3f5c343ee7ded9e53f6447302cc560e73f6447302cc560e7bf5c343ee7ded9e53fe1a4e5c65522ed3f1bf3dbd30c79da3f1bf3dbd30c79dabfe1a4e5c65522ed3fcb63ad9c947bd63f9ca59b6ae3f5ed3f9ca59b6ae3f5edbfcb63ad9c947bd63fce0946fc1728ef3feebd2c4d7731cd3feebd2c4d7731cdbfce0946fc1728ef3fb6c44bb8d0dee03ff37bf3a51531eb3ff37bf3a51531ebbfb6c44bb8d0dee03fde4931f1f4fde93f58eb7ae876aae23f58eb7ae876aae2bfde4931f1f4fde93f88fa797fb1b8c43f08ac854ff193ef3f08ac854ff193efbf88fa797fb1b8c43fb7ad668dd1b8ef3f8667b2bc4dd6c03f8667b2bc4dd6c0bfb7ad668dd1b8ef3f8d7f811b5374e33fe17fbd423f68e93fe17fbd423f68e9bf8d7f811b5374e33f0dc4b6a049b2eb3fe1822bc84007e03fe1822bc84007e0bf0dc4b6a049b2eb3f1e66eb054e80d03f44a5504c07ebee3f44a5504c07ebeebf1e66eb054e80d03f5ece81ff8d4aee3ff3821bd153a2d43ff3821bd153a2d4bf5ece81ff8d4aee3f293126476d3fdc3f99da000ae2b6ec3f99da000ae2b6ecbf293126476d3fdc3ffa526e758b09e83fa69ad91ca81fe53fa69ad91ca81fe5bffa526e758b09e83f6430464e617bb03f9161820201efef3f9161820201efefbf6430464e617bb03f86d8e92be9e3ef3f0a4d4d4a772eb53f0a4d4d4a772eb5bf86d8e92be9e3ef3ff122675179ade43f95a19a1d0a6ce83f95a19a1d0a6ce8bff122675179ade43fd7aa9e891573ec3f9d60a82bd04cdd3f9d60a82bd04cddbfd7aa9e891573ec3fabb653e3f583d33f5a16a529db79ee3f5a16a529db79eebfabb653e3f583d33fb2f61a4bcfc2ee3f43f2e8fbf7a2d13f43f2e8fbf7a2d1bfb2f61a4bcfc2ee3ffef7bf061908df3f47b1a1259dfceb3f47b1a1259dfcebbffef7bf061908df3ffe5e5743790be93f8006beea33ebe33f8006beea33ebe3bffe5e5743790be93fc17d303b53ffbc3f5443910347cbef3f5443910347cbefbfc17d303b53ffbc3f2a321a9c297aef3fffc4088dfd0ac73fffc4088dfd0ac7bf2a321a9c297aef3fe2132c662d2fe23f23f59010c954ea3f23f59010c954eabfe2132c662d2fe23fefec45f368e0ea3fbce2dbe4365ee13fbce2dbe4365ee1bfefec45f368e0ea3fabb9f3d5f1e4ca3fb4abbc062249ef3fb4abbc062249efbfabb9f3d5f1e4ca3f9a7595439ebfed3faedf13e6f594d73faedf13e6f594d7bf9a7595439ebfed3f8f94abb75565d93f7f8a8872715fed3f7f8a8872715fedbf8f94abb75565d93f755bc999caf8e63f5b537f431547e63f5b537f431547e6bf755bc999caf8e63fcb97b96a296a8f3fd13bc54309ffef3fd13bc54309ffefbfcb97b96a296a8f3f77cb70681cfeef3f26b2fa214dfd953f26b2fa214dfd95bf77cb70681cfeef3fff22ec4fe422e63fbf410e96ac1be73fbf410e96ac1be7bfff22ec4fe422e63f2475181b5b4bed3ff2f90d447dc1d93ff2f90d447dc1d9bf2475181b5b4bed3f921026c96337d73f5a918af3fed1ed3f5a918af3fed1edbf921026c96337d73f65bc1bbc6b3eef3fad5df13463a9cb3fad5df13463a9cbbf65bc1bbc6b3eef3f4f25eecfe933e13fb6579fd88ffbea3fb6579fd88ffbeabf4f25eecfe933e13fc63b594a1838ea3f1071bb4c7358e23f1071bb4c7358e2bfc63b594a1838ea3f0d831d831a45c63f0cc6404a0f83ef3f0cc6404a0f83efbf0d831d831a45c63ff69a7d3b6ec5ef3f3faae4fdb78ebe3f3faae4fdb78ebebff69a7d3b6ec5ef3f18c58149c4c3e33f15a8c51fa42ae93f15a8c51fa42ae9bf18c58149c4c3e33fc15411611be4eb3fa3cd56e6de5fdf3fa3cd56e6de5fdfbfc15411611be4eb3f7893c6ef3e42d13f0990995e83d0ee3f0990995e83d0eebf7893c6ef3e42d13fa7535dc5616aee3f71c26ee99be3d33f71c26ee99be3d3bfa7535dc5616aee3f21cde1ae4bf3dc3f139c0287f589ec3f139c0287f589ecbf21cde1ae4bf3dc3ffa83af11714be83f7f9f586dbcd3e43f7f9f586dbcd3e4bffa83af11714be83f99a2c5129f9db33f602d4885eae7ef3f602d4885eae7efbf99a2c5129f9db33f0f4130259debef3f4d44ed74960cb23f4d44ed74960cb2bf0f4130259debef3f86a4cc25ccf9e43fff45f5139c2ae83fff45f5139c2ae8bf86a4cc25ccf9e43f49c4b9198fa0ec3f895386c37f99dc3f895386c37f99dcbf49c4b9198fa0ec3ff03689dc1043d43fd36704559d5aee3fd36704559d5aeebff03689dc1043d43f5186076aebddee3fce49174e5be1d03fce49174e5be1d0bf5186076aebddee3fded2245c57b7df3f27230dcb54cbeb3f27230dcb54cbebbfded2245c57b7df3f6c4aace39049e93f2930d6e3239ce33f2930d6e3239ce3bf6c4aace39049e93f5bb86fade80ec03f888d0a0f47bfef3f888d0a0f47bfefbf5bb86fade80ec03f784bcb37a78bef3fdecb5486007fc53fdecb5486007fc5bf784bcb37a78bef3fba3c4def8b81e23f5ea7c0d2261bea3f5ea7c0d2261beabfba3c4def8b81e23ff5a24c2a7416eb3f57a9d0487209e13f57a9d0487209e1bff5a24c2a7416eb3fdd745d53906dcc3ff0ae3a5a6833ef3ff0ae3a5a6833efbfdd745d53906dcc3f818d6d0f16e4ed3fb60c8a6398d9d63fb60c8a6398d9d6bf818d6d0f16e4ed3fc00ab543651dda3fdcfbcb7bfc36ed3fdcfbcb7bfc36edbfc00ab543651dda3f4299078e553ee73f106ae5bd7cfee53f106ae5bd7cfee5bf4299078e553ee73f1d3be54c4f459c3f79a6e29ce0fcef3f79a6e29ce0fcefbf1d3be54c4f459c3f64911bbb53f7ef3f864687a5ba8da73f864687a5ba8da7bf64911bbb53f7ef3fdf23f7d50190e53fd297bf07f7a4e73fd297bf07f7a4e7bfdf23f7d50190e53f7b46cee830f8ec3f7219b31d972fdb3f7219b31d972fdbbf7b46cee830f8ec3fb6b39d8be7bed53fd966dc2fa018ee3fd966dc2fa018eebfb6b39d8be7bed53f5f8f89bc9010ef3f48e32d466bb8ce3f48e32d466bb8cebf5f8f89bc9010ef3f8cb032201189e03f47bcfd148f65eb3f47bcfd148f65ebbf8cb032201189e03fc275f010d1c2e93f1510444bc2fbe23f1510444bc2fbe2bfc275f010d1c2e93fa71645f97b2bc33f91177aac9ba3ef3f91177aac9ba3efbfa71645f97b2bc33fdcfd0ccbfbaaef3f0934fd4d9964c23f0934fd4d9964c2bfdcfd0ccbfbaaef3f1fa649ec2124e33fb2062ba4dfa4e93fb2062ba4dfa4e9bf1fa649ec2124e33fe992e786667feb3fb7b831ecf35de03fb7b831ecf35de0bfe992e786667feb3f0238bd80747bcf3f8c73cf145a04ef3f8c73cf145a04efbf0238bd80747bcf3f7a1939448f29ee3fb467f4124060d53fb467f4124060d5bf7a1939448f29ee3f9356fd14788adb3f60a09927b3e2ec3f60a09927b3e2ecbf9356fd14788adb3f33d3e29cb8c6e73f9f649751c36ae53f9f649751c36ae5bf33d3e29cb8c6e73f17835fbd01b1aa3fd3beb154dcf4ef3fd3beb154dcf4efbf17835fbd01b1aa3f8c531475fadaef3fa130c112874fb83fa130c112874fb8bf8c531475fadaef3fa2322b695a60e43f881dde1e87ace83f881dde1e87ace8bfa2322b695a60e43f04c041318344ec3fde41a966fffedd3fde41a966fffeddbf04c041318344ec3f2045954e1ac4d23f306b0136ec97ee3f306b0136ec97eebf2045954e1ac4d23f0058e69383a6ee3fba545599e663d23fba545599e663d2bf0058e69383a6ee3f25d83c6da857de3ff1e33149d12cec3ff1e33149d12cecbf25d83c6da857de3f554618756acce83f80432a5b7f39e43f80432a5b7f39e4bf554618756acce83f5ca824ebb6dfb93f9e5ca72d0dd6ef3f9e5ca72d0dd6efbf5ca824ebb6dfb93fee3c88567567ef3f0418c4271796c83f0418c4271796c8bfee3c88567567ef3f7248dc641bdce13fd25a546e678dea3fd25a546e678deabf7248dc641bdce13f8eb92c7a54a9ea3fbf73131750b2e13fbf73131750b2e1bf8eb92c7a54a9ea3ffa2ab6e9495bc93f5d6843eda65def3f5d6843eda65defbffa2ab6e9495bc93f463d8bdd009aed3f3f90f3aa6a4fd83f3f90f3aa6a4fd8bf463d8bdd009aed3f44edd5864bacd83f4fa44584c486ed3f4fa44584c486edbf44edd5864bacd83f9ce22fed5cb2e63f719ca1ead18ee63f719ca1ead18ee6bf9ce22fed5cb2e63fbaa4ccbef821693f021d6221f6ffef3f021d6221f6ffefbfbaa4ccbef821693f"
|
|
673
|
+
)
|
|
674
|
+
);
|
|
675
|
+
const rootBytes = u8f(baswap64If(Float64Array.from(roots)));
|
|
676
|
+
if ((0, import_utils4.bytesToHex)((0, import_sha32.shake256)(rootBytes)) !== "f45a496cf56ccc6e3e3395a20209206d81d71a7905a661447bd5bc0e24e0af1e") {
|
|
677
|
+
throw new Error("COMPLEX_ROOTS mismatch");
|
|
678
|
+
}
|
|
679
|
+
return roots;
|
|
680
|
+
})();
|
|
681
|
+
var intField = {
|
|
682
|
+
mul(x, y) {
|
|
683
|
+
let z = Math.imul(x, y);
|
|
684
|
+
let w = Math.imul(Q, Math.imul(z, Q0I) & 65535);
|
|
685
|
+
z = (z + w >>> 16) - Q;
|
|
686
|
+
z += Q & z >> 31;
|
|
687
|
+
return z >>> 0;
|
|
688
|
+
},
|
|
689
|
+
inv(y) {
|
|
690
|
+
if (y === 0) throw new Error("divison by zero");
|
|
691
|
+
const e00 = this.mul(y, R2);
|
|
692
|
+
const e01 = this.mul(e00, e00);
|
|
693
|
+
const e02 = this.mul(e01, e00);
|
|
694
|
+
const e03 = this.mul(e02, e01);
|
|
695
|
+
const e04 = this.mul(e03, e03);
|
|
696
|
+
const e05 = this.mul(e04, e04);
|
|
697
|
+
const e06 = this.mul(e05, e05);
|
|
698
|
+
const e07 = this.mul(e06, e06);
|
|
699
|
+
const e08 = this.mul(e07, e07);
|
|
700
|
+
const e09 = this.mul(e08, e02);
|
|
701
|
+
const e10 = this.mul(e09, e08);
|
|
702
|
+
const e11 = this.mul(e10, e10);
|
|
703
|
+
const e12 = this.mul(e11, e11);
|
|
704
|
+
const e13 = this.mul(e12, e09);
|
|
705
|
+
const e14 = this.mul(e13, e13);
|
|
706
|
+
const e15 = this.mul(e14, e14);
|
|
707
|
+
const e16 = this.mul(e15, e10);
|
|
708
|
+
const e17 = this.mul(e16, e16);
|
|
709
|
+
const e18 = this.mul(e17, e00);
|
|
710
|
+
return e18;
|
|
711
|
+
},
|
|
712
|
+
div: (x, y) => intField.mul(x, intField.inv(y))
|
|
713
|
+
};
|
|
714
|
+
function getIntPoly(logn) {
|
|
715
|
+
const n = 1 << logn;
|
|
716
|
+
const newPoly = (n2) => new Uint16Array(n2);
|
|
717
|
+
const F = Number((0, import_modular.invert)(BigInt(n), QBig));
|
|
718
|
+
const { mod, smod, NTT } = genCrystals({
|
|
719
|
+
N: n,
|
|
720
|
+
Q,
|
|
721
|
+
F,
|
|
722
|
+
ROOT_OF_UNITY: 7,
|
|
723
|
+
newPoly,
|
|
724
|
+
isKyber: false,
|
|
725
|
+
brvBits: 10
|
|
726
|
+
});
|
|
727
|
+
const ntt2 = (r) => NTT.encode(r);
|
|
728
|
+
const intt2 = (r) => NTT.decode(r);
|
|
729
|
+
const signedCoder = {
|
|
730
|
+
encode: (p) => Int16Array.from(p, (x) => smod(x)),
|
|
731
|
+
decode: (p) => Uint16Array.from(p, (x) => mod(x))
|
|
732
|
+
};
|
|
733
|
+
const intPoly = {
|
|
734
|
+
create: newPoly,
|
|
735
|
+
smallSqnorm(f) {
|
|
736
|
+
let s = 0;
|
|
737
|
+
let ng = 0;
|
|
738
|
+
for (let u = 0; u < n; u++) {
|
|
739
|
+
const z = f[u];
|
|
740
|
+
s = s + z * z >>> 0;
|
|
741
|
+
ng |= s;
|
|
742
|
+
}
|
|
743
|
+
return (s | -(ng >>> 31)) >>> 0;
|
|
744
|
+
},
|
|
745
|
+
isShort(s1, s2) {
|
|
746
|
+
let s = 0 >>> 0;
|
|
747
|
+
let ng = 0 >>> 0;
|
|
748
|
+
for (let u = 0; u < n; u++) {
|
|
749
|
+
let z1 = s1[u] << 16 >> 16;
|
|
750
|
+
s = s + (z1 * z1 >>> 0) >>> 0;
|
|
751
|
+
ng |= s;
|
|
752
|
+
let z2 = s2[u] << 16 >> 16;
|
|
753
|
+
s = s + (z2 * z2 >>> 0) >>> 0;
|
|
754
|
+
ng |= s;
|
|
755
|
+
}
|
|
756
|
+
if (ng & 2147483648) s = 4294967295;
|
|
757
|
+
return s <= L2BOUND[logn];
|
|
758
|
+
},
|
|
759
|
+
sub(a, b) {
|
|
760
|
+
for (let i = 0; i < n; i++) a[i] = mod(a[i] - b[i]);
|
|
761
|
+
return a;
|
|
762
|
+
},
|
|
763
|
+
ntt: ntt2,
|
|
764
|
+
intt: intt2,
|
|
765
|
+
toMontgomery(d) {
|
|
766
|
+
for (let i = 0; i < n; i++) d[i] = intField.mul(d[i], R2);
|
|
767
|
+
return d;
|
|
768
|
+
},
|
|
769
|
+
mul(f, d) {
|
|
770
|
+
for (let i = 0; i < n; i++) f[i] = intField.mul(f[i], d[i]);
|
|
771
|
+
return f;
|
|
772
|
+
},
|
|
773
|
+
div(f, d) {
|
|
774
|
+
for (let i = 0; i < n; i++) f[i] = intField.div(f[i], d[i]);
|
|
775
|
+
this.intt(f);
|
|
776
|
+
return f;
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
return { newPoly, intPoly, signedCoder };
|
|
780
|
+
}
|
|
781
|
+
var fComplex = getComplex({
|
|
782
|
+
ZERO: 0,
|
|
783
|
+
ONE: 1,
|
|
784
|
+
add: (x, y) => x + y,
|
|
785
|
+
sub: (x, y) => x - y,
|
|
786
|
+
mul: (x, y) => x * y,
|
|
787
|
+
div: (x, y) => x / y,
|
|
788
|
+
eql: (x, y) => x === y,
|
|
789
|
+
inv: (x) => 1 / x,
|
|
790
|
+
neg: (x) => -x
|
|
791
|
+
});
|
|
792
|
+
var COMPLEX_ROOTS_O = ComplexArrInterleaved.decode(COMPLEX_ROOTS);
|
|
793
|
+
var FFTCoreRoots = {};
|
|
794
|
+
var FFTCoreRootsConj = {};
|
|
795
|
+
for (let logn = 0; logn < 10; logn++) {
|
|
796
|
+
const out = new Array(1 << logn);
|
|
797
|
+
const outC = new Array(1 << logn);
|
|
798
|
+
for (let i = 0, g1 = 1, g2 = 1; i < logn; i++) {
|
|
799
|
+
const ng = 1 << i;
|
|
800
|
+
for (let k = 0; k < ng; k++) out[g1++] = COMPLEX_ROOTS_O[(ng << 1) + k];
|
|
801
|
+
const ng2 = 1 << logn - i;
|
|
802
|
+
for (let k = 0; k < ng2 >> 1; k++)
|
|
803
|
+
outC[out.length - g2++] = fComplex.neg(fComplex.conj(COMPLEX_ROOTS_O[ng2 + k]));
|
|
804
|
+
}
|
|
805
|
+
FFTCoreRoots[logn] = out;
|
|
806
|
+
FFTCoreRootsConj[logn] = outC;
|
|
807
|
+
}
|
|
808
|
+
function getFloatPoly(logn) {
|
|
809
|
+
const n = 1 << logn;
|
|
810
|
+
const N_COMPLEX = n >> 1;
|
|
811
|
+
const hn = Math.log2(N_COMPLEX);
|
|
812
|
+
const fftOpts = { N: N_COMPLEX, invertButterflies: true, skipStages: 0, brp: false };
|
|
813
|
+
const inv = 1 / N_COMPLEX;
|
|
814
|
+
return {
|
|
815
|
+
to: (f) => ComplexArr.decode(Array.from(f)),
|
|
816
|
+
from: (f) => new Float64Array(ComplexArr.encode(f)),
|
|
817
|
+
// Runtime callers also pass HashToPoint's Uint16Array output here;
|
|
818
|
+
// the implementation only needs a numeric typed-array shape,
|
|
819
|
+
// even though the local type is narrower.
|
|
820
|
+
convSmall: (f) => ComplexArr.decode(Array.from(f)),
|
|
821
|
+
add: (a, b) => a.map((i, j) => fComplex.add(i, b[j])),
|
|
822
|
+
sub: (a, b) => a.map((i, j) => fComplex.sub(i, b[j])),
|
|
823
|
+
neg: (a) => a.map((i) => fComplex.neg(i)),
|
|
824
|
+
mul: (a, b) => a.map((i, j) => fComplex.mul(i, b[j])),
|
|
825
|
+
conj: (a) => a.map((i) => fComplex.conj(i)),
|
|
826
|
+
mulConst: (a, x) => a.map((i) => fComplex.scale(i, x)),
|
|
827
|
+
scaleNorm: (a, b) => a.map((i, j) => fComplex.scale(i, b[j])),
|
|
828
|
+
invNorm: (a, b) => new Float64Array(a.map((i, j) => 1 / fComplex.magSqSum(i, b[j]))),
|
|
829
|
+
FFT: (f) => (0, import_fft2.FFTCore)(fComplex, { ...fftOpts, dit: false, roots: FFTCoreRoots[hn] })(f),
|
|
830
|
+
iFFT(f) {
|
|
831
|
+
(0, import_fft2.FFTCore)(fComplex, { ...fftOpts, dit: true, roots: FFTCoreRootsConj[hn] })(f);
|
|
832
|
+
for (let i = 0; i < f.length; i++) f[i] = fComplex.scale(f[i], inv);
|
|
833
|
+
return f;
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
function ldlFFT(logn, g00t, g01t, g11t) {
|
|
838
|
+
g00t = g00t.slice();
|
|
839
|
+
g01t = g01t.slice();
|
|
840
|
+
g11t = g11t.slice();
|
|
841
|
+
const hn = 1 << logn - 1;
|
|
842
|
+
for (let i = 0; i < hn; i++) {
|
|
843
|
+
const g01 = g01t[i];
|
|
844
|
+
const g11 = g11t[i];
|
|
845
|
+
const mu = fComplex.scale(g01, 1 / g00t[i].re);
|
|
846
|
+
g11t[i] = { re: g11.re - (mu.re * g01.re + mu.im * g01.im), im: g11.im };
|
|
847
|
+
g01t[i] = fComplex.conj(mu);
|
|
848
|
+
}
|
|
849
|
+
return { g00: g00t, g01: g01t, g11: g11t };
|
|
850
|
+
}
|
|
851
|
+
function ApproxExp(x, ccs) {
|
|
852
|
+
const ev = [
|
|
853
|
+
0.9999999999999949,
|
|
854
|
+
0.5000000000000192,
|
|
855
|
+
0.16666666666698401,
|
|
856
|
+
0.04166666666611049,
|
|
857
|
+
0.008333333327800835,
|
|
858
|
+
0.001388888894063187,
|
|
859
|
+
1984127392773119e-19,
|
|
860
|
+
2480156683358538e-20,
|
|
861
|
+
27555863502191225e-22,
|
|
862
|
+
2756073561604778e-22,
|
|
863
|
+
2529950637944207e-23,
|
|
864
|
+
2073772366009083e-24
|
|
865
|
+
];
|
|
866
|
+
const y = -x;
|
|
867
|
+
let z = ev[ev.length - 1];
|
|
868
|
+
for (let i = ev.length - 2; i >= 0; i--) z = z * y + ev[i];
|
|
869
|
+
return ccs * (1 + z * y);
|
|
870
|
+
}
|
|
871
|
+
function genFalcon(opts) {
|
|
872
|
+
const { N: N2 } = opts;
|
|
873
|
+
const logn = Math.log2(N2);
|
|
874
|
+
const id = (n) => n;
|
|
875
|
+
const { newPoly, intPoly, signedCoder } = getIntPoly(logn);
|
|
876
|
+
const floatPoly = getFloatPoly(logn);
|
|
877
|
+
class NTRU {
|
|
878
|
+
logn;
|
|
879
|
+
shake;
|
|
880
|
+
constructor(logn2, seed) {
|
|
881
|
+
this.logn = logn2;
|
|
882
|
+
this.shake = import_sha32.shake256.create().update(seed);
|
|
883
|
+
}
|
|
884
|
+
gaussSingle() {
|
|
885
|
+
const g = 1 << 10 - this.logn;
|
|
886
|
+
let val = 0;
|
|
887
|
+
for (let i = 0; i < g; i++) {
|
|
888
|
+
const r128 = (0, import_utils3.bytesToNumberLE)(this.shake.xof(16));
|
|
889
|
+
const r1 = r128 & MASK_63n;
|
|
890
|
+
const r2 = r128 >> _64n & MASK_63n;
|
|
891
|
+
const sign2 = Number(r128 >> _63n & _1n);
|
|
892
|
+
let f = r1 < gauss_1024_12289[0] ? 1 : 0;
|
|
893
|
+
let v = 0;
|
|
894
|
+
for (let k = 1; k < gauss_1024_12289.length; k++) {
|
|
895
|
+
const tBit = r2 >= gauss_1024_12289[k] ? 1 : 0;
|
|
896
|
+
v |= k & -(tBit & (f ^ 1));
|
|
897
|
+
f |= tBit;
|
|
898
|
+
}
|
|
899
|
+
val += sign2 === 1 ? -v : v;
|
|
900
|
+
}
|
|
901
|
+
return val;
|
|
902
|
+
}
|
|
903
|
+
polyGauss() {
|
|
904
|
+
const n = 1 << this.logn;
|
|
905
|
+
let mod2 = 0;
|
|
906
|
+
const f = new Int8Array(n);
|
|
907
|
+
for (let u = 0; u < n; u++) {
|
|
908
|
+
let s;
|
|
909
|
+
while (true) {
|
|
910
|
+
s = this.gaussSingle();
|
|
911
|
+
if (s < -127 || s > 127) continue;
|
|
912
|
+
if (u === n - 1) {
|
|
913
|
+
if ((mod2 ^ s & 1) === 0) continue;
|
|
914
|
+
}
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
if (u < n - 1) mod2 ^= s & 1;
|
|
918
|
+
f[u] = s;
|
|
919
|
+
}
|
|
920
|
+
return f;
|
|
921
|
+
}
|
|
922
|
+
galoisNorm(logn2, a) {
|
|
923
|
+
const n = 1 << logn2;
|
|
924
|
+
const d = new Array(n >> 1);
|
|
925
|
+
for (let k = 0; k < n; k += 2) {
|
|
926
|
+
let s = _0n;
|
|
927
|
+
for (let i = 0; i <= k; i += 2) s += a[i] * a[k - i];
|
|
928
|
+
for (let i = k + 2; i < n; i += 2) s -= a[i] * a[k + n - i];
|
|
929
|
+
d[k >>> 1] = s;
|
|
930
|
+
}
|
|
931
|
+
for (let k = 0; k < n; k += 2) {
|
|
932
|
+
let s = _0n;
|
|
933
|
+
for (let i = 1; i < k; i += 2) s += a[i] * a[k - i];
|
|
934
|
+
for (let i = k + 1; i < n; i += 2) s -= a[i] * a[k + n - i];
|
|
935
|
+
d[k >>> 1] -= s;
|
|
936
|
+
}
|
|
937
|
+
return d;
|
|
938
|
+
}
|
|
939
|
+
mulConjD(logn2, d, a, b) {
|
|
940
|
+
const n = 1 << logn2;
|
|
941
|
+
for (let k = 0; k < n; k++) {
|
|
942
|
+
let s = _0n;
|
|
943
|
+
for (let i = 0; i <= k; i += 2) s += b[i >>> 1] * a[k - i];
|
|
944
|
+
for (let i = k + 2 - (k & 1); i < n; i += 2) s -= b[i >>> 1] * a[k + n - i];
|
|
945
|
+
if ((k & 1) === 0) d[k] = s;
|
|
946
|
+
else d[k] = -s;
|
|
947
|
+
}
|
|
948
|
+
return d;
|
|
949
|
+
}
|
|
950
|
+
subMul(logn2, a, b, c, e) {
|
|
951
|
+
const n = 1 << logn2;
|
|
952
|
+
for (let k = 0; k < n; k++) {
|
|
953
|
+
let s = _0n;
|
|
954
|
+
for (let i = 0; i <= k; i++) s += b[i] * c[k - i];
|
|
955
|
+
for (let i = k + 1; i < n; i++) s -= b[i] * c[k + n - i];
|
|
956
|
+
a[k] -= s << e;
|
|
957
|
+
}
|
|
958
|
+
return a;
|
|
959
|
+
}
|
|
960
|
+
reduce(logn2, f, g, F, G, logn_top) {
|
|
961
|
+
const n = 1 << logn2;
|
|
962
|
+
const depth = logn_top - logn2;
|
|
963
|
+
const floatPoly2 = getFloatPoly(logn2);
|
|
964
|
+
const slen = MAX_BL_SMALL[depth];
|
|
965
|
+
const llen = MAX_BL_LARGE[depth];
|
|
966
|
+
let maxFGBits = BigInt(31 * llen);
|
|
967
|
+
let FGlen = BigInt(llen);
|
|
968
|
+
const scalefg = BigInt(31 * (slen - 10));
|
|
969
|
+
const fgMaxBits = BITLENGTH[depth].avg + 6 * BITLENGTH[depth].std;
|
|
970
|
+
const fgMinBits = BITLENGTH[depth].avg - 6 * BITLENGTH[depth].std;
|
|
971
|
+
let scaleK = BigInt(Math.round(31 * llen - fgMinBits));
|
|
972
|
+
let fx = new Float64Array(n);
|
|
973
|
+
let gx = new Float64Array(n);
|
|
974
|
+
for (let i = 0; i < n; i++) {
|
|
975
|
+
fx[i] = Number(f[i] >> scalefg);
|
|
976
|
+
gx[i] = Number(g[i] >> scalefg);
|
|
977
|
+
}
|
|
978
|
+
const rt3 = floatPoly2.conj(floatPoly2.FFT(floatPoly2.to(fx)));
|
|
979
|
+
const rt4 = floatPoly2.conj(floatPoly2.FFT(floatPoly2.to(gx)));
|
|
980
|
+
const rt5 = floatPoly2.invNorm(rt3, rt4);
|
|
981
|
+
const Fx = new Float64Array(n);
|
|
982
|
+
const Gx = new Float64Array(n);
|
|
983
|
+
const k = new Array(n);
|
|
984
|
+
while (true) {
|
|
985
|
+
let scaleFG = _31n * (FGlen - _10n);
|
|
986
|
+
for (let i = 0; i < n; i++) {
|
|
987
|
+
Fx[i] = Number(F[i] >> scaleFG);
|
|
988
|
+
Gx[i] = Number(G[i] >> scaleFG);
|
|
989
|
+
}
|
|
990
|
+
const rt2 = floatPoly2.mul(floatPoly2.FFT(floatPoly2.to(Gx)), rt4);
|
|
991
|
+
const rt1 = floatPoly2.mul(floatPoly2.FFT(floatPoly2.to(Fx)), rt3);
|
|
992
|
+
const rt2f = floatPoly2.from(
|
|
993
|
+
floatPoly2.iFFT(floatPoly2.scaleNorm(floatPoly2.add(rt2, rt1), rt5))
|
|
994
|
+
);
|
|
995
|
+
const pdc = 2 ** Number(scaleFG - scalefg - scaleK);
|
|
996
|
+
for (let i = 0; i < n; i++) {
|
|
997
|
+
const BOUND = 2147483647;
|
|
998
|
+
const val = rt2f[i] * pdc;
|
|
999
|
+
if (val <= -BOUND || val >= BOUND) return false;
|
|
1000
|
+
k[i] = BigInt(Math.round(val));
|
|
1001
|
+
}
|
|
1002
|
+
F = this.subMul(logn2, F, f, k, scaleK);
|
|
1003
|
+
G = this.subMul(logn2, G, g, k, scaleK);
|
|
1004
|
+
const maxfgNew = scaleK + BigInt(Math.round(fgMaxBits)) + _10n;
|
|
1005
|
+
if (maxfgNew < maxFGBits) maxFGBits = maxfgNew;
|
|
1006
|
+
if (FGlen > _1n && FGlen * _31n >= maxFGBits + _31n) FGlen--;
|
|
1007
|
+
if (scaleK <= _0n) break;
|
|
1008
|
+
scaleK -= _25n;
|
|
1009
|
+
if (scaleK < _0n) scaleK = _0n;
|
|
1010
|
+
}
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
1013
|
+
// This is recursive thing that goes from logn to 0
|
|
1014
|
+
solveBranch(logn2, f, g, F, G, logn_top) {
|
|
1015
|
+
if (logn2 === 0) {
|
|
1016
|
+
const xf = f[0];
|
|
1017
|
+
const xg = g[0];
|
|
1018
|
+
if (xf <= _0n || xg <= _0n) return false;
|
|
1019
|
+
try {
|
|
1020
|
+
const u1 = (0, import_modular.invert)(xf, xg);
|
|
1021
|
+
const v1 = (_1n - u1 * xf) / xg;
|
|
1022
|
+
F[0] = -v1 * QBig;
|
|
1023
|
+
G[0] = u1 * QBig;
|
|
1024
|
+
return true;
|
|
1025
|
+
} catch (e) {
|
|
1026
|
+
return false;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
if (logn_top === void 0) logn_top = logn2;
|
|
1030
|
+
const n = 1 << logn2;
|
|
1031
|
+
const hn = n >>> 1;
|
|
1032
|
+
if (!f || f.length < n || !g || g.length < n) return false;
|
|
1033
|
+
const fp = this.galoisNorm(logn2, f);
|
|
1034
|
+
const gp = this.galoisNorm(logn2, g);
|
|
1035
|
+
const Fp = new Array(hn);
|
|
1036
|
+
const Gp = new Array(hn);
|
|
1037
|
+
if (!this.solveBranch(logn2 - 1, fp, gp, Fp, Gp, logn_top)) return false;
|
|
1038
|
+
F = this.mulConjD(logn2, F, g, Fp);
|
|
1039
|
+
G = this.mulConjD(logn2, G, f, Gp);
|
|
1040
|
+
return this.reduce(logn2, f, g, F, G, logn_top);
|
|
1041
|
+
}
|
|
1042
|
+
solve(f, g) {
|
|
1043
|
+
const n = 1 << logn;
|
|
1044
|
+
const bf = Array.from(f).map(BigInt);
|
|
1045
|
+
const bg = Array.from(g).map(BigInt);
|
|
1046
|
+
const bF = new Array(n);
|
|
1047
|
+
const bG = new Array(n);
|
|
1048
|
+
if (!this.solveBranch(logn, bf, bg, bF, bG)) return false;
|
|
1049
|
+
const F = new Int8Array(n);
|
|
1050
|
+
const G = new Int8Array(n);
|
|
1051
|
+
for (let i = 0; i < n; i++) {
|
|
1052
|
+
const x = bF[i];
|
|
1053
|
+
const y = bG[i];
|
|
1054
|
+
if (x < -127 || x > 127 || y < -127 || y > 127) return false;
|
|
1055
|
+
F[i] = Number(x);
|
|
1056
|
+
G[i] = Number(y);
|
|
1057
|
+
}
|
|
1058
|
+
return [F, G];
|
|
1059
|
+
}
|
|
1060
|
+
generate() {
|
|
1061
|
+
let max = 1e6;
|
|
1062
|
+
let curr = 0;
|
|
1063
|
+
while (true) {
|
|
1064
|
+
if (curr++ === max) throw new Error("can't generate key");
|
|
1065
|
+
const f = this.polyGauss();
|
|
1066
|
+
const g = this.polyGauss();
|
|
1067
|
+
let lim = 1 << opts.fgBits - 1;
|
|
1068
|
+
for (let u = 0; u < N2; u++) {
|
|
1069
|
+
if (f[u] >= lim || f[u] <= -lim || g[u] >= lim || g[u] <= -lim) {
|
|
1070
|
+
lim = -1;
|
|
1071
|
+
break;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
if (lim < 0) continue;
|
|
1075
|
+
const normf = intPoly.smallSqnorm(f);
|
|
1076
|
+
const normg = intPoly.smallSqnorm(g);
|
|
1077
|
+
const norm = normf + normg | -((normf | normg) >>> 31);
|
|
1078
|
+
if (norm >= 16823) continue;
|
|
1079
|
+
let rt1 = floatPoly.FFT(floatPoly.convSmall(f));
|
|
1080
|
+
let rt2 = floatPoly.FFT(floatPoly.convSmall(g));
|
|
1081
|
+
const rt3 = floatPoly.invNorm(rt1, rt2);
|
|
1082
|
+
rt1 = floatPoly.iFFT(floatPoly.scaleNorm(floatPoly.mulConst(floatPoly.conj(rt1), Q), rt3));
|
|
1083
|
+
rt2 = floatPoly.iFFT(floatPoly.scaleNorm(floatPoly.mulConst(floatPoly.conj(rt2), Q), rt3));
|
|
1084
|
+
let bnorm = 0;
|
|
1085
|
+
for (let u = 0; u < rt1.length; u++) {
|
|
1086
|
+
bnorm += rt1[u].re * rt1[u].re;
|
|
1087
|
+
bnorm += rt2[u].re * rt2[u].re;
|
|
1088
|
+
}
|
|
1089
|
+
for (let u = 0; u < rt1.length; u++) {
|
|
1090
|
+
bnorm += rt1[u].im * rt1[u].im;
|
|
1091
|
+
bnorm += rt2[u].im * rt2[u].im;
|
|
1092
|
+
}
|
|
1093
|
+
if (!(bnorm < BNORM_MAX)) continue;
|
|
1094
|
+
let pub;
|
|
1095
|
+
try {
|
|
1096
|
+
pub = computePublic(f, g);
|
|
1097
|
+
} catch (_) {
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
const solved = this.solve(f, g);
|
|
1101
|
+
if (solved === false) continue;
|
|
1102
|
+
return [f, g, solved[0], solved[1], pub];
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
const modqCoder = () => {
|
|
1107
|
+
const coder = bitsCoderMSB(newPoly, N2, 14, {
|
|
1108
|
+
encode: id,
|
|
1109
|
+
decode: id
|
|
1110
|
+
});
|
|
1111
|
+
return {
|
|
1112
|
+
bytesLen: coder.bytesLen,
|
|
1113
|
+
encode(poly) {
|
|
1114
|
+
for (let i = 0; i < poly.length; i++)
|
|
1115
|
+
if (poly[i] >= 12289) throw new Error("public key coeff out of range");
|
|
1116
|
+
return coder.encode(poly);
|
|
1117
|
+
},
|
|
1118
|
+
decode(bytes) {
|
|
1119
|
+
if (bytes.length !== coder.bytesLen) throw new Error("wrong public key length");
|
|
1120
|
+
const poly = coder.decode(bytes);
|
|
1121
|
+
for (let i = 0; i < poly.length; i++)
|
|
1122
|
+
if (poly[i] >= 12289) throw new Error("public key coeff out of range");
|
|
1123
|
+
const normalized = coder.encode(poly);
|
|
1124
|
+
if (normalized.length !== bytes.length) throw new Error("wrong public key length");
|
|
1125
|
+
for (let i = 0; i < bytes.length; i++)
|
|
1126
|
+
if (bytes[i] !== normalized[i]) throw new Error("wrong public key encoding");
|
|
1127
|
+
return poly;
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
};
|
|
1131
|
+
const trimI8Coder = (bits) => {
|
|
1132
|
+
const shift = 32 - bits;
|
|
1133
|
+
const coder = bitsCoderMSB((len) => new Int8Array(len), N2, bits, {
|
|
1134
|
+
encode: (v) => v & (1 << bits) - 1,
|
|
1135
|
+
decode: (w) => (w & getMask(bits)) << shift >> shift
|
|
1136
|
+
});
|
|
1137
|
+
return {
|
|
1138
|
+
bytesLen: coder.bytesLen,
|
|
1139
|
+
encode(poly) {
|
|
1140
|
+
const max = (1 << bits - 1) - 1;
|
|
1141
|
+
const min = -max;
|
|
1142
|
+
for (let i = 0; i < poly.length; i++)
|
|
1143
|
+
if (poly[i] < min || poly[i] > max) throw new Error("private key coeff out of range");
|
|
1144
|
+
return coder.encode(poly);
|
|
1145
|
+
},
|
|
1146
|
+
decode(bytes) {
|
|
1147
|
+
const poly = coder.decode(bytes);
|
|
1148
|
+
const min = -(1 << bits - 1);
|
|
1149
|
+
for (let i = 0; i < poly.length; i++)
|
|
1150
|
+
if (poly[i] === min) throw new Error("forbidden private key coeff");
|
|
1151
|
+
return poly;
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
};
|
|
1155
|
+
const fgCoder = trimI8Coder(opts.fgBits);
|
|
1156
|
+
const FGCoder = trimI8Coder(opts.FGBits);
|
|
1157
|
+
const secretKeyCoder = headerCoder(
|
|
1158
|
+
80 + logn,
|
|
1159
|
+
splitCoder("falcon.secretKey", fgCoder, fgCoder, FGCoder)
|
|
1160
|
+
);
|
|
1161
|
+
const publicKeyCoder = headerCoder(0 + logn, modqCoder());
|
|
1162
|
+
const decodePaddedSig = (s2) => {
|
|
1163
|
+
const normalized = compCoder(N2).encode(compCoder(N2).decode(s2));
|
|
1164
|
+
for (let i = normalized.length; i < s2.length; i++)
|
|
1165
|
+
if (s2[i] !== 0) throw new Error("non-zero padding");
|
|
1166
|
+
return normalized;
|
|
1167
|
+
};
|
|
1168
|
+
const decodeUnpaddedSig = (s2) => {
|
|
1169
|
+
const normalized = compCoder(N2).encode(compCoder(N2).decode(s2));
|
|
1170
|
+
if (normalized.length !== s2.length) throw new Error("wrong signature length");
|
|
1171
|
+
return s2;
|
|
1172
|
+
};
|
|
1173
|
+
const decodeSig = opts.padded ? decodePaddedSig : decodeUnpaddedSig;
|
|
1174
|
+
const SignatureCoderBasic = (logn2) => {
|
|
1175
|
+
const TYPE_BYTE = 32 + logn2;
|
|
1176
|
+
return {
|
|
1177
|
+
encode({ msg, nonce, s2 }) {
|
|
1178
|
+
let compressed = s2;
|
|
1179
|
+
const payloadLen = 1 + compressed.length;
|
|
1180
|
+
const totalLen = 2 + NONCELEN + msg.length + payloadLen;
|
|
1181
|
+
const out = new Uint8Array(totalLen);
|
|
1182
|
+
let i = 0;
|
|
1183
|
+
out[i++] = payloadLen >> 8 & 255;
|
|
1184
|
+
out[i++] = payloadLen & 255;
|
|
1185
|
+
out.set(nonce, i);
|
|
1186
|
+
i += NONCELEN;
|
|
1187
|
+
out.set(msg, i);
|
|
1188
|
+
i += msg.length;
|
|
1189
|
+
out[i++] = TYPE_BYTE;
|
|
1190
|
+
out.set(compressed, i);
|
|
1191
|
+
return out;
|
|
1192
|
+
},
|
|
1193
|
+
decode(data) {
|
|
1194
|
+
if (!data || data.length < NONCELEN + 3) throw new Error("signature coder: wrong length");
|
|
1195
|
+
const len = data[0] << 8 | data[1];
|
|
1196
|
+
const s2Len = len - 1;
|
|
1197
|
+
const msgLen = data.length - NONCELEN - 3 - s2Len;
|
|
1198
|
+
if (msgLen < 0) throw new Error("signature coder: wrong msg length");
|
|
1199
|
+
const typeByte = data[2 + NONCELEN + msgLen];
|
|
1200
|
+
if (typeByte !== TYPE_BYTE) throw new Error("signature coder: wrong type byte");
|
|
1201
|
+
const nonce = data.subarray(2, 2 + NONCELEN);
|
|
1202
|
+
const msg = data.subarray(2 + NONCELEN, 2 + NONCELEN + msgLen);
|
|
1203
|
+
const s2 = decodeUnpaddedSig(data.subarray(2 + NONCELEN + msgLen + 1));
|
|
1204
|
+
if (s2.length !== s2Len) throw new Error("signature coder: wrong s2 length");
|
|
1205
|
+
return { msg, nonce, s2 };
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
};
|
|
1209
|
+
const SignatureCoderPadded = (logn2) => {
|
|
1210
|
+
const sigLen = opts.paddedLen;
|
|
1211
|
+
return {
|
|
1212
|
+
encode({ msg, nonce, s2 }) {
|
|
1213
|
+
return headerCoder(
|
|
1214
|
+
48 + logn2,
|
|
1215
|
+
splitCoder("falcon.signature", NONCELEN, sigLen, msg.length)
|
|
1216
|
+
).encode([nonce, pad(sigLen).encode(s2), msg]);
|
|
1217
|
+
},
|
|
1218
|
+
decode(data) {
|
|
1219
|
+
(0, import_utils4.abytes)(data, void 0, "signature");
|
|
1220
|
+
const msgLen = data.length - NONCELEN - sigLen - 1;
|
|
1221
|
+
if (msgLen < 0) throw new Error("signature coder: wrong length");
|
|
1222
|
+
const [nonce, s2, msg] = headerCoder(
|
|
1223
|
+
48 + logn2,
|
|
1224
|
+
splitCoder("falcon.signature", NONCELEN, sigLen, msgLen)
|
|
1225
|
+
).decode(data);
|
|
1226
|
+
return { nonce, s2: decodeSig(s2), msg };
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
};
|
|
1230
|
+
const SignatureCoderDetached = (logn2) => {
|
|
1231
|
+
const paddedSigLen = opts.sigLen - 1 - NONCELEN;
|
|
1232
|
+
const getSigLen = (s2) => opts.padded ? paddedSigLen : s2.length;
|
|
1233
|
+
return {
|
|
1234
|
+
encode({ nonce, s2 }) {
|
|
1235
|
+
return headerCoder(
|
|
1236
|
+
48 + logn2,
|
|
1237
|
+
splitCoder("falcon.detachedSignature", NONCELEN, getSigLen(s2))
|
|
1238
|
+
).encode([nonce, opts.padded ? pad(paddedSigLen).encode(s2) : s2]);
|
|
1239
|
+
},
|
|
1240
|
+
decode(data) {
|
|
1241
|
+
if (!opts.padded && data.length > 1 + NONCELEN + opts.maxS2Len)
|
|
1242
|
+
throw new Error("detached signature too long");
|
|
1243
|
+
const payloadLen = opts.padded ? paddedSigLen : data.length - NONCELEN - 1;
|
|
1244
|
+
const [nonce, raw] = headerCoder(
|
|
1245
|
+
48 + logn2,
|
|
1246
|
+
splitCoder("falcon.detachedSignature", NONCELEN, payloadLen)
|
|
1247
|
+
).decode(data);
|
|
1248
|
+
const s2 = decodeSig(raw);
|
|
1249
|
+
return { nonce, s2 };
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
};
|
|
1253
|
+
const SignatureCoder = (opts.padded ? SignatureCoderPadded : SignatureCoderBasic)(logn);
|
|
1254
|
+
const invertF = (f) => {
|
|
1255
|
+
const tt = intPoly.ntt(signedCoder.decode(f));
|
|
1256
|
+
for (let u = 0; u < N2; u++)
|
|
1257
|
+
if (tt[u] === 0) throw new Error("invalid secretKey: non-invertible f");
|
|
1258
|
+
return tt;
|
|
1259
|
+
};
|
|
1260
|
+
function computePublic(f, g) {
|
|
1261
|
+
const tt = invertF(f);
|
|
1262
|
+
const h = intPoly.ntt(signedCoder.decode(g));
|
|
1263
|
+
const res2 = intPoly.div(h, tt);
|
|
1264
|
+
cleanBytes(tt);
|
|
1265
|
+
return res2;
|
|
1266
|
+
}
|
|
1267
|
+
function completePrivate(f, g, F) {
|
|
1268
|
+
let t1 = intPoly.toMontgomery(intPoly.ntt(signedCoder.decode(g)));
|
|
1269
|
+
const t2 = intPoly.ntt(signedCoder.decode(F));
|
|
1270
|
+
const tt = invertF(f);
|
|
1271
|
+
t1 = intPoly.div(intPoly.mul(t1, t2), tt);
|
|
1272
|
+
const G = new Int8Array(N2);
|
|
1273
|
+
for (let u = 0; u < N2; u++) {
|
|
1274
|
+
let w = t1[u];
|
|
1275
|
+
w -= Q & ~-(w - Qhalf >>> 31);
|
|
1276
|
+
const gi = w | 0;
|
|
1277
|
+
if (gi < -127 || gi > 127) {
|
|
1278
|
+
cleanBytes(t1, t2, tt, G);
|
|
1279
|
+
throw new Error("Coefficient out of bounds");
|
|
1280
|
+
}
|
|
1281
|
+
G[u] = gi;
|
|
1282
|
+
}
|
|
1283
|
+
cleanBytes(t1, t2, tt);
|
|
1284
|
+
return G;
|
|
1285
|
+
}
|
|
1286
|
+
function HashToPoint(nonce, msg) {
|
|
1287
|
+
const h = import_sha32.shake256.create().update(nonce).update(msg);
|
|
1288
|
+
const c = new Uint16Array(N2);
|
|
1289
|
+
const kQ = 5 * Q;
|
|
1290
|
+
for (let i = 0; i < N2; ) {
|
|
1291
|
+
const tmp = h.xof(2);
|
|
1292
|
+
let w = tmp[0] << 8 | tmp[1];
|
|
1293
|
+
if (w < kQ) c[i++] = w % Q;
|
|
1294
|
+
}
|
|
1295
|
+
return c;
|
|
1296
|
+
}
|
|
1297
|
+
class FFSampler {
|
|
1298
|
+
logn;
|
|
1299
|
+
// Shake
|
|
1300
|
+
shake;
|
|
1301
|
+
shakeBuf;
|
|
1302
|
+
ctrView;
|
|
1303
|
+
// ChaCha
|
|
1304
|
+
ctr = _0n;
|
|
1305
|
+
buf;
|
|
1306
|
+
buf32;
|
|
1307
|
+
pos;
|
|
1308
|
+
key;
|
|
1309
|
+
nonce32;
|
|
1310
|
+
curBlock;
|
|
1311
|
+
curBlock32;
|
|
1312
|
+
view;
|
|
1313
|
+
// Sampler
|
|
1314
|
+
b01;
|
|
1315
|
+
b11;
|
|
1316
|
+
g00;
|
|
1317
|
+
g01;
|
|
1318
|
+
g11;
|
|
1319
|
+
constructor(logn2, seed, b00, b01, b10, b11) {
|
|
1320
|
+
this.logn = logn2;
|
|
1321
|
+
this.shake = import_sha32.shake256.create().update(seed);
|
|
1322
|
+
this.shakeBuf = new Uint8Array(56);
|
|
1323
|
+
this.key = this.shakeBuf.subarray(0, 32);
|
|
1324
|
+
this.nonce32 = (0, import_utils4.u32)(this.shakeBuf.subarray(32, 48));
|
|
1325
|
+
this.ctrView = (0, import_utils4.createView)(this.shakeBuf.subarray(48, 56));
|
|
1326
|
+
this.curBlock = new Uint8Array(64);
|
|
1327
|
+
this.curBlock32 = (0, import_utils4.u32)(this.curBlock);
|
|
1328
|
+
this.buf = new Uint8Array(8 * this.curBlock.length);
|
|
1329
|
+
this.buf32 = (0, import_utils4.u32)(this.buf);
|
|
1330
|
+
this.pos = this.buf.length;
|
|
1331
|
+
this.view = (0, import_utils4.createView)(this.buf);
|
|
1332
|
+
this.b01 = b01;
|
|
1333
|
+
this.b11 = b11;
|
|
1334
|
+
const { g00, g01, g11 } = this.gramFFT(b00, b10);
|
|
1335
|
+
this.g00 = g00;
|
|
1336
|
+
this.g01 = g01;
|
|
1337
|
+
this.g11 = g11;
|
|
1338
|
+
}
|
|
1339
|
+
destroy() {
|
|
1340
|
+
this.shake.destroy();
|
|
1341
|
+
cleanBytes(this.shakeBuf, this.curBlock, this.buf);
|
|
1342
|
+
cleanCPoly(this.b01, this.b11, this.g00, this.g01, this.g11);
|
|
1343
|
+
}
|
|
1344
|
+
refill(minBytes) {
|
|
1345
|
+
if (this.buf.length - this.pos >= minBytes) return;
|
|
1346
|
+
const out32 = (0, import_utils4.swap32IfBE)(this.buf32);
|
|
1347
|
+
for (let i = 0; i < 8; i++, this.ctr++) {
|
|
1348
|
+
const n = (0, import_utils4.swap32IfBE)(this.nonce32.slice());
|
|
1349
|
+
n[2] ^= Number(this.ctr & MASK_32n);
|
|
1350
|
+
n[3] ^= Number(this.ctr >> _32n);
|
|
1351
|
+
(0, import_utils4.swap32IfBE)(n.subarray(1));
|
|
1352
|
+
(0, import_chacha.chacha20)(this.key, (0, import_utils4.u8)(n.subarray(1)), EMPTY_CHACHA20_BLOCK, this.curBlock, n[0]);
|
|
1353
|
+
const block32 = (0, import_utils4.swap32IfBE)(this.curBlock32);
|
|
1354
|
+
for (let j = 0; j < 16; j++) out32[i + j * 8] = block32[j];
|
|
1355
|
+
(0, import_utils4.swap32IfBE)(block32);
|
|
1356
|
+
}
|
|
1357
|
+
(0, import_utils4.swap32IfBE)(out32);
|
|
1358
|
+
this.pos = 0;
|
|
1359
|
+
}
|
|
1360
|
+
// Sampler
|
|
1361
|
+
gaussian0() {
|
|
1362
|
+
this.refill(9);
|
|
1363
|
+
const t0 = this.view.getUint32(this.pos, true);
|
|
1364
|
+
const t1 = this.view.getUint32(this.pos + 4, true);
|
|
1365
|
+
const t2 = this.buf[this.pos + 8];
|
|
1366
|
+
this.pos += 9;
|
|
1367
|
+
const v0 = t0 & 16777215;
|
|
1368
|
+
const v1 = t0 >>> 24 & 255 | (t1 & 65535) << 8;
|
|
1369
|
+
const v2 = t1 >>> 16 & 65535 | t2 << 16;
|
|
1370
|
+
let z = 0;
|
|
1371
|
+
for (let i = 0; i < GAUSS0.length; i += 3) {
|
|
1372
|
+
let cc = v0 - GAUSS0[i + 2] >>> 31;
|
|
1373
|
+
cc = (v1 - GAUSS0[i + 1] | 0) - cc >>> 31;
|
|
1374
|
+
cc = (v2 - GAUSS0[i + 0] | 0) - cc >>> 31;
|
|
1375
|
+
z += cc;
|
|
1376
|
+
}
|
|
1377
|
+
return z;
|
|
1378
|
+
}
|
|
1379
|
+
berExp(x, ccs) {
|
|
1380
|
+
let s = Math.trunc(x * 1.4426950408889634);
|
|
1381
|
+
const r = x - s * 0.6931471805599453;
|
|
1382
|
+
let e = ApproxExp(r, ccs);
|
|
1383
|
+
e *= 2147483648;
|
|
1384
|
+
let z1 = e | 0;
|
|
1385
|
+
e = (e - z1) * 4294967296;
|
|
1386
|
+
let z0 = e | 0;
|
|
1387
|
+
z1 = z1 << 1 | z0 >>> 31;
|
|
1388
|
+
z0 <<= 1;
|
|
1389
|
+
s = (s | 63 - s >>> 26) & 63;
|
|
1390
|
+
const sm = -(s >>> 5) | 0;
|
|
1391
|
+
z0 ^= sm & (z0 ^ z1);
|
|
1392
|
+
z1 &= ~sm;
|
|
1393
|
+
s &= 31;
|
|
1394
|
+
z0 = z0 >>> s | z1 << 31 - s << 1;
|
|
1395
|
+
z1 >>>= s;
|
|
1396
|
+
for (let j = 0; j < 2; j++) {
|
|
1397
|
+
for (let i = 24; i >= 0; i -= 8) {
|
|
1398
|
+
this.refill(1);
|
|
1399
|
+
const w = this.buf[this.pos++];
|
|
1400
|
+
const bz = z1 >>> i & 255;
|
|
1401
|
+
if (w !== bz) return w < bz;
|
|
1402
|
+
}
|
|
1403
|
+
z1 = z0;
|
|
1404
|
+
}
|
|
1405
|
+
return false;
|
|
1406
|
+
}
|
|
1407
|
+
samplerZ(mu, isigma) {
|
|
1408
|
+
const s = Math.floor(mu);
|
|
1409
|
+
const r = mu - s;
|
|
1410
|
+
const dss = isigma * isigma * 0.5;
|
|
1411
|
+
const ccs = isigma * SIGMA_MIN[this.logn];
|
|
1412
|
+
for (; ; ) {
|
|
1413
|
+
const z0 = this.gaussian0();
|
|
1414
|
+
this.refill(1);
|
|
1415
|
+
const b = this.buf[this.pos++] & 1;
|
|
1416
|
+
const z = ((z0 << 1) + 1 & -b) - z0;
|
|
1417
|
+
let x = z - r;
|
|
1418
|
+
x = x * x * dss - z0 * z0 * 0.15086504887537272;
|
|
1419
|
+
if (this.berExp(x, ccs)) return s + z;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
splitFFT(logn2, f) {
|
|
1423
|
+
const hn = 1 << logn2 - 1;
|
|
1424
|
+
const qn = hn >> 1;
|
|
1425
|
+
if (logn2 === 1) return { f0: [{ re: f[0].re, im: 0 }], f1: [{ re: f[0].im, im: 0 }] };
|
|
1426
|
+
const f0t = new Array(qn);
|
|
1427
|
+
const f1t = new Array(qn);
|
|
1428
|
+
const ft = f;
|
|
1429
|
+
for (let i = 0; i < qn; i++) {
|
|
1430
|
+
const a = ft[(i << 1) + 0];
|
|
1431
|
+
const b = ft[(i << 1) + 1];
|
|
1432
|
+
f0t[i] = fComplex.scale(fComplex.add(a, b), 0.5);
|
|
1433
|
+
f1t[i] = fComplex.scale(
|
|
1434
|
+
fComplex.mul(fComplex.sub(a, b), fComplex.conj(COMPLEX_ROOTS_O[i + hn])),
|
|
1435
|
+
0.5
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1438
|
+
return { f0: f0t, f1: f1t };
|
|
1439
|
+
}
|
|
1440
|
+
splitSelfAdjFFT(logn2, f) {
|
|
1441
|
+
const hn = 1 << logn2 - 1;
|
|
1442
|
+
const qn = hn >> 1;
|
|
1443
|
+
if (logn2 === 1) return { f0: [{ re: f[0].re, im: 0 }], f1: [{ re: 0, im: 0 }] };
|
|
1444
|
+
const f0t = new Array(qn);
|
|
1445
|
+
const f1t = new Array(qn);
|
|
1446
|
+
const ft = f;
|
|
1447
|
+
for (let i = 0; i < qn; i++) {
|
|
1448
|
+
const a = ft[(i << 1) + 0];
|
|
1449
|
+
const b = ft[(i << 1) + 1];
|
|
1450
|
+
f0t[i] = fComplex.scale(fComplex.add(a, b), 0.5);
|
|
1451
|
+
f1t[i] = fComplex.scale(
|
|
1452
|
+
fComplex.scale(fComplex.conj(COMPLEX_ROOTS_O[i + hn]), fComplex.sub(a, b).re),
|
|
1453
|
+
0.5
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
return { f0: f0t, f1: f1t };
|
|
1457
|
+
}
|
|
1458
|
+
mergeFFT(logn2, f0, f1) {
|
|
1459
|
+
const hn = 1 << logn2 - 1;
|
|
1460
|
+
const qn = hn >> 1;
|
|
1461
|
+
if (logn2 === 1) return [{ re: f0[0].re, im: f1[0].re }];
|
|
1462
|
+
const ft = new Array(2 * qn);
|
|
1463
|
+
for (let i = 0; i < qn; i++) {
|
|
1464
|
+
const a = f0[i];
|
|
1465
|
+
const c = fComplex.mul(f1[i], COMPLEX_ROOTS_O[i + hn]);
|
|
1466
|
+
ft[(i << 1) + 0] = fComplex.add(a, c);
|
|
1467
|
+
ft[(i << 1) + 1] = fComplex.sub(a, c);
|
|
1468
|
+
}
|
|
1469
|
+
return ft;
|
|
1470
|
+
}
|
|
1471
|
+
gramFFT(b00, b10) {
|
|
1472
|
+
const { b01, b11 } = this;
|
|
1473
|
+
const hn = 1 << this.logn >> 1;
|
|
1474
|
+
const g00 = new Array(hn);
|
|
1475
|
+
const g01 = new Array(hn);
|
|
1476
|
+
const g11 = new Array(hn);
|
|
1477
|
+
for (let i = 0; i < hn; i++) {
|
|
1478
|
+
const b00t = b00[i];
|
|
1479
|
+
const b01t = b01[i];
|
|
1480
|
+
const b10t = b10[i];
|
|
1481
|
+
const b11t = b11[i];
|
|
1482
|
+
const u = fComplex.mul(b00t, fComplex.conj(b10t));
|
|
1483
|
+
const v = fComplex.mul(b01t, fComplex.conj(b11t));
|
|
1484
|
+
g00[i] = { re: fComplex.magSqSum(b00t, b01t), im: 0 };
|
|
1485
|
+
g01[i] = fComplex.add(u, v);
|
|
1486
|
+
g11[i] = { re: fComplex.magSqSum(b10t, b11t), im: 0 };
|
|
1487
|
+
}
|
|
1488
|
+
return { g00, g01, g11 };
|
|
1489
|
+
}
|
|
1490
|
+
ffsampRec(logn2, t0, t1, g00i, g01i, g11i) {
|
|
1491
|
+
if (logn2 === 0) {
|
|
1492
|
+
const leaf = Math.sqrt(g00i[0].re) * INV_SIGMA[this.logn];
|
|
1493
|
+
const sigmaPrime = 1 / leaf;
|
|
1494
|
+
if (!(sigmaPrime >= SIGMA_MIN[this.logn] && sigmaPrime <= SIGMA_MAX))
|
|
1495
|
+
throw new Error("invalid secretKey: sampler sigma out of range");
|
|
1496
|
+
const t0re = this.samplerZ(t0[0].re, leaf);
|
|
1497
|
+
const t1re = this.samplerZ(t1[0].re, leaf);
|
|
1498
|
+
return { t0: [{ re: t0re, im: 0 }], t1: [{ re: t1re, im: 0 }] };
|
|
1499
|
+
}
|
|
1500
|
+
const { g00, g01, g11 } = ldlFFT(logn2, g00i, g01i, g11i);
|
|
1501
|
+
const { f0: g00f0, f1: g00f1 } = this.splitSelfAdjFFT(logn2, g00);
|
|
1502
|
+
const { f0: g11f0, f1: g11f1 } = this.splitSelfAdjFFT(logn2, g11);
|
|
1503
|
+
const { f0: t1f0in, f1: t1f1in } = this.splitFFT(logn2, t1);
|
|
1504
|
+
const { t0: t1f0out, t1: t1f1out } = this.ffsampRec(
|
|
1505
|
+
logn2 - 1,
|
|
1506
|
+
t1f0in,
|
|
1507
|
+
t1f1in,
|
|
1508
|
+
g11f0,
|
|
1509
|
+
g11f1,
|
|
1510
|
+
g11f0
|
|
1511
|
+
);
|
|
1512
|
+
const t1new = this.mergeFFT(logn2, t1f0out, t1f1out);
|
|
1513
|
+
const t0tmp = floatPoly.add(t0, floatPoly.mul(g01, floatPoly.sub(t1, t1new)));
|
|
1514
|
+
const { f0: t0f0in, f1: t0f1in } = this.splitFFT(logn2, t0tmp);
|
|
1515
|
+
const { t0: t0f0out, t1: t0f1out } = this.ffsampRec(
|
|
1516
|
+
logn2 - 1,
|
|
1517
|
+
t0f0in,
|
|
1518
|
+
t0f1in,
|
|
1519
|
+
g00f0,
|
|
1520
|
+
g00f1,
|
|
1521
|
+
g00f0
|
|
1522
|
+
);
|
|
1523
|
+
const z1 = this.mergeFFT(logn2, t0f0out, t0f1out);
|
|
1524
|
+
return { t0: z1, t1: t1new };
|
|
1525
|
+
}
|
|
1526
|
+
// sampling a preimage in FFT domain
|
|
1527
|
+
sample(hm) {
|
|
1528
|
+
const t0t = floatPoly.FFT(floatPoly.convSmall(hm));
|
|
1529
|
+
const t0f = floatPoly.mulConst(floatPoly.mul(t0t, this.b11), F_INV_Q);
|
|
1530
|
+
const t1f = floatPoly.mulConst(floatPoly.mul(t0t, this.b01), F_MINUS_INV_Q);
|
|
1531
|
+
this.shake.xofInto(this.shakeBuf);
|
|
1532
|
+
this.ctr = this.ctrView.getBigUint64(0, true);
|
|
1533
|
+
return this.ffsampRec(this.logn, t0f, t1f, this.g00, this.g01, this.g11);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
const signRaw = (sk, msg, maxLen, rnd = import_utils4.randomBytes) => {
|
|
1537
|
+
(0, import_utils4.abytes)(msg, void 0, "msg");
|
|
1538
|
+
(0, import_utils4.abytes)(sk, secretKeyCoder.bytesLen, "secretKey");
|
|
1539
|
+
const nonce = rnd(40);
|
|
1540
|
+
(0, import_utils4.abytes)(nonce, 40, "nonce");
|
|
1541
|
+
const hm = HashToPoint(nonce, msg);
|
|
1542
|
+
const seed = rnd(48);
|
|
1543
|
+
(0, import_utils4.abytes)(seed, 48, "seed");
|
|
1544
|
+
try {
|
|
1545
|
+
const [f, g, F] = secretKeyCoder.decode(sk);
|
|
1546
|
+
try {
|
|
1547
|
+
const G = completePrivate(f, g, F);
|
|
1548
|
+
const b00 = floatPoly.FFT(floatPoly.convSmall(g));
|
|
1549
|
+
const b01 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(f)));
|
|
1550
|
+
const b10 = floatPoly.FFT(floatPoly.convSmall(G));
|
|
1551
|
+
const b11 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(F)));
|
|
1552
|
+
const sampler = new FFSampler(logn, seed, b00, b01, b10, b11);
|
|
1553
|
+
const s2 = new Int16Array(N2);
|
|
1554
|
+
try {
|
|
1555
|
+
while (true) {
|
|
1556
|
+
const { t0, t1 } = sampler.sample(hm);
|
|
1557
|
+
const t2 = floatPoly.add(floatPoly.mul(t0, b00), floatPoly.mul(t1, b10));
|
|
1558
|
+
const t3 = floatPoly.mul(t0, b01);
|
|
1559
|
+
const t4 = floatPoly.iFFT(t2);
|
|
1560
|
+
const t5 = floatPoly.iFFT(floatPoly.add(floatPoly.mul(t1, b11), t3));
|
|
1561
|
+
const hn = N2 >> 1;
|
|
1562
|
+
let sqn = 0;
|
|
1563
|
+
for (let i = 0; i < hn; i++) {
|
|
1564
|
+
sqn += (hm[i] - (Math.round(t4[i].re) | 0)) ** 2;
|
|
1565
|
+
sqn += (hm[hn + i] - (Math.round(t4[i].im) | 0)) ** 2;
|
|
1566
|
+
const z = -Math.round(t5[i].re);
|
|
1567
|
+
sqn += z * z;
|
|
1568
|
+
s2[i] = z & 65535;
|
|
1569
|
+
const z2 = -Math.round(t5[i].im);
|
|
1570
|
+
sqn += z2 * z2;
|
|
1571
|
+
s2[i + hn] = z2 & 65535;
|
|
1572
|
+
}
|
|
1573
|
+
cleanCPoly(t0, t1, t2, t3, t4, t5);
|
|
1574
|
+
if (!(sqn <= L2BOUND[logn])) continue;
|
|
1575
|
+
const s2comp = compCoder(N2).encode(s2);
|
|
1576
|
+
if (s2comp.length > maxLen) {
|
|
1577
|
+
cleanBytes(s2comp);
|
|
1578
|
+
continue;
|
|
1579
|
+
}
|
|
1580
|
+
return { s2: s2comp, nonce, msg };
|
|
1581
|
+
}
|
|
1582
|
+
} finally {
|
|
1583
|
+
cleanBytes(s2);
|
|
1584
|
+
sampler.destroy();
|
|
1585
|
+
cleanCPoly(b00, b01, b10, b11);
|
|
1586
|
+
cleanBytes(G);
|
|
1587
|
+
}
|
|
1588
|
+
} finally {
|
|
1589
|
+
cleanBytes(f, g, F);
|
|
1590
|
+
}
|
|
1591
|
+
} finally {
|
|
1592
|
+
cleanBytes(seed);
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
const verifyRaw = (pk, s2comp, nonce, msg) => {
|
|
1596
|
+
const s2 = compCoder(N2).decode(s2comp);
|
|
1597
|
+
const c0 = HashToPoint(nonce, msg);
|
|
1598
|
+
const h = intPoly.toMontgomery(intPoly.ntt(publicKeyCoder.decode(pk)));
|
|
1599
|
+
const s1 = intPoly.intt(intPoly.mul(intPoly.ntt(signedCoder.decode(s2)), h));
|
|
1600
|
+
intPoly.sub(s1, c0);
|
|
1601
|
+
return intPoly.isShort(signedCoder.encode(s1), s2);
|
|
1602
|
+
};
|
|
1603
|
+
const info = Object.freeze({ type: "falcon" });
|
|
1604
|
+
const keyLengths = Object.freeze({
|
|
1605
|
+
seed: 48,
|
|
1606
|
+
publicKey: publicKeyCoder.bytesLen,
|
|
1607
|
+
secretKey: secretKeyCoder.bytesLen
|
|
1608
|
+
});
|
|
1609
|
+
const FALCON_SIG_OPT_KEYS = [...SIG_OPT_KEYS, "random"];
|
|
1610
|
+
const getRnd = (opts2 = {}) => {
|
|
1611
|
+
opts2 = validateSigOpts(opts2, FALCON_SIG_OPT_KEYS);
|
|
1612
|
+
if (opts2.context !== void 0) throw new Error("context is not supported");
|
|
1613
|
+
if (opts2.random !== void 0 && typeof opts2.random !== "function")
|
|
1614
|
+
throw new TypeError('"opts.random" expected function, got type=' + typeof opts2.random);
|
|
1615
|
+
if (opts2.random !== void 0) return opts2.random;
|
|
1616
|
+
if (opts2.extraEntropy === void 0) return import_utils4.randomBytes;
|
|
1617
|
+
const seed = opts2.extraEntropy === false ? new Uint8Array(48) : opts2.extraEntropy;
|
|
1618
|
+
(0, import_utils4.abytes)(seed, 48, "opts.extraEntropy");
|
|
1619
|
+
const drbg = (0, import_aes.rngAesCtrDrbg256)(seed);
|
|
1620
|
+
return (len = 0) => drbg.randomBytes(len);
|
|
1621
|
+
};
|
|
1622
|
+
const checkVerOpts = (opts2 = {}) => {
|
|
1623
|
+
const normalized = validateVerOpts(opts2);
|
|
1624
|
+
if (normalized.context !== void 0) throw new Error("context is not supported");
|
|
1625
|
+
};
|
|
1626
|
+
const tests = Object.freeze({
|
|
1627
|
+
publicKeyCoder: Object.freeze(publicKeyCoder),
|
|
1628
|
+
privateKeyCoder: Object.freeze(secretKeyCoder),
|
|
1629
|
+
maxS2Len: opts.maxS2Len
|
|
1630
|
+
});
|
|
1631
|
+
const attachedLengths = Object.freeze({ ...keyLengths, signRand: 48 });
|
|
1632
|
+
const lengths = opts.padded ? Object.freeze({ ...attachedLengths, signature: opts.sigLen }) : attachedLengths;
|
|
1633
|
+
const keygen = (seed) => {
|
|
1634
|
+
const randSeed = seed === void 0;
|
|
1635
|
+
if (randSeed) seed = (0, import_utils4.randomBytes)(48);
|
|
1636
|
+
(0, import_utils4.abytes)(seed, 48, "seed");
|
|
1637
|
+
const [f, g, F, _G, pub] = new NTRU(logn, seed).generate();
|
|
1638
|
+
const sk = secretKeyCoder.encode([f, g, F]);
|
|
1639
|
+
const pk = publicKeyCoder.encode(pub);
|
|
1640
|
+
if (randSeed) cleanBytes(seed);
|
|
1641
|
+
cleanBytes(f, g, F, _G);
|
|
1642
|
+
return { publicKey: pk, secretKey: sk };
|
|
1643
|
+
};
|
|
1644
|
+
const getPublicKey2 = (sk) => {
|
|
1645
|
+
(0, import_utils4.abytes)(sk, secretKeyCoder.bytesLen, "secretKey");
|
|
1646
|
+
const [f, g, F] = secretKeyCoder.decode(sk);
|
|
1647
|
+
try {
|
|
1648
|
+
const h = computePublic(f, g);
|
|
1649
|
+
cleanBytes(f, g, F);
|
|
1650
|
+
return publicKeyCoder.encode(h);
|
|
1651
|
+
} catch (e) {
|
|
1652
|
+
cleanBytes(f, g, F);
|
|
1653
|
+
throw e;
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
const sign = (msg, sk, sigOpts = {}) => {
|
|
1657
|
+
const { s2, nonce } = signRaw(sk, msg, opts.maxS2Len, getRnd(sigOpts));
|
|
1658
|
+
return SignatureCoderDetached(logn).encode({ nonce, s2 });
|
|
1659
|
+
};
|
|
1660
|
+
const verify2 = (sig, msg, pk, verOpts = {}) => {
|
|
1661
|
+
checkVerOpts(verOpts);
|
|
1662
|
+
(0, import_utils4.abytes)(sig, void 0, "signature");
|
|
1663
|
+
(0, import_utils4.abytes)(msg, void 0, "msg");
|
|
1664
|
+
(0, import_utils4.abytes)(pk, void 0, "publicKey");
|
|
1665
|
+
try {
|
|
1666
|
+
const { s2, nonce } = SignatureCoderDetached(logn).decode(sig);
|
|
1667
|
+
return verifyRaw(pk, s2, nonce, msg);
|
|
1668
|
+
} catch {
|
|
1669
|
+
return false;
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
const attached = Object.freeze({
|
|
1673
|
+
info,
|
|
1674
|
+
lengths: attachedLengths,
|
|
1675
|
+
keygen,
|
|
1676
|
+
getPublicKey: getPublicKey2,
|
|
1677
|
+
seal(msg, sk, sigOpts = {}) {
|
|
1678
|
+
const { s2, nonce } = signRaw(sk, msg, opts.maxS2Len, getRnd(sigOpts));
|
|
1679
|
+
return SignatureCoder.encode({ msg, nonce, s2 });
|
|
1680
|
+
},
|
|
1681
|
+
open(sig, pk, verOpts = {}) {
|
|
1682
|
+
checkVerOpts(verOpts);
|
|
1683
|
+
(0, import_utils4.abytes)(sig, void 0, "signature");
|
|
1684
|
+
(0, import_utils4.abytes)(pk, void 0, "publicKey");
|
|
1685
|
+
const ownedSig = copyBytes(sig);
|
|
1686
|
+
const ownedPk = copyBytes(pk);
|
|
1687
|
+
try {
|
|
1688
|
+
let verifiedMsg;
|
|
1689
|
+
try {
|
|
1690
|
+
const { s2, nonce, msg } = SignatureCoder.decode(ownedSig);
|
|
1691
|
+
if (verifyRaw(ownedPk, s2, nonce, msg)) verifiedMsg = msg;
|
|
1692
|
+
} catch (cause) {
|
|
1693
|
+
throw new Error("invalid signature", { cause });
|
|
1694
|
+
}
|
|
1695
|
+
if (verifiedMsg === void 0) throw new Error("invalid signature");
|
|
1696
|
+
return copyBytes(verifiedMsg);
|
|
1697
|
+
} finally {
|
|
1698
|
+
cleanBytes(ownedSig, ownedPk);
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
const INTERNAL_MAX_ITERATIONS = 1e3;
|
|
1703
|
+
const checkHashPoint = (hashPoint) => {
|
|
1704
|
+
if (!(hashPoint instanceof Uint16Array) || hashPoint.length !== N2)
|
|
1705
|
+
throw new Error(`hashPoint: expected Uint16Array(${N2})`);
|
|
1706
|
+
for (let i = 0; i < N2; i++)
|
|
1707
|
+
if (hashPoint[i] >= Q) throw new Error("hashPoint: coefficient out of range");
|
|
1708
|
+
};
|
|
1709
|
+
const internal = Object.freeze({
|
|
1710
|
+
sign(hashPoint, sk, internalOpts = {}) {
|
|
1711
|
+
checkHashPoint(hashPoint);
|
|
1712
|
+
(0, import_utils4.abytes)(sk, secretKeyCoder.bytesLen, "secretKey");
|
|
1713
|
+
const rnd = internalOpts.random ?? import_utils4.randomBytes;
|
|
1714
|
+
const maxIterations = internalOpts.maxIterations ?? INTERNAL_MAX_ITERATIONS;
|
|
1715
|
+
const hm = Uint16Array.from(hashPoint);
|
|
1716
|
+
const seed = rnd(48);
|
|
1717
|
+
(0, import_utils4.abytes)(seed, 48, "seed");
|
|
1718
|
+
try {
|
|
1719
|
+
const [f, g, F] = secretKeyCoder.decode(sk);
|
|
1720
|
+
try {
|
|
1721
|
+
const G = completePrivate(f, g, F);
|
|
1722
|
+
const b00 = floatPoly.FFT(floatPoly.convSmall(g));
|
|
1723
|
+
const b01 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(f)));
|
|
1724
|
+
const b10 = floatPoly.FFT(floatPoly.convSmall(G));
|
|
1725
|
+
const b11 = floatPoly.FFT(floatPoly.neg(floatPoly.convSmall(F)));
|
|
1726
|
+
const sampler = new FFSampler(logn, seed, b00, b01, b10, b11);
|
|
1727
|
+
const s2 = new Int16Array(N2);
|
|
1728
|
+
try {
|
|
1729
|
+
for (let iteration = 0; iteration < maxIterations; iteration++) {
|
|
1730
|
+
const { t0, t1 } = sampler.sample(hm);
|
|
1731
|
+
const t2 = floatPoly.add(floatPoly.mul(t0, b00), floatPoly.mul(t1, b10));
|
|
1732
|
+
const t3 = floatPoly.mul(t0, b01);
|
|
1733
|
+
const t4 = floatPoly.iFFT(t2);
|
|
1734
|
+
const t5 = floatPoly.iFFT(floatPoly.add(floatPoly.mul(t1, b11), t3));
|
|
1735
|
+
const hn = N2 >> 1;
|
|
1736
|
+
let sqn = 0;
|
|
1737
|
+
for (let i = 0; i < hn; i++) {
|
|
1738
|
+
sqn += (hm[i] - (Math.round(t4[i].re) | 0)) ** 2;
|
|
1739
|
+
sqn += (hm[hn + i] - (Math.round(t4[i].im) | 0)) ** 2;
|
|
1740
|
+
const z = -Math.round(t5[i].re);
|
|
1741
|
+
sqn += z * z;
|
|
1742
|
+
s2[i] = z & 65535;
|
|
1743
|
+
const z2 = -Math.round(t5[i].im);
|
|
1744
|
+
sqn += z2 * z2;
|
|
1745
|
+
s2[i + hn] = z2 & 65535;
|
|
1746
|
+
}
|
|
1747
|
+
cleanCPoly(t0, t1, t2, t3, t4, t5);
|
|
1748
|
+
if (sqn <= L2BOUND[logn]) return s2.slice();
|
|
1749
|
+
}
|
|
1750
|
+
throw new Error("internal.sign: no short signature found within the iteration cap");
|
|
1751
|
+
} finally {
|
|
1752
|
+
cleanBytes(s2);
|
|
1753
|
+
sampler.destroy();
|
|
1754
|
+
cleanCPoly(b00, b01, b10, b11);
|
|
1755
|
+
cleanBytes(G);
|
|
1756
|
+
}
|
|
1757
|
+
} finally {
|
|
1758
|
+
cleanBytes(f, g, F);
|
|
1759
|
+
}
|
|
1760
|
+
} finally {
|
|
1761
|
+
cleanBytes(seed);
|
|
1762
|
+
}
|
|
1763
|
+
},
|
|
1764
|
+
verify(s2, hashPoint, pk) {
|
|
1765
|
+
checkHashPoint(hashPoint);
|
|
1766
|
+
if (!(s2 instanceof Int16Array) || s2.length !== N2)
|
|
1767
|
+
throw new Error(`s2: expected Int16Array(${N2})`);
|
|
1768
|
+
(0, import_utils4.abytes)(pk, publicKeyCoder.bytesLen, "publicKey");
|
|
1769
|
+
const h = intPoly.toMontgomery(intPoly.ntt(publicKeyCoder.decode(pk)));
|
|
1770
|
+
const s1 = intPoly.intt(intPoly.mul(intPoly.ntt(signedCoder.decode(s2)), h));
|
|
1771
|
+
intPoly.sub(s1, hashPoint);
|
|
1772
|
+
return intPoly.isShort(signedCoder.encode(s1), s2);
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
const res = {
|
|
1776
|
+
info,
|
|
1777
|
+
lengths,
|
|
1778
|
+
attached,
|
|
1779
|
+
keygen,
|
|
1780
|
+
getPublicKey: getPublicKey2,
|
|
1781
|
+
sign,
|
|
1782
|
+
verify: verify2,
|
|
1783
|
+
internal
|
|
1784
|
+
};
|
|
1785
|
+
res.__test = tests;
|
|
1786
|
+
return Object.freeze(res);
|
|
1787
|
+
}
|
|
1788
|
+
var falcon512opts = {
|
|
1789
|
+
N: 512,
|
|
1790
|
+
// Keep the mode an own property: omitted config fields must not inherit from Object.prototype.
|
|
1791
|
+
padded: false,
|
|
1792
|
+
// Table 3.3 fixed padded detached bytes, including the detached header byte and 40-byte nonce.
|
|
1793
|
+
sigLen: 666,
|
|
1794
|
+
fgBits: 6,
|
|
1795
|
+
FGBits: 8,
|
|
1796
|
+
// Compressed-s payload bytes only, excluding the detached header byte and 40-byte nonce.
|
|
1797
|
+
paddedLen: 625
|
|
1798
|
+
};
|
|
1799
|
+
var falcon512 = /* @__PURE__ */ (() => genFalcon({ ...falcon512opts, maxS2Len: 711 }))();
|
|
1800
|
+
|
|
1801
|
+
// src/falcon/engine/engine.ts
|
|
1802
|
+
var nobleEngine = Object.freeze({
|
|
1803
|
+
keygen: (seed) => falcon512.keygen(seed),
|
|
1804
|
+
getPublicKey: (secretKey) => falcon512.getPublicKey(secretKey),
|
|
1805
|
+
signHashPoint: (hashPoint, secretKey) => falcon512.internal.sign(hashPoint, secretKey),
|
|
1806
|
+
verifyHashPoint: (s2, hashPoint, publicKey) => falcon512.internal.verify(s2, hashPoint, publicKey)
|
|
1807
|
+
});
|
|
1808
|
+
|
|
1809
|
+
// src/falcon/s2morrow/constants.ts
|
|
1810
|
+
var Q2 = 12289;
|
|
1811
|
+
var QB = 12289n;
|
|
1812
|
+
var N = 512;
|
|
1813
|
+
var SIG_BOUND_512 = 34034726;
|
|
1814
|
+
var PACKED_SLOTS = 29;
|
|
1815
|
+
var VALUES_PER_HALF = 9;
|
|
1816
|
+
var SALT_FELTS = 2;
|
|
1817
|
+
var SIGNATURE_FELTS = 61;
|
|
1818
|
+
|
|
1819
|
+
// src/falcon/s2morrow/nttRoots.ts
|
|
1820
|
+
var NTT_ROOTS_ALL = Object.freeze([
|
|
1821
|
+
1479,
|
|
1822
|
+
10810,
|
|
1823
|
+
4043,
|
|
1824
|
+
8246,
|
|
1825
|
+
5146,
|
|
1826
|
+
7143,
|
|
1827
|
+
5736,
|
|
1828
|
+
6553,
|
|
1829
|
+
4134,
|
|
1830
|
+
8155,
|
|
1831
|
+
722,
|
|
1832
|
+
11567,
|
|
1833
|
+
1305,
|
|
1834
|
+
10984,
|
|
1835
|
+
1646,
|
|
1836
|
+
10643,
|
|
1837
|
+
1212,
|
|
1838
|
+
11077,
|
|
1839
|
+
5860,
|
|
1840
|
+
6429,
|
|
1841
|
+
3195,
|
|
1842
|
+
9094,
|
|
1843
|
+
2545,
|
|
1844
|
+
9744,
|
|
1845
|
+
3621,
|
|
1846
|
+
8668,
|
|
1847
|
+
3504,
|
|
1848
|
+
8785,
|
|
1849
|
+
3542,
|
|
1850
|
+
8747,
|
|
1851
|
+
4591,
|
|
1852
|
+
7698,
|
|
1853
|
+
5728,
|
|
1854
|
+
6561,
|
|
1855
|
+
5023,
|
|
1856
|
+
7266,
|
|
1857
|
+
5828,
|
|
1858
|
+
6461,
|
|
1859
|
+
4978,
|
|
1860
|
+
7311,
|
|
1861
|
+
1351,
|
|
1862
|
+
10938,
|
|
1863
|
+
3328,
|
|
1864
|
+
8961,
|
|
1865
|
+
5777,
|
|
1866
|
+
6512,
|
|
1867
|
+
2975,
|
|
1868
|
+
9314,
|
|
1869
|
+
563,
|
|
1870
|
+
11726,
|
|
1871
|
+
3006,
|
|
1872
|
+
9283,
|
|
1873
|
+
2744,
|
|
1874
|
+
9545,
|
|
1875
|
+
949,
|
|
1876
|
+
11340,
|
|
1877
|
+
2625,
|
|
1878
|
+
9664,
|
|
1879
|
+
4821,
|
|
1880
|
+
7468,
|
|
1881
|
+
2639,
|
|
1882
|
+
9650,
|
|
1883
|
+
1e3,
|
|
1884
|
+
11289,
|
|
1885
|
+
4320,
|
|
1886
|
+
7969,
|
|
1887
|
+
3091,
|
|
1888
|
+
9198,
|
|
1889
|
+
81,
|
|
1890
|
+
12208,
|
|
1891
|
+
2963,
|
|
1892
|
+
9326,
|
|
1893
|
+
4896,
|
|
1894
|
+
7393,
|
|
1895
|
+
3051,
|
|
1896
|
+
9238,
|
|
1897
|
+
2366,
|
|
1898
|
+
9923,
|
|
1899
|
+
1853,
|
|
1900
|
+
10436,
|
|
1901
|
+
140,
|
|
1902
|
+
12149,
|
|
1903
|
+
4611,
|
|
1904
|
+
7678,
|
|
1905
|
+
726,
|
|
1906
|
+
11563,
|
|
1907
|
+
4255,
|
|
1908
|
+
8034,
|
|
1909
|
+
1177,
|
|
1910
|
+
11112,
|
|
1911
|
+
2768,
|
|
1912
|
+
9521,
|
|
1913
|
+
1635,
|
|
1914
|
+
10654,
|
|
1915
|
+
3712,
|
|
1916
|
+
8577,
|
|
1917
|
+
3135,
|
|
1918
|
+
9154,
|
|
1919
|
+
2747,
|
|
1920
|
+
9542,
|
|
1921
|
+
4846,
|
|
1922
|
+
7443,
|
|
1923
|
+
3553,
|
|
1924
|
+
8736,
|
|
1925
|
+
4805,
|
|
1926
|
+
7484,
|
|
1927
|
+
2294,
|
|
1928
|
+
9995,
|
|
1929
|
+
1062,
|
|
1930
|
+
11227,
|
|
1931
|
+
1326,
|
|
1932
|
+
10963,
|
|
1933
|
+
5086,
|
|
1934
|
+
7203,
|
|
1935
|
+
3014,
|
|
1936
|
+
9275,
|
|
1937
|
+
3201,
|
|
1938
|
+
9088,
|
|
1939
|
+
1170,
|
|
1940
|
+
11119,
|
|
1941
|
+
2319,
|
|
1942
|
+
9970,
|
|
1943
|
+
955,
|
|
1944
|
+
11334,
|
|
1945
|
+
790,
|
|
1946
|
+
11499,
|
|
1947
|
+
544,
|
|
1948
|
+
11745,
|
|
1949
|
+
5791,
|
|
1950
|
+
6498,
|
|
1951
|
+
339,
|
|
1952
|
+
11950,
|
|
1953
|
+
2468,
|
|
1954
|
+
9821,
|
|
1955
|
+
2842,
|
|
1956
|
+
9447,
|
|
1957
|
+
480,
|
|
1958
|
+
11809,
|
|
1959
|
+
9,
|
|
1960
|
+
12280,
|
|
1961
|
+
1022,
|
|
1962
|
+
11267,
|
|
1963
|
+
4278,
|
|
1964
|
+
8011,
|
|
1965
|
+
1673,
|
|
1966
|
+
10616,
|
|
1967
|
+
4989,
|
|
1968
|
+
7300,
|
|
1969
|
+
5331,
|
|
1970
|
+
6958,
|
|
1971
|
+
3584,
|
|
1972
|
+
8705,
|
|
1973
|
+
4177,
|
|
1974
|
+
8112,
|
|
1975
|
+
1381,
|
|
1976
|
+
10908,
|
|
1977
|
+
2525,
|
|
1978
|
+
9764,
|
|
1979
|
+
2396,
|
|
1980
|
+
9893,
|
|
1981
|
+
4452,
|
|
1982
|
+
7837,
|
|
1983
|
+
3296,
|
|
1984
|
+
8993,
|
|
1985
|
+
3949,
|
|
1986
|
+
8340,
|
|
1987
|
+
130,
|
|
1988
|
+
12159,
|
|
1989
|
+
4354,
|
|
1990
|
+
7935,
|
|
1991
|
+
5374,
|
|
1992
|
+
6915,
|
|
1993
|
+
2837,
|
|
1994
|
+
9452,
|
|
1995
|
+
5767,
|
|
1996
|
+
6522,
|
|
1997
|
+
827,
|
|
1998
|
+
11462,
|
|
1999
|
+
3748,
|
|
2000
|
+
8541,
|
|
2001
|
+
953,
|
|
2002
|
+
11336,
|
|
2003
|
+
5067,
|
|
2004
|
+
7222,
|
|
2005
|
+
2197,
|
|
2006
|
+
10092,
|
|
2007
|
+
118,
|
|
2008
|
+
12171,
|
|
2009
|
+
2476,
|
|
2010
|
+
9813,
|
|
2011
|
+
2548,
|
|
2012
|
+
9741,
|
|
2013
|
+
4231,
|
|
2014
|
+
8058,
|
|
2015
|
+
355,
|
|
2016
|
+
11934,
|
|
2017
|
+
3382,
|
|
2018
|
+
8907,
|
|
2019
|
+
3707,
|
|
2020
|
+
8582,
|
|
2021
|
+
1759,
|
|
2022
|
+
10530,
|
|
2023
|
+
3694,
|
|
2024
|
+
8595,
|
|
2025
|
+
5179,
|
|
2026
|
+
7110,
|
|
2027
|
+
5542,
|
|
2028
|
+
6747,
|
|
2029
|
+
145,
|
|
2030
|
+
12144,
|
|
2031
|
+
3637,
|
|
2032
|
+
8652,
|
|
2033
|
+
3459,
|
|
2034
|
+
8830,
|
|
2035
|
+
5911,
|
|
2036
|
+
6378,
|
|
2037
|
+
4890,
|
|
2038
|
+
7399,
|
|
2039
|
+
3932,
|
|
2040
|
+
8357,
|
|
2041
|
+
2731,
|
|
2042
|
+
9558,
|
|
2043
|
+
2089,
|
|
2044
|
+
10200,
|
|
2045
|
+
5092,
|
|
2046
|
+
7197,
|
|
2047
|
+
2881,
|
|
2048
|
+
9408,
|
|
2049
|
+
3284,
|
|
2050
|
+
9005,
|
|
2051
|
+
729,
|
|
2052
|
+
11560,
|
|
2053
|
+
3241,
|
|
2054
|
+
9048,
|
|
2055
|
+
3289,
|
|
2056
|
+
9e3,
|
|
2057
|
+
2013,
|
|
2058
|
+
10276,
|
|
2059
|
+
5755,
|
|
2060
|
+
6534,
|
|
2061
|
+
4632,
|
|
2062
|
+
7657,
|
|
2063
|
+
1260,
|
|
2064
|
+
11029,
|
|
2065
|
+
4388,
|
|
2066
|
+
7901,
|
|
2067
|
+
334,
|
|
2068
|
+
11955,
|
|
2069
|
+
2426,
|
|
2070
|
+
9863,
|
|
2071
|
+
1696,
|
|
2072
|
+
10593,
|
|
2073
|
+
1428,
|
|
2074
|
+
10861,
|
|
2075
|
+
1663,
|
|
2076
|
+
10626,
|
|
2077
|
+
1777,
|
|
2078
|
+
10512,
|
|
2079
|
+
1426,
|
|
2080
|
+
10863,
|
|
2081
|
+
4654,
|
|
2082
|
+
7635,
|
|
2083
|
+
5291,
|
|
2084
|
+
6998,
|
|
2085
|
+
2704,
|
|
2086
|
+
9585,
|
|
2087
|
+
4938,
|
|
2088
|
+
7351,
|
|
2089
|
+
3636,
|
|
2090
|
+
8653,
|
|
2091
|
+
3915,
|
|
2092
|
+
8374,
|
|
2093
|
+
2166,
|
|
2094
|
+
10123,
|
|
2095
|
+
113,
|
|
2096
|
+
12176,
|
|
2097
|
+
4919,
|
|
2098
|
+
7370,
|
|
2099
|
+
3,
|
|
2100
|
+
12286,
|
|
2101
|
+
4437,
|
|
2102
|
+
7852,
|
|
2103
|
+
160,
|
|
2104
|
+
12129,
|
|
2105
|
+
3149,
|
|
2106
|
+
9140,
|
|
2107
|
+
4057,
|
|
2108
|
+
8232,
|
|
2109
|
+
3271,
|
|
2110
|
+
9018,
|
|
2111
|
+
1689,
|
|
2112
|
+
10600,
|
|
2113
|
+
3364,
|
|
2114
|
+
8925,
|
|
2115
|
+
4372,
|
|
2116
|
+
7917,
|
|
2117
|
+
2174,
|
|
2118
|
+
10115,
|
|
2119
|
+
4414,
|
|
2120
|
+
7875,
|
|
2121
|
+
2847,
|
|
2122
|
+
9442,
|
|
2123
|
+
2645,
|
|
2124
|
+
9644,
|
|
2125
|
+
4053,
|
|
2126
|
+
8236,
|
|
2127
|
+
2305,
|
|
2128
|
+
9984,
|
|
2129
|
+
5042,
|
|
2130
|
+
7247,
|
|
2131
|
+
5195,
|
|
2132
|
+
7094,
|
|
2133
|
+
2780,
|
|
2134
|
+
9509,
|
|
2135
|
+
1484,
|
|
2136
|
+
10805,
|
|
2137
|
+
4895,
|
|
2138
|
+
7394,
|
|
2139
|
+
3016,
|
|
2140
|
+
9273,
|
|
2141
|
+
243,
|
|
2142
|
+
12046,
|
|
2143
|
+
3e3,
|
|
2144
|
+
9289,
|
|
2145
|
+
671,
|
|
2146
|
+
11618,
|
|
2147
|
+
3136,
|
|
2148
|
+
9153,
|
|
2149
|
+
5191,
|
|
2150
|
+
7098,
|
|
2151
|
+
2399,
|
|
2152
|
+
9890,
|
|
2153
|
+
3400,
|
|
2154
|
+
8889,
|
|
2155
|
+
2178,
|
|
2156
|
+
10111,
|
|
2157
|
+
1544,
|
|
2158
|
+
10745,
|
|
2159
|
+
420,
|
|
2160
|
+
11869,
|
|
2161
|
+
5559,
|
|
2162
|
+
6730,
|
|
2163
|
+
476,
|
|
2164
|
+
11813,
|
|
2165
|
+
3531,
|
|
2166
|
+
8758,
|
|
2167
|
+
3985,
|
|
2168
|
+
8304,
|
|
2169
|
+
4905,
|
|
2170
|
+
7384,
|
|
2171
|
+
5332,
|
|
2172
|
+
6957,
|
|
2173
|
+
3510,
|
|
2174
|
+
8779,
|
|
2175
|
+
2370,
|
|
2176
|
+
9919,
|
|
2177
|
+
2865,
|
|
2178
|
+
9424,
|
|
2179
|
+
2969,
|
|
2180
|
+
9320,
|
|
2181
|
+
3978,
|
|
2182
|
+
8311,
|
|
2183
|
+
2686,
|
|
2184
|
+
9603,
|
|
2185
|
+
3247,
|
|
2186
|
+
9042,
|
|
2187
|
+
4048,
|
|
2188
|
+
8241,
|
|
2189
|
+
2249,
|
|
2190
|
+
10040,
|
|
2191
|
+
1153,
|
|
2192
|
+
11136,
|
|
2193
|
+
2884,
|
|
2194
|
+
9405,
|
|
2195
|
+
5407,
|
|
2196
|
+
6882,
|
|
2197
|
+
3186,
|
|
2198
|
+
9103,
|
|
2199
|
+
1630,
|
|
2200
|
+
10659,
|
|
2201
|
+
2126,
|
|
2202
|
+
10163,
|
|
2203
|
+
2187,
|
|
2204
|
+
10102,
|
|
2205
|
+
2566,
|
|
2206
|
+
9723,
|
|
2207
|
+
2422,
|
|
2208
|
+
9867,
|
|
2209
|
+
6039,
|
|
2210
|
+
6250,
|
|
2211
|
+
2987,
|
|
2212
|
+
9302,
|
|
2213
|
+
6022,
|
|
2214
|
+
6267,
|
|
2215
|
+
2437,
|
|
2216
|
+
9852,
|
|
2217
|
+
3646,
|
|
2218
|
+
8643,
|
|
2219
|
+
875,
|
|
2220
|
+
11414,
|
|
2221
|
+
3780,
|
|
2222
|
+
8509,
|
|
2223
|
+
1607,
|
|
2224
|
+
10682,
|
|
2225
|
+
4976,
|
|
2226
|
+
7313,
|
|
2227
|
+
5011,
|
|
2228
|
+
7278,
|
|
2229
|
+
1002,
|
|
2230
|
+
11287,
|
|
2231
|
+
4284,
|
|
2232
|
+
8005,
|
|
2233
|
+
5088,
|
|
2234
|
+
7201,
|
|
2235
|
+
3248,
|
|
2236
|
+
9041,
|
|
2237
|
+
1207,
|
|
2238
|
+
11082,
|
|
2239
|
+
1168,
|
|
2240
|
+
11121,
|
|
2241
|
+
5277,
|
|
2242
|
+
7012,
|
|
2243
|
+
1065,
|
|
2244
|
+
11224,
|
|
2245
|
+
2143,
|
|
2246
|
+
10146,
|
|
2247
|
+
404,
|
|
2248
|
+
11885,
|
|
2249
|
+
4645,
|
|
2250
|
+
7644,
|
|
2251
|
+
1912,
|
|
2252
|
+
10377,
|
|
2253
|
+
1378,
|
|
2254
|
+
10911,
|
|
2255
|
+
435,
|
|
2256
|
+
11854,
|
|
2257
|
+
4337,
|
|
2258
|
+
7952,
|
|
2259
|
+
2381,
|
|
2260
|
+
9908,
|
|
2261
|
+
5444,
|
|
2262
|
+
6845,
|
|
2263
|
+
4096,
|
|
2264
|
+
8193,
|
|
2265
|
+
493,
|
|
2266
|
+
11796,
|
|
2267
|
+
545,
|
|
2268
|
+
11744,
|
|
2269
|
+
5019,
|
|
2270
|
+
7270,
|
|
2271
|
+
3704,
|
|
2272
|
+
8585,
|
|
2273
|
+
2678,
|
|
2274
|
+
9611,
|
|
2275
|
+
1537,
|
|
2276
|
+
10752,
|
|
2277
|
+
242,
|
|
2278
|
+
12047,
|
|
2279
|
+
4714,
|
|
2280
|
+
7575,
|
|
2281
|
+
4143,
|
|
2282
|
+
8146,
|
|
2283
|
+
27,
|
|
2284
|
+
12262,
|
|
2285
|
+
3066,
|
|
2286
|
+
9223,
|
|
2287
|
+
3763,
|
|
2288
|
+
8526,
|
|
2289
|
+
1440,
|
|
2290
|
+
10849,
|
|
2291
|
+
5084,
|
|
2292
|
+
7205,
|
|
2293
|
+
1632,
|
|
2294
|
+
10657,
|
|
2295
|
+
1017,
|
|
2296
|
+
11272,
|
|
2297
|
+
4885,
|
|
2298
|
+
7404,
|
|
2299
|
+
3778,
|
|
2300
|
+
8511,
|
|
2301
|
+
3833,
|
|
2302
|
+
8456,
|
|
2303
|
+
390,
|
|
2304
|
+
11899,
|
|
2305
|
+
773,
|
|
2306
|
+
11516,
|
|
2307
|
+
2401,
|
|
2308
|
+
9888,
|
|
2309
|
+
442,
|
|
2310
|
+
11847,
|
|
2311
|
+
5101,
|
|
2312
|
+
7188,
|
|
2313
|
+
1067,
|
|
2314
|
+
11222,
|
|
2315
|
+
2912,
|
|
2316
|
+
9377,
|
|
2317
|
+
5698,
|
|
2318
|
+
6591,
|
|
2319
|
+
354,
|
|
2320
|
+
11935,
|
|
2321
|
+
4861,
|
|
2322
|
+
7428,
|
|
2323
|
+
2859,
|
|
2324
|
+
9430,
|
|
2325
|
+
1045,
|
|
2326
|
+
11244,
|
|
2327
|
+
5012,
|
|
2328
|
+
7277,
|
|
2329
|
+
2481,
|
|
2330
|
+
9808,
|
|
2331
|
+
3957,
|
|
2332
|
+
8332,
|
|
2333
|
+
2839,
|
|
2334
|
+
9450,
|
|
2335
|
+
2127,
|
|
2336
|
+
10162,
|
|
2337
|
+
151,
|
|
2338
|
+
12138,
|
|
2339
|
+
431,
|
|
2340
|
+
11858,
|
|
2341
|
+
1579,
|
|
2342
|
+
10710,
|
|
2343
|
+
5906,
|
|
2344
|
+
6383,
|
|
2345
|
+
2505,
|
|
2346
|
+
9784,
|
|
2347
|
+
1323,
|
|
2348
|
+
10966,
|
|
2349
|
+
2766,
|
|
2350
|
+
9523,
|
|
2351
|
+
52,
|
|
2352
|
+
12237,
|
|
2353
|
+
3174,
|
|
2354
|
+
9115,
|
|
2355
|
+
6055,
|
|
2356
|
+
6234,
|
|
2357
|
+
3336,
|
|
2358
|
+
8953,
|
|
2359
|
+
677,
|
|
2360
|
+
11612,
|
|
2361
|
+
5874,
|
|
2362
|
+
6415,
|
|
2363
|
+
4169,
|
|
2364
|
+
8120,
|
|
2365
|
+
3127,
|
|
2366
|
+
9162,
|
|
2367
|
+
5241,
|
|
2368
|
+
7048,
|
|
2369
|
+
2920,
|
|
2370
|
+
9369,
|
|
2371
|
+
1010,
|
|
2372
|
+
11279,
|
|
2373
|
+
5468,
|
|
2374
|
+
6821,
|
|
2375
|
+
787,
|
|
2376
|
+
11502,
|
|
2377
|
+
3482,
|
|
2378
|
+
8807,
|
|
2379
|
+
1321,
|
|
2380
|
+
10968,
|
|
2381
|
+
192,
|
|
2382
|
+
12097,
|
|
2383
|
+
4912,
|
|
2384
|
+
7377,
|
|
2385
|
+
2049,
|
|
2386
|
+
10240,
|
|
2387
|
+
4698,
|
|
2388
|
+
7591,
|
|
2389
|
+
5057,
|
|
2390
|
+
7232,
|
|
2391
|
+
4780,
|
|
2392
|
+
7509,
|
|
2393
|
+
3445,
|
|
2394
|
+
8844,
|
|
2395
|
+
1956,
|
|
2396
|
+
10333,
|
|
2397
|
+
5009,
|
|
2398
|
+
7280,
|
|
2399
|
+
6008,
|
|
2400
|
+
6281,
|
|
2401
|
+
885,
|
|
2402
|
+
11404,
|
|
2403
|
+
3532,
|
|
2404
|
+
8757,
|
|
2405
|
+
1003,
|
|
2406
|
+
11286,
|
|
2407
|
+
58,
|
|
2408
|
+
12231,
|
|
2409
|
+
241,
|
|
2410
|
+
12048,
|
|
2411
|
+
975,
|
|
2412
|
+
11314,
|
|
2413
|
+
4212,
|
|
2414
|
+
8077,
|
|
2415
|
+
2844,
|
|
2416
|
+
9445,
|
|
2417
|
+
3438,
|
|
2418
|
+
8851,
|
|
2419
|
+
1105,
|
|
2420
|
+
11184,
|
|
2421
|
+
142,
|
|
2422
|
+
12147,
|
|
2423
|
+
5681,
|
|
2424
|
+
6608,
|
|
2425
|
+
3477,
|
|
2426
|
+
8812,
|
|
2427
|
+
2302,
|
|
2428
|
+
9987,
|
|
2429
|
+
605,
|
|
2430
|
+
11684,
|
|
2431
|
+
4213,
|
|
2432
|
+
8076,
|
|
2433
|
+
504,
|
|
2434
|
+
11785,
|
|
2435
|
+
5886,
|
|
2436
|
+
6403,
|
|
2437
|
+
4782,
|
|
2438
|
+
7507,
|
|
2439
|
+
5594,
|
|
2440
|
+
6695,
|
|
2441
|
+
3029,
|
|
2442
|
+
9260,
|
|
2443
|
+
421,
|
|
2444
|
+
11868,
|
|
2445
|
+
4080,
|
|
2446
|
+
8209,
|
|
2447
|
+
6068,
|
|
2448
|
+
6221,
|
|
2449
|
+
3602,
|
|
2450
|
+
8687,
|
|
2451
|
+
6077,
|
|
2452
|
+
6212,
|
|
2453
|
+
4624,
|
|
2454
|
+
7665,
|
|
2455
|
+
3263,
|
|
2456
|
+
9026,
|
|
2457
|
+
3600,
|
|
2458
|
+
8689,
|
|
2459
|
+
4948,
|
|
2460
|
+
7341,
|
|
2461
|
+
6137,
|
|
2462
|
+
6152,
|
|
2463
|
+
400,
|
|
2464
|
+
11889,
|
|
2465
|
+
1728,
|
|
2466
|
+
10561,
|
|
2467
|
+
5862,
|
|
2468
|
+
6427,
|
|
2469
|
+
6136,
|
|
2470
|
+
6153,
|
|
2471
|
+
5415,
|
|
2472
|
+
6874,
|
|
2473
|
+
3643,
|
|
2474
|
+
8646,
|
|
2475
|
+
56,
|
|
2476
|
+
12233,
|
|
2477
|
+
3199,
|
|
2478
|
+
9090,
|
|
2479
|
+
5206,
|
|
2480
|
+
7083,
|
|
2481
|
+
5529,
|
|
2482
|
+
6760,
|
|
2483
|
+
3565,
|
|
2484
|
+
8724,
|
|
2485
|
+
654,
|
|
2486
|
+
11635,
|
|
2487
|
+
1987,
|
|
2488
|
+
10302,
|
|
2489
|
+
1702,
|
|
2490
|
+
10587,
|
|
2491
|
+
3988,
|
|
2492
|
+
8301,
|
|
2493
|
+
468,
|
|
2494
|
+
11821,
|
|
2495
|
+
316,
|
|
2496
|
+
11973,
|
|
2497
|
+
382,
|
|
2498
|
+
11907,
|
|
2499
|
+
3710,
|
|
2500
|
+
8579,
|
|
2501
|
+
6093,
|
|
2502
|
+
6196,
|
|
2503
|
+
5446,
|
|
2504
|
+
6843,
|
|
2505
|
+
5339,
|
|
2506
|
+
6950,
|
|
2507
|
+
973,
|
|
2508
|
+
11316,
|
|
2509
|
+
1254,
|
|
2510
|
+
11035,
|
|
2511
|
+
1359,
|
|
2512
|
+
10930,
|
|
2513
|
+
5435,
|
|
2514
|
+
6854,
|
|
2515
|
+
2033,
|
|
2516
|
+
10256,
|
|
2517
|
+
3998,
|
|
2518
|
+
8291,
|
|
2519
|
+
3879,
|
|
2520
|
+
8410,
|
|
2521
|
+
1922,
|
|
2522
|
+
10367,
|
|
2523
|
+
3860,
|
|
2524
|
+
8429,
|
|
2525
|
+
5445,
|
|
2526
|
+
6844,
|
|
2527
|
+
4536,
|
|
2528
|
+
7753,
|
|
2529
|
+
1050,
|
|
2530
|
+
11239,
|
|
2531
|
+
3818,
|
|
2532
|
+
8471,
|
|
2533
|
+
6118,
|
|
2534
|
+
6171,
|
|
2535
|
+
1190,
|
|
2536
|
+
11099,
|
|
2537
|
+
2683,
|
|
2538
|
+
9606,
|
|
2539
|
+
3789,
|
|
2540
|
+
8500,
|
|
2541
|
+
147,
|
|
2542
|
+
12142,
|
|
2543
|
+
5456,
|
|
2544
|
+
6833,
|
|
2545
|
+
4449,
|
|
2546
|
+
7840,
|
|
2547
|
+
4749,
|
|
2548
|
+
7540,
|
|
2549
|
+
5537,
|
|
2550
|
+
6752,
|
|
2551
|
+
4789,
|
|
2552
|
+
7500,
|
|
2553
|
+
4467,
|
|
2554
|
+
7822,
|
|
2555
|
+
1018,
|
|
2556
|
+
11271,
|
|
2557
|
+
5925,
|
|
2558
|
+
6364,
|
|
2559
|
+
1041,
|
|
2560
|
+
11248,
|
|
2561
|
+
3514,
|
|
2562
|
+
8775,
|
|
2563
|
+
2344,
|
|
2564
|
+
9945,
|
|
2565
|
+
1278,
|
|
2566
|
+
11011,
|
|
2567
|
+
5574,
|
|
2568
|
+
6715,
|
|
2569
|
+
1973,
|
|
2570
|
+
10316,
|
|
2571
|
+
4324,
|
|
2572
|
+
7965,
|
|
2573
|
+
4916,
|
|
2574
|
+
7373,
|
|
2575
|
+
4075,
|
|
2576
|
+
8214,
|
|
2577
|
+
5315,
|
|
2578
|
+
6974,
|
|
2579
|
+
5079,
|
|
2580
|
+
7210,
|
|
2581
|
+
3262,
|
|
2582
|
+
9027,
|
|
2583
|
+
522,
|
|
2584
|
+
11767,
|
|
2585
|
+
2169,
|
|
2586
|
+
10120,
|
|
2587
|
+
1200,
|
|
2588
|
+
11089,
|
|
2589
|
+
5184,
|
|
2590
|
+
7105,
|
|
2591
|
+
2555,
|
|
2592
|
+
9734,
|
|
2593
|
+
6122,
|
|
2594
|
+
6167,
|
|
2595
|
+
5297,
|
|
2596
|
+
6992,
|
|
2597
|
+
6119,
|
|
2598
|
+
6170,
|
|
2599
|
+
3956,
|
|
2600
|
+
8333,
|
|
2601
|
+
1360,
|
|
2602
|
+
10929,
|
|
2603
|
+
1962,
|
|
2604
|
+
10327,
|
|
2605
|
+
1594,
|
|
2606
|
+
10695,
|
|
2607
|
+
5961,
|
|
2608
|
+
6328,
|
|
2609
|
+
5106,
|
|
2610
|
+
7183,
|
|
2611
|
+
4298,
|
|
2612
|
+
7991,
|
|
2613
|
+
3329,
|
|
2614
|
+
8960,
|
|
2615
|
+
168,
|
|
2616
|
+
12121,
|
|
2617
|
+
2692,
|
|
2618
|
+
9597,
|
|
2619
|
+
4049,
|
|
2620
|
+
8240,
|
|
2621
|
+
3728,
|
|
2622
|
+
8561,
|
|
2623
|
+
1159,
|
|
2624
|
+
11130,
|
|
2625
|
+
5990,
|
|
2626
|
+
6299,
|
|
2627
|
+
948,
|
|
2628
|
+
11341,
|
|
2629
|
+
1146,
|
|
2630
|
+
11143,
|
|
2631
|
+
1404,
|
|
2632
|
+
10885,
|
|
2633
|
+
325,
|
|
2634
|
+
11964,
|
|
2635
|
+
5766,
|
|
2636
|
+
6523,
|
|
2637
|
+
652,
|
|
2638
|
+
11637,
|
|
2639
|
+
295,
|
|
2640
|
+
11994,
|
|
2641
|
+
6099,
|
|
2642
|
+
6190,
|
|
2643
|
+
2919,
|
|
2644
|
+
9370,
|
|
2645
|
+
3762,
|
|
2646
|
+
8527,
|
|
2647
|
+
4016,
|
|
2648
|
+
8273,
|
|
2649
|
+
4077,
|
|
2650
|
+
8212,
|
|
2651
|
+
6065,
|
|
2652
|
+
6224,
|
|
2653
|
+
835,
|
|
2654
|
+
11454,
|
|
2655
|
+
3570,
|
|
2656
|
+
8719,
|
|
2657
|
+
4240,
|
|
2658
|
+
8049,
|
|
2659
|
+
4046,
|
|
2660
|
+
8243,
|
|
2661
|
+
709,
|
|
2662
|
+
11580,
|
|
2663
|
+
3150,
|
|
2664
|
+
9139,
|
|
2665
|
+
1319,
|
|
2666
|
+
10970,
|
|
2667
|
+
1058,
|
|
2668
|
+
11231,
|
|
2669
|
+
4079,
|
|
2670
|
+
8210,
|
|
2671
|
+
922,
|
|
2672
|
+
11367,
|
|
2673
|
+
441,
|
|
2674
|
+
11848,
|
|
2675
|
+
4322,
|
|
2676
|
+
7967,
|
|
2677
|
+
1958,
|
|
2678
|
+
10331,
|
|
2679
|
+
2078,
|
|
2680
|
+
10211,
|
|
2681
|
+
1112,
|
|
2682
|
+
11177,
|
|
2683
|
+
3834,
|
|
2684
|
+
8455,
|
|
2685
|
+
5257,
|
|
2686
|
+
7032,
|
|
2687
|
+
4433,
|
|
2688
|
+
7856,
|
|
2689
|
+
5919,
|
|
2690
|
+
6370,
|
|
2691
|
+
5486,
|
|
2692
|
+
6803,
|
|
2693
|
+
3054,
|
|
2694
|
+
9235,
|
|
2695
|
+
1747,
|
|
2696
|
+
10542,
|
|
2697
|
+
3123,
|
|
2698
|
+
9166,
|
|
2699
|
+
2948,
|
|
2700
|
+
9341,
|
|
2701
|
+
2503,
|
|
2702
|
+
9786,
|
|
2703
|
+
5782,
|
|
2704
|
+
6507,
|
|
2705
|
+
1566,
|
|
2706
|
+
10723,
|
|
2707
|
+
64,
|
|
2708
|
+
12225,
|
|
2709
|
+
3656,
|
|
2710
|
+
8633,
|
|
2711
|
+
2459,
|
|
2712
|
+
9830,
|
|
2713
|
+
683,
|
|
2714
|
+
11606,
|
|
2715
|
+
1293,
|
|
2716
|
+
10996,
|
|
2717
|
+
4737,
|
|
2718
|
+
7552,
|
|
2719
|
+
5429,
|
|
2720
|
+
6860,
|
|
2721
|
+
4774,
|
|
2722
|
+
7515,
|
|
2723
|
+
5908,
|
|
2724
|
+
6381,
|
|
2725
|
+
453,
|
|
2726
|
+
11836,
|
|
2727
|
+
418,
|
|
2728
|
+
11871,
|
|
2729
|
+
3772,
|
|
2730
|
+
8517,
|
|
2731
|
+
3991,
|
|
2732
|
+
8298,
|
|
2733
|
+
3969,
|
|
2734
|
+
8320,
|
|
2735
|
+
2767,
|
|
2736
|
+
9522,
|
|
2737
|
+
156,
|
|
2738
|
+
12133,
|
|
2739
|
+
2281,
|
|
2740
|
+
10008,
|
|
2741
|
+
5876,
|
|
2742
|
+
6413,
|
|
2743
|
+
5333,
|
|
2744
|
+
6956,
|
|
2745
|
+
2031,
|
|
2746
|
+
10258,
|
|
2747
|
+
3963,
|
|
2748
|
+
8326,
|
|
2749
|
+
576,
|
|
2750
|
+
11713,
|
|
2751
|
+
2447,
|
|
2752
|
+
9842,
|
|
2753
|
+
6142,
|
|
2754
|
+
6147,
|
|
2755
|
+
2051,
|
|
2756
|
+
10238,
|
|
2757
|
+
1954,
|
|
2758
|
+
10335,
|
|
2759
|
+
1805,
|
|
2760
|
+
10484,
|
|
2761
|
+
2882,
|
|
2762
|
+
9407,
|
|
2763
|
+
3529,
|
|
2764
|
+
8760,
|
|
2765
|
+
3434,
|
|
2766
|
+
8855,
|
|
2767
|
+
2908,
|
|
2768
|
+
9381,
|
|
2769
|
+
218,
|
|
2770
|
+
12071,
|
|
2771
|
+
3030,
|
|
2772
|
+
9259,
|
|
2773
|
+
4115,
|
|
2774
|
+
8174,
|
|
2775
|
+
1843,
|
|
2776
|
+
10446,
|
|
2777
|
+
2361,
|
|
2778
|
+
9928,
|
|
2779
|
+
3202,
|
|
2780
|
+
9087,
|
|
2781
|
+
4493,
|
|
2782
|
+
7796,
|
|
2783
|
+
2057,
|
|
2784
|
+
10232,
|
|
2785
|
+
5369,
|
|
2786
|
+
6920,
|
|
2787
|
+
1512,
|
|
2788
|
+
10777,
|
|
2789
|
+
350,
|
|
2790
|
+
11939,
|
|
2791
|
+
1815,
|
|
2792
|
+
10474,
|
|
2793
|
+
5383,
|
|
2794
|
+
6906,
|
|
2795
|
+
49,
|
|
2796
|
+
12240,
|
|
2797
|
+
1263,
|
|
2798
|
+
11026,
|
|
2799
|
+
5915,
|
|
2800
|
+
6374,
|
|
2801
|
+
1483,
|
|
2802
|
+
10806,
|
|
2803
|
+
1489,
|
|
2804
|
+
10800,
|
|
2805
|
+
2500,
|
|
2806
|
+
9789,
|
|
2807
|
+
5942,
|
|
2808
|
+
6347,
|
|
2809
|
+
1583,
|
|
2810
|
+
10706,
|
|
2811
|
+
1693,
|
|
2812
|
+
10596,
|
|
2813
|
+
3009,
|
|
2814
|
+
9280,
|
|
2815
|
+
174,
|
|
2816
|
+
12115,
|
|
2817
|
+
723,
|
|
2818
|
+
11566,
|
|
2819
|
+
2738,
|
|
2820
|
+
9551,
|
|
2821
|
+
5868,
|
|
2822
|
+
6421,
|
|
2823
|
+
5735,
|
|
2824
|
+
6554,
|
|
2825
|
+
2655,
|
|
2826
|
+
9634,
|
|
2827
|
+
3315,
|
|
2828
|
+
8974,
|
|
2829
|
+
426,
|
|
2830
|
+
11863,
|
|
2831
|
+
4754,
|
|
2832
|
+
7535,
|
|
2833
|
+
1858,
|
|
2834
|
+
10431,
|
|
2835
|
+
1975,
|
|
2836
|
+
10314,
|
|
2837
|
+
3757,
|
|
2838
|
+
8532,
|
|
2839
|
+
2925,
|
|
2840
|
+
9364,
|
|
2841
|
+
347,
|
|
2842
|
+
11942
|
|
2843
|
+
]);
|
|
2844
|
+
|
|
2845
|
+
// src/falcon/s2morrow/ntt.ts
|
|
2846
|
+
var I2 = 6145;
|
|
2847
|
+
var SQR1 = 1479;
|
|
2848
|
+
var modQ = (a) => (a % Q2 + Q2) % Q2;
|
|
2849
|
+
function powMod(base, exponent) {
|
|
2850
|
+
let result = 1;
|
|
2851
|
+
let b = modQ(base);
|
|
2852
|
+
for (let e = exponent; e > 0; e >>= 1) {
|
|
2853
|
+
if (e & 1) result = result * b % Q2;
|
|
2854
|
+
b = b * b % Q2;
|
|
2855
|
+
}
|
|
2856
|
+
return result;
|
|
2857
|
+
}
|
|
2858
|
+
function invMod(x) {
|
|
2859
|
+
const r = modQ(x);
|
|
2860
|
+
if (r === 0) throw new Error("Falcon512: 0 has no inverse mod q");
|
|
2861
|
+
return powMod(r, Q2 - 2);
|
|
2862
|
+
}
|
|
2863
|
+
var nttRoots = (n) => NTT_ROOTS_ALL.slice(n - 2, 2 * n - 2);
|
|
2864
|
+
function checkSize(n) {
|
|
2865
|
+
if (n < 2 || n > N || (n & n - 1) !== 0) {
|
|
2866
|
+
throw new Error(`Falcon512: NTT size must be a power of 2 in [2, ${N}], got ${n}`);
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
function nttRec(f) {
|
|
2870
|
+
const n = f.length;
|
|
2871
|
+
if (n === 2) {
|
|
2872
|
+
const t = SQR1 * f[1] % Q2;
|
|
2873
|
+
return [modQ(f[0] + t), modQ(f[0] - t)];
|
|
2874
|
+
}
|
|
2875
|
+
const half = n / 2;
|
|
2876
|
+
const even = new Array(half);
|
|
2877
|
+
const odd = new Array(half);
|
|
2878
|
+
for (let i = 0; i < half; i++) {
|
|
2879
|
+
even[i] = f[2 * i];
|
|
2880
|
+
odd[i] = f[2 * i + 1];
|
|
2881
|
+
}
|
|
2882
|
+
const a = nttRec(even);
|
|
2883
|
+
const b = nttRec(odd);
|
|
2884
|
+
const w = nttRoots(n);
|
|
2885
|
+
const out = new Array(n);
|
|
2886
|
+
for (let i = 0; i < half; i++) {
|
|
2887
|
+
const wb = w[2 * i] * b[i] % Q2;
|
|
2888
|
+
out[2 * i] = modQ(a[i] + wb);
|
|
2889
|
+
out[2 * i + 1] = modQ(a[i] - wb);
|
|
2890
|
+
}
|
|
2891
|
+
return out;
|
|
2892
|
+
}
|
|
2893
|
+
function inttRec(fNtt) {
|
|
2894
|
+
const n = fNtt.length;
|
|
2895
|
+
if (n === 2) {
|
|
2896
|
+
const s = modQ(fNtt[0] + fNtt[1]);
|
|
2897
|
+
const d = modQ(fNtt[0] - fNtt[1]);
|
|
2898
|
+
return [I2 * s % Q2, I2 * invMod(SQR1) % Q2 * d % Q2];
|
|
2899
|
+
}
|
|
2900
|
+
const half = n / 2;
|
|
2901
|
+
const w = nttRoots(n);
|
|
2902
|
+
const f0 = new Array(half);
|
|
2903
|
+
const f1 = new Array(half);
|
|
2904
|
+
for (let i = 0; i < half; i++) {
|
|
2905
|
+
const s = modQ(fNtt[2 * i] + fNtt[2 * i + 1]);
|
|
2906
|
+
const d = modQ(fNtt[2 * i] - fNtt[2 * i + 1]);
|
|
2907
|
+
f0[i] = I2 * s % Q2;
|
|
2908
|
+
f1[i] = I2 * d % Q2 * invMod(w[2 * i]) % Q2;
|
|
2909
|
+
}
|
|
2910
|
+
const a = inttRec(f0);
|
|
2911
|
+
const b = inttRec(f1);
|
|
2912
|
+
const out = new Array(n);
|
|
2913
|
+
for (let i = 0; i < half; i++) {
|
|
2914
|
+
out[2 * i] = a[i];
|
|
2915
|
+
out[2 * i + 1] = b[i];
|
|
2916
|
+
}
|
|
2917
|
+
return out;
|
|
2918
|
+
}
|
|
2919
|
+
function ntt(f) {
|
|
2920
|
+
checkSize(f.length);
|
|
2921
|
+
return nttRec(Array.from(f, modQ));
|
|
2922
|
+
}
|
|
2923
|
+
function intt(fNtt) {
|
|
2924
|
+
checkSize(fNtt.length);
|
|
2925
|
+
return inttRec(Array.from(fNtt, modQ));
|
|
2926
|
+
}
|
|
2927
|
+
function mulZq(a, b) {
|
|
2928
|
+
if (a.length !== b.length) throw new Error("Falcon512: polynomial sizes differ");
|
|
2929
|
+
const an = ntt(a);
|
|
2930
|
+
const bn = ntt(b);
|
|
2931
|
+
return intt(an.map((v, i) => v * bn[i] % Q2));
|
|
2932
|
+
}
|
|
2933
|
+
function divZq(a, b) {
|
|
2934
|
+
if (a.length !== b.length) throw new Error("Falcon512: polynomial sizes differ");
|
|
2935
|
+
const an = ntt(a);
|
|
2936
|
+
const bn = ntt(b);
|
|
2937
|
+
if (bn.some((v) => v === 0)) throw new Error("Falcon512: polynomial is not invertible mod q");
|
|
2938
|
+
return intt(an.map((v, i) => v * invMod(bn[i]) % Q2));
|
|
2939
|
+
}
|
|
2940
|
+
function mulNegacyclicInt(a, b) {
|
|
2941
|
+
const n = a.length;
|
|
2942
|
+
if (b.length !== n) throw new Error("Falcon512: polynomial sizes differ");
|
|
2943
|
+
const r = new Array(n).fill(0);
|
|
2944
|
+
for (let i = 0; i < n; i++) {
|
|
2945
|
+
const ai = a[i];
|
|
2946
|
+
if (ai !== 0) {
|
|
2947
|
+
for (let j = 0; j < n; j++) {
|
|
2948
|
+
const k = i + j;
|
|
2949
|
+
if (k < n) r[k] += ai * b[j];
|
|
2950
|
+
else r[k - n] -= ai * b[j];
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
return r;
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
// src/falcon/s2morrow/packing.ts
|
|
2958
|
+
var starknet2 = __toESM(require("starknet"));
|
|
2959
|
+
|
|
2960
|
+
// src/falcon/s2morrow/felt.ts
|
|
2961
|
+
var starknet = __toESM(require("starknet"));
|
|
2962
|
+
function assertFelt(x, label) {
|
|
2963
|
+
if (typeof x !== "bigint") throw new Error(`Falcon512: ${label} is not a felt252`);
|
|
2964
|
+
starknet.CairoFelt252.assertRange(x);
|
|
2965
|
+
}
|
|
2966
|
+
var FELT_STRING = /^(0[xX][0-9a-fA-F]{1,64}|[0-9]{1,76})$/;
|
|
2967
|
+
function parseFelt(value, label) {
|
|
2968
|
+
const accepted = typeof value === "bigint" && value >= 0n || typeof value === "number" && Number.isSafeInteger(value) && value >= 0 || typeof value === "string" && FELT_STRING.test(value);
|
|
2969
|
+
if (!accepted) throw new Error(`Falcon512: ${label} is not a felt252`);
|
|
2970
|
+
return new starknet.CairoFelt252(value).toBigInt();
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
// src/falcon/s2morrow/packing.ts
|
|
2974
|
+
var horner = (values, start, end) => {
|
|
2975
|
+
let acc = 0n;
|
|
2976
|
+
for (let i = end - 1; i >= start; i--) acc = acc * QB + BigInt(values[i]);
|
|
2977
|
+
return acc;
|
|
2978
|
+
};
|
|
2979
|
+
function packPoly(poly) {
|
|
2980
|
+
if (poly.length !== N) throw new Error(`Falcon512: polynomial must have ${N} coefficients`);
|
|
2981
|
+
for (let i = 0; i < N; i++) {
|
|
2982
|
+
const v = poly[i];
|
|
2983
|
+
if (!Number.isInteger(v) || v < 0 || v >= Q2) {
|
|
2984
|
+
throw new Error("Falcon512: polynomial coefficient out of range");
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
const out = [];
|
|
2988
|
+
for (let start = 0; start < N; start += 2 * VALUES_PER_HALF) {
|
|
2989
|
+
const mid = Math.min(start + VALUES_PER_HALF, N);
|
|
2990
|
+
const end = Math.min(start + 2 * VALUES_PER_HALF, N);
|
|
2991
|
+
out.push(horner(poly, start, mid) + (horner(poly, mid, end) << 128n));
|
|
2992
|
+
}
|
|
2993
|
+
return out;
|
|
2994
|
+
}
|
|
2995
|
+
function unpackPoly(felts) {
|
|
2996
|
+
if (felts.length !== PACKED_SLOTS) {
|
|
2997
|
+
throw new Error(`Falcon512: packed polynomial must have ${PACKED_SLOTS} felts`);
|
|
2998
|
+
}
|
|
2999
|
+
const out = new Uint16Array(N);
|
|
3000
|
+
let idx = 0;
|
|
3001
|
+
for (const felt of felts) {
|
|
3002
|
+
assertFelt(felt, "packed polynomial slot");
|
|
3003
|
+
for (const half of [felt & starknet2.UINT_128_MAX, felt >> 128n]) {
|
|
3004
|
+
const count = Math.min(VALUES_PER_HALF, N - idx);
|
|
3005
|
+
if (half >= QB ** BigInt(count)) {
|
|
3006
|
+
throw new Error("Falcon512: non-canonical packed polynomial");
|
|
3007
|
+
}
|
|
3008
|
+
let v = half;
|
|
3009
|
+
for (let i = 0; i < count; i++) {
|
|
3010
|
+
out[idx++] = Number(v % QB);
|
|
3011
|
+
v /= QB;
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
return out;
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3018
|
+
// src/falcon/s2morrow/keys.ts
|
|
3019
|
+
var SECRET_KEY_LENGTH = 1281;
|
|
3020
|
+
var PUBLIC_KEY_LENGTH = 897;
|
|
3021
|
+
var SEED_LENGTH = 48;
|
|
3022
|
+
var FALCON_RS_SECRET_KEY_LENGTH = 3584;
|
|
3023
|
+
var FALCON_RS_POLY_LENGTH = 896;
|
|
3024
|
+
var SECRET_KEY_HEADER = 89;
|
|
3025
|
+
var PUBLIC_KEY_HEADER = 9;
|
|
3026
|
+
var FG_BITS = 6;
|
|
3027
|
+
var CAPITAL_FG_BITS = 8;
|
|
3028
|
+
var FG_MAX = 31;
|
|
3029
|
+
var CAPITAL_FG_MAX = 127;
|
|
3030
|
+
var FG_BYTES = N * FG_BITS / 8;
|
|
3031
|
+
function toBytes(input, expectedLength, label) {
|
|
3032
|
+
if ((0, import_utils6.isBytes)(input)) {
|
|
3033
|
+
if (input.length !== expectedLength) {
|
|
3034
|
+
throw new Error(`Falcon512: ${label} must be ${expectedLength} bytes, got ${input.length}`);
|
|
3035
|
+
}
|
|
3036
|
+
return Uint8Array.from(input);
|
|
3037
|
+
}
|
|
3038
|
+
if (typeof input !== "string") {
|
|
3039
|
+
throw new Error(`Falcon512: ${label} must be a Uint8Array or a hex string`);
|
|
3040
|
+
}
|
|
3041
|
+
const hex = starknet3.encode.removeHexPrefix(input);
|
|
3042
|
+
if (!/^[0-9a-fA-F]*$/.test(hex)) {
|
|
3043
|
+
throw new Error(`Falcon512: ${label} is not a valid hex string`);
|
|
3044
|
+
}
|
|
3045
|
+
if (hex.length !== 2 * expectedLength) {
|
|
3046
|
+
throw new Error(
|
|
3047
|
+
`Falcon512: ${label} must have ${2 * expectedLength} hex digits, got ${hex.length}`
|
|
3048
|
+
);
|
|
3049
|
+
}
|
|
3050
|
+
return starknet3.num.hexToBytes(starknet3.encode.addHexPrefix(hex));
|
|
3051
|
+
}
|
|
3052
|
+
var wipe = (...arrays) => {
|
|
3053
|
+
arrays.forEach((a) => a.fill(0));
|
|
3054
|
+
};
|
|
3055
|
+
var center = (x) => x > Q2 >> 1 ? x - Q2 : x;
|
|
3056
|
+
var toSigned = (raw, bits) => raw << 32 - bits >> 32 - bits;
|
|
3057
|
+
function encodeBitsMSB(values, bits) {
|
|
3058
|
+
const out = new Uint8Array(values.length * bits / 8);
|
|
3059
|
+
const mask = (1 << bits) - 1;
|
|
3060
|
+
let acc = 0;
|
|
3061
|
+
let accBits = 0;
|
|
3062
|
+
let pos = 0;
|
|
3063
|
+
for (let i = 0; i < values.length; i++) {
|
|
3064
|
+
acc = acc << bits | values[i] & mask;
|
|
3065
|
+
accBits += bits;
|
|
3066
|
+
while (accBits >= 8) {
|
|
3067
|
+
accBits -= 8;
|
|
3068
|
+
out[pos++] = acc >>> accBits & 255;
|
|
3069
|
+
}
|
|
3070
|
+
acc &= (1 << accBits) - 1;
|
|
3071
|
+
}
|
|
3072
|
+
return out;
|
|
3073
|
+
}
|
|
3074
|
+
function decodeBitsMSB(bytes, count, bits) {
|
|
3075
|
+
if (bytes.length * 8 !== count * bits) throw new Error("Falcon512: invalid encoding length");
|
|
3076
|
+
const out = [];
|
|
3077
|
+
const mask = (1 << bits) - 1;
|
|
3078
|
+
let acc = 0;
|
|
3079
|
+
let accBits = 0;
|
|
3080
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
3081
|
+
acc = acc << 8 | bytes[i];
|
|
3082
|
+
accBits += 8;
|
|
3083
|
+
while (accBits >= bits) {
|
|
3084
|
+
accBits -= bits;
|
|
3085
|
+
out.push(acc >>> accBits & mask);
|
|
3086
|
+
}
|
|
3087
|
+
acc &= (1 << accBits) - 1;
|
|
3088
|
+
}
|
|
3089
|
+
return out;
|
|
3090
|
+
}
|
|
3091
|
+
function encode14LSB(values) {
|
|
3092
|
+
const out = new Uint8Array(FALCON_RS_POLY_LENGTH);
|
|
3093
|
+
let acc = 0;
|
|
3094
|
+
let accBits = 0;
|
|
3095
|
+
let pos = 0;
|
|
3096
|
+
for (let i = 0; i < values.length; i++) {
|
|
3097
|
+
acc |= values[i] << accBits;
|
|
3098
|
+
accBits += 14;
|
|
3099
|
+
while (accBits >= 8) {
|
|
3100
|
+
out[pos++] = acc & 255;
|
|
3101
|
+
acc >>>= 8;
|
|
3102
|
+
accBits -= 8;
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
return out;
|
|
3106
|
+
}
|
|
3107
|
+
function decode14LSB(bytes) {
|
|
3108
|
+
const out = [];
|
|
3109
|
+
let acc = 0;
|
|
3110
|
+
let accBits = 0;
|
|
3111
|
+
let pos = 0;
|
|
3112
|
+
try {
|
|
3113
|
+
for (let i = 0; i < N; i++) {
|
|
3114
|
+
while (accBits < 14) {
|
|
3115
|
+
acc |= bytes[pos++] << accBits;
|
|
3116
|
+
accBits += 8;
|
|
3117
|
+
}
|
|
3118
|
+
const v = acc & 16383;
|
|
3119
|
+
acc >>>= 14;
|
|
3120
|
+
accBits -= 14;
|
|
3121
|
+
if (v >= Q2) {
|
|
3122
|
+
throw new Error("Falcon512: invalid falcon-rs secret key (coefficient out of range)");
|
|
3123
|
+
}
|
|
3124
|
+
out.push(v);
|
|
3125
|
+
}
|
|
3126
|
+
return out;
|
|
3127
|
+
} catch (error) {
|
|
3128
|
+
wipe(out);
|
|
3129
|
+
throw error;
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
function checkRange(poly, max, label) {
|
|
3133
|
+
for (let i = 0; i < poly.length; i++) {
|
|
3134
|
+
if (poly[i] < -max || poly[i] > max) {
|
|
3135
|
+
throw new Error(`Falcon512: invalid secret key (${label} coefficient out of range)`);
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
function completeG(f, g, F) {
|
|
3140
|
+
const gF = mulZq(g, F);
|
|
3141
|
+
let quotient = [];
|
|
3142
|
+
let G = [];
|
|
3143
|
+
try {
|
|
3144
|
+
quotient = divZq(gF, f);
|
|
3145
|
+
G = quotient.map(center);
|
|
3146
|
+
checkRange(G, CAPITAL_FG_MAX, "G");
|
|
3147
|
+
return Int8Array.from(G);
|
|
3148
|
+
} finally {
|
|
3149
|
+
wipe(gF, quotient, G);
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
function checkNtruEquation({ f, g, F, G }) {
|
|
3153
|
+
const fG = mulNegacyclicInt(f, G);
|
|
3154
|
+
const gF = mulNegacyclicInt(g, F);
|
|
3155
|
+
try {
|
|
3156
|
+
for (let i = 0; i < N; i++) {
|
|
3157
|
+
if (fG[i] - gF[i] !== (i === 0 ? Q2 : 0)) {
|
|
3158
|
+
throw new Error("Falcon512: invalid secret key (NTRU equation not satisfied)");
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
} finally {
|
|
3162
|
+
wipe(fG, gF);
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
function decodeSigned(bytes, bits, label) {
|
|
3166
|
+
const min = -(1 << bits - 1);
|
|
3167
|
+
const raw = decodeBitsMSB(bytes, N, bits);
|
|
3168
|
+
try {
|
|
3169
|
+
return Int8Array.from(raw, (value) => {
|
|
3170
|
+
const v = toSigned(value, bits);
|
|
3171
|
+
if (v === min) {
|
|
3172
|
+
throw new Error(`Falcon512: invalid secret key (forbidden ${label} coefficient)`);
|
|
3173
|
+
}
|
|
3174
|
+
return v;
|
|
3175
|
+
});
|
|
3176
|
+
} finally {
|
|
3177
|
+
wipe(raw);
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
function decodeSecretKey(secretKey) {
|
|
3181
|
+
const bytes = toBytes(secretKey, SECRET_KEY_LENGTH, "secret key");
|
|
3182
|
+
const parts = [];
|
|
3183
|
+
try {
|
|
3184
|
+
if (bytes[0] !== SECRET_KEY_HEADER) throw new Error("Falcon512: invalid secret key header");
|
|
3185
|
+
const f = decodeSigned(bytes.subarray(1, 1 + FG_BYTES), FG_BITS, "f");
|
|
3186
|
+
parts.push(f);
|
|
3187
|
+
const g = decodeSigned(bytes.subarray(1 + FG_BYTES, 1 + 2 * FG_BYTES), FG_BITS, "g");
|
|
3188
|
+
parts.push(g);
|
|
3189
|
+
const F = decodeSigned(bytes.subarray(1 + 2 * FG_BYTES), CAPITAL_FG_BITS, "F");
|
|
3190
|
+
parts.push(F);
|
|
3191
|
+
const G = completeG(f, g, F);
|
|
3192
|
+
parts.push(G);
|
|
3193
|
+
const polys = { f, g, F, G };
|
|
3194
|
+
checkNtruEquation(polys);
|
|
3195
|
+
return polys;
|
|
3196
|
+
} catch (error) {
|
|
3197
|
+
wipe(...parts);
|
|
3198
|
+
throw error;
|
|
3199
|
+
} finally {
|
|
3200
|
+
wipe(bytes);
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
function encodeSecretKey({ f, g, F }) {
|
|
3204
|
+
checkRange(f, FG_MAX, "f");
|
|
3205
|
+
checkRange(g, FG_MAX, "g");
|
|
3206
|
+
checkRange(F, CAPITAL_FG_MAX, "F");
|
|
3207
|
+
const fBits = Array.from(f, (v) => v & 63);
|
|
3208
|
+
const gBits = Array.from(g, (v) => v & 63);
|
|
3209
|
+
const capitalFBits = Array.from(F, (v) => v & 255);
|
|
3210
|
+
const encoded = [
|
|
3211
|
+
encodeBitsMSB(fBits, FG_BITS),
|
|
3212
|
+
encodeBitsMSB(gBits, FG_BITS),
|
|
3213
|
+
encodeBitsMSB(capitalFBits, CAPITAL_FG_BITS)
|
|
3214
|
+
];
|
|
3215
|
+
try {
|
|
3216
|
+
const out = new Uint8Array(SECRET_KEY_LENGTH);
|
|
3217
|
+
out[0] = SECRET_KEY_HEADER;
|
|
3218
|
+
out.set(encoded[0], 1);
|
|
3219
|
+
out.set(encoded[1], 1 + FG_BYTES);
|
|
3220
|
+
out.set(encoded[2], 1 + 2 * FG_BYTES);
|
|
3221
|
+
return out;
|
|
3222
|
+
} finally {
|
|
3223
|
+
wipe(fBits, gBits, capitalFBits, ...encoded);
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
function decodePublicKey(publicKey) {
|
|
3227
|
+
const bytes = toBytes(publicKey, PUBLIC_KEY_LENGTH, "public key");
|
|
3228
|
+
if (bytes[0] !== PUBLIC_KEY_HEADER) throw new Error("Falcon512: invalid public key header");
|
|
3229
|
+
const h = decodeBitsMSB(bytes.subarray(1), N, 14);
|
|
3230
|
+
if (h.some((v) => v >= Q2)) {
|
|
3231
|
+
throw new Error("Falcon512: invalid public key (coefficient out of range)");
|
|
3232
|
+
}
|
|
3233
|
+
return Uint16Array.from(h);
|
|
3234
|
+
}
|
|
3235
|
+
function encodePublicKey(h) {
|
|
3236
|
+
if (h.length !== N) {
|
|
3237
|
+
throw new Error(`Falcon512: public key polynomial must have ${N} coefficients`);
|
|
3238
|
+
}
|
|
3239
|
+
for (let i = 0; i < N; i++) {
|
|
3240
|
+
if (!Number.isInteger(h[i]) || h[i] < 0 || h[i] >= Q2) {
|
|
3241
|
+
throw new Error("Falcon512: invalid public key (coefficient out of range)");
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
const out = new Uint8Array(PUBLIC_KEY_LENGTH);
|
|
3245
|
+
out[0] = PUBLIC_KEY_HEADER;
|
|
3246
|
+
out.set(encodeBitsMSB(h, 14), 1);
|
|
3247
|
+
return out;
|
|
3248
|
+
}
|
|
3249
|
+
function generateKeyPair(seed) {
|
|
3250
|
+
if (seed !== void 0 && (!(0, import_utils6.isBytes)(seed) || seed.length !== SEED_LENGTH)) {
|
|
3251
|
+
throw new Error(`Falcon512: seed must be a Uint8Array of ${SEED_LENGTH} bytes`);
|
|
3252
|
+
}
|
|
3253
|
+
return nobleEngine.keygen(seed);
|
|
3254
|
+
}
|
|
3255
|
+
function getPublicKey(secretKey) {
|
|
3256
|
+
const polys = decodeSecretKey(secretKey);
|
|
3257
|
+
try {
|
|
3258
|
+
return encodePublicKey(divZq(polys.g, polys.f));
|
|
3259
|
+
} finally {
|
|
3260
|
+
wipe(polys.f, polys.g, polys.F, polys.G);
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
function publicKeyToNtt(publicKey) {
|
|
3264
|
+
return Uint16Array.from(ntt(decodePublicKey(publicKey)));
|
|
3265
|
+
}
|
|
3266
|
+
function getPackedPublicKey(publicKey) {
|
|
3267
|
+
return packPoly(publicKeyToNtt(publicKey)).map((x) => starknet3.num.toHex(x));
|
|
3268
|
+
}
|
|
3269
|
+
function importFalconRsSecretKey(secretKey) {
|
|
3270
|
+
const bytes = toBytes(secretKey, FALCON_RS_SECRET_KEY_LENGTH, "falcon-rs secret key");
|
|
3271
|
+
const parts = [];
|
|
3272
|
+
try {
|
|
3273
|
+
const names = ["f", "g", "F", "G"];
|
|
3274
|
+
const [f, g, F, G] = names.map((name, k) => {
|
|
3275
|
+
const chunk = bytes.subarray(k * FALCON_RS_POLY_LENGTH, (k + 1) * FALCON_RS_POLY_LENGTH);
|
|
3276
|
+
const decoded = decode14LSB(chunk);
|
|
3277
|
+
parts.push(decoded);
|
|
3278
|
+
const poly = decoded.map(center);
|
|
3279
|
+
parts.push(poly);
|
|
3280
|
+
checkRange(poly, k < 2 ? FG_MAX : CAPITAL_FG_MAX, name);
|
|
3281
|
+
const p = Int8Array.from(poly);
|
|
3282
|
+
parts.push(p);
|
|
3283
|
+
return p;
|
|
3284
|
+
});
|
|
3285
|
+
const recomputed = completeG(f, g, F);
|
|
3286
|
+
parts.push(recomputed);
|
|
3287
|
+
if (recomputed.some((v, i) => v !== G[i])) {
|
|
3288
|
+
throw new Error("Falcon512: invalid falcon-rs secret key (G does not match f, g, F)");
|
|
3289
|
+
}
|
|
3290
|
+
checkNtruEquation({ f, g, F, G });
|
|
3291
|
+
return encodeSecretKey({ f, g, F });
|
|
3292
|
+
} finally {
|
|
3293
|
+
wipe(bytes, ...parts);
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
function exportFalconRsSecretKey(secretKey) {
|
|
3297
|
+
const polys = decodeSecretKey(secretKey);
|
|
3298
|
+
const parts = [];
|
|
3299
|
+
try {
|
|
3300
|
+
const out = new Uint8Array(FALCON_RS_SECRET_KEY_LENGTH);
|
|
3301
|
+
[polys.f, polys.g, polys.F, polys.G].forEach((p, k) => {
|
|
3302
|
+
const values = Array.from(p, modQ);
|
|
3303
|
+
const encoded = encode14LSB(values);
|
|
3304
|
+
parts.push(values, encoded);
|
|
3305
|
+
out.set(encoded, k * FALCON_RS_POLY_LENGTH);
|
|
3306
|
+
});
|
|
3307
|
+
return out;
|
|
3308
|
+
} finally {
|
|
3309
|
+
wipe(polys.f, polys.g, polys.F, polys.G, ...parts);
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
// src/falcon/s2morrow/signature.ts
|
|
3314
|
+
var import_utils7 = require("@noble/hashes/utils.js");
|
|
3315
|
+
var starknet5 = __toESM(require("starknet"));
|
|
3316
|
+
|
|
3317
|
+
// src/falcon/s2morrow/hashToPoint.ts
|
|
3318
|
+
var import_starknet = require("@scure/starknet");
|
|
3319
|
+
var starknet4 = __toESM(require("starknet"));
|
|
3320
|
+
function hashToPoint(message, salt) {
|
|
3321
|
+
message.forEach((m) => assertFelt(m, "message element"));
|
|
3322
|
+
salt.forEach((s) => assertFelt(s, "salt element"));
|
|
3323
|
+
const out = new Uint16Array(N);
|
|
3324
|
+
let idx = 0;
|
|
3325
|
+
const extract6 = (value) => {
|
|
3326
|
+
let v = value;
|
|
3327
|
+
for (let i = 0; i < 6 && idx < N; i++) {
|
|
3328
|
+
out[idx++] = Number(v % QB);
|
|
3329
|
+
v /= QB;
|
|
3330
|
+
}
|
|
3331
|
+
};
|
|
3332
|
+
const extract12 = (felt) => {
|
|
3333
|
+
extract6(felt & starknet4.UINT_128_MAX);
|
|
3334
|
+
extract6(felt >> 128n);
|
|
3335
|
+
};
|
|
3336
|
+
let state = [(0, import_starknet.poseidonHashMany)([...message, ...salt]), 0n, 0n];
|
|
3337
|
+
for (let round = 0; round < 21; round++) {
|
|
3338
|
+
state = (0, import_starknet.poseidonSmall)(state);
|
|
3339
|
+
extract12(state[0]);
|
|
3340
|
+
extract12(state[1]);
|
|
3341
|
+
}
|
|
3342
|
+
state = (0, import_starknet.poseidonSmall)(state);
|
|
3343
|
+
extract12(state[0]);
|
|
3344
|
+
return out;
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
// src/falcon/s2morrow/signature.ts
|
|
3348
|
+
var defaultDeps = { engine: nobleEngine, randomBytes: import_utils7.randomBytes };
|
|
3349
|
+
function computeMulHint(s1, pkNtt) {
|
|
3350
|
+
const s1Ntt = ntt(s1);
|
|
3351
|
+
return intt(s1Ntt.map((v, i) => v * pkNtt[i] % Q2));
|
|
3352
|
+
}
|
|
3353
|
+
var centeredSquare = (x) => {
|
|
3354
|
+
const c = x <= (Q2 - 1) / 2 ? x : Q2 - x;
|
|
3355
|
+
return c * c;
|
|
3356
|
+
};
|
|
3357
|
+
function checkSignatureEquation(hashPoint, s1, mulHint, pkNtt) {
|
|
3358
|
+
if (hashPoint.length !== N || s1.length !== N || mulHint.length !== N || pkNtt.length !== N) {
|
|
3359
|
+
return false;
|
|
3360
|
+
}
|
|
3361
|
+
const s1Ntt = ntt(s1);
|
|
3362
|
+
const hintNtt = ntt(mulHint);
|
|
3363
|
+
for (let i = 0; i < N; i += 1) {
|
|
3364
|
+
if (s1Ntt[i] * pkNtt[i] % Q2 !== hintNtt[i]) return false;
|
|
3365
|
+
}
|
|
3366
|
+
let norm = 0;
|
|
3367
|
+
for (let i = 0; i < N; i += 1) {
|
|
3368
|
+
norm += centeredSquare(modQ(hashPoint[i] - mulHint[i])) + centeredSquare(s1[i]);
|
|
3369
|
+
}
|
|
3370
|
+
return norm <= SIG_BOUND_512;
|
|
3371
|
+
}
|
|
3372
|
+
function formatSignature(sig) {
|
|
3373
|
+
const felts = [
|
|
3374
|
+
...packPoly(sig.s1),
|
|
3375
|
+
BigInt(sig.salt.length),
|
|
3376
|
+
...sig.salt,
|
|
3377
|
+
...packPoly(sig.mulHint)
|
|
3378
|
+
];
|
|
3379
|
+
return felts.map((x) => starknet5.num.toHex(x));
|
|
3380
|
+
}
|
|
3381
|
+
function parseSignature(signature) {
|
|
3382
|
+
if (!Array.isArray(signature) || signature.length !== SIGNATURE_FELTS) {
|
|
3383
|
+
throw new Error(`Falcon512: signature must have ${SIGNATURE_FELTS} felts`);
|
|
3384
|
+
}
|
|
3385
|
+
const felts = signature.map((x, i) => parseFelt(x, `signature[${i}]`));
|
|
3386
|
+
if (felts[PACKED_SLOTS] !== BigInt(SALT_FELTS)) {
|
|
3387
|
+
throw new Error("Falcon512: unexpected salt length");
|
|
3388
|
+
}
|
|
3389
|
+
const saltStart = PACKED_SLOTS + 1;
|
|
3390
|
+
return {
|
|
3391
|
+
s1: unpackPoly(felts.slice(0, PACKED_SLOTS)),
|
|
3392
|
+
salt: felts.slice(saltStart, saltStart + SALT_FELTS),
|
|
3393
|
+
mulHint: unpackPoly(felts.slice(saltStart + SALT_FELTS))
|
|
3394
|
+
};
|
|
3395
|
+
}
|
|
3396
|
+
var randomSaltFelt = (randomBytes2) => BigInt(`0x${starknet5.encode.buf2hex(randomBytes2(31))}`);
|
|
3397
|
+
function signHash(msgHash, secretKey, pkNtt, deps = defaultDeps) {
|
|
3398
|
+
assertFelt(msgHash, "message hash");
|
|
3399
|
+
const salt = [randomSaltFelt(deps.randomBytes), randomSaltFelt(deps.randomBytes)];
|
|
3400
|
+
const hashPoint = hashToPoint([msgHash], salt);
|
|
3401
|
+
const s2 = deps.engine.signHashPoint(hashPoint, secretKey);
|
|
3402
|
+
const s1 = Uint16Array.from(s2, modQ);
|
|
3403
|
+
const mulHint = Uint16Array.from(computeMulHint(s1, pkNtt));
|
|
3404
|
+
const signature = formatSignature({ s1, salt, mulHint });
|
|
3405
|
+
const decoded = parseSignature(signature);
|
|
3406
|
+
if (!checkSignatureEquation(hashPoint, decoded.s1, decoded.mulHint, pkNtt)) {
|
|
3407
|
+
throw new Error("Falcon512: self-verification failed, signature discarded");
|
|
3408
|
+
}
|
|
3409
|
+
return signature;
|
|
3410
|
+
}
|
|
3411
|
+
function verifyHash(msgHash, signature, pkNtt) {
|
|
3412
|
+
let decoded;
|
|
3413
|
+
try {
|
|
3414
|
+
assertFelt(msgHash, "message hash");
|
|
3415
|
+
decoded = parseSignature(signature);
|
|
3416
|
+
} catch {
|
|
3417
|
+
return false;
|
|
3418
|
+
}
|
|
3419
|
+
return checkSignatureEquation(
|
|
3420
|
+
hashToPoint([msgHash], decoded.salt),
|
|
3421
|
+
decoded.s1,
|
|
3422
|
+
decoded.mulHint,
|
|
3423
|
+
pkNtt
|
|
3424
|
+
);
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
// src/falcon/Falcon512Signer.ts
|
|
3428
|
+
function assertV3(details) {
|
|
3429
|
+
if (!starknet6.isV3Tx(details)) throw new Error("Falcon512: only V3 transactions are supported");
|
|
3430
|
+
}
|
|
3431
|
+
var Falcon512Signer = class _Falcon512Signer {
|
|
3432
|
+
#secretKey;
|
|
3433
|
+
#publicKey;
|
|
3434
|
+
#pkNtt;
|
|
3435
|
+
#packedPublicKey;
|
|
3436
|
+
/**
|
|
3437
|
+
* Builds a signer from a NIST Falcon-512 secret key. The key is fully checked, then copied: the
|
|
3438
|
+
* signer keeps its own copy, in a private field.
|
|
3439
|
+
* @param {Uint8Array | string} secretKey NIST Falcon-512 secret key (1281 bytes), Uint8Array or
|
|
3440
|
+
* hex string. Prefer a Uint8Array: a string cannot be wiped from memory.
|
|
3441
|
+
* @throws {Error} when the secret key is invalid
|
|
3442
|
+
* @example
|
|
3443
|
+
* ```typescript
|
|
3444
|
+
* const { secretKey } = falcon512.generateKeyPair();
|
|
3445
|
+
* const mySigner = new Falcon512Signer(secretKey);
|
|
3446
|
+
* new Falcon512Signer(new Uint8Array(1281));
|
|
3447
|
+
* // throws Error("Falcon512: invalid secret key header")
|
|
3448
|
+
* ```
|
|
3449
|
+
*/
|
|
3450
|
+
constructor(secretKey) {
|
|
3451
|
+
const bytes = toBytes(secretKey, SECRET_KEY_LENGTH, "secret key");
|
|
3452
|
+
let publicKey;
|
|
3453
|
+
try {
|
|
3454
|
+
publicKey = getPublicKey(bytes);
|
|
3455
|
+
} catch (error) {
|
|
3456
|
+
bytes.fill(0);
|
|
3457
|
+
throw error;
|
|
3458
|
+
}
|
|
3459
|
+
this.#publicKey = publicKey;
|
|
3460
|
+
this.#secretKey = bytes;
|
|
3461
|
+
this.#pkNtt = publicKeyToNtt(this.#publicKey);
|
|
3462
|
+
this.#packedPublicKey = getPackedPublicKey(this.#publicKey);
|
|
3463
|
+
}
|
|
3464
|
+
/**
|
|
3465
|
+
* Builds a signer from a falcon-rs secret key (3584 bytes), converted to the NIST format.
|
|
3466
|
+
*
|
|
3467
|
+
* Warning: falcon-rs derives the seed of its sampler from the public salt of each signature, so
|
|
3468
|
+
* the signatures it produced may leak information about the secret key. Use this for continuity
|
|
3469
|
+
* only; for real funds, generate a new key with `falcon512.generateKeyPair`. The S2morrow account
|
|
3470
|
+
* cannot change its key: a new key means a new account.
|
|
3471
|
+
* @param {Uint8Array | string} secretKey the falcon-rs secret key (3584 bytes), or its hex string
|
|
3472
|
+
* @returns {Falcon512Signer} a signer that holds the same key, in the NIST format
|
|
3473
|
+
* @throws {Error} when the falcon-rs secret key is invalid
|
|
3474
|
+
* @example
|
|
3475
|
+
* ```typescript
|
|
3476
|
+
* const mySigner = Falcon512Signer.fromFalconRs(falconRsSecretKey); // 3584 bytes, from falcon-rs
|
|
3477
|
+
* const result = mySigner.getPackedPublicKey();
|
|
3478
|
+
* // result = ['0xb2cf4f8b3c6f60cc662f438970ad34017e260c52d7911297a42811ce3cea2b', …] (29 felts)
|
|
3479
|
+
* ```
|
|
3480
|
+
*/
|
|
3481
|
+
static fromFalconRs(secretKey) {
|
|
3482
|
+
const nist = importFalconRsSecretKey(secretKey);
|
|
3483
|
+
try {
|
|
3484
|
+
return new _Falcon512Signer(nist);
|
|
3485
|
+
} finally {
|
|
3486
|
+
nist.fill(0);
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
/**
|
|
3490
|
+
* NIST Falcon-512 public key (897 bytes), as a hex string.
|
|
3491
|
+
* @returns {Promise<string>} the public key: 0x, then 1794 hex digits
|
|
3492
|
+
* @example
|
|
3493
|
+
* ```typescript
|
|
3494
|
+
* const { secretKey } = falcon512.generateKeyPair();
|
|
3495
|
+
* const mySigner = new Falcon512Signer(secretKey);
|
|
3496
|
+
* const result = await mySigner.getPubKey();
|
|
3497
|
+
* // result = '0x09…' (1796 characters; 09 is the header of the format)
|
|
3498
|
+
* ```
|
|
3499
|
+
*/
|
|
3500
|
+
async getPubKey() {
|
|
3501
|
+
return starknet6.encode.addHexPrefix(starknet6.encode.buf2hex(this.#publicKey));
|
|
3502
|
+
}
|
|
3503
|
+
/**
|
|
3504
|
+
* The 29 felts of the account constructor argument `pk_packed`.
|
|
3505
|
+
* @returns {string[]} the 29 felts, as hex strings (a new array at each call)
|
|
3506
|
+
* @example
|
|
3507
|
+
* ```typescript
|
|
3508
|
+
* const { secretKey } = falcon512.generateKeyPair();
|
|
3509
|
+
* const mySigner = new Falcon512Signer(secretKey);
|
|
3510
|
+
* const result = mySigner.getPackedPublicKey();
|
|
3511
|
+
* // result = ['0x…', …] (29 felts)
|
|
3512
|
+
* ```
|
|
3513
|
+
*/
|
|
3514
|
+
getPackedPublicKey() {
|
|
3515
|
+
return [...this.#packedPublicKey];
|
|
3516
|
+
}
|
|
3517
|
+
/**
|
|
3518
|
+
* Signs a SNIP-12 message (TypedData) for off-chain use.
|
|
3519
|
+
* @param {TypedData} typedData the message to sign
|
|
3520
|
+
* @param {string} accountAddress address of the account that signs the message
|
|
3521
|
+
* @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
|
|
3522
|
+
* @example
|
|
3523
|
+
* ```typescript
|
|
3524
|
+
* const result = await mySigner.signMessage(myTypedData, accountAddress);
|
|
3525
|
+
* // result = ['0x…', …] (61 felts, random salt); result[29] = '0x2' (salt length)
|
|
3526
|
+
* ```
|
|
3527
|
+
*/
|
|
3528
|
+
async signMessage(typedData3, accountAddress) {
|
|
3529
|
+
return this.signRaw(starknet6.typedData.getMessageHash(typedData3, accountAddress));
|
|
3530
|
+
}
|
|
3531
|
+
/**
|
|
3532
|
+
* Signs an INVOKE transaction (V3 only).
|
|
3533
|
+
* @param {Call[]} transactions the calls of the transaction
|
|
3534
|
+
* @param {InvocationsSignerDetails} details the details needed to hash the transaction
|
|
3535
|
+
* @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
|
|
3536
|
+
* @throws {Error} when the transaction is not V3
|
|
3537
|
+
* @example
|
|
3538
|
+
* ```typescript
|
|
3539
|
+
* const calls: Call[] = [
|
|
3540
|
+
* {
|
|
3541
|
+
* contractAddress: '0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
|
|
3542
|
+
* entrypoint: 'transfer',
|
|
3543
|
+
* calldata: ['0x123', '1000', '0'],
|
|
3544
|
+
* },
|
|
3545
|
+
* ];
|
|
3546
|
+
* const details: InvocationsSignerDetails = {
|
|
3547
|
+
* walletAddress: accountAddress,
|
|
3548
|
+
* chainId: constants.StarknetChainId.SN_SEPOLIA,
|
|
3549
|
+
* cairoVersion: '1',
|
|
3550
|
+
* version: '0x3',
|
|
3551
|
+
* nonce: 1,
|
|
3552
|
+
* resourceBounds: {
|
|
3553
|
+
* l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },
|
|
3554
|
+
* l2_gas: { max_amount: 40000000n, max_price_per_unit: 20000000000n },
|
|
3555
|
+
* l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },
|
|
3556
|
+
* },
|
|
3557
|
+
* tip: 0,
|
|
3558
|
+
* paymasterData: [],
|
|
3559
|
+
* accountDeploymentData: [],
|
|
3560
|
+
* nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
|
|
3561
|
+
* feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
|
|
3562
|
+
* };
|
|
3563
|
+
* const result = await mySigner.signTransaction(calls, details);
|
|
3564
|
+
* // result = ['0x…', …] (61 felts)
|
|
3565
|
+
* ```
|
|
3566
|
+
*/
|
|
3567
|
+
async signTransaction(transactions, details) {
|
|
3568
|
+
assertV3(details);
|
|
3569
|
+
const compiledCalldata = starknet6.transaction.getExecuteCalldata(
|
|
3570
|
+
transactions,
|
|
3571
|
+
details.cairoVersion
|
|
3572
|
+
);
|
|
3573
|
+
const msgHash = starknet6.hash.calculateInvokeTransactionHash({
|
|
3574
|
+
...details,
|
|
3575
|
+
senderAddress: details.walletAddress,
|
|
3576
|
+
compiledCalldata,
|
|
3577
|
+
version: details.version,
|
|
3578
|
+
nonceDataAvailabilityMode: starknet6.stark.intDAM(details.nonceDataAvailabilityMode),
|
|
3579
|
+
feeDataAvailabilityMode: starknet6.stark.intDAM(details.feeDataAvailabilityMode)
|
|
3580
|
+
});
|
|
3581
|
+
return this.signRaw(msgHash);
|
|
3582
|
+
}
|
|
3583
|
+
/**
|
|
3584
|
+
* Signs the DEPLOY_ACCOUNT transaction of a Falcon-512 account (V3 only).
|
|
3585
|
+
* @param {DeployAccountSignerDetails} details the details needed to hash the transaction
|
|
3586
|
+
* @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
|
|
3587
|
+
* @throws {Error} when the transaction is not V3
|
|
3588
|
+
* @example
|
|
3589
|
+
* ```typescript
|
|
3590
|
+
* const packedPublicKey = mySigner.getPackedPublicKey();
|
|
3591
|
+
* const classHash = '0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5';
|
|
3592
|
+
* const salt = packedPublicKey[0];
|
|
3593
|
+
* const details: DeployAccountSignerDetails = {
|
|
3594
|
+
* classHash,
|
|
3595
|
+
* constructorCalldata: packedPublicKey,
|
|
3596
|
+
* addressSalt: salt,
|
|
3597
|
+
* contractAddress: hash.calculateContractAddressFromHash(salt, classHash, packedPublicKey, 0),
|
|
3598
|
+
* chainId: constants.StarknetChainId.SN_SEPOLIA,
|
|
3599
|
+
* version: '0x3',
|
|
3600
|
+
* nonce: 0,
|
|
3601
|
+
* resourceBounds: {
|
|
3602
|
+
* l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },
|
|
3603
|
+
* l2_gas: { max_amount: 60000000n, max_price_per_unit: 20000000000n },
|
|
3604
|
+
* l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },
|
|
3605
|
+
* },
|
|
3606
|
+
* tip: 0,
|
|
3607
|
+
* paymasterData: [],
|
|
3608
|
+
* accountDeploymentData: [],
|
|
3609
|
+
* nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
|
|
3610
|
+
* feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
|
|
3611
|
+
* };
|
|
3612
|
+
* const result = await mySigner.signDeployAccountTransaction(details);
|
|
3613
|
+
* // result = ['0x…', …] (61 felts)
|
|
3614
|
+
* ```
|
|
3615
|
+
*/
|
|
3616
|
+
async signDeployAccountTransaction(details) {
|
|
3617
|
+
assertV3(details);
|
|
3618
|
+
const compiledConstructorCalldata = starknet6.CallData.compile(details.constructorCalldata);
|
|
3619
|
+
const msgHash = starknet6.hash.calculateDeployAccountTransactionHash({
|
|
3620
|
+
...details,
|
|
3621
|
+
salt: details.addressSalt,
|
|
3622
|
+
compiledConstructorCalldata,
|
|
3623
|
+
version: details.version,
|
|
3624
|
+
nonceDataAvailabilityMode: starknet6.stark.intDAM(details.nonceDataAvailabilityMode),
|
|
3625
|
+
feeDataAvailabilityMode: starknet6.stark.intDAM(details.feeDataAvailabilityMode)
|
|
3626
|
+
});
|
|
3627
|
+
return this.signRaw(msgHash);
|
|
3628
|
+
}
|
|
3629
|
+
/**
|
|
3630
|
+
* Signs a DECLARE transaction (V3 only).
|
|
3631
|
+
* @param {DeclareSignerDetails} details the details needed to hash the transaction
|
|
3632
|
+
* @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
|
|
3633
|
+
* @throws {Error} when the transaction is not V3
|
|
3634
|
+
* @example
|
|
3635
|
+
* ```typescript
|
|
3636
|
+
* const details: DeclareSignerDetails = {
|
|
3637
|
+
* senderAddress: accountAddress,
|
|
3638
|
+
* classHash: '0x37c7626b50ba517835c9556b53bce57cb6633704bb702f8c2f13a44cf151d5',
|
|
3639
|
+
* compiledClassHash: '0x1f2afb8ae690b84f4b7acfde52fbd2e5a1dc0c910ed898a778dc1ad3339e5c5',
|
|
3640
|
+
* chainId: constants.StarknetChainId.SN_SEPOLIA,
|
|
3641
|
+
* version: '0x3',
|
|
3642
|
+
* nonce: 2,
|
|
3643
|
+
* resourceBounds: {
|
|
3644
|
+
* l1_gas: { max_amount: 0n, max_price_per_unit: 50000000000000n },
|
|
3645
|
+
* l2_gas: { max_amount: 80000000n, max_price_per_unit: 20000000000n },
|
|
3646
|
+
* l1_data_gas: { max_amount: 1000n, max_price_per_unit: 100000n },
|
|
3647
|
+
* },
|
|
3648
|
+
* tip: 0,
|
|
3649
|
+
* paymasterData: [],
|
|
3650
|
+
* accountDeploymentData: [],
|
|
3651
|
+
* nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
|
|
3652
|
+
* feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
|
|
3653
|
+
* };
|
|
3654
|
+
* const result = await mySigner.signDeclareTransaction(details);
|
|
3655
|
+
* // result = ['0x…', …] (61 felts)
|
|
3656
|
+
* ```
|
|
3657
|
+
*/
|
|
3658
|
+
async signDeclareTransaction(details) {
|
|
3659
|
+
assertV3(details);
|
|
3660
|
+
const msgHash = starknet6.hash.calculateDeclareTransactionHash({
|
|
3661
|
+
...details,
|
|
3662
|
+
version: details.version,
|
|
3663
|
+
nonceDataAvailabilityMode: starknet6.stark.intDAM(details.nonceDataAvailabilityMode),
|
|
3664
|
+
feeDataAvailabilityMode: starknet6.stark.intDAM(details.feeDataAvailabilityMode)
|
|
3665
|
+
});
|
|
3666
|
+
return this.signRaw(msgHash);
|
|
3667
|
+
}
|
|
3668
|
+
/**
|
|
3669
|
+
* Signs a hash: the last step of all the methods above. It stays protected, so that no public
|
|
3670
|
+
* method signs an arbitrary hash. A subclass can override it, as for every starknet.js signer.
|
|
3671
|
+
* @param {string} msgHash the hash to sign, a felt252
|
|
3672
|
+
* @returns {Promise<Signature>} the 61 felts of the signature, as hex strings
|
|
3673
|
+
* @example
|
|
3674
|
+
* ```typescript
|
|
3675
|
+
* class LoggedFalconSigner extends Falcon512Signer {
|
|
3676
|
+
* protected async signRaw(msgHash: string): Promise<Signature> {
|
|
3677
|
+
* console.log('Falcon-512 signs', msgHash);
|
|
3678
|
+
* return super.signRaw(msgHash);
|
|
3679
|
+
* }
|
|
3680
|
+
* }
|
|
3681
|
+
* const result = await new LoggedFalconSigner(secretKey).signMessage(myTypedData, accountAddress);
|
|
3682
|
+
* // logs the hash of the message; result = ['0x…', …] (61 felts)
|
|
3683
|
+
* ```
|
|
3684
|
+
*/
|
|
3685
|
+
async signRaw(msgHash) {
|
|
3686
|
+
return signHash(starknet6.num.toBigInt(msgHash), this.#secretKey, this.#pkNtt);
|
|
3687
|
+
}
|
|
3688
|
+
};
|
|
3689
|
+
|
|
3690
|
+
// src/falcon/falcon512.ts
|
|
3691
|
+
var falcon512_exports = {};
|
|
3692
|
+
__export(falcon512_exports, {
|
|
3693
|
+
exportFalconRsSecretKey: () => exportFalconRsSecretKey,
|
|
3694
|
+
generateKeyPair: () => generateKeyPair,
|
|
3695
|
+
getPackedPublicKey: () => getPackedPublicKey,
|
|
3696
|
+
getPublicKey: () => getPublicKey,
|
|
3697
|
+
importFalconRsSecretKey: () => importFalconRsSecretKey,
|
|
3698
|
+
verify: () => verify,
|
|
3699
|
+
verifyMessage: () => verifyMessage
|
|
3700
|
+
});
|
|
3701
|
+
|
|
3702
|
+
// src/falcon/verify.ts
|
|
3703
|
+
var starknet7 = __toESM(require("starknet"));
|
|
3704
|
+
function toMessageHash(value) {
|
|
3705
|
+
try {
|
|
3706
|
+
return parseFelt(value, "message hash");
|
|
3707
|
+
} catch {
|
|
3708
|
+
return void 0;
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
function verify(signature, msgHash, fullPublicKey) {
|
|
3712
|
+
const pkNtt = publicKeyToNtt(fullPublicKey);
|
|
3713
|
+
const h = toMessageHash(msgHash);
|
|
3714
|
+
if (h === void 0 || !Array.isArray(signature)) return false;
|
|
3715
|
+
return verifyHash(h, signature, pkNtt);
|
|
3716
|
+
}
|
|
3717
|
+
function verifyMessage(message, signature, fullPublicKey, accountAddress) {
|
|
3718
|
+
if (typeof message === "object" && message !== null) {
|
|
3719
|
+
if (accountAddress === void 0) {
|
|
3720
|
+
throw new Error("Falcon512: accountAddress is required to verify a TypedData message");
|
|
3721
|
+
}
|
|
3722
|
+
return verify(
|
|
3723
|
+
signature,
|
|
3724
|
+
starknet7.typedData.getMessageHash(message, accountAddress),
|
|
3725
|
+
fullPublicKey
|
|
3726
|
+
);
|
|
3727
|
+
}
|
|
3728
|
+
return verify(signature, message, fullPublicKey);
|
|
3729
|
+
}
|
|
3730
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3731
|
+
0 && (module.exports = {
|
|
3732
|
+
Falcon512Signer,
|
|
3733
|
+
falcon512
|
|
3734
|
+
});
|
|
3735
|
+
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
|
3736
|
+
//# sourceMappingURL=index.js.map
|