@blamejs/blamejs-shop 0.5.19 → 0.5.21
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 +4 -0
- package/README.md +1 -0
- package/SECURITY.md +17 -0
- package/lib/addresses.js +2 -2
- package/lib/admin.js +49 -45
- package/lib/affiliates.js +7 -23
- package/lib/announcement-bar.js +5 -22
- package/lib/api-keys.js +4 -13
- package/lib/asset-manifest.json +1 -1
- package/lib/banner-ab-tests.js +5 -9
- package/lib/blog-articles.js +8 -26
- package/lib/captcha-gate.js +7 -17
- package/lib/carrier-accounts.js +3 -10
- package/lib/catalog-drafts.js +5 -12
- package/lib/category-navigation.js +4 -20
- package/lib/cms-blocks.js +4 -7
- package/lib/compliance-export.js +4 -11
- package/lib/consent-ledger.js +2 -4
- package/lib/cost-layers.js +56 -21
- package/lib/customer-import.js +2 -2
- package/lib/customer-notes.js +7 -23
- package/lib/customer-roles.js +3 -5
- package/lib/customer-segments.js +17 -14
- package/lib/customer-surveys.js +7 -14
- package/lib/customers.js +2 -4
- package/lib/dispute-resolution.js +5 -13
- package/lib/dropship-forwarding.js +3 -5
- package/lib/dunning.js +2 -7
- package/lib/email-ab-tests.js +4 -8
- package/lib/email-campaigns.js +25 -14
- package/lib/email-warmup.js +2 -7
- package/lib/experiments.js +6 -10
- package/lib/externaldb-d1.js +78 -44
- package/lib/geolocation.js +18 -28
- package/lib/gift-options.js +5 -23
- package/lib/knowledge-base.js +7 -22
- package/lib/line-gift-wrap.js +3 -17
- package/lib/live-chat.js +5 -18
- package/lib/metered-usage.js +3 -8
- package/lib/notifications.js +3 -7
- package/lib/operator-accounts.js +3 -5
- package/lib/operator-approvals.js +6 -8
- package/lib/operator-audit-log.js +2 -7
- package/lib/operator-help-center.js +5 -21
- package/lib/operator-inbox.js +4 -11
- package/lib/operator-roles.js +5 -7
- package/lib/order-escalation.js +2 -2
- package/lib/order-export.js +24 -20
- package/lib/order-notes.js +4 -14
- package/lib/order-ratings.js +4 -10
- package/lib/payment-methods.js +5 -13
- package/lib/payment-retries.js +2 -7
- package/lib/payment.js +103 -58
- package/lib/pixel-events.js +8 -23
- package/lib/plan-changes.js +2 -7
- package/lib/product-qa.js +4 -8
- package/lib/promo-banners.js +7 -15
- package/lib/purchase-orders.js +3 -6
- package/lib/push-notifications.js +7 -32
- package/lib/pwa-manifest.js +6 -11
- package/lib/quotes.js +5 -9
- package/lib/referrals.js +10 -6
- package/lib/reviews.js +4 -10
- package/lib/robots-config.js +6 -14
- package/lib/sales-tax-filings.js +2 -2
- package/lib/search-facets.js +5 -5
- package/lib/search-ranking.js +4 -7
- package/lib/search-synonyms.js +7 -21
- package/lib/security-middleware.js +125 -70
- package/lib/seller-signup.js +10 -26
- package/lib/sidebar-widgets.js +6 -15
- package/lib/site-redirects.js +49 -137
- package/lib/sitemap-generator.js +3 -7
- package/lib/sms-dispatcher.js +7 -23
- package/lib/stock-receipts.js +4 -10
- package/lib/storefront-dashboards.js +2 -10
- package/lib/storefront-forms.js +9 -22
- package/lib/storefront-pages.js +6 -20
- package/lib/storefront.js +21 -23
- package/lib/subscription-billing.js +3 -8
- package/lib/subscription-controls.js +2 -7
- package/lib/suggestion-box.js +9 -26
- package/lib/support-tickets.js +6 -24
- package/lib/tax-remittance.js +2 -2
- package/lib/tenants.js +2 -7
- package/lib/text-guard.js +137 -35
- package/lib/theme-assets.js +4 -16
- package/lib/translations.js +3 -6
- package/lib/trust-badges.js +4 -7
- package/lib/vendor/MANIFEST.json +107 -97
- package/lib/vendor/blamejs/CHANGELOG.md +180 -0
- package/lib/vendor/blamejs/NOTICE +14 -10
- package/lib/vendor/blamejs/README.md +17 -5
- package/lib/vendor/blamejs/index.js +2 -0
- package/lib/vendor/blamejs/lib/acme.js +9 -9
- package/lib/vendor/blamejs/lib/api-snapshot.js +35 -16
- package/lib/vendor/blamejs/lib/app-shutdown.js +1 -1
- package/lib/vendor/blamejs/lib/archive-adapters.js +1 -1
- package/lib/vendor/blamejs/lib/archive.js +13 -24
- package/lib/vendor/blamejs/lib/auth/access-lock.js +2 -1
- package/lib/vendor/blamejs/lib/auth/bot-challenge.js +3 -6
- package/lib/vendor/blamejs/lib/auth/ciba.js +32 -3
- package/lib/vendor/blamejs/lib/auth/oauth.js +65 -8
- package/lib/vendor/blamejs/lib/auth/password.js +1 -1
- package/lib/vendor/blamejs/lib/auth/saml.js +21 -3
- package/lib/vendor/blamejs/lib/auth-bot-challenge.js +3 -3
- package/lib/vendor/blamejs/lib/backup/index.js +5 -5
- package/lib/vendor/blamejs/lib/case-fold-classes.js +491 -0
- package/lib/vendor/blamejs/lib/codepoint-class.js +131 -0
- package/lib/vendor/blamejs/lib/constants.js +79 -0
- package/lib/vendor/blamejs/lib/db-declare-view.js +8 -2
- package/lib/vendor/blamejs/lib/error-page.js +20 -1
- package/lib/vendor/blamejs/lib/external-db.js +5 -1
- package/lib/vendor/blamejs/lib/flag-evaluation-context.js +24 -6
- package/lib/vendor/blamejs/lib/flag.js +28 -2
- package/lib/vendor/blamejs/lib/framework-schema.js +14 -3
- package/lib/vendor/blamejs/lib/guard-regex.js +2345 -89
- package/lib/vendor/blamejs/lib/http-client.js +217 -40
- package/lib/vendor/blamejs/lib/mail-bimi.js +1 -1
- package/lib/vendor/blamejs/lib/mail-crypto-pgp.js +3 -2
- package/lib/vendor/blamejs/lib/mail-dav.js +26 -26
- package/lib/vendor/blamejs/lib/mail-deploy.js +10 -10
- package/lib/vendor/blamejs/lib/mail-scan.js +3 -0
- package/lib/vendor/blamejs/lib/mail-store.js +7 -1
- package/lib/vendor/blamejs/lib/mail.js +5 -1
- package/lib/vendor/blamejs/lib/middleware/age-gate.js +3 -2
- package/lib/vendor/blamejs/lib/middleware/api-encrypt.js +1 -1
- package/lib/vendor/blamejs/lib/middleware/assetlinks.js +2 -1
- package/lib/vendor/blamejs/lib/middleware/asyncapi-serve.js +3 -2
- package/lib/vendor/blamejs/lib/middleware/bearer-auth.js +2 -1
- package/lib/vendor/blamejs/lib/middleware/compression.js +1 -1
- package/lib/vendor/blamejs/lib/middleware/cors.js +1 -1
- package/lib/vendor/blamejs/lib/middleware/csp-report.js +5 -5
- package/lib/vendor/blamejs/lib/middleware/csrf-protect.js +2 -1
- package/lib/vendor/blamejs/lib/middleware/daily-byte-quota.js +2 -2
- package/lib/vendor/blamejs/lib/middleware/deny-response.js +2 -1
- package/lib/vendor/blamejs/lib/middleware/dpop.js +2 -2
- package/lib/vendor/blamejs/lib/middleware/fetch-metadata.js +2 -1
- package/lib/vendor/blamejs/lib/middleware/flag-context.js +17 -0
- package/lib/vendor/blamejs/lib/middleware/idempotency-key.js +10 -8
- package/lib/vendor/blamejs/lib/middleware/openapi-serve.js +3 -2
- package/lib/vendor/blamejs/lib/middleware/require-aal.js +3 -2
- package/lib/vendor/blamejs/lib/middleware/require-auth.js +4 -3
- package/lib/vendor/blamejs/lib/middleware/require-bound-key.js +4 -3
- package/lib/vendor/blamejs/lib/middleware/require-content-type.js +3 -2
- package/lib/vendor/blamejs/lib/middleware/require-methods.js +3 -2
- package/lib/vendor/blamejs/lib/middleware/require-mtls.js +3 -2
- package/lib/vendor/blamejs/lib/middleware/security-txt.js +2 -1
- package/lib/vendor/blamejs/lib/middleware/web-app-manifest.js +2 -1
- package/lib/vendor/blamejs/lib/network-dns-resolver.js +1 -1
- package/lib/vendor/blamejs/lib/network-dns.js +3 -3
- package/lib/vendor/blamejs/lib/network-nts.js +35 -14
- package/lib/vendor/blamejs/lib/network-proxy.js +42 -4
- package/lib/vendor/blamejs/lib/network-smtp-policy.js +1 -1
- package/lib/vendor/blamejs/lib/network-tls.js +341 -11
- package/lib/vendor/blamejs/lib/nist-crosswalk.js +2 -2
- package/lib/vendor/blamejs/lib/ntp-check.js +30 -19
- package/lib/vendor/blamejs/lib/object-store/azure-blob.js +1 -1
- package/lib/vendor/blamejs/lib/object-store/gcs.js +1 -1
- package/lib/vendor/blamejs/lib/object-store/http-put.js +2 -1
- package/lib/vendor/blamejs/lib/object-store/sigv4-bucket-ops.js +5 -5
- package/lib/vendor/blamejs/lib/object-store/sigv4.js +2 -2
- package/lib/vendor/blamejs/lib/observability-otlp-exporter.js +4 -2
- package/lib/vendor/blamejs/lib/openapi.js +1 -1
- package/lib/vendor/blamejs/lib/pqc-agent.js +4 -7
- package/lib/vendor/blamejs/lib/problem-details.js +2 -1
- package/lib/vendor/blamejs/lib/redis-client.js +12 -1
- package/lib/vendor/blamejs/lib/regex-linear.js +1349 -0
- package/lib/vendor/blamejs/lib/render.js +531 -7
- package/lib/vendor/blamejs/lib/request-helpers.js +181 -5
- package/lib/vendor/blamejs/lib/router.js +37 -13
- package/lib/vendor/blamejs/lib/safe-async.js +142 -0
- package/lib/vendor/blamejs/lib/safe-icap.js +3 -0
- package/lib/vendor/blamejs/lib/safe-sql.js +15 -3
- package/lib/vendor/blamejs/lib/self-update.js +2 -2
- package/lib/vendor/blamejs/lib/testing.js +54 -7
- package/lib/vendor/blamejs/lib/validate-opts.js +56 -0
- package/lib/vendor/blamejs/lib/vendor/MANIFEST.json +62 -25
- package/lib/vendor/blamejs/lib/vendor/blamejs-pki.cjs +2004 -142
- package/lib/vendor/blamejs/lib/vendor/browser/noble-ciphers.mjs +727 -0
- package/lib/vendor/blamejs/lib/vendor/browser/noble-hashes.mjs +1070 -0
- package/lib/vendor/blamejs/lib/vendor/browser/noble-post-quantum.mjs +1090 -0
- package/lib/vendor/blamejs/lib/vendor/noble-post-quantum.cjs +510 -227
- package/lib/vendor/blamejs/lib/webhook-hmac.js +19 -2
- package/lib/vendor/blamejs/lib/webhook.js +1 -1
- package/lib/vendor/blamejs/lib/ws-client.js +24 -2
- package/lib/vendor/blamejs/package.json +1 -1
- package/lib/vendor/blamejs/sbom.cdx.json +6 -6
- package/lib/vendor-invoices.js +3 -6
- package/lib/vendors.js +5 -19
- package/lib/webhook-receiver.js +46 -83
- package/lib/webhook-subscriptions.js +3 -13
- package/lib/wishlist-sharing.js +5 -10
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @noble/post-quantum v0.
|
|
1
|
+
// @noble/post-quantum v0.7.0 — vendored from Paul Miller
|
|
2
2
|
// License: MIT — https://github.com/paulmillr/noble-post-quantum
|
|
3
3
|
// Bundled with esbuild. Exports: ml_kem512 / ml_kem768 / ml_kem1024 (FIPS 203 KEM),
|
|
4
4
|
// ml_dsa44 / ml_dsa65 / ml_dsa87 (FIPS 204 lattice signatures),
|
|
@@ -40,7 +40,7 @@ __export(entry_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(entry_exports);
|
|
41
41
|
|
|
42
42
|
// node_modules/@noble/hashes/_u64.js
|
|
43
|
-
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
43
|
+
var U32_MASK64 = /* @__PURE__ */ (() => BigInt(2 ** 32 - 1))();
|
|
44
44
|
var _32n = /* @__PURE__ */ BigInt(32);
|
|
45
45
|
function fromBig(n, le = false) {
|
|
46
46
|
if (le)
|
|
@@ -57,16 +57,20 @@ function split(lst, le = false) {
|
|
|
57
57
|
}
|
|
58
58
|
return [Ah, Al];
|
|
59
59
|
}
|
|
60
|
+
var fromNumH = (n) => n / 2 ** 32 | 0;
|
|
61
|
+
var fromNumL = (n) => n >>> 0;
|
|
62
|
+
function setU64FromNum(view, byteOffset, n, isLE2) {
|
|
63
|
+
const h = fromNumH(n);
|
|
64
|
+
const l = fromNumL(n);
|
|
65
|
+
view.setUint32(byteOffset, isLE2 ? l : h, isLE2);
|
|
66
|
+
view.setUint32(byteOffset + 4, isLE2 ? h : l, isLE2);
|
|
67
|
+
}
|
|
60
68
|
var shrSH = (h, _l, s) => h >>> s;
|
|
61
69
|
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
62
70
|
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
63
71
|
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
64
72
|
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
65
73
|
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
66
|
-
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
67
|
-
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
68
|
-
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
69
|
-
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
70
74
|
function add(Ah, Al, Bh, Bl) {
|
|
71
75
|
const l = (Al >>> 0) + (Bl >>> 0);
|
|
72
76
|
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
@@ -82,52 +86,55 @@ var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32
|
|
|
82
86
|
function isBytes(a) {
|
|
83
87
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
84
88
|
}
|
|
89
|
+
var atitle = (title) => title ? `"${title}" ` : "";
|
|
85
90
|
function anumber(n, title = "") {
|
|
86
|
-
if (typeof n !== "number")
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
if (typeof n !== "number")
|
|
92
|
+
throw new TypeError(atitle(title) + "expected number, got " + typeof n);
|
|
93
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
94
|
+
throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
|
|
95
|
+
return n;
|
|
96
|
+
}
|
|
97
|
+
function abool(value, title = "") {
|
|
98
|
+
if (typeof value !== "boolean")
|
|
99
|
+
throw new TypeError(atitle(title) + "expected boolean, got type=" + typeof value);
|
|
100
|
+
return value;
|
|
94
101
|
}
|
|
95
102
|
function abytes(value, length, title = "") {
|
|
103
|
+
if (isBytes(value) && (length === void 0 || value.length === length))
|
|
104
|
+
return value;
|
|
105
|
+
if (length !== void 0)
|
|
106
|
+
anumber(length, "length");
|
|
96
107
|
const bytes = isBytes(value);
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
|
|
104
|
-
if (!bytes)
|
|
105
|
-
throw new TypeError(message);
|
|
106
|
-
throw new RangeError(message);
|
|
107
|
-
}
|
|
108
|
-
return value;
|
|
108
|
+
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
109
|
+
const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
|
|
110
|
+
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
111
|
+
if (!bytes)
|
|
112
|
+
throw new TypeError(message);
|
|
113
|
+
throw new RangeError(message);
|
|
109
114
|
}
|
|
110
115
|
function ahash(h) {
|
|
111
116
|
if (typeof h !== "function" || typeof h.create !== "function")
|
|
112
|
-
throw new TypeError("
|
|
117
|
+
throw new TypeError("expected hash wrapped by utils.createHasher");
|
|
113
118
|
anumber(h.outputLen);
|
|
114
119
|
anumber(h.blockLen);
|
|
115
|
-
if (h.outputLen < 1)
|
|
116
|
-
throw new Error(
|
|
117
|
-
if (h.blockLen < 1)
|
|
118
|
-
throw new Error('"blockLen" must be >= 1');
|
|
120
|
+
if (h.outputLen < 1 || h.blockLen < 1)
|
|
121
|
+
throw new Error("hash blockLen / outputLen must be >= 1");
|
|
119
122
|
}
|
|
123
|
+
var aobject = (value, label) => {
|
|
124
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
125
|
+
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
126
|
+
};
|
|
120
127
|
function aexists(instance, checkFinished = true) {
|
|
121
128
|
if (instance.destroyed)
|
|
122
|
-
throw new Error("
|
|
129
|
+
throw new Error("hash was destroyed");
|
|
123
130
|
if (checkFinished && instance.finished)
|
|
124
|
-
throw new Error("
|
|
131
|
+
throw new Error("digest() was already called");
|
|
125
132
|
}
|
|
126
133
|
function aoutput(out, instance) {
|
|
127
|
-
abytes(out, void 0, "
|
|
134
|
+
abytes(out, void 0, "output");
|
|
128
135
|
const min = instance.outputLen;
|
|
129
|
-
if (out.length
|
|
130
|
-
throw new RangeError('"
|
|
136
|
+
if (!(out.length >= min)) {
|
|
137
|
+
throw new RangeError('"output" expected length >= ' + min);
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
140
|
function u32(arr) {
|
|
@@ -170,15 +177,8 @@ function bytesToHex(bytes) {
|
|
|
170
177
|
}
|
|
171
178
|
return hex;
|
|
172
179
|
}
|
|
173
|
-
var asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
174
180
|
function asciiToBase16(ch) {
|
|
175
|
-
|
|
176
|
-
return ch - asciis._0;
|
|
177
|
-
if (ch >= asciis.A && ch <= asciis.F)
|
|
178
|
-
return ch - (asciis.A - 10);
|
|
179
|
-
if (ch >= asciis.a && ch <= asciis.f)
|
|
180
|
-
return ch - (asciis.a - 10);
|
|
181
|
-
return;
|
|
181
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
182
182
|
}
|
|
183
183
|
function hexToBytes(hex) {
|
|
184
184
|
if (typeof hex !== "string")
|
|
@@ -223,7 +223,17 @@ function concatBytes(...arrays) {
|
|
|
223
223
|
}
|
|
224
224
|
return res;
|
|
225
225
|
}
|
|
226
|
+
function checkOpts(defaults, opts2, title = "opts") {
|
|
227
|
+
aobject(defaults, "defaults");
|
|
228
|
+
if (opts2 !== void 0)
|
|
229
|
+
aobject(opts2, title);
|
|
230
|
+
const merged = Object.assign(defaults, opts2);
|
|
231
|
+
return merged;
|
|
232
|
+
}
|
|
226
233
|
function createHasher(hashCons, info = {}) {
|
|
234
|
+
if (typeof hashCons !== "function")
|
|
235
|
+
throw new TypeError('"hashCons" expected function, got type=' + typeof hashCons);
|
|
236
|
+
info = checkOpts({}, info, "info");
|
|
227
237
|
const hashC = (msg, opts2) => hashCons(opts2).update(msg).digest();
|
|
228
238
|
const tmp = hashCons(void 0);
|
|
229
239
|
hashC.outputLen = tmp.outputLen;
|
|
@@ -273,13 +283,21 @@ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
|
273
283
|
var IOTAS = split(_SHA3_IOTA, true);
|
|
274
284
|
var SHA3_IOTA_H = IOTAS[0];
|
|
275
285
|
var SHA3_IOTA_L = IOTAS[1];
|
|
286
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
287
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
288
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
289
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
276
290
|
var rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
277
291
|
var rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
292
|
+
var B = new Uint32Array(5 * 2);
|
|
278
293
|
function keccakP(s, rounds = 24) {
|
|
294
|
+
if (!(s instanceof Uint32Array))
|
|
295
|
+
throw new TypeError('"s" expected Uint32Array(50), got type=' + typeof s);
|
|
296
|
+
if (s.length !== 50)
|
|
297
|
+
throw new RangeError('"s" expected Uint32Array(50), got length=' + s.length);
|
|
279
298
|
anumber(rounds, "rounds");
|
|
280
299
|
if (rounds < 1 || rounds > 24)
|
|
281
300
|
throw new Error('"rounds" expected integer 1..24');
|
|
282
|
-
const B = new Uint32Array(5 * 2);
|
|
283
301
|
for (let round = 24 - rounds; round < 24; round++) {
|
|
284
302
|
for (let x = 0; x < 10; x++)
|
|
285
303
|
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
@@ -340,6 +358,10 @@ var Keccak = class _Keccak {
|
|
|
340
358
|
rounds;
|
|
341
359
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
342
360
|
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
361
|
+
anumber(blockLen, "blockLen");
|
|
362
|
+
anumber(suffix, "suffix");
|
|
363
|
+
anumber(rounds, "rounds");
|
|
364
|
+
abool(enableXOF, "enableXOF");
|
|
343
365
|
this.blockLen = blockLen;
|
|
344
366
|
this.suffix = suffix;
|
|
345
367
|
this.outputLen = outputLen;
|
|
@@ -348,7 +370,7 @@ var Keccak = class _Keccak {
|
|
|
348
370
|
this.rounds = rounds;
|
|
349
371
|
anumber(outputLen, "outputLen");
|
|
350
372
|
if (!(0 < blockLen && blockLen < 200))
|
|
351
|
-
throw new Error("
|
|
373
|
+
throw new Error('"blockLen" must be 1..199');
|
|
352
374
|
this.state = new Uint8Array(200);
|
|
353
375
|
this.state32 = u32(this.state);
|
|
354
376
|
}
|
|
@@ -365,9 +387,20 @@ var Keccak = class _Keccak {
|
|
|
365
387
|
update(data) {
|
|
366
388
|
aexists(this);
|
|
367
389
|
abytes(data);
|
|
368
|
-
const { blockLen, state } = this;
|
|
390
|
+
const { blockLen, state, state32 } = this;
|
|
369
391
|
const len = data.length;
|
|
392
|
+
const canUseU32 = blockLen % 4 === 0 && data.byteOffset % 4 === 0;
|
|
393
|
+
const blockLen32 = blockLen / 4;
|
|
394
|
+
const data32 = canUseU32 && len >= blockLen ? u32(data) : void 0;
|
|
370
395
|
for (let pos = 0; pos < len; ) {
|
|
396
|
+
if (data32 !== void 0 && this.pos === 0 && pos % 4 === 0 && len - pos >= blockLen) {
|
|
397
|
+
for (let i = 0, o = pos / 4; i < blockLen32; i++)
|
|
398
|
+
state32[i] ^= data32[o + i];
|
|
399
|
+
pos += blockLen;
|
|
400
|
+
this.pos = blockLen;
|
|
401
|
+
this.keccak();
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
371
404
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
372
405
|
for (let i = 0; i < take; i++)
|
|
373
406
|
state[this.pos++] ^= data[pos++];
|
|
@@ -405,7 +438,7 @@ var Keccak = class _Keccak {
|
|
|
405
438
|
}
|
|
406
439
|
xofInto(out) {
|
|
407
440
|
if (!this.enableXOF)
|
|
408
|
-
throw new Error("XOF is not
|
|
441
|
+
throw new Error("XOF is not enabled");
|
|
409
442
|
return this.writeInto(out);
|
|
410
443
|
}
|
|
411
444
|
xof(bytes) {
|
|
@@ -416,7 +449,7 @@ var Keccak = class _Keccak {
|
|
|
416
449
|
aoutput(out, this);
|
|
417
450
|
if (this.finished)
|
|
418
451
|
throw new Error("digest() was already called");
|
|
419
|
-
this.writeInto(out.subarray(0, this.outputLen));
|
|
452
|
+
this.writeInto(out.length === this.outputLen ? out : out.subarray(0, this.outputLen));
|
|
420
453
|
this.destroy();
|
|
421
454
|
}
|
|
422
455
|
digest() {
|
|
@@ -458,22 +491,94 @@ var sha3_512 = /* @__PURE__ */ genKeccak(
|
|
|
458
491
|
64,
|
|
459
492
|
/* @__PURE__ */ oidNist(10)
|
|
460
493
|
);
|
|
461
|
-
var genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts2 = {}) =>
|
|
494
|
+
var genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts2 = {}) => {
|
|
495
|
+
opts2 = checkOpts({}, opts2);
|
|
496
|
+
return new Keccak(blockLen, suffix, opts2.dkLen === void 0 ? outputLen : opts2.dkLen, true);
|
|
497
|
+
}, info);
|
|
462
498
|
var shake128 = /* @__PURE__ */ genShake(31, 168, 16, /* @__PURE__ */ oidNist(11));
|
|
463
499
|
var shake256 = /* @__PURE__ */ genShake(31, 136, 32, /* @__PURE__ */ oidNist(12));
|
|
464
500
|
|
|
501
|
+
// node_modules/@noble/curves/utils.js
|
|
502
|
+
var anumber2 = anumber;
|
|
503
|
+
function aobject2(value, title = "object") {
|
|
504
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
505
|
+
throw new TypeError(title === "object" ? "expected valid options object" : `"${title}" expected object, got type=${typeof value}`);
|
|
506
|
+
return value;
|
|
507
|
+
}
|
|
508
|
+
var _0n2 = /* @__PURE__ */ BigInt(0);
|
|
509
|
+
var atitle2 = (title) => title ? `"${title}" ` : "";
|
|
510
|
+
function abool2(value, title = "") {
|
|
511
|
+
if (typeof value !== "boolean")
|
|
512
|
+
throw new TypeError(atitle2(title) + "expected boolean, got type=" + typeof value);
|
|
513
|
+
return value;
|
|
514
|
+
}
|
|
515
|
+
function abignumber(n) {
|
|
516
|
+
if (typeof n === "bigint") {
|
|
517
|
+
if (!isPosBig(n))
|
|
518
|
+
throw new RangeError("positive bigint expected, got " + n);
|
|
519
|
+
} else
|
|
520
|
+
anumber2(n);
|
|
521
|
+
return n;
|
|
522
|
+
}
|
|
523
|
+
function hexToNumber(hex) {
|
|
524
|
+
if (typeof hex !== "string")
|
|
525
|
+
throw new TypeError("hex string expected, got " + typeof hex);
|
|
526
|
+
return hex === "" ? _0n2 : BigInt("0x" + hex);
|
|
527
|
+
}
|
|
528
|
+
function bytesToNumberBE(bytes) {
|
|
529
|
+
return hexToNumber(bytesToHex(bytes));
|
|
530
|
+
}
|
|
531
|
+
function numberToBytesBE(n, len) {
|
|
532
|
+
anumber(len);
|
|
533
|
+
if (len === 0)
|
|
534
|
+
throw new Error("zero output length is invalid");
|
|
535
|
+
n = abignumber(n);
|
|
536
|
+
const expectedLen = len * 2;
|
|
537
|
+
const hex = n.toString(16);
|
|
538
|
+
if (hex.length > expectedLen)
|
|
539
|
+
throw new RangeError("number is too large");
|
|
540
|
+
return hexToBytes(hex.padStart(expectedLen, "0"));
|
|
541
|
+
}
|
|
542
|
+
function isPosBig(n) {
|
|
543
|
+
return typeof n === "bigint" && _0n2 <= n;
|
|
544
|
+
}
|
|
545
|
+
function validateObject(object, fields = {}, optFields = {}, title = "object") {
|
|
546
|
+
aobject2(object, title);
|
|
547
|
+
aobject2(fields, "fields");
|
|
548
|
+
aobject2(optFields, "optFields");
|
|
549
|
+
function checkField(fieldName, expectedType, isOpt) {
|
|
550
|
+
const label = title === "object" ? `param "${String(fieldName)}"` : `"${title}.${String(fieldName)}"`;
|
|
551
|
+
const val = object[fieldName];
|
|
552
|
+
if (!Object.hasOwn(object, fieldName) && (isOpt ? val !== void 0 : expectedType !== "function")) {
|
|
553
|
+
throw new TypeError(`${label} is invalid: expected own property`);
|
|
554
|
+
}
|
|
555
|
+
if (isOpt && val === void 0)
|
|
556
|
+
return;
|
|
557
|
+
const current = typeof val;
|
|
558
|
+
if (current !== expectedType || val === null)
|
|
559
|
+
throw new TypeError(`${label} is invalid: expected ${expectedType}, got ${current}`);
|
|
560
|
+
}
|
|
561
|
+
const iter = (f, isOpt) => Object.entries(f).forEach(([k, v]) => checkField(k, v, isOpt));
|
|
562
|
+
iter(fields, false);
|
|
563
|
+
iter(optFields, true);
|
|
564
|
+
}
|
|
565
|
+
|
|
465
566
|
// node_modules/@noble/curves/abstract/fft.js
|
|
466
|
-
function checkU32(n) {
|
|
567
|
+
function checkU32(n, title = "n") {
|
|
568
|
+
if (typeof n !== "number")
|
|
569
|
+
throw new TypeError(`wrong u32 integer "${title}": expected number, got type=${typeof n}`);
|
|
467
570
|
if (!Number.isSafeInteger(n) || n < 0 || n > 4294967295)
|
|
468
|
-
throw new
|
|
571
|
+
throw new RangeError(`wrong u32 integer "${title}": expected 0..4294967295, got ${n}`);
|
|
469
572
|
return n;
|
|
470
573
|
}
|
|
471
574
|
function isPowerOfTwo(x) {
|
|
472
|
-
checkU32(x);
|
|
575
|
+
checkU32(x, "x");
|
|
473
576
|
return (x & x - 1) === 0 && x !== 0;
|
|
474
577
|
}
|
|
475
578
|
function reverseBits(n, bits) {
|
|
476
579
|
checkU32(n);
|
|
580
|
+
if (typeof bits !== "number")
|
|
581
|
+
throw new TypeError('"bits" expected number, got type=' + typeof bits);
|
|
477
582
|
if (!Number.isSafeInteger(bits) || bits < 0 || bits > 32)
|
|
478
583
|
throw new Error(`expected integer 0 <= bits <= 32, got ${bits}`);
|
|
479
584
|
let reversed = 0;
|
|
@@ -486,6 +591,8 @@ function log2(n) {
|
|
|
486
591
|
return 31 - Math.clz32(n);
|
|
487
592
|
}
|
|
488
593
|
function bitReversalInplace(values) {
|
|
594
|
+
if (!values || typeof values !== "object" || typeof values.length !== "number")
|
|
595
|
+
throw new TypeError('"values" expected array-like, got type=' + typeof values);
|
|
489
596
|
const n = values.length;
|
|
490
597
|
if (!isPowerOfTwo(n))
|
|
491
598
|
throw new Error("expected positive power-of-two length, got " + n);
|
|
@@ -501,14 +608,19 @@ function bitReversalInplace(values) {
|
|
|
501
608
|
return values;
|
|
502
609
|
}
|
|
503
610
|
var FFTCore = (F3, coreOpts) => {
|
|
611
|
+
validateObject(coreOpts, { N: "number", roots: "object", dit: "boolean" }, { invertButterflies: "boolean", skipStages: "number", brp: "boolean" }, "coreOpts");
|
|
504
612
|
const { N: N3, roots, dit, invertButterflies = false, skipStages = 0, brp = true } = coreOpts;
|
|
613
|
+
checkU32(N3, "coreOpts.N");
|
|
505
614
|
const bits = log2(N3);
|
|
506
615
|
if (!isPowerOfTwo(N3))
|
|
507
616
|
throw new Error("FFT: Polynomial size should be power of two");
|
|
617
|
+
checkU32(skipStages, "coreOpts.skipStages");
|
|
618
|
+
const maxSkipStages = bits === 0 ? 0 : bits - 1;
|
|
619
|
+
if (skipStages > maxSkipStages)
|
|
620
|
+
throw new Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${maxSkipStages}`);
|
|
508
621
|
if (roots.length !== N3)
|
|
509
622
|
throw new Error(`FFT: wrong roots length: expected ${N3}, got ${roots.length}`);
|
|
510
623
|
const isDit = dit !== invertButterflies;
|
|
511
|
-
isDit;
|
|
512
624
|
return (values) => {
|
|
513
625
|
if (values.length !== N3)
|
|
514
626
|
throw new Error("FFT: wrong Polynomial length");
|
|
@@ -550,7 +662,22 @@ var FFTCore = (F3, coreOpts) => {
|
|
|
550
662
|
// node_modules/@noble/post-quantum/utils.js
|
|
551
663
|
var abytesDoc = abytes;
|
|
552
664
|
var randomBytes2 = randomBytes;
|
|
665
|
+
function aarray2(item, title, inner = () => {
|
|
666
|
+
}) {
|
|
667
|
+
if (!Array.isArray(item))
|
|
668
|
+
throw new TypeError(`"${title}" expected array, got type=${typeof item}`);
|
|
669
|
+
for (let i = 0; i < item.length; i++)
|
|
670
|
+
inner(item[i], `${title}[${i}]`);
|
|
671
|
+
return item;
|
|
672
|
+
}
|
|
673
|
+
function aobject3(value, title = "object") {
|
|
674
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
675
|
+
throw new TypeError(title === "object" ? "expected valid options object" : `"${title}" expected object, got type=${typeof value}`);
|
|
676
|
+
return value;
|
|
677
|
+
}
|
|
553
678
|
function equalBytes(a, b) {
|
|
679
|
+
a = abytes(a);
|
|
680
|
+
b = abytes(b);
|
|
554
681
|
if (a.length !== b.length)
|
|
555
682
|
return false;
|
|
556
683
|
let diff = 0;
|
|
@@ -562,8 +689,9 @@ function copyBytes(bytes) {
|
|
|
562
689
|
return Uint8Array.from(abytes(bytes));
|
|
563
690
|
}
|
|
564
691
|
function validateOpts(opts2) {
|
|
565
|
-
if (
|
|
566
|
-
throw new TypeError("expected
|
|
692
|
+
if (isBytes(opts2))
|
|
693
|
+
throw new TypeError('"opts" expected object, got Uint8Array');
|
|
694
|
+
aobject3(opts2, "opts");
|
|
567
695
|
}
|
|
568
696
|
function validateVerOpts(opts2) {
|
|
569
697
|
validateOpts(opts2);
|
|
@@ -613,11 +741,12 @@ function vecCoder(c, vecLen) {
|
|
|
613
741
|
return {
|
|
614
742
|
bytesLen,
|
|
615
743
|
encode: (u) => {
|
|
616
|
-
|
|
617
|
-
|
|
744
|
+
const uArr = aarray2(u, "u");
|
|
745
|
+
if (uArr.length !== vecLen)
|
|
746
|
+
throw new RangeError(`vecCoder.encode: wrong length=${uArr.length}. Expected: ${vecLen}`);
|
|
618
747
|
const res = new Uint8Array(bytesLen);
|
|
619
|
-
for (let i = 0, pos = 0; i <
|
|
620
|
-
const b = coder.encode(
|
|
748
|
+
for (let i = 0, pos = 0; i < uArr.length; i++) {
|
|
749
|
+
const b = coder.encode(uArr[i]);
|
|
621
750
|
res.set(b, pos);
|
|
622
751
|
b.fill(0);
|
|
623
752
|
pos += b.length;
|
|
@@ -643,30 +772,38 @@ function cleanBytes(...list) {
|
|
|
643
772
|
}
|
|
644
773
|
}
|
|
645
774
|
function getMask(bits) {
|
|
646
|
-
|
|
647
|
-
|
|
775
|
+
anumber(bits, "bits");
|
|
776
|
+
if (bits > 32)
|
|
777
|
+
throw new RangeError('"bits" expected <= 32, got ' + bits);
|
|
648
778
|
return bits === 32 ? 4294967295 : ~(-1 << bits) >>> 0;
|
|
649
779
|
}
|
|
650
780
|
var EMPTY = /* @__PURE__ */ Uint8Array.of();
|
|
651
781
|
function getMessage(msg, ctx = EMPTY) {
|
|
652
|
-
abytes(msg);
|
|
653
|
-
abytes(ctx);
|
|
782
|
+
abytes(msg, void 0, "msg");
|
|
783
|
+
abytes(ctx, void 0, "ctx");
|
|
654
784
|
if (ctx.length > 255)
|
|
655
785
|
throw new RangeError("context should be 255 bytes or less");
|
|
656
786
|
return concatBytes(new Uint8Array([0, ctx.length]), ctx, msg);
|
|
657
787
|
}
|
|
658
788
|
var oidNistP = /* @__PURE__ */ Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2]);
|
|
659
789
|
function checkHash(hash, requiredStrength = 0) {
|
|
660
|
-
if (
|
|
661
|
-
throw new
|
|
790
|
+
if (typeof hash !== "function" || typeof hash.create !== "function")
|
|
791
|
+
throw new TypeError('"hash" expected hash function, got type=' + typeof hash);
|
|
792
|
+
ahash(hash);
|
|
793
|
+
anumber(requiredStrength, "requiredStrength");
|
|
794
|
+
const oid = hash.oid;
|
|
795
|
+
abytes(oid, void 0, "hash.oid");
|
|
796
|
+
if (!equalBytes(oid.subarray(0, 10), oidNistP))
|
|
797
|
+
throw new Error('"hash.oid" is invalid: expected NIST hash');
|
|
662
798
|
const collisionResistance = hash.outputLen * 8 / 2;
|
|
663
799
|
if (requiredStrength > collisionResistance) {
|
|
664
800
|
throw new Error("Pre-hash security strength too low: " + collisionResistance + ", required: " + requiredStrength);
|
|
665
801
|
}
|
|
666
802
|
}
|
|
667
803
|
function getMessagePrehash(hash, msg, ctx = EMPTY) {
|
|
668
|
-
|
|
669
|
-
abytes(
|
|
804
|
+
checkHash(hash);
|
|
805
|
+
abytes(msg, void 0, "msg");
|
|
806
|
+
abytes(ctx, void 0, "ctx");
|
|
670
807
|
if (ctx.length > 255)
|
|
671
808
|
throw new RangeError("context should be 255 bytes or less");
|
|
672
809
|
const hashed = hash(msg);
|
|
@@ -694,13 +831,25 @@ var genCrystals = (opts2) => {
|
|
|
694
831
|
return out;
|
|
695
832
|
}
|
|
696
833
|
const nttZetas = getZettas();
|
|
697
|
-
const
|
|
834
|
+
const inv = (_a) => {
|
|
835
|
+
throw new Error("not implemented");
|
|
836
|
+
};
|
|
837
|
+
const field = isKyber ? {
|
|
838
|
+
add: (a, b) => {
|
|
839
|
+
const r = a + b | 0;
|
|
840
|
+
return r >= Q3 ? r - Q3 | 0 : r;
|
|
841
|
+
},
|
|
842
|
+
sub: (a, b) => {
|
|
843
|
+
const r = a - b | 0;
|
|
844
|
+
return r < 0 ? r + Q3 | 0 : r;
|
|
845
|
+
},
|
|
846
|
+
mul: (a, b) => mod((a | 0) * (b | 0)) | 0,
|
|
847
|
+
inv
|
|
848
|
+
} : {
|
|
698
849
|
add: (a, b) => mod((a | 0) + (b | 0)) | 0,
|
|
699
850
|
sub: (a, b) => mod((a | 0) - (b | 0)) | 0,
|
|
700
851
|
mul: (a, b) => mod((a | 0) * (b | 0)) | 0,
|
|
701
|
-
inv
|
|
702
|
-
throw new Error("not implemented");
|
|
703
|
-
}
|
|
852
|
+
inv
|
|
704
853
|
};
|
|
705
854
|
const nttOpts = {
|
|
706
855
|
N: N3,
|
|
@@ -723,6 +872,12 @@ var genCrystals = (opts2) => {
|
|
|
723
872
|
}
|
|
724
873
|
};
|
|
725
874
|
const bitsCoder = (d, c) => {
|
|
875
|
+
for (let i = 0, bufLen = 0; i < N3; i++) {
|
|
876
|
+
bufLen += d;
|
|
877
|
+
if (bufLen > 32)
|
|
878
|
+
getMask(bufLen);
|
|
879
|
+
bufLen %= 8;
|
|
880
|
+
}
|
|
726
881
|
const mask = getMask(d);
|
|
727
882
|
const bytesLen = d * (N3 / 8);
|
|
728
883
|
return {
|
|
@@ -734,7 +889,7 @@ var genCrystals = (opts2) => {
|
|
|
734
889
|
buf |= (c.encode(poly[i]) & mask) << bufLen;
|
|
735
890
|
bufLen += d;
|
|
736
891
|
for (; bufLen >= 8; bufLen -= 8, buf >>= 8)
|
|
737
|
-
r[pos++] = buf &
|
|
892
|
+
r[pos++] = buf & 255;
|
|
738
893
|
}
|
|
739
894
|
return r;
|
|
740
895
|
},
|
|
@@ -828,17 +983,21 @@ var polyCoder = (d) => d === 12 ? byteCoder(12) : crystals.bitsCoder(d, compress
|
|
|
828
983
|
function polyAdd(a_, b_) {
|
|
829
984
|
const a = a_;
|
|
830
985
|
const b = b_;
|
|
831
|
-
for (let i = 0; i < N; i++)
|
|
832
|
-
|
|
986
|
+
for (let i = 0; i < N; i++) {
|
|
987
|
+
const r = a[i] + b[i];
|
|
988
|
+
a[i] = r >= Q ? r - Q : r;
|
|
989
|
+
}
|
|
833
990
|
}
|
|
834
991
|
function polySub(a_, b_) {
|
|
835
992
|
const a = a_;
|
|
836
993
|
const b = b_;
|
|
837
|
-
for (let i = 0; i < N; i++)
|
|
838
|
-
|
|
994
|
+
for (let i = 0; i < N; i++) {
|
|
995
|
+
const r = a[i] - b[i];
|
|
996
|
+
a[i] = r < 0 ? r + Q : r;
|
|
997
|
+
}
|
|
839
998
|
}
|
|
840
999
|
function BaseCaseMultiply(a0, a1, b0, b1, zeta) {
|
|
841
|
-
const c0 = crystals.mod(a1 * b1 * zeta + a0 * b0);
|
|
1000
|
+
const c0 = crystals.mod(crystals.mod(a1 * b1) * zeta + a0 * b0);
|
|
842
1001
|
const c1 = crystals.mod(a0 * b1 + a1 * b0);
|
|
843
1002
|
return { c0, c1 };
|
|
844
1003
|
}
|
|
@@ -913,6 +1072,31 @@ var genKPKE = (opts_) => {
|
|
|
913
1072
|
const secretCoder = vecCoder(polyCoder(12), K);
|
|
914
1073
|
const cipherCoder = splitCoder("ciphertext", vecCoder(polyU, K), polyV);
|
|
915
1074
|
const seedCoder = splitCoder("seed", 32, 32);
|
|
1075
|
+
const encryptCore = (tHat, getA, msg, seed) => {
|
|
1076
|
+
const rHat = [];
|
|
1077
|
+
for (let i = 0; i < K; i++)
|
|
1078
|
+
rHat.push(crystals.NTT.encode(sampleCBD(PRF, seed, i, ETA1)));
|
|
1079
|
+
const tmp2 = new Uint16Array(N);
|
|
1080
|
+
const u = [];
|
|
1081
|
+
for (let i = 0; i < K; i++) {
|
|
1082
|
+
const e1 = sampleCBD(PRF, seed, K + i, ETA2);
|
|
1083
|
+
const tmp = new Uint16Array(N);
|
|
1084
|
+
for (let j = 0; j < K; j++) {
|
|
1085
|
+
const aij = getA(i, j);
|
|
1086
|
+
polyAdd(tmp, MultiplyNTTs(aij, rHat[j]));
|
|
1087
|
+
}
|
|
1088
|
+
polyAdd(e1, crystals.NTT.decode(tmp));
|
|
1089
|
+
u.push(e1);
|
|
1090
|
+
polyAdd(tmp2, MultiplyNTTs(tHat[i], rHat[i]));
|
|
1091
|
+
cleanBytes(tmp);
|
|
1092
|
+
}
|
|
1093
|
+
const e2 = sampleCBD(PRF, seed, 2 * K, ETA2);
|
|
1094
|
+
polyAdd(e2, crystals.NTT.decode(tmp2));
|
|
1095
|
+
const v = poly1.decode(msg);
|
|
1096
|
+
polyAdd(v, e2);
|
|
1097
|
+
cleanBytes(tHat, rHat, tmp2, e2);
|
|
1098
|
+
return cipherCoder.encode([u, v]);
|
|
1099
|
+
};
|
|
916
1100
|
return {
|
|
917
1101
|
secretCoder,
|
|
918
1102
|
lengths: {
|
|
@@ -950,31 +1134,26 @@ var genKPKE = (opts_) => {
|
|
|
950
1134
|
},
|
|
951
1135
|
encrypt: (publicKey, msg, seed) => {
|
|
952
1136
|
const [tHat, rho] = publicCoder.decode(publicKey);
|
|
953
|
-
const rHat = [];
|
|
954
|
-
for (let i = 0; i < K; i++)
|
|
955
|
-
rHat.push(crystals.NTT.encode(sampleCBD(PRF, seed, i, ETA1)));
|
|
956
1137
|
const x = XOF(rho);
|
|
957
|
-
const
|
|
958
|
-
const u = [];
|
|
959
|
-
for (let i = 0; i < K; i++) {
|
|
960
|
-
const e1 = sampleCBD(PRF, seed, K + i, ETA2);
|
|
961
|
-
const tmp = new Uint16Array(N);
|
|
962
|
-
for (let j = 0; j < K; j++) {
|
|
963
|
-
const aij = SampleNTT(x.get(i, j));
|
|
964
|
-
polyAdd(tmp, MultiplyNTTs(aij, rHat[j]));
|
|
965
|
-
}
|
|
966
|
-
polyAdd(e1, crystals.NTT.decode(tmp));
|
|
967
|
-
u.push(e1);
|
|
968
|
-
polyAdd(tmp2, MultiplyNTTs(tHat[i], rHat[i]));
|
|
969
|
-
cleanBytes(tmp);
|
|
970
|
-
}
|
|
1138
|
+
const res = encryptCore(tHat, (i, j) => SampleNTT(x.get(i, j)), msg, seed);
|
|
971
1139
|
x.clean();
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1140
|
+
return res;
|
|
1141
|
+
},
|
|
1142
|
+
// Expands the full  matrix (public data derived from rho) once, so repeated encryptions
|
|
1143
|
+
// against the same ek skip the K² SampleNTT XOF expansions. Cached polys are copied per
|
|
1144
|
+
// call because encryptCore mutates its inputs in place.
|
|
1145
|
+
prepare: (publicKey) => {
|
|
1146
|
+
const [tHat, rho] = publicCoder.decode(publicKey);
|
|
1147
|
+
const x = XOF(rho);
|
|
1148
|
+
const A = [];
|
|
1149
|
+
for (let i = 0; i < K; i++)
|
|
1150
|
+
for (let j = 0; j < K; j++)
|
|
1151
|
+
A.push(SampleNTT(x.get(i, j)));
|
|
1152
|
+
x.clean();
|
|
1153
|
+
return {
|
|
1154
|
+
encrypt: (msg, seed) => encryptCore(tHat.map((p) => p.slice()), (i, j) => A[i * K + j].slice(), msg, seed),
|
|
1155
|
+
clean: () => cleanBytes(tHat, A)
|
|
1156
|
+
};
|
|
978
1157
|
},
|
|
979
1158
|
decrypt: (cipherText, privateKey) => {
|
|
980
1159
|
const [u, v] = cipherCoder.decode(cipherText);
|
|
@@ -996,6 +1175,14 @@ function createKyber(opts2) {
|
|
|
996
1175
|
const secretCoder = splitCoder("secretKey", lengths.secretKey, lengths.publicKey, 32, 32);
|
|
997
1176
|
const msgLen = 32;
|
|
998
1177
|
const seedLen = 64;
|
|
1178
|
+
const validateModulus = (publicKey, fn) => {
|
|
1179
|
+
const eke = publicKey.subarray(0, 384 * rawOpts.K);
|
|
1180
|
+
const ek = KPKESecretCoder.encode(KPKESecretCoder.decode(copyBytes(eke)));
|
|
1181
|
+
const ok = equalBytes(ek, eke);
|
|
1182
|
+
cleanBytes(ek);
|
|
1183
|
+
if (!ok)
|
|
1184
|
+
throw new Error(`ML-KEM.${fn}: wrong publicKey modulus`);
|
|
1185
|
+
};
|
|
999
1186
|
const kemLengths = Object.freeze({
|
|
1000
1187
|
...lengths,
|
|
1001
1188
|
seed: 64,
|
|
@@ -1024,13 +1211,7 @@ function createKyber(opts2) {
|
|
|
1024
1211
|
encapsulate: (publicKey, msg = randomBytes2(msgLen)) => {
|
|
1025
1212
|
abytesDoc(publicKey, lengths.publicKey, "publicKey");
|
|
1026
1213
|
abytesDoc(msg, msgLen, "message");
|
|
1027
|
-
|
|
1028
|
-
const ek = KPKESecretCoder.encode(KPKESecretCoder.decode(copyBytes(eke)));
|
|
1029
|
-
if (!equalBytes(ek, eke)) {
|
|
1030
|
-
cleanBytes(ek);
|
|
1031
|
-
throw new Error("ML-KEM.encapsulate: wrong publicKey modulus");
|
|
1032
|
-
}
|
|
1033
|
-
cleanBytes(ek);
|
|
1214
|
+
validateModulus(publicKey, "encapsulate");
|
|
1034
1215
|
const kr = HASH512.create().update(msg).update(HASH256(publicKey)).digest();
|
|
1035
1216
|
const cipherText = KPKE.encrypt(publicKey, msg, kr.subarray(32, 64));
|
|
1036
1217
|
cleanBytes(kr.subarray(32));
|
|
@@ -1054,8 +1235,49 @@ function createKyber(opts2) {
|
|
|
1054
1235
|
const cipherText2 = KPKE.encrypt(publicKey, msg, kr.subarray(32, 64));
|
|
1055
1236
|
const isValid = equalBytes(cipherText, cipherText2);
|
|
1056
1237
|
const Kbar = KDF.create({ dkLen: 32 }).update(z).update(cipherText).digest();
|
|
1057
|
-
cleanBytes(msg, cipherText2, !isValid ? Khat : Kbar);
|
|
1238
|
+
cleanBytes(msg, cipherText2, kr.subarray(32), !isValid ? Khat : Kbar);
|
|
1058
1239
|
return isValid ? Khat : Kbar;
|
|
1240
|
+
},
|
|
1241
|
+
/**
|
|
1242
|
+
* Experimental prototype: pre-expand a public key so repeated encapsulate/decapsulate
|
|
1243
|
+
* against the same key skip re-validation, H(ek), t̂ decoding and the K² SampleNTT
|
|
1244
|
+
* XOF expansions of Â. Only public data is cached; see {@link KEMPrepared}.
|
|
1245
|
+
*/
|
|
1246
|
+
prepare: (publicKey) => {
|
|
1247
|
+
abytesDoc(publicKey, lengths.publicKey, "publicKey");
|
|
1248
|
+
validateModulus(publicKey, "prepare");
|
|
1249
|
+
const ek = copyBytes(publicKey);
|
|
1250
|
+
const publicKeyHash = HASH256(ek);
|
|
1251
|
+
const cached = KPKE.prepare(ek);
|
|
1252
|
+
return Object.freeze({
|
|
1253
|
+
publicKey: ek,
|
|
1254
|
+
encapsulate: (msg = randomBytes2(msgLen)) => {
|
|
1255
|
+
abytesDoc(msg, msgLen, "message");
|
|
1256
|
+
const kr = HASH512.create().update(msg).update(publicKeyHash).digest();
|
|
1257
|
+
const cipherText = cached.encrypt(msg, kr.subarray(32, 64));
|
|
1258
|
+
cleanBytes(kr.subarray(32));
|
|
1259
|
+
return {
|
|
1260
|
+
cipherText,
|
|
1261
|
+
sharedSecret: kr.subarray(0, 32)
|
|
1262
|
+
};
|
|
1263
|
+
},
|
|
1264
|
+
decapsulate: (cipherText, secretKey) => {
|
|
1265
|
+
abytesDoc(secretKey, secretCoder.bytesLen, "secretKey");
|
|
1266
|
+
abytesDoc(cipherText, lengths.cipherText, "cipherText");
|
|
1267
|
+
const [sk, ekEmbedded, storedHash, z] = secretCoder.decode(secretKey);
|
|
1268
|
+
if (!equalBytes(ekEmbedded, ek) || !equalBytes(storedHash, publicKeyHash))
|
|
1269
|
+
throw new Error("ML-KEM.decapsulate: secretKey does not match prepared publicKey");
|
|
1270
|
+
const msg = KPKE.decrypt(cipherText, sk);
|
|
1271
|
+
const kr = HASH512.create().update(msg).update(publicKeyHash).digest();
|
|
1272
|
+
const Khat = kr.subarray(0, 32);
|
|
1273
|
+
const cipherText2 = cached.encrypt(msg, kr.subarray(32, 64));
|
|
1274
|
+
const isValid = equalBytes(cipherText, cipherText2);
|
|
1275
|
+
const Kbar = KDF.create({ dkLen: 32 }).update(z).update(cipherText).digest();
|
|
1276
|
+
cleanBytes(msg, cipherText2, kr.subarray(32), !isValid ? Khat : Kbar);
|
|
1277
|
+
return isValid ? Khat : Kbar;
|
|
1278
|
+
},
|
|
1279
|
+
clean: cached.clean
|
|
1280
|
+
});
|
|
1059
1281
|
}
|
|
1060
1282
|
});
|
|
1061
1283
|
}
|
|
@@ -1077,20 +1299,11 @@ var ml_kem512 = /* @__PURE__ */ (() => mk(PARAMS[512]))();
|
|
|
1077
1299
|
var ml_kem768 = /* @__PURE__ */ (() => mk(PARAMS[768]))();
|
|
1078
1300
|
var ml_kem1024 = /* @__PURE__ */ (() => mk(PARAMS[1024]))();
|
|
1079
1301
|
|
|
1080
|
-
// node_modules/@noble/curves/utils.js
|
|
1081
|
-
function abool(value, title = "") {
|
|
1082
|
-
if (typeof value !== "boolean") {
|
|
1083
|
-
const prefix = title && `"${title}" `;
|
|
1084
|
-
throw new TypeError(prefix + "expected boolean, got type=" + typeof value);
|
|
1085
|
-
}
|
|
1086
|
-
return value;
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
1302
|
// node_modules/@noble/post-quantum/ml-dsa.js
|
|
1090
1303
|
function validateInternalOpts(opts2) {
|
|
1091
1304
|
validateOpts(opts2);
|
|
1092
1305
|
if (opts2.externalMu !== void 0)
|
|
1093
|
-
|
|
1306
|
+
abool2(opts2.externalMu, "opts.externalMu");
|
|
1094
1307
|
}
|
|
1095
1308
|
var N2 = 256;
|
|
1096
1309
|
var Q2 = 8380417;
|
|
@@ -1166,10 +1379,10 @@ var polyShiftl = (p_) => {
|
|
|
1166
1379
|
p[i] <<= D;
|
|
1167
1380
|
return p;
|
|
1168
1381
|
};
|
|
1169
|
-
var polyChknorm = (p_,
|
|
1382
|
+
var polyChknorm = (p_, B2) => {
|
|
1170
1383
|
const p = p_;
|
|
1171
1384
|
for (let i = 0; i < N2; i++)
|
|
1172
|
-
if (Math.abs(crystals2.smod(p[i])) >=
|
|
1385
|
+
if (Math.abs(crystals2.smod(p[i])) >= B2)
|
|
1173
1386
|
return true;
|
|
1174
1387
|
return false;
|
|
1175
1388
|
};
|
|
@@ -1221,11 +1434,11 @@ function getDilithium(opts_) {
|
|
|
1221
1434
|
const res0 = z <= GAMMA2 || z > Q2 - GAMMA2 || z === Q2 - GAMMA2 && r === 0 ? 0 : 1;
|
|
1222
1435
|
return res0;
|
|
1223
1436
|
};
|
|
1437
|
+
const HINT_M = Math.floor((Q2 - 1) / (2 * GAMMA2));
|
|
1224
1438
|
const UseHint = (h, r) => {
|
|
1225
|
-
const m = Math.floor((Q2 - 1) / (2 * GAMMA2));
|
|
1226
1439
|
const { r1, r0 } = decompose(r);
|
|
1227
1440
|
if (h === 1)
|
|
1228
|
-
return r0 > 0 ? crystals2.mod(r1 + 1,
|
|
1441
|
+
return r0 > 0 ? crystals2.mod(r1 + 1, HINT_M) | 0 : crystals2.mod(r1 - 1, HINT_M) | 0;
|
|
1229
1442
|
return r1 | 0;
|
|
1230
1443
|
};
|
|
1231
1444
|
const Power2Round = (r) => {
|
|
@@ -1435,8 +1648,22 @@ function getDilithium(opts_) {
|
|
|
1435
1648
|
sign: (msg, secretKey, opts3 = {}) => {
|
|
1436
1649
|
validateSigOpts(opts3);
|
|
1437
1650
|
validateInternalOpts(opts3);
|
|
1438
|
-
|
|
1439
|
-
|
|
1651
|
+
const { extraEntropy: random, externalMu = false } = opts3;
|
|
1652
|
+
if (externalMu)
|
|
1653
|
+
abytesDoc(msg, CRH_BYTES, "mu");
|
|
1654
|
+
const ownRnd = random === false || random === void 0;
|
|
1655
|
+
const rnd = random === false ? new Uint8Array(32) : random === void 0 ? randomBytes2(signRandBytes) : random;
|
|
1656
|
+
abytesDoc(rnd, 32, "extraEntropy");
|
|
1657
|
+
const decoded = (() => {
|
|
1658
|
+
try {
|
|
1659
|
+
return secretCoder.decode(secretKey);
|
|
1660
|
+
} catch (error) {
|
|
1661
|
+
if (ownRnd)
|
|
1662
|
+
cleanBytes(rnd);
|
|
1663
|
+
throw error;
|
|
1664
|
+
}
|
|
1665
|
+
})();
|
|
1666
|
+
const [rho, _K, tr, s1, s2, t0] = decoded;
|
|
1440
1667
|
const A = [];
|
|
1441
1668
|
const xof = XOF1282(rho);
|
|
1442
1669
|
for (let i = 0; i < K; i++) {
|
|
@@ -1457,9 +1684,9 @@ function getDilithium(opts_) {
|
|
|
1457
1684
|
// ▷ Compute message representative µ
|
|
1458
1685
|
shake256.create({ dkLen: CRH_BYTES }).update(tr).update(msg).digest()
|
|
1459
1686
|
);
|
|
1460
|
-
const rnd = random === false ? new Uint8Array(32) : random === void 0 ? randomBytes2(signRandBytes) : random;
|
|
1461
|
-
abytesDoc(rnd, 32, "extraEntropy");
|
|
1462
1687
|
const rhoprime = shake256.create({ dkLen: CRH_BYTES }).update(_K).update(rnd).update(mu).digest();
|
|
1688
|
+
if (ownRnd)
|
|
1689
|
+
cleanBytes(rnd);
|
|
1463
1690
|
abytesDoc(rhoprime, CRH_BYTES);
|
|
1464
1691
|
const x256 = XOF2562(rhoprime, ZCoder.bytesLen);
|
|
1465
1692
|
main_loop: for (let kappa = 0; ; ) {
|
|
@@ -1513,6 +1740,8 @@ function getDilithium(opts_) {
|
|
|
1513
1740
|
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
1514
1741
|
validateInternalOpts(opts3);
|
|
1515
1742
|
const { externalMu = false } = opts3;
|
|
1743
|
+
if (externalMu)
|
|
1744
|
+
abytesDoc(msg, CRH_BYTES, "mu");
|
|
1516
1745
|
const [rho, t1] = publicCoder.decode(publicKey);
|
|
1517
1746
|
const tr = shake256(publicKey, { dkLen: TR_BYTES });
|
|
1518
1747
|
if (sig.length !== sigCoder.bytesLen)
|
|
@@ -1572,10 +1801,12 @@ function getDilithium(opts_) {
|
|
|
1572
1801
|
},
|
|
1573
1802
|
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
1574
1803
|
validateVerOpts(opts3);
|
|
1804
|
+
abytesDoc(sig, void 0, "signature");
|
|
1575
1805
|
return internal.verify(sig, getMessage(msg, opts3.context), publicKey);
|
|
1576
1806
|
},
|
|
1577
1807
|
prehash: (hash) => {
|
|
1578
1808
|
checkHash(hash, securityLevel);
|
|
1809
|
+
const rawHash = hash;
|
|
1579
1810
|
return Object.freeze({
|
|
1580
1811
|
info: Object.freeze({ type: "hashml-dsa" }),
|
|
1581
1812
|
securityLevel,
|
|
@@ -1584,14 +1815,15 @@ function getDilithium(opts_) {
|
|
|
1584
1815
|
getPublicKey: internal.getPublicKey,
|
|
1585
1816
|
sign: (msg, secretKey, opts3 = {}) => {
|
|
1586
1817
|
validateSigOpts(opts3);
|
|
1587
|
-
const M = getMessagePrehash(
|
|
1818
|
+
const M = getMessagePrehash(rawHash, msg, opts3.context);
|
|
1588
1819
|
const res = internal.sign(M, secretKey, opts3);
|
|
1589
1820
|
cleanBytes(M);
|
|
1590
1821
|
return res;
|
|
1591
1822
|
},
|
|
1592
1823
|
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
1593
1824
|
validateVerOpts(opts3);
|
|
1594
|
-
|
|
1825
|
+
abytesDoc(sig, void 0, "signature");
|
|
1826
|
+
return internal.verify(sig, getMessagePrehash(rawHash, msg, opts3.context), publicKey);
|
|
1595
1827
|
}
|
|
1596
1828
|
});
|
|
1597
1829
|
}
|
|
@@ -1639,7 +1871,7 @@ var _HMAC = class {
|
|
|
1639
1871
|
abytes(key, void 0, "key");
|
|
1640
1872
|
this.iHash = hash.create();
|
|
1641
1873
|
if (typeof this.iHash.update !== "function")
|
|
1642
|
-
throw new Error("
|
|
1874
|
+
throw new Error("expected Hash instance");
|
|
1643
1875
|
this.blockLen = this.iHash.blockLen;
|
|
1644
1876
|
this.outputLen = this.iHash.outputLen;
|
|
1645
1877
|
const blockLen = this.blockLen;
|
|
@@ -1676,12 +1908,13 @@ var _HMAC = class {
|
|
|
1676
1908
|
}
|
|
1677
1909
|
_cloneInto(to) {
|
|
1678
1910
|
to ||= Object.create(Object.getPrototypeOf(this), {});
|
|
1679
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
1911
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen, canXOF } = this;
|
|
1680
1912
|
to = to;
|
|
1681
1913
|
to.finished = finished;
|
|
1682
1914
|
to.destroyed = destroyed;
|
|
1683
1915
|
to.blockLen = blockLen;
|
|
1684
1916
|
to.outputLen = outputLen;
|
|
1917
|
+
to.canXOF = canXOF;
|
|
1685
1918
|
to.oHash = oHash._cloneInto(to.oHash);
|
|
1686
1919
|
to.iHash = iHash._cloneInto(to.iHash);
|
|
1687
1920
|
return to;
|
|
@@ -1734,24 +1967,28 @@ var HashMD = class {
|
|
|
1734
1967
|
abytes(data);
|
|
1735
1968
|
const { view, buffer, blockLen } = this;
|
|
1736
1969
|
const len = data.length;
|
|
1970
|
+
let processed = false;
|
|
1737
1971
|
for (let pos = 0; pos < len; ) {
|
|
1738
1972
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
1739
1973
|
if (take === blockLen) {
|
|
1740
1974
|
const dataView = createView(data);
|
|
1741
1975
|
for (; blockLen <= len - pos; pos += blockLen)
|
|
1742
1976
|
this.process(dataView, pos);
|
|
1977
|
+
processed = true;
|
|
1743
1978
|
continue;
|
|
1744
1979
|
}
|
|
1745
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
1980
|
+
buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
|
|
1746
1981
|
this.pos += take;
|
|
1747
1982
|
pos += take;
|
|
1748
1983
|
if (this.pos === blockLen) {
|
|
1749
1984
|
this.process(view, 0);
|
|
1750
1985
|
this.pos = 0;
|
|
1986
|
+
processed = true;
|
|
1751
1987
|
}
|
|
1752
1988
|
}
|
|
1753
1989
|
this.length += data.length;
|
|
1754
|
-
|
|
1990
|
+
if (processed)
|
|
1991
|
+
this.roundClean();
|
|
1755
1992
|
return this;
|
|
1756
1993
|
}
|
|
1757
1994
|
digestInto(out) {
|
|
@@ -1761,23 +1998,20 @@ var HashMD = class {
|
|
|
1761
1998
|
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
1762
1999
|
let { pos } = this;
|
|
1763
2000
|
buffer[pos++] = 128;
|
|
1764
|
-
|
|
2001
|
+
buffer.fill(0, pos);
|
|
1765
2002
|
if (this.padOffset > blockLen - pos) {
|
|
1766
2003
|
this.process(view, 0);
|
|
1767
|
-
|
|
2004
|
+
buffer.fill(0);
|
|
1768
2005
|
}
|
|
1769
|
-
|
|
1770
|
-
buffer[i] = 0;
|
|
1771
|
-
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
2006
|
+
setU64FromNum(view, blockLen - 8, this.length * 8, isLE2);
|
|
1772
2007
|
this.process(view, 0);
|
|
1773
|
-
|
|
2008
|
+
this.roundClean();
|
|
2009
|
+
const oview = out === buffer ? view : createView(out);
|
|
1774
2010
|
const len = this.outputLen;
|
|
1775
|
-
if (len % 4)
|
|
1776
|
-
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
1777
2011
|
const outLen = len / 4;
|
|
1778
2012
|
const state = this.get();
|
|
1779
|
-
if (outLen > state.length)
|
|
1780
|
-
throw new Error("
|
|
2013
|
+
if (len % 4 || outLen > state.length)
|
|
2014
|
+
throw new Error("invalid outputLen");
|
|
1781
2015
|
for (let i = 0; i < outLen; i++)
|
|
1782
2016
|
oview.setUint32(4 * i, state[i], isLE2);
|
|
1783
2017
|
}
|
|
@@ -1788,15 +2022,13 @@ var HashMD = class {
|
|
|
1788
2022
|
this.destroy();
|
|
1789
2023
|
return res;
|
|
1790
2024
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
to.set(...this.get());
|
|
1794
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
2025
|
+
_cloneIntoMeta(to) {
|
|
2026
|
+
const { buffer, length, finished, destroyed, pos } = this;
|
|
1795
2027
|
to.destroyed = destroyed;
|
|
1796
2028
|
to.finished = finished;
|
|
1797
2029
|
to.length = length;
|
|
1798
2030
|
to.pos = pos;
|
|
1799
|
-
if (
|
|
2031
|
+
if (pos)
|
|
1800
2032
|
to.buffer.set(buffer);
|
|
1801
2033
|
return to;
|
|
1802
2034
|
}
|
|
@@ -1902,17 +2134,37 @@ var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
|
1902
2134
|
]);
|
|
1903
2135
|
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
1904
2136
|
var SHA2_32B = class extends HashMD {
|
|
1905
|
-
|
|
2137
|
+
// We cannot use array here since array allows indexing by variable
|
|
2138
|
+
// which means optimizer/compiler cannot use registers.
|
|
2139
|
+
// Numeric initializers matter: starting the fields as `undefined` changes
|
|
2140
|
+
// V8's field representation and makes sha256 3x slower (measured).
|
|
2141
|
+
A = 0;
|
|
2142
|
+
B = 0;
|
|
2143
|
+
C = 0;
|
|
2144
|
+
D = 0;
|
|
2145
|
+
E = 0;
|
|
2146
|
+
F = 0;
|
|
2147
|
+
G = 0;
|
|
2148
|
+
H = 0;
|
|
2149
|
+
constructor(outputLen, IV) {
|
|
1906
2150
|
super(64, outputLen, 8, false);
|
|
2151
|
+
this.A = IV[0] | 0;
|
|
2152
|
+
this.B = IV[1] | 0;
|
|
2153
|
+
this.C = IV[2] | 0;
|
|
2154
|
+
this.D = IV[3] | 0;
|
|
2155
|
+
this.E = IV[4] | 0;
|
|
2156
|
+
this.F = IV[5] | 0;
|
|
2157
|
+
this.G = IV[6] | 0;
|
|
2158
|
+
this.H = IV[7] | 0;
|
|
1907
2159
|
}
|
|
1908
2160
|
get() {
|
|
1909
|
-
const { A, B, C, D: D2, E, F: F3, G, H } = this;
|
|
1910
|
-
return [A,
|
|
2161
|
+
const { A, B: B2, C, D: D2, E, F: F3, G, H } = this;
|
|
2162
|
+
return [A, B2, C, D2, E, F3, G, H];
|
|
1911
2163
|
}
|
|
1912
2164
|
// prettier-ignore
|
|
1913
|
-
set(A,
|
|
2165
|
+
set(A, B2, C, D2, E, F3, G, H) {
|
|
1914
2166
|
this.A = A | 0;
|
|
1915
|
-
this.B =
|
|
2167
|
+
this.B = B2 | 0;
|
|
1916
2168
|
this.C = C | 0;
|
|
1917
2169
|
this.D = D2 | 0;
|
|
1918
2170
|
this.E = E | 0;
|
|
@@ -1920,6 +2172,10 @@ var SHA2_32B = class extends HashMD {
|
|
|
1920
2172
|
this.G = G | 0;
|
|
1921
2173
|
this.H = H | 0;
|
|
1922
2174
|
}
|
|
2175
|
+
_cloneInto(to) {
|
|
2176
|
+
(to ||= new this.constructor()).set(...this.get());
|
|
2177
|
+
return this._cloneIntoMeta(to);
|
|
2178
|
+
}
|
|
1923
2179
|
process(view, offset) {
|
|
1924
2180
|
for (let i = 0; i < 16; i++, offset += 4)
|
|
1925
2181
|
SHA256_W[i] = view.getUint32(offset, false);
|
|
@@ -1930,30 +2186,30 @@ var SHA2_32B = class extends HashMD {
|
|
|
1930
2186
|
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
1931
2187
|
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
1932
2188
|
}
|
|
1933
|
-
let { A, B, C, D: D2, E, F: F3, G, H } = this;
|
|
2189
|
+
let { A, B: B2, C, D: D2, E, F: F3, G, H } = this;
|
|
1934
2190
|
for (let i = 0; i < 64; i++) {
|
|
1935
2191
|
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
1936
2192
|
const T1 = H + sigma1 + Chi(E, F3, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
1937
2193
|
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
1938
|
-
const T2 = sigma0 + Maj(A,
|
|
2194
|
+
const T2 = sigma0 + Maj(A, B2, C) | 0;
|
|
1939
2195
|
H = G;
|
|
1940
2196
|
G = F3;
|
|
1941
2197
|
F3 = E;
|
|
1942
2198
|
E = D2 + T1 | 0;
|
|
1943
2199
|
D2 = C;
|
|
1944
|
-
C =
|
|
1945
|
-
|
|
2200
|
+
C = B2;
|
|
2201
|
+
B2 = A;
|
|
1946
2202
|
A = T1 + T2 | 0;
|
|
1947
2203
|
}
|
|
1948
2204
|
A = A + this.A | 0;
|
|
1949
|
-
|
|
2205
|
+
B2 = B2 + this.B | 0;
|
|
1950
2206
|
C = C + this.C | 0;
|
|
1951
2207
|
D2 = D2 + this.D | 0;
|
|
1952
2208
|
E = E + this.E | 0;
|
|
1953
2209
|
F3 = F3 + this.F | 0;
|
|
1954
2210
|
G = G + this.G | 0;
|
|
1955
2211
|
H = H + this.H | 0;
|
|
1956
|
-
this.set(A,
|
|
2212
|
+
this.set(A, B2, C, D2, E, F3, G, H);
|
|
1957
2213
|
}
|
|
1958
2214
|
roundClean() {
|
|
1959
2215
|
clean(SHA256_W);
|
|
@@ -1965,18 +2221,8 @@ var SHA2_32B = class extends HashMD {
|
|
|
1965
2221
|
}
|
|
1966
2222
|
};
|
|
1967
2223
|
var _SHA256 = class extends SHA2_32B {
|
|
1968
|
-
// We cannot use array here since array allows indexing by variable
|
|
1969
|
-
// which means optimizer/compiler cannot use registers.
|
|
1970
|
-
A = SHA256_IV[0] | 0;
|
|
1971
|
-
B = SHA256_IV[1] | 0;
|
|
1972
|
-
C = SHA256_IV[2] | 0;
|
|
1973
|
-
D = SHA256_IV[3] | 0;
|
|
1974
|
-
E = SHA256_IV[4] | 0;
|
|
1975
|
-
F = SHA256_IV[5] | 0;
|
|
1976
|
-
G = SHA256_IV[6] | 0;
|
|
1977
|
-
H = SHA256_IV[7] | 0;
|
|
1978
2224
|
constructor() {
|
|
1979
|
-
super(32);
|
|
2225
|
+
super(32, SHA256_IV);
|
|
1980
2226
|
}
|
|
1981
2227
|
};
|
|
1982
2228
|
var K512 = /* @__PURE__ */ (() => split([
|
|
@@ -2066,8 +2312,45 @@ var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
|
2066
2312
|
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
2067
2313
|
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
2068
2314
|
var SHA2_64B = class extends HashMD {
|
|
2069
|
-
|
|
2315
|
+
// We cannot use array here since array allows indexing by variable
|
|
2316
|
+
// which means optimizer/compiler cannot use registers.
|
|
2317
|
+
// h -- high 32 bits, l -- low 32 bits
|
|
2318
|
+
// Numeric initializers matter: starting the fields as `undefined` changes
|
|
2319
|
+
// V8's field representation and slows hashing down (measured on sha256).
|
|
2320
|
+
Ah = 0;
|
|
2321
|
+
Al = 0;
|
|
2322
|
+
Bh = 0;
|
|
2323
|
+
Bl = 0;
|
|
2324
|
+
Ch = 0;
|
|
2325
|
+
Cl = 0;
|
|
2326
|
+
Dh = 0;
|
|
2327
|
+
Dl = 0;
|
|
2328
|
+
Eh = 0;
|
|
2329
|
+
El = 0;
|
|
2330
|
+
Fh = 0;
|
|
2331
|
+
Fl = 0;
|
|
2332
|
+
Gh = 0;
|
|
2333
|
+
Gl = 0;
|
|
2334
|
+
Hh = 0;
|
|
2335
|
+
Hl = 0;
|
|
2336
|
+
constructor(outputLen, IV) {
|
|
2070
2337
|
super(128, outputLen, 16, false);
|
|
2338
|
+
this.Ah = IV[0] | 0;
|
|
2339
|
+
this.Al = IV[1] | 0;
|
|
2340
|
+
this.Bh = IV[2] | 0;
|
|
2341
|
+
this.Bl = IV[3] | 0;
|
|
2342
|
+
this.Ch = IV[4] | 0;
|
|
2343
|
+
this.Cl = IV[5] | 0;
|
|
2344
|
+
this.Dh = IV[6] | 0;
|
|
2345
|
+
this.Dl = IV[7] | 0;
|
|
2346
|
+
this.Eh = IV[8] | 0;
|
|
2347
|
+
this.El = IV[9] | 0;
|
|
2348
|
+
this.Fh = IV[10] | 0;
|
|
2349
|
+
this.Fl = IV[11] | 0;
|
|
2350
|
+
this.Gh = IV[12] | 0;
|
|
2351
|
+
this.Gl = IV[13] | 0;
|
|
2352
|
+
this.Hh = IV[14] | 0;
|
|
2353
|
+
this.Hl = IV[15] | 0;
|
|
2071
2354
|
}
|
|
2072
2355
|
// prettier-ignore
|
|
2073
2356
|
get() {
|
|
@@ -2093,6 +2376,10 @@ var SHA2_64B = class extends HashMD {
|
|
|
2093
2376
|
this.Hh = Hh | 0;
|
|
2094
2377
|
this.Hl = Hl | 0;
|
|
2095
2378
|
}
|
|
2379
|
+
_cloneInto(to) {
|
|
2380
|
+
(to ||= new this.constructor()).set(...this.get());
|
|
2381
|
+
return this._cloneIntoMeta(to);
|
|
2382
|
+
}
|
|
2096
2383
|
process(view, offset) {
|
|
2097
2384
|
for (let i = 0; i < 16; i++, offset += 4) {
|
|
2098
2385
|
SHA512_W_H[i] = view.getUint32(offset);
|
|
@@ -2162,24 +2449,8 @@ var SHA2_64B = class extends HashMD {
|
|
|
2162
2449
|
}
|
|
2163
2450
|
};
|
|
2164
2451
|
var _SHA512 = class extends SHA2_64B {
|
|
2165
|
-
Ah = SHA512_IV[0] | 0;
|
|
2166
|
-
Al = SHA512_IV[1] | 0;
|
|
2167
|
-
Bh = SHA512_IV[2] | 0;
|
|
2168
|
-
Bl = SHA512_IV[3] | 0;
|
|
2169
|
-
Ch = SHA512_IV[4] | 0;
|
|
2170
|
-
Cl = SHA512_IV[5] | 0;
|
|
2171
|
-
Dh = SHA512_IV[6] | 0;
|
|
2172
|
-
Dl = SHA512_IV[7] | 0;
|
|
2173
|
-
Eh = SHA512_IV[8] | 0;
|
|
2174
|
-
El = SHA512_IV[9] | 0;
|
|
2175
|
-
Fh = SHA512_IV[10] | 0;
|
|
2176
|
-
Fl = SHA512_IV[11] | 0;
|
|
2177
|
-
Gh = SHA512_IV[12] | 0;
|
|
2178
|
-
Gl = SHA512_IV[13] | 0;
|
|
2179
|
-
Hh = SHA512_IV[14] | 0;
|
|
2180
|
-
Hl = SHA512_IV[15] | 0;
|
|
2181
2452
|
constructor() {
|
|
2182
|
-
super(64);
|
|
2453
|
+
super(64, SHA512_IV);
|
|
2183
2454
|
}
|
|
2184
2455
|
};
|
|
2185
2456
|
var sha256 = /* @__PURE__ */ createHasher(
|
|
@@ -2209,17 +2480,6 @@ var AddressType = {
|
|
|
2209
2480
|
WOTSPRF: 5,
|
|
2210
2481
|
FORSPRF: 6
|
|
2211
2482
|
};
|
|
2212
|
-
function hexToNumber(hex) {
|
|
2213
|
-
if (typeof hex !== "string")
|
|
2214
|
-
throw new Error("hex string expected, got " + typeof hex);
|
|
2215
|
-
return BigInt(hex === "" ? "0" : "0x" + hex);
|
|
2216
|
-
}
|
|
2217
|
-
function bytesToNumberBE(bytes) {
|
|
2218
|
-
return hexToNumber(bytesToHex(bytes));
|
|
2219
|
-
}
|
|
2220
|
-
function numberToBytesBE(n, len) {
|
|
2221
|
-
return hexToBytes(n.toString(16).padStart(len * 2, "0"));
|
|
2222
|
-
}
|
|
2223
2483
|
var base2b = (outLen, b) => {
|
|
2224
2484
|
const mask = getMask(b);
|
|
2225
2485
|
return (bytes) => {
|
|
@@ -2235,8 +2495,11 @@ var base2b = (outLen, b) => {
|
|
|
2235
2495
|
return baseB;
|
|
2236
2496
|
};
|
|
2237
2497
|
};
|
|
2498
|
+
var _1n2 = /* @__PURE__ */ BigInt(1);
|
|
2499
|
+
var _8n = /* @__PURE__ */ BigInt(8);
|
|
2500
|
+
var _0xffn = /* @__PURE__ */ BigInt(255);
|
|
2238
2501
|
function getMaskBig(bits) {
|
|
2239
|
-
return (
|
|
2502
|
+
return (_1n2 << BigInt(bits)) - _1n2;
|
|
2240
2503
|
}
|
|
2241
2504
|
function gen(opts2, hashOpts_) {
|
|
2242
2505
|
const hashOpts = hashOpts_;
|
|
@@ -2272,7 +2535,6 @@ function gen(opts2, hashOpts_) {
|
|
|
2272
2535
|
const setAddr = (opts3, addr = new Uint8Array(ADDR_BYTES)) => {
|
|
2273
2536
|
const { type, height, tree, layer, index, chain, hash, keypair } = opts3;
|
|
2274
2537
|
const { subtreeAddr, keypairAddr } = opts3;
|
|
2275
|
-
const v = createView(addr);
|
|
2276
2538
|
if (height !== void 0)
|
|
2277
2539
|
addr[OFFSET_CHAIN_ADDR] = height;
|
|
2278
2540
|
if (layer !== void 0)
|
|
@@ -2283,12 +2545,19 @@ function gen(opts2, hashOpts_) {
|
|
|
2283
2545
|
addr[OFFSET_CHAIN_ADDR] = chain;
|
|
2284
2546
|
if (hash !== void 0)
|
|
2285
2547
|
addr[OFFSET_HASH_ADDR] = hash;
|
|
2286
|
-
if (index !== void 0)
|
|
2287
|
-
|
|
2548
|
+
if (index !== void 0) {
|
|
2549
|
+
addr[OFFSET_TREE_INDEX + 0] = index >>> 24;
|
|
2550
|
+
addr[OFFSET_TREE_INDEX + 1] = index >>> 16;
|
|
2551
|
+
addr[OFFSET_TREE_INDEX + 2] = index >>> 8;
|
|
2552
|
+
addr[OFFSET_TREE_INDEX + 3] = index;
|
|
2553
|
+
}
|
|
2288
2554
|
if (subtreeAddr)
|
|
2289
2555
|
addr.set(subtreeAddr.subarray(0, OFFSET_TREE + 8));
|
|
2290
|
-
if (tree !== void 0)
|
|
2291
|
-
|
|
2556
|
+
if (tree !== void 0) {
|
|
2557
|
+
let t = tree;
|
|
2558
|
+
for (let i = 7; i >= 0; i--, t >>= _8n)
|
|
2559
|
+
addr[OFFSET_TREE + i] = Number(t & _0xffn);
|
|
2560
|
+
}
|
|
2292
2561
|
if (keypair !== void 0) {
|
|
2293
2562
|
addr[OFFSET_KP_ADDR1] = keypair;
|
|
2294
2563
|
if (TREE_HEIGHT > 8)
|
|
@@ -2333,10 +2602,10 @@ function gen(opts2, hashOpts_) {
|
|
|
2333
2602
|
const maxIdx = (1 << height) - 1;
|
|
2334
2603
|
const stack = new Uint8Array(height * N3);
|
|
2335
2604
|
const authPath = new Uint8Array(height * N3);
|
|
2605
|
+
const current = new Uint8Array(2 * N3);
|
|
2606
|
+
const cur0 = current.subarray(0, N3);
|
|
2607
|
+
const cur1 = current.subarray(N3);
|
|
2336
2608
|
for (let idx = 0; ; idx++) {
|
|
2337
|
-
const current = new Uint8Array(2 * N3);
|
|
2338
|
-
const cur0 = current.subarray(0, N3);
|
|
2339
|
-
const cur1 = current.subarray(N3);
|
|
2340
2609
|
const addrOffset = idx + idxOffset;
|
|
2341
2610
|
cur1.set(leafFn(leafIdx, addrOffset, rawContext, info));
|
|
2342
2611
|
let h = 0;
|
|
@@ -2497,7 +2766,7 @@ function gen(opts2, hashOpts_) {
|
|
|
2497
2766
|
height: 0,
|
|
2498
2767
|
index: indices[i] + idxOffset
|
|
2499
2768
|
}, forsTreeAddr);
|
|
2500
|
-
const prf = context.PRFaddr(forsTreeAddr);
|
|
2769
|
+
const prf = copyBytes(context.PRFaddr(forsTreeAddr));
|
|
2501
2770
|
setAddr({ type: AddressType.FORSTREE }, forsTreeAddr);
|
|
2502
2771
|
const { root: root2, authPath } = forsTreehash(context, indices[i], idxOffset, forsTreeAddr, forsLeaf);
|
|
2503
2772
|
roots.push(root2);
|
|
@@ -2507,7 +2776,7 @@ function gen(opts2, hashOpts_) {
|
|
|
2507
2776
|
type: AddressType.FORSPK,
|
|
2508
2777
|
keypairAddr: wotsAddr
|
|
2509
2778
|
});
|
|
2510
|
-
const root = context.thashN(K, concatBytes(...roots), forsPkAddr);
|
|
2779
|
+
const root = copyBytes(context.thashN(K, concatBytes(...roots), forsPkAddr));
|
|
2511
2780
|
const treeAddr = setAddr({ type: AddressType.HASHTREE });
|
|
2512
2781
|
const wots = [];
|
|
2513
2782
|
for (let i = 0; i < D2; i++, tree >>= BigInt(TREE_HEIGHT)) {
|
|
@@ -2526,10 +2795,11 @@ function gen(opts2, hashOpts_) {
|
|
|
2526
2795
|
},
|
|
2527
2796
|
verify: (sig, msg, publicKey) => {
|
|
2528
2797
|
const [pkSeed, pubRoot] = publicCoder.decode(publicKey);
|
|
2529
|
-
const [random, forsVec, wotsVec] = sigCoder.decode(sig);
|
|
2530
2798
|
const pk = publicKey;
|
|
2799
|
+
abytesDoc(sig, void 0, "signature");
|
|
2531
2800
|
if (sig.length !== sigCoder.bytesLen)
|
|
2532
2801
|
return false;
|
|
2802
|
+
const [random, forsVec, wotsVec] = sigCoder.decode(sig);
|
|
2533
2803
|
const context = getContext(pkSeed);
|
|
2534
2804
|
let { tree, leafIdx, md } = hashMessage(random, pk, msg, context);
|
|
2535
2805
|
const wotsAddr = setAddr({
|
|
@@ -2548,13 +2818,13 @@ function gen(opts2, hashOpts_) {
|
|
|
2548
2818
|
const idxOffset = i << A;
|
|
2549
2819
|
setAddr({ height: 0, index: indices[i] + idxOffset }, forsTreeAddr);
|
|
2550
2820
|
const leaf = context.thash1(prf, forsTreeAddr);
|
|
2551
|
-
roots.push(computeRoot(leaf, indices[i], idxOffset, authPath, A, context, forsTreeAddr));
|
|
2821
|
+
roots.push(copyBytes(computeRoot(leaf, indices[i], idxOffset, authPath, A, context, forsTreeAddr)));
|
|
2552
2822
|
}
|
|
2553
2823
|
const forsPkAddr = setAddr({
|
|
2554
2824
|
type: AddressType.FORSPK,
|
|
2555
2825
|
keypairAddr: wotsAddr
|
|
2556
2826
|
});
|
|
2557
|
-
let root = context.thashN(K, concatBytes(...roots), forsPkAddr);
|
|
2827
|
+
let root = copyBytes(context.thashN(K, concatBytes(...roots), forsPkAddr));
|
|
2558
2828
|
const treeAddr = setAddr({ type: AddressType.HASHTREE });
|
|
2559
2829
|
const wotsPkAddr = setAddr({ type: AddressType.WOTSPK });
|
|
2560
2830
|
const wotsPk = new Uint8Array(WOTS_LEN * N3);
|
|
@@ -2576,7 +2846,7 @@ function gen(opts2, hashOpts_) {
|
|
|
2576
2846
|
}
|
|
2577
2847
|
}
|
|
2578
2848
|
const leaf = context.thashN(WOTS_LEN, wotsPk, wotsPkAddr);
|
|
2579
|
-
root = computeRoot(leaf, leafIdx, 0, sigAuth, TREE_HEIGHT, context, treeAddr);
|
|
2849
|
+
root = copyBytes(computeRoot(leaf, leafIdx, 0, sigAuth, TREE_HEIGHT, context, treeAddr));
|
|
2580
2850
|
leafIdx = Number(tree & getMaskBig(TREE_HEIGHT));
|
|
2581
2851
|
}
|
|
2582
2852
|
return equalBytes(root, pubRoot);
|
|
@@ -2628,17 +2898,21 @@ var genShake2 = () => (opts2) => (pubSeed, skSeed) => {
|
|
|
2628
2898
|
const stats = { prf: 0, thash: 0, hmsg: 0, gen_message_random: 0 };
|
|
2629
2899
|
const h0 = shake256.create({}).update(pubSeed);
|
|
2630
2900
|
const h0tmp = h0.clone();
|
|
2901
|
+
const thashOut = new Uint8Array(N3);
|
|
2902
|
+
const prfOut = new Uint8Array(N3);
|
|
2631
2903
|
const thash = (blocks, input, addr) => {
|
|
2632
2904
|
stats.thash++;
|
|
2633
|
-
|
|
2905
|
+
const len = blocks * N3;
|
|
2906
|
+
h0._cloneInto(h0tmp).update(addr).update(input.length === len ? input : input.subarray(0, len)).xofInto(thashOut);
|
|
2907
|
+
return thashOut;
|
|
2634
2908
|
};
|
|
2635
2909
|
return {
|
|
2636
2910
|
PRFaddr: (addr) => {
|
|
2637
2911
|
if (!skSeed)
|
|
2638
2912
|
throw new Error("no sk seed");
|
|
2639
2913
|
stats.prf++;
|
|
2640
|
-
|
|
2641
|
-
return
|
|
2914
|
+
h0._cloneInto(h0tmp).update(addr).update(skSeed).xofInto(prfOut);
|
|
2915
|
+
return prfOut;
|
|
2642
2916
|
},
|
|
2643
2917
|
PRFmsg: (skPRF, random, msg) => {
|
|
2644
2918
|
stats.gen_message_random++;
|
|
@@ -2653,6 +2927,7 @@ var genShake2 = () => (opts2) => (pubSeed, skSeed) => {
|
|
|
2653
2927
|
clean: () => {
|
|
2654
2928
|
h0.destroy();
|
|
2655
2929
|
h0tmp.destroy();
|
|
2930
|
+
cleanBytes(thashOut, prfOut);
|
|
2656
2931
|
}
|
|
2657
2932
|
};
|
|
2658
2933
|
};
|
|
@@ -2669,6 +2944,12 @@ var genSha = (h0, h1) => (opts2) => (pub_seed, sk_seed) => {
|
|
|
2669
2944
|
const h1ps = h1.create().update(pub_seed).update(new Uint8Array(h1.blockLen - N3));
|
|
2670
2945
|
const h0tmp = h0ps.clone();
|
|
2671
2946
|
const h1tmp = h1ps.clone();
|
|
2947
|
+
const h0out = new Uint8Array(h0.outputLen);
|
|
2948
|
+
const h1out = new Uint8Array(h1.outputLen);
|
|
2949
|
+
const prfOut = new Uint8Array(h0.outputLen);
|
|
2950
|
+
const h0outN = h0out.subarray(0, N3);
|
|
2951
|
+
const h1outN = h1out.subarray(0, N3);
|
|
2952
|
+
const prfOutN = prfOut.subarray(0, N3);
|
|
2672
2953
|
function mgf1(seed, length, hash) {
|
|
2673
2954
|
stats.mgf1++;
|
|
2674
2955
|
const out = new Uint8Array(Math.ceil(length / hash.outputLen) * hash.outputLen);
|
|
@@ -2682,18 +2963,19 @@ var genSha = (h0, h1) => (opts2) => (pub_seed, sk_seed) => {
|
|
|
2682
2963
|
cleanBytes(out.subarray(length));
|
|
2683
2964
|
return out.subarray(0, length);
|
|
2684
2965
|
}
|
|
2685
|
-
const thash = (
|
|
2966
|
+
const thash = (h, hTmp, out, outN) => (blocks, input, addr) => {
|
|
2686
2967
|
stats.thash++;
|
|
2687
|
-
const
|
|
2688
|
-
|
|
2968
|
+
const len = blocks * N3;
|
|
2969
|
+
h._cloneInto(hTmp).update(addr).update(input.length === len ? input : input.subarray(0, len)).digestInto(out);
|
|
2970
|
+
return outN;
|
|
2689
2971
|
};
|
|
2690
2972
|
return {
|
|
2691
2973
|
PRFaddr: (addr) => {
|
|
2692
2974
|
if (!sk_seed)
|
|
2693
2975
|
throw new Error("No sk seed");
|
|
2694
2976
|
stats.prf++;
|
|
2695
|
-
|
|
2696
|
-
return
|
|
2977
|
+
h0ps._cloneInto(h0tmp).update(addr).update(sk_seed).digestInto(prfOut);
|
|
2978
|
+
return prfOutN;
|
|
2697
2979
|
},
|
|
2698
2980
|
PRFmsg: (skPRF, random, msg) => {
|
|
2699
2981
|
stats.gen_message_random++;
|
|
@@ -2704,13 +2986,14 @@ var genSha = (h0, h1) => (opts2) => (pub_seed, sk_seed) => {
|
|
|
2704
2986
|
const seed = concatBytes(R.subarray(0, N3), pk.subarray(0, N3), h1.create().update(R.subarray(0, N3)).update(pk).update(m).digest());
|
|
2705
2987
|
return mgf1(seed, outLen, h1);
|
|
2706
2988
|
},
|
|
2707
|
-
thash1: thash(
|
|
2708
|
-
thashN: thash(
|
|
2989
|
+
thash1: thash(h0ps, h0tmp, h0out, h0outN).bind(null, 1),
|
|
2990
|
+
thashN: thash(h1ps, h1tmp, h1out, h1outN),
|
|
2709
2991
|
clean: () => {
|
|
2710
2992
|
h0ps.destroy();
|
|
2711
2993
|
h1ps.destroy();
|
|
2712
2994
|
h0tmp.destroy();
|
|
2713
2995
|
h1tmp.destroy();
|
|
2996
|
+
cleanBytes(h0out, h1out, prfOut);
|
|
2714
2997
|
}
|
|
2715
2998
|
};
|
|
2716
2999
|
};
|
|
@@ -2742,13 +3025,13 @@ var slh_dsa_sha2_256f = /* @__PURE__ */ (() => gen(PARAMS3["256f"], SHA512_SIMPL
|
|
|
2742
3025
|
});
|
|
2743
3026
|
/*! Bundled license information:
|
|
2744
3027
|
|
|
3028
|
+
@noble/curves/utils.js:
|
|
3029
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3030
|
+
|
|
2745
3031
|
@noble/post-quantum/utils.js:
|
|
2746
3032
|
@noble/post-quantum/_crystals.js:
|
|
2747
3033
|
@noble/post-quantum/ml-kem.js:
|
|
2748
3034
|
@noble/post-quantum/ml-dsa.js:
|
|
2749
3035
|
@noble/post-quantum/slh-dsa.js:
|
|
2750
3036
|
(*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) *)
|
|
2751
|
-
|
|
2752
|
-
@noble/curves/utils.js:
|
|
2753
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2754
3037
|
*/
|