@blamejs/core 0.18.55 → 0.18.56
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 +36 -0
- package/NOTICE +4 -4
- package/README.md +6 -6
- package/lib/audit.js +26 -24
- package/lib/chain-writer.js +17 -0
- package/lib/mail-server-managesieve.js +15 -5
- package/lib/mail-server-mx.js +201 -9
- package/lib/mail-server-tls.js +23 -8
- package/lib/middleware/csrf-protect.js +37 -20
- package/lib/session-stores.js +6 -3
- package/lib/vendor/MANIFEST.json +30 -30
- package/lib/vendor/browser/noble-ciphers.mjs +15 -1
- package/lib/vendor/browser/noble-hashes.mjs +12 -4
- package/lib/vendor/browser/noble-post-quantum.mjs +78 -37
- package/lib/vendor/noble-ciphers.cjs +15 -1
- package/lib/vendor/noble-curves.cjs +46 -21
- package/lib/vendor/noble-post-quantum.cjs +184 -75
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @noble/curves v2.
|
|
1
|
+
// @noble/curves v2.4.0 — vendored from Paul Miller
|
|
2
2
|
// License: MIT — https://github.com/paulmillr/noble-curves
|
|
3
3
|
// Bundled with esbuild. Exports the RFC 9497 OPRF suites:
|
|
4
4
|
// ristretto255_oprf (ristretto255-SHA512), p256_oprf (P-256-SHA256),
|
|
@@ -104,6 +104,14 @@ var aobject = (value, label) => {
|
|
|
104
104
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
105
105
|
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
106
106
|
};
|
|
107
|
+
var aopts = (value, label) => {
|
|
108
|
+
aobject(value, label);
|
|
109
|
+
const proto = Object.getPrototypeOf(value);
|
|
110
|
+
if (proto !== Object.prototype && proto !== null)
|
|
111
|
+
throw new TypeError(`"${label}" expected plain object`);
|
|
112
|
+
if (Object.hasOwn(value, "__proto__"))
|
|
113
|
+
throw new TypeError(`"${label}.__proto__" is not allowed`);
|
|
114
|
+
};
|
|
107
115
|
function aexists(instance, checkFinished = true) {
|
|
108
116
|
if (instance.destroyed)
|
|
109
117
|
throw new Error("hash was destroyed");
|
|
@@ -190,10 +198,10 @@ function concatBytes(...arrays) {
|
|
|
190
198
|
return res;
|
|
191
199
|
}
|
|
192
200
|
function checkOpts(defaults, opts, title = "opts") {
|
|
193
|
-
|
|
201
|
+
aopts(defaults, "defaults");
|
|
194
202
|
if (opts !== void 0)
|
|
195
|
-
|
|
196
|
-
const merged = Object.assign(defaults, opts);
|
|
203
|
+
aopts(opts, title);
|
|
204
|
+
const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts);
|
|
197
205
|
return merged;
|
|
198
206
|
}
|
|
199
207
|
function createHasher(hashCons, info = {}) {
|
|
@@ -1019,6 +1027,17 @@ function invert(number, modulo) {
|
|
|
1019
1027
|
throw new Error("invert: does not exist");
|
|
1020
1028
|
return mod(x, modulo);
|
|
1021
1029
|
}
|
|
1030
|
+
function invertCt(a, prime) {
|
|
1031
|
+
if (prime <= _1n2)
|
|
1032
|
+
throw new Error("invertCt: expected prime modulus > 1, got " + prime);
|
|
1033
|
+
const an = mod(a, prime);
|
|
1034
|
+
if (an === _0n2)
|
|
1035
|
+
throw new Error("invertCt: expected non-zero number");
|
|
1036
|
+
const inverse = pow(an, prime - _2n, prime);
|
|
1037
|
+
if (mod(an * inverse, prime) !== _1n2)
|
|
1038
|
+
throw new Error("invertCt: does not exist");
|
|
1039
|
+
return inverse;
|
|
1040
|
+
}
|
|
1022
1041
|
function assertIsSquare(Fp2, root, n) {
|
|
1023
1042
|
const F = Fp2;
|
|
1024
1043
|
if (!F.eql(F.sqr(root), n))
|
|
@@ -2454,12 +2473,13 @@ function createOPRF(opts) {
|
|
|
2454
2473
|
hashToGroup: "function"
|
|
2455
2474
|
});
|
|
2456
2475
|
validatePointCons(opts.Point);
|
|
2457
|
-
const { name, Point, hash } = opts;
|
|
2476
|
+
const { name, Point, hash, hashToGroup: hashToGroupHook, hashToScalar } = opts;
|
|
2458
2477
|
const { Fn: Fn2 } = Point;
|
|
2459
|
-
const
|
|
2478
|
+
const invertSecret = (value) => invertCt(value, Fn2.ORDER);
|
|
2479
|
+
const hashToGroup = (msg, ctx) => hashToGroupHook(msg, {
|
|
2460
2480
|
DST: concatBytes2(asciiToBytes("HashToGroup-"), ctx)
|
|
2461
2481
|
});
|
|
2462
|
-
const hashToScalarPrefixed = (msg, ctx) =>
|
|
2482
|
+
const hashToScalarPrefixed = (msg, ctx) => hashToScalar(msg, { DST: concatBytes2(_DST_scalarBytes, ctx) });
|
|
2463
2483
|
const randomScalar = (rng = randomBytes2) => {
|
|
2464
2484
|
if (typeof rng !== "function")
|
|
2465
2485
|
throw new TypeError('"rng" expected function, got type=' + typeof rng);
|
|
@@ -2551,7 +2571,7 @@ function createOPRF(opts) {
|
|
|
2551
2571
|
const msg = concatBytes2(seed, encode(info), Uint8Array.of(0));
|
|
2552
2572
|
for (let counter = 0; counter <= 255; counter++) {
|
|
2553
2573
|
msg[msg.length - 1] = counter;
|
|
2554
|
-
const skS =
|
|
2574
|
+
const skS = hashToScalar(msg, { DST: dst });
|
|
2555
2575
|
if (Fn2.is0(skS))
|
|
2556
2576
|
continue;
|
|
2557
2577
|
return {
|
|
@@ -2669,7 +2689,7 @@ function createOPRF(opts) {
|
|
|
2669
2689
|
throw new Error("expected array");
|
|
2670
2690
|
const skS = Fn2.fromBytes(secretKey);
|
|
2671
2691
|
const t = Fn2.add(skS, m);
|
|
2672
|
-
const invT =
|
|
2692
|
+
const invT = invertSecret(t);
|
|
2673
2693
|
const blindedPoints = blinded.map((i) => wirePoint("blinded", i));
|
|
2674
2694
|
const evalPoints = blindedPoints.map((i) => i.multiply(invT));
|
|
2675
2695
|
const tweakedKey = Point.BASE.multiply(t);
|
|
@@ -2702,13 +2722,13 @@ function createOPRF(opts) {
|
|
|
2702
2722
|
if (inputPoint.equals(Point.ZERO))
|
|
2703
2723
|
throw new Error("Input point at infinity");
|
|
2704
2724
|
const t = Fn2.add(skS, m);
|
|
2705
|
-
const invT =
|
|
2725
|
+
const invT = invertSecret(t);
|
|
2706
2726
|
const unblinded = inputPoint.multiply(invT).toBytes();
|
|
2707
2727
|
return hashInput(input, info, unblinded);
|
|
2708
2728
|
}
|
|
2709
2729
|
});
|
|
2710
2730
|
};
|
|
2711
|
-
const res = { name, oprf, voprf, poprf, __tests: Object.freeze({ Fn: Fn2 }) };
|
|
2731
|
+
const res = { name, oprf, voprf, poprf, __tests: Object.freeze({ Fn: Fn2, invertSecret }) };
|
|
2712
2732
|
return Object.freeze(res);
|
|
2713
2733
|
}
|
|
2714
2734
|
|
|
@@ -2999,21 +3019,28 @@ function weierstrass(params, extraOpts = {}) {
|
|
|
2999
3019
|
endo: "object",
|
|
3000
3020
|
randomBytes: "function"
|
|
3001
3021
|
});
|
|
3002
|
-
const { endo, allowInfinityPoint } = extraOpts;
|
|
3022
|
+
const { endo: endoOpts, allowInfinityPoint, clearCofactor, isTorsionFree, fromBytes, toBytes } = extraOpts;
|
|
3003
3023
|
const randomBytes3 = extraOpts.randomBytes === void 0 ? randomBytes2 : extraOpts.randomBytes;
|
|
3004
|
-
if (
|
|
3005
|
-
if (!Fp2.is0(CURVE.a) || typeof
|
|
3024
|
+
if (endoOpts) {
|
|
3025
|
+
if (!Fp2.is0(CURVE.a) || typeof endoOpts.beta !== "bigint" || !Array.isArray(endoOpts.basises)) {
|
|
3006
3026
|
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
3007
3027
|
}
|
|
3008
3028
|
}
|
|
3029
|
+
const endo = endoOpts ? {
|
|
3030
|
+
beta: endoOpts.beta,
|
|
3031
|
+
basises: endoOpts.basises.map((basis) => [...basis])
|
|
3032
|
+
} : void 0;
|
|
3009
3033
|
const lengths = getWLengths(Fp2, Fn2);
|
|
3010
3034
|
function assertCompressionIsSupported() {
|
|
3011
3035
|
if (!Fp2.isOdd)
|
|
3012
3036
|
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
3013
3037
|
}
|
|
3014
3038
|
function pointToBytes(_c, point, isCompressed) {
|
|
3015
|
-
if (
|
|
3039
|
+
if (point.is0()) {
|
|
3040
|
+
if (!allowInfinityPoint)
|
|
3041
|
+
throw new Error("bad point: ZERO");
|
|
3016
3042
|
return Uint8Array.of(0);
|
|
3043
|
+
}
|
|
3017
3044
|
const { x, y } = point.toAffine();
|
|
3018
3045
|
const bx = Fp2.toBytes(x);
|
|
3019
3046
|
abool(isCompressed, "isCompressed");
|
|
@@ -3062,8 +3089,8 @@ function weierstrass(params, extraOpts = {}) {
|
|
|
3062
3089
|
throw new Error(`bad point: got length ${length}, expected compressed=${comp} or uncompressed=${uncomp}`);
|
|
3063
3090
|
}
|
|
3064
3091
|
}
|
|
3065
|
-
const encodePoint =
|
|
3066
|
-
const decodePoint =
|
|
3092
|
+
const encodePoint = toBytes === void 0 ? pointToBytes : toBytes;
|
|
3093
|
+
const decodePoint = fromBytes === void 0 ? pointFromBytes : fromBytes;
|
|
3067
3094
|
const b3 = Fp2.mul(CURVE.b, _3n3);
|
|
3068
3095
|
const mulA = Fp2.is0(CURVE.a) ? (_) => Fp2.ZERO : (x) => Fp2.mul(CURVE.a, x);
|
|
3069
3096
|
function weierstrassEquation(x) {
|
|
@@ -3085,7 +3112,7 @@ function weierstrass(params, extraOpts = {}) {
|
|
|
3085
3112
|
function acoord(title, n, banZero = false) {
|
|
3086
3113
|
if (!Fp2.isValid(n) || banZero && Fp2.is0(n))
|
|
3087
3114
|
throw new Error(`bad point coordinate ${title}`);
|
|
3088
|
-
return n;
|
|
3115
|
+
return typeof n === "object" && n !== null ? Fp2.create(n) : n;
|
|
3089
3116
|
}
|
|
3090
3117
|
function aprjpoint(other) {
|
|
3091
3118
|
if (!(other instanceof Point))
|
|
@@ -3167,7 +3194,7 @@ function weierstrass(params, extraOpts = {}) {
|
|
|
3167
3194
|
assertValidity() {
|
|
3168
3195
|
const p = this;
|
|
3169
3196
|
if (p.is0()) {
|
|
3170
|
-
if (
|
|
3197
|
+
if (allowInfinityPoint && Fp2.is0(p.X) && Fp2.eql(p.Y, Fp2.ONE) && Fp2.is0(p.Z))
|
|
3171
3198
|
return;
|
|
3172
3199
|
throw new Error("bad point: ZERO");
|
|
3173
3200
|
}
|
|
@@ -3379,7 +3406,6 @@ function weierstrass(params, extraOpts = {}) {
|
|
|
3379
3406
|
* Always torsion-free for cofactor=1 curves.
|
|
3380
3407
|
*/
|
|
3381
3408
|
isTorsionFree() {
|
|
3382
|
-
const { isTorsionFree } = extraOpts;
|
|
3383
3409
|
if (cofactor === _1n7)
|
|
3384
3410
|
return true;
|
|
3385
3411
|
if (isTorsionFree)
|
|
@@ -3387,7 +3413,6 @@ function weierstrass(params, extraOpts = {}) {
|
|
|
3387
3413
|
return wnaf.mulUnsafe(this, CURVE_ORDER).is0();
|
|
3388
3414
|
}
|
|
3389
3415
|
clearCofactor() {
|
|
3390
|
-
const { clearCofactor } = extraOpts;
|
|
3391
3416
|
if (cofactor === _1n7)
|
|
3392
3417
|
return this;
|
|
3393
3418
|
if (clearCofactor)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @noble/post-quantum v0.7.
|
|
1
|
+
// @noble/post-quantum v0.7.1 — 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),
|
|
@@ -124,6 +124,14 @@ var aobject = (value, label) => {
|
|
|
124
124
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
125
125
|
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
126
126
|
};
|
|
127
|
+
var aopts = (value, label) => {
|
|
128
|
+
aobject(value, label);
|
|
129
|
+
const proto = Object.getPrototypeOf(value);
|
|
130
|
+
if (proto !== Object.prototype && proto !== null)
|
|
131
|
+
throw new TypeError(`"${label}" expected plain object`);
|
|
132
|
+
if (Object.hasOwn(value, "__proto__"))
|
|
133
|
+
throw new TypeError(`"${label}.__proto__" is not allowed`);
|
|
134
|
+
};
|
|
127
135
|
function aexists(instance, checkFinished = true) {
|
|
128
136
|
if (instance.destroyed)
|
|
129
137
|
throw new Error("hash was destroyed");
|
|
@@ -224,10 +232,10 @@ function concatBytes(...arrays) {
|
|
|
224
232
|
return res;
|
|
225
233
|
}
|
|
226
234
|
function checkOpts(defaults, opts2, title = "opts") {
|
|
227
|
-
|
|
235
|
+
aopts(defaults, "defaults");
|
|
228
236
|
if (opts2 !== void 0)
|
|
229
|
-
|
|
230
|
-
const merged = Object.assign(defaults, opts2);
|
|
237
|
+
aopts(opts2, title);
|
|
238
|
+
const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts2);
|
|
231
239
|
return merged;
|
|
232
240
|
}
|
|
233
241
|
function createHasher(hashCons, info = {}) {
|
|
@@ -686,22 +694,47 @@ function equalBytes(a, b) {
|
|
|
686
694
|
return diff === 0;
|
|
687
695
|
}
|
|
688
696
|
function copyBytes(bytes) {
|
|
689
|
-
return Uint8Array
|
|
697
|
+
return new Uint8Array(abytes(bytes));
|
|
690
698
|
}
|
|
691
699
|
function validateOpts(opts2) {
|
|
692
700
|
if (isBytes(opts2))
|
|
693
701
|
throw new TypeError('"opts" expected object, got Uint8Array');
|
|
694
702
|
aobject3(opts2, "opts");
|
|
703
|
+
const proto = Object.getPrototypeOf(opts2);
|
|
704
|
+
if (proto !== null && proto !== Object.prototype)
|
|
705
|
+
throw new TypeError('"opts" expected a plain object');
|
|
695
706
|
}
|
|
696
|
-
|
|
707
|
+
var VER_OPT_KEYS = /* @__PURE__ */ Object.freeze([
|
|
708
|
+
"context"
|
|
709
|
+
]);
|
|
710
|
+
var SIG_OPT_KEYS = /* @__PURE__ */ Object.freeze([
|
|
711
|
+
"context",
|
|
712
|
+
"extraEntropy"
|
|
713
|
+
]);
|
|
714
|
+
function checkOptKeys(opts2, allowed) {
|
|
697
715
|
validateOpts(opts2);
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
716
|
+
const normalized = Object.assign(/* @__PURE__ */ Object.create(null), opts2);
|
|
717
|
+
for (const [k, v] of Object.entries(normalized)) {
|
|
718
|
+
if (v === void 0)
|
|
719
|
+
continue;
|
|
720
|
+
if (!allowed.includes(k))
|
|
721
|
+
throw new TypeError('unexpected option "' + String(k) + '"; expected one of: ' + allowed.join(", "));
|
|
722
|
+
}
|
|
723
|
+
return Object.freeze(normalized);
|
|
724
|
+
}
|
|
725
|
+
function validateVerOpts(opts2, allowed = VER_OPT_KEYS) {
|
|
726
|
+
const normalized = checkOptKeys(opts2, allowed);
|
|
727
|
+
if (normalized.context !== void 0)
|
|
728
|
+
abytes(normalized.context, void 0, "opts.context");
|
|
729
|
+
return normalized;
|
|
730
|
+
}
|
|
731
|
+
function validateSigOpts(opts2, allowed = SIG_OPT_KEYS) {
|
|
732
|
+
const normalized = checkOptKeys(opts2, allowed);
|
|
733
|
+
if (normalized.context !== void 0)
|
|
734
|
+
abytes(normalized.context, void 0, "opts.context");
|
|
735
|
+
if (normalized.extraEntropy !== false && normalized.extraEntropy !== void 0)
|
|
736
|
+
abytes(normalized.extraEntropy, void 0, "opts.extraEntropy");
|
|
737
|
+
return normalized;
|
|
705
738
|
}
|
|
706
739
|
function splitCoder(label, ...lengths) {
|
|
707
740
|
const getLength = (c) => typeof c === "number" ? c : c.bytesLen;
|
|
@@ -786,6 +819,12 @@ function getMessage(msg, ctx = EMPTY) {
|
|
|
786
819
|
return concatBytes(new Uint8Array([0, ctx.length]), ctx, msg);
|
|
787
820
|
}
|
|
788
821
|
var oidNistP = /* @__PURE__ */ Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2]);
|
|
822
|
+
var XOF_OID_OUTPUT_LEN = /* @__PURE__ */ (() => ({
|
|
823
|
+
"060960864801650304020b": 32,
|
|
824
|
+
// id-shake128, SHAKE128(M, 256)
|
|
825
|
+
"060960864801650304020c": 64
|
|
826
|
+
// id-shake256, SHAKE256(M, 512)
|
|
827
|
+
}))();
|
|
789
828
|
function checkHash(hash, requiredStrength = 0) {
|
|
790
829
|
if (typeof hash !== "function" || typeof hash.create !== "function")
|
|
791
830
|
throw new TypeError('"hash" expected hash function, got type=' + typeof hash);
|
|
@@ -795,6 +834,10 @@ function checkHash(hash, requiredStrength = 0) {
|
|
|
795
834
|
abytes(oid, void 0, "hash.oid");
|
|
796
835
|
if (!equalBytes(oid.subarray(0, 10), oidNistP))
|
|
797
836
|
throw new Error('"hash.oid" is invalid: expected NIST hash');
|
|
837
|
+
const xofLen = XOF_OID_OUTPUT_LEN[bytesToHex(oid)];
|
|
838
|
+
if (xofLen !== void 0 && hash.outputLen !== xofLen) {
|
|
839
|
+
throw new Error("Pre-hash XOF output length must be " + xofLen + " bytes for this OID, got: " + hash.outputLen);
|
|
840
|
+
}
|
|
798
841
|
const collisionResistance = hash.outputLen * 8 / 2;
|
|
799
842
|
if (requiredStrength > collisionResistance) {
|
|
800
843
|
throw new Error("Pre-hash security strength too low: " + collisionResistance + ", required: " + requiredStrength);
|
|
@@ -1162,8 +1205,9 @@ var genKPKE = (opts_) => {
|
|
|
1162
1205
|
for (let i = 0; i < K; i++)
|
|
1163
1206
|
polyAdd(tmp, MultiplyNTTs(sk[i], crystals.NTT.encode(u[i])));
|
|
1164
1207
|
polySub(v, crystals.NTT.decode(tmp));
|
|
1165
|
-
|
|
1166
|
-
|
|
1208
|
+
const res = poly1.encode(v);
|
|
1209
|
+
cleanBytes(tmp, sk, u, v);
|
|
1210
|
+
return res;
|
|
1167
1211
|
}
|
|
1168
1212
|
};
|
|
1169
1213
|
};
|
|
@@ -1193,32 +1237,55 @@ function createKyber(opts2) {
|
|
|
1193
1237
|
return Object.freeze({
|
|
1194
1238
|
info: Object.freeze({ type: "ml-kem" }),
|
|
1195
1239
|
lengths: kemLengths,
|
|
1196
|
-
keygen: (seed
|
|
1197
|
-
|
|
1198
|
-
const
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1240
|
+
keygen: (seed) => {
|
|
1241
|
+
const ownSeed = seed === void 0;
|
|
1242
|
+
const s = ownSeed ? randomBytes2(seedLen) : seed;
|
|
1243
|
+
let sk;
|
|
1244
|
+
let publicKeyHash;
|
|
1245
|
+
try {
|
|
1246
|
+
abytesDoc(s, seedLen, "seed");
|
|
1247
|
+
const keys = KPKE.keygen(s.subarray(0, 32));
|
|
1248
|
+
const publicKey = keys.publicKey;
|
|
1249
|
+
sk = keys.secretKey;
|
|
1250
|
+
publicKeyHash = HASH256(publicKey);
|
|
1251
|
+
const secretKey = secretCoder.encode([sk, publicKey, publicKeyHash, s.subarray(32)]);
|
|
1252
|
+
return {
|
|
1253
|
+
publicKey,
|
|
1254
|
+
secretKey
|
|
1255
|
+
};
|
|
1256
|
+
} finally {
|
|
1257
|
+
if (sk !== void 0)
|
|
1258
|
+
cleanBytes(sk);
|
|
1259
|
+
if (publicKeyHash !== void 0)
|
|
1260
|
+
cleanBytes(publicKeyHash);
|
|
1261
|
+
if (ownSeed)
|
|
1262
|
+
cleanBytes(s);
|
|
1263
|
+
}
|
|
1206
1264
|
},
|
|
1207
1265
|
getPublicKey: (secretKey) => {
|
|
1208
1266
|
const [_sk, publicKey, _publicKeyHash, _z] = secretCoder.decode(secretKey);
|
|
1209
1267
|
return Uint8Array.from(publicKey);
|
|
1210
1268
|
},
|
|
1211
|
-
encapsulate: (publicKey, msg
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1269
|
+
encapsulate: (publicKey, msg) => {
|
|
1270
|
+
const ownMsg = msg === void 0;
|
|
1271
|
+
const m = ownMsg ? randomBytes2(msgLen) : msg;
|
|
1272
|
+
let kr;
|
|
1273
|
+
try {
|
|
1274
|
+
abytesDoc(publicKey, lengths.publicKey, "publicKey");
|
|
1275
|
+
abytesDoc(m, msgLen, "message");
|
|
1276
|
+
validateModulus(publicKey, "encapsulate");
|
|
1277
|
+
kr = HASH512.create().update(m).update(HASH256(publicKey)).digest();
|
|
1278
|
+
const cipherText = KPKE.encrypt(publicKey, m, kr.subarray(32, 64));
|
|
1279
|
+
return {
|
|
1280
|
+
cipherText,
|
|
1281
|
+
sharedSecret: kr.subarray(0, 32)
|
|
1282
|
+
};
|
|
1283
|
+
} finally {
|
|
1284
|
+
if (kr !== void 0)
|
|
1285
|
+
cleanBytes(kr.subarray(32));
|
|
1286
|
+
if (ownMsg)
|
|
1287
|
+
cleanBytes(m);
|
|
1288
|
+
}
|
|
1222
1289
|
},
|
|
1223
1290
|
decapsulate: (cipherText, secretKey) => {
|
|
1224
1291
|
abytesDoc(secretKey, secretCoder.bytesLen, "secretKey");
|
|
@@ -1251,15 +1318,24 @@ function createKyber(opts2) {
|
|
|
1251
1318
|
const cached = KPKE.prepare(ek);
|
|
1252
1319
|
return Object.freeze({
|
|
1253
1320
|
publicKey: ek,
|
|
1254
|
-
encapsulate: (msg
|
|
1255
|
-
|
|
1256
|
-
const
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1321
|
+
encapsulate: (msg) => {
|
|
1322
|
+
const ownMsg = msg === void 0;
|
|
1323
|
+
const m = ownMsg ? randomBytes2(msgLen) : msg;
|
|
1324
|
+
let kr;
|
|
1325
|
+
try {
|
|
1326
|
+
abytesDoc(m, msgLen, "message");
|
|
1327
|
+
kr = HASH512.create().update(m).update(publicKeyHash).digest();
|
|
1328
|
+
const cipherText = cached.encrypt(m, kr.subarray(32, 64));
|
|
1329
|
+
return {
|
|
1330
|
+
cipherText,
|
|
1331
|
+
sharedSecret: kr.subarray(0, 32)
|
|
1332
|
+
};
|
|
1333
|
+
} finally {
|
|
1334
|
+
if (kr !== void 0)
|
|
1335
|
+
cleanBytes(kr.subarray(32));
|
|
1336
|
+
if (ownMsg)
|
|
1337
|
+
cleanBytes(m);
|
|
1338
|
+
}
|
|
1263
1339
|
},
|
|
1264
1340
|
decapsulate: (cipherText, secretKey) => {
|
|
1265
1341
|
abytesDoc(secretKey, secretCoder.bytesLen, "secretKey");
|
|
@@ -1300,10 +1376,16 @@ var ml_kem768 = /* @__PURE__ */ (() => mk(PARAMS[768]))();
|
|
|
1300
1376
|
var ml_kem1024 = /* @__PURE__ */ (() => mk(PARAMS[1024]))();
|
|
1301
1377
|
|
|
1302
1378
|
// node_modules/@noble/post-quantum/ml-dsa.js
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1379
|
+
var INTERNAL_SIG_OPT_KEYS = /* @__PURE__ */ Object.freeze([
|
|
1380
|
+
"extraEntropy",
|
|
1381
|
+
"externalMu"
|
|
1382
|
+
]);
|
|
1383
|
+
var INTERNAL_VER_OPT_KEYS = /* @__PURE__ */ Object.freeze(["externalMu"]);
|
|
1384
|
+
function validateInternalOpts(opts2, allowed) {
|
|
1385
|
+
const normalized = checkOptKeys(opts2, allowed);
|
|
1386
|
+
if (normalized.externalMu !== void 0)
|
|
1387
|
+
abool2(normalized.externalMu, "opts.externalMu");
|
|
1388
|
+
return normalized;
|
|
1307
1389
|
}
|
|
1308
1390
|
var N2 = 256;
|
|
1309
1391
|
var Q2 = 8380417;
|
|
@@ -1646,8 +1728,8 @@ function getDilithium(opts_) {
|
|
|
1646
1728
|
},
|
|
1647
1729
|
// NOTE: random is optional.
|
|
1648
1730
|
sign: (msg, secretKey, opts3 = {}) => {
|
|
1649
|
-
validateSigOpts(opts3);
|
|
1650
|
-
validateInternalOpts(opts3);
|
|
1731
|
+
opts3 = validateSigOpts(opts3, INTERNAL_SIG_OPT_KEYS);
|
|
1732
|
+
opts3 = validateInternalOpts(opts3, INTERNAL_SIG_OPT_KEYS);
|
|
1651
1733
|
const { extraEntropy: random, externalMu = false } = opts3;
|
|
1652
1734
|
if (externalMu)
|
|
1653
1735
|
abytesDoc(msg, CRH_BYTES, "mu");
|
|
@@ -1708,26 +1790,34 @@ function getDilithium(opts_) {
|
|
|
1708
1790
|
const cs1 = s1.map((i) => MultiplyNTTs2(i, cHat));
|
|
1709
1791
|
for (let i = 0; i < L; i++) {
|
|
1710
1792
|
polyAdd2(crystals2.NTT.decode(cs1[i]), y[i]);
|
|
1711
|
-
if (polyChknorm(cs1[i], GAMMA1 - BETA))
|
|
1793
|
+
if (polyChknorm(cs1[i], GAMMA1 - BETA)) {
|
|
1794
|
+
cleanBytes(cTilde, cs1, cHat, w1, w, z, y);
|
|
1712
1795
|
continue main_loop;
|
|
1796
|
+
}
|
|
1713
1797
|
}
|
|
1714
1798
|
let cnt = 0;
|
|
1715
1799
|
const h = [];
|
|
1716
1800
|
for (let i = 0; i < K; i++) {
|
|
1717
1801
|
const cs2 = crystals2.NTT.decode(MultiplyNTTs2(s2[i], cHat));
|
|
1718
1802
|
const r0 = polySub2(w[i], cs2).map(LowBits);
|
|
1719
|
-
if (polyChknorm(r0, GAMMA2 - BETA))
|
|
1803
|
+
if (polyChknorm(r0, GAMMA2 - BETA)) {
|
|
1804
|
+
cleanBytes(cTilde, cs1, cHat, w1, w, z, y, h, cs2, r0);
|
|
1720
1805
|
continue main_loop;
|
|
1806
|
+
}
|
|
1721
1807
|
const ct0 = crystals2.NTT.decode(MultiplyNTTs2(t0[i], cHat));
|
|
1722
|
-
if (polyChknorm(ct0, GAMMA2))
|
|
1808
|
+
if (polyChknorm(ct0, GAMMA2)) {
|
|
1809
|
+
cleanBytes(cTilde, cs1, cHat, w1, w, z, y, h, cs2, r0, ct0);
|
|
1723
1810
|
continue main_loop;
|
|
1811
|
+
}
|
|
1724
1812
|
polyAdd2(r0, ct0);
|
|
1725
1813
|
const hint = polyMakeHint(r0, w1[i]);
|
|
1726
1814
|
h.push(hint.v);
|
|
1727
1815
|
cnt += hint.cnt;
|
|
1728
1816
|
}
|
|
1729
|
-
if (cnt > OMEGA)
|
|
1817
|
+
if (cnt > OMEGA) {
|
|
1818
|
+
cleanBytes(cTilde, cs1, cHat, w1, w, z, y, h);
|
|
1730
1819
|
continue;
|
|
1820
|
+
}
|
|
1731
1821
|
x256.clean();
|
|
1732
1822
|
const res = sigCoder.encode([cTilde, cs1, h]);
|
|
1733
1823
|
cleanBytes(cTilde, cs1, h, cHat, w1, w, z, y, rhoprime, s1, s2, t0, ...A);
|
|
@@ -1738,7 +1828,7 @@ function getDilithium(opts_) {
|
|
|
1738
1828
|
throw new Error("Unreachable code path reached, report this error");
|
|
1739
1829
|
},
|
|
1740
1830
|
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
1741
|
-
validateInternalOpts(opts3);
|
|
1831
|
+
opts3 = validateInternalOpts(opts3, INTERNAL_VER_OPT_KEYS);
|
|
1742
1832
|
const { externalMu = false } = opts3;
|
|
1743
1833
|
if (externalMu)
|
|
1744
1834
|
abytesDoc(msg, CRH_BYTES, "mu");
|
|
@@ -1793,16 +1883,19 @@ function getDilithium(opts_) {
|
|
|
1793
1883
|
lengths: internal.lengths,
|
|
1794
1884
|
getPublicKey: internal.getPublicKey,
|
|
1795
1885
|
sign: (msg, secretKey, opts3 = {}) => {
|
|
1796
|
-
validateSigOpts(opts3);
|
|
1886
|
+
opts3 = validateSigOpts(opts3);
|
|
1797
1887
|
const M = getMessage(msg, opts3.context);
|
|
1798
|
-
const res = internal.sign(M, secretKey,
|
|
1888
|
+
const res = internal.sign(M, secretKey, {
|
|
1889
|
+
extraEntropy: opts3.extraEntropy,
|
|
1890
|
+
externalMu: false
|
|
1891
|
+
});
|
|
1799
1892
|
cleanBytes(M);
|
|
1800
1893
|
return res;
|
|
1801
1894
|
},
|
|
1802
1895
|
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
1803
|
-
validateVerOpts(opts3);
|
|
1896
|
+
opts3 = validateVerOpts(opts3);
|
|
1804
1897
|
abytesDoc(sig, void 0, "signature");
|
|
1805
|
-
return internal.verify(sig, getMessage(msg, opts3.context), publicKey);
|
|
1898
|
+
return internal.verify(sig, getMessage(msg, opts3.context), publicKey, { externalMu: false });
|
|
1806
1899
|
},
|
|
1807
1900
|
prehash: (hash) => {
|
|
1808
1901
|
checkHash(hash, securityLevel);
|
|
@@ -1814,16 +1907,21 @@ function getDilithium(opts_) {
|
|
|
1814
1907
|
keygen: internal.keygen,
|
|
1815
1908
|
getPublicKey: internal.getPublicKey,
|
|
1816
1909
|
sign: (msg, secretKey, opts3 = {}) => {
|
|
1817
|
-
validateSigOpts(opts3);
|
|
1910
|
+
opts3 = validateSigOpts(opts3);
|
|
1818
1911
|
const M = getMessagePrehash(rawHash, msg, opts3.context);
|
|
1819
|
-
const res = internal.sign(M, secretKey,
|
|
1912
|
+
const res = internal.sign(M, secretKey, {
|
|
1913
|
+
extraEntropy: opts3.extraEntropy,
|
|
1914
|
+
externalMu: false
|
|
1915
|
+
});
|
|
1820
1916
|
cleanBytes(M);
|
|
1821
1917
|
return res;
|
|
1822
1918
|
},
|
|
1823
1919
|
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
1824
|
-
validateVerOpts(opts3);
|
|
1920
|
+
opts3 = validateVerOpts(opts3);
|
|
1825
1921
|
abytesDoc(sig, void 0, "signature");
|
|
1826
|
-
return internal.verify(sig, getMessagePrehash(rawHash, msg, opts3.context), publicKey
|
|
1922
|
+
return internal.verify(sig, getMessagePrehash(rawHash, msg, opts3.context), publicKey, {
|
|
1923
|
+
externalMu: false
|
|
1924
|
+
});
|
|
1827
1925
|
}
|
|
1828
1926
|
});
|
|
1829
1927
|
}
|
|
@@ -2463,6 +2561,8 @@ var sha512 = /* @__PURE__ */ createHasher(
|
|
|
2463
2561
|
);
|
|
2464
2562
|
|
|
2465
2563
|
// node_modules/@noble/post-quantum/slh-dsa.js
|
|
2564
|
+
var INTERNAL_SIG_OPT_KEYS2 = /* @__PURE__ */ Object.freeze(["extraEntropy"]);
|
|
2565
|
+
var INTERNAL_VER_OPT_KEYS2 = /* @__PURE__ */ Object.freeze([]);
|
|
2466
2566
|
var PARAMS3 = /* @__PURE__ */ (() => Object.freeze({
|
|
2467
2567
|
"128f": Object.freeze({ W: 16, N: 16, H: 66, D: 22, K: 33, A: 6, securityLevel: 128 }),
|
|
2468
2568
|
"128s": Object.freeze({ W: 16, N: 16, H: 63, D: 7, K: 14, A: 12, securityLevel: 128 }),
|
|
@@ -2533,8 +2633,16 @@ function gen(opts2, hashOpts_) {
|
|
|
2533
2633
|
OFFSET_HASH_ADDR += 10;
|
|
2534
2634
|
}
|
|
2535
2635
|
const setAddr = (opts3, addr = new Uint8Array(ADDR_BYTES)) => {
|
|
2536
|
-
const
|
|
2537
|
-
const
|
|
2636
|
+
const type = Object.hasOwn(opts3, "type") ? opts3.type : void 0;
|
|
2637
|
+
const height = Object.hasOwn(opts3, "height") ? opts3.height : void 0;
|
|
2638
|
+
const tree = Object.hasOwn(opts3, "tree") ? opts3.tree : void 0;
|
|
2639
|
+
const layer = Object.hasOwn(opts3, "layer") ? opts3.layer : void 0;
|
|
2640
|
+
const index = Object.hasOwn(opts3, "index") ? opts3.index : void 0;
|
|
2641
|
+
const chain = Object.hasOwn(opts3, "chain") ? opts3.chain : void 0;
|
|
2642
|
+
const hash = Object.hasOwn(opts3, "hash") ? opts3.hash : void 0;
|
|
2643
|
+
const keypair = Object.hasOwn(opts3, "keypair") ? opts3.keypair : void 0;
|
|
2644
|
+
const subtreeAddr = Object.hasOwn(opts3, "subtreeAddr") ? opts3.subtreeAddr : void 0;
|
|
2645
|
+
const keypairAddr = Object.hasOwn(opts3, "keypairAddr") ? opts3.keypairAddr : void 0;
|
|
2538
2646
|
if (height !== void 0)
|
|
2539
2647
|
addr[OFFSET_CHAIN_ADDR] = height;
|
|
2540
2648
|
if (layer !== void 0)
|
|
@@ -2735,7 +2843,7 @@ function gen(opts2, hashOpts_) {
|
|
|
2735
2843
|
return Uint8Array.from(pk);
|
|
2736
2844
|
},
|
|
2737
2845
|
sign: (msg, sk, opts3 = {}) => {
|
|
2738
|
-
validateSigOpts(opts3);
|
|
2846
|
+
opts3 = validateSigOpts(opts3, INTERNAL_SIG_OPT_KEYS2);
|
|
2739
2847
|
let { extraEntropy: random } = opts3;
|
|
2740
2848
|
const [skSeed, skPRF, pk] = secretCoder.decode(sk);
|
|
2741
2849
|
const [pkSeed, _] = publicCoder.decode(pk);
|
|
@@ -2793,7 +2901,8 @@ function gen(opts2, hashOpts_) {
|
|
|
2793
2901
|
cleanBytes(R, random, treeAddr, wotsAddr, forsLeaf, forsTreeAddr, indices, roots);
|
|
2794
2902
|
return SIG;
|
|
2795
2903
|
},
|
|
2796
|
-
verify: (sig, msg, publicKey) => {
|
|
2904
|
+
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
2905
|
+
validateVerOpts(opts3, INTERNAL_VER_OPT_KEYS2);
|
|
2797
2906
|
const [pkSeed, pubRoot] = publicCoder.decode(publicKey);
|
|
2798
2907
|
const pk = publicKey;
|
|
2799
2908
|
abytesDoc(sig, void 0, "signature");
|
|
@@ -2860,14 +2969,14 @@ function gen(opts2, hashOpts_) {
|
|
|
2860
2969
|
keygen: internal.keygen,
|
|
2861
2970
|
getPublicKey: internal.getPublicKey,
|
|
2862
2971
|
sign: (msg, secretKey, opts3 = {}) => {
|
|
2863
|
-
validateSigOpts(opts3);
|
|
2972
|
+
opts3 = validateSigOpts(opts3);
|
|
2864
2973
|
const M = getMessage(msg, opts3.context);
|
|
2865
|
-
const res = internal.sign(M, secretKey, opts3);
|
|
2974
|
+
const res = internal.sign(M, secretKey, { extraEntropy: opts3.extraEntropy });
|
|
2866
2975
|
cleanBytes(M);
|
|
2867
2976
|
return res;
|
|
2868
2977
|
},
|
|
2869
2978
|
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
2870
|
-
validateVerOpts(opts3);
|
|
2979
|
+
opts3 = validateVerOpts(opts3);
|
|
2871
2980
|
return internal.verify(sig, getMessage(msg, opts3.context), publicKey);
|
|
2872
2981
|
},
|
|
2873
2982
|
prehash: (hash) => {
|
|
@@ -2879,14 +2988,14 @@ function gen(opts2, hashOpts_) {
|
|
|
2879
2988
|
keygen: internal.keygen,
|
|
2880
2989
|
getPublicKey: internal.getPublicKey,
|
|
2881
2990
|
sign: (msg, secretKey, opts3 = {}) => {
|
|
2882
|
-
validateSigOpts(opts3);
|
|
2991
|
+
opts3 = validateSigOpts(opts3);
|
|
2883
2992
|
const M = getMessagePrehash(rawHash, msg, opts3.context);
|
|
2884
|
-
const res = internal.sign(M, secretKey, opts3);
|
|
2993
|
+
const res = internal.sign(M, secretKey, { extraEntropy: opts3.extraEntropy });
|
|
2885
2994
|
cleanBytes(M);
|
|
2886
2995
|
return res;
|
|
2887
2996
|
},
|
|
2888
2997
|
verify: (sig, msg, publicKey, opts3 = {}) => {
|
|
2889
|
-
validateVerOpts(opts3);
|
|
2998
|
+
opts3 = validateVerOpts(opts3);
|
|
2890
2999
|
return internal.verify(sig, getMessagePrehash(rawHash, msg, opts3.context), publicKey);
|
|
2891
3000
|
}
|
|
2892
3001
|
});
|
|
@@ -2931,7 +3040,7 @@ var genShake2 = () => (opts2) => (pubSeed, skSeed) => {
|
|
|
2931
3040
|
}
|
|
2932
3041
|
};
|
|
2933
3042
|
};
|
|
2934
|
-
var SHAKE_SIMPLE = /* @__PURE__ */ (() => ({ getContext: genShake2() }))();
|
|
3043
|
+
var SHAKE_SIMPLE = /* @__PURE__ */ (() => ({ isCompressed: false, getContext: genShake2() }))();
|
|
2935
3044
|
var slh_dsa_shake_128f = /* @__PURE__ */ (() => gen(PARAMS3["128f"], SHAKE_SIMPLE))();
|
|
2936
3045
|
var slh_dsa_shake_192f = /* @__PURE__ */ (() => gen(PARAMS3["192f"], SHAKE_SIMPLE))();
|
|
2937
3046
|
var slh_dsa_shake_256f = /* @__PURE__ */ (() => gen(PARAMS3["256f"], SHAKE_SIMPLE))();
|