@atlasauth/pca-mpc 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +30 -2
  2. package/dist/beaver.d.ts +49 -0
  3. package/dist/beaver.js +72 -0
  4. package/dist/beaver.js.map +1 -0
  5. package/dist/compose.d.ts +21 -0
  6. package/dist/compose.js +33 -0
  7. package/dist/compose.js.map +1 -0
  8. package/dist/csprng.d.ts +46 -0
  9. package/dist/csprng.js +86 -0
  10. package/dist/csprng.js.map +1 -0
  11. package/dist/ec.d.ts +110 -0
  12. package/dist/ec.js +306 -0
  13. package/dist/ec.js.map +1 -0
  14. package/dist/field.d.ts +34 -0
  15. package/dist/field.js +65 -0
  16. package/dist/field.js.map +1 -0
  17. package/dist/gf128.d.ts +23 -0
  18. package/dist/gf128.js +59 -0
  19. package/dist/gf128.js.map +1 -0
  20. package/dist/index.d.ts +27 -0
  21. package/dist/index.js +44 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/kem-ot.d.ts +137 -0
  24. package/dist/kem-ot.js +224 -0
  25. package/dist/kem-ot.js.map +1 -0
  26. package/dist/mascot.d.ts +189 -0
  27. package/dist/mascot.js +322 -0
  28. package/dist/mascot.js.map +1 -0
  29. package/dist/ot.d.ts +212 -0
  30. package/dist/ot.js +536 -0
  31. package/dist/ot.js.map +1 -0
  32. package/dist/party.d.ts +38 -0
  33. package/dist/party.js +40 -0
  34. package/dist/party.js.map +1 -0
  35. package/dist/runner.d.ts +56 -0
  36. package/dist/runner.js +97 -0
  37. package/dist/runner.js.map +1 -0
  38. package/dist/sharing.d.ts +40 -0
  39. package/dist/sharing.js +97 -0
  40. package/dist/sharing.js.map +1 -0
  41. package/dist/spdz-runner.d.ts +50 -0
  42. package/dist/spdz-runner.js +107 -0
  43. package/dist/spdz-runner.js.map +1 -0
  44. package/dist/spdz.d.ts +136 -0
  45. package/dist/spdz.js +243 -0
  46. package/dist/spdz.js.map +1 -0
  47. package/dist/thermometer.d.ts +22 -0
  48. package/dist/thermometer.js +41 -0
  49. package/dist/thermometer.js.map +1 -0
  50. package/package.json +31 -3
package/dist/ec.js ADDED
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+ /**
3
+ * A small, self-contained prime-order elliptic-curve group, used by the base oblivious transfer in
4
+ * `ot.ts`. The no-dealer offline phase (MASCOT-style triple generation) rests on real OT, and real OT
5
+ * rests on a real group with a hard discrete log — this module provides that group with nothing but
6
+ * BigInt arithmetic, so the whole stack stays dependency-free and testable in-process.
7
+ *
8
+ * Curve: **Ed25519** (twisted Edwards `−x² + y² = 1 + d·x²·y²` over `F_q`, `q = 2^255 − 19`). We work
9
+ * exclusively in the prime-order subgroup of order `L = 2^252 + 27742317777372353535851937790883648493`
10
+ * generated by the standard base point `B`, keeping every scalar in `[0, L)`; all group elements we
11
+ * ever form are scalar multiples of subgroup points, so they stay in the subgroup. Points are held in
12
+ * **extended coordinates** `(X, Y, Z, T)` with `x = X/Z`, `y = Y/Z`, `T = XY/Z`, and combined with the
13
+ * unified ("hwcd-3") addition law, which is *complete* on the subgroup — there are no special cases to
14
+ * branch on, which is exactly what keeps the implementation free of the subtle point-at-infinity bugs
15
+ * that plague short-Weierstrass code.
16
+ *
17
+ * SECURITY NOTES (prototype honesty, mirrored in docs §7.1):
18
+ * - **Point validation IS implemented** (`isOnCurve` / `hasPrimeOrder` / `assertInSubgroup`): every
19
+ * point a party RECEIVES across the OT trust boundary is validated to be on the curve and in the
20
+ * prime-order subgroup (cofactor check `[L]·P = O`), and non-identity, so a malicious party cannot
21
+ * inject an off-curve / small-order / mixed-order point to mount a small-subgroup attack. A
22
+ * `schnorrProve`/`schnorrVerify` NIZK of knowledge of the sender's discrete log `y` (`S = y·B`)
23
+ * binds `S` to a known exponent, which — with validation — is what makes the base OT malicious-secure.
24
+ * - **Constant-time is NOT achieved and cannot be, in pure JS.** BigInt modular arithmetic branches on
25
+ * operand size and is not constant-time; this is a genuine language/runtime boundary (see docs §7.1),
26
+ * not a shortcut — full constant-time needs a native/WASM constant-time field, exactly as the TEE
27
+ * seam needs real hardware. We add what is cheap and honest (constant-time byte comparison for
28
+ * commitments lives in `ot.ts`), and do not pretend the field layer is constant-time.
29
+ * - Discrete log in the order-`L` subgroup is the hardness the OT's receiver-choice privacy relies on.
30
+ */
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.PointValidationError = exports.BASE = exports.IDENTITY = exports.L = exports.Q = void 0;
33
+ exports.modFq = modFq;
34
+ exports.add = add;
35
+ exports.dbl = dbl;
36
+ exports.mul = mul;
37
+ exports.mulBase = mulBase;
38
+ exports.sub = sub;
39
+ exports.neg = neg;
40
+ exports.toAffine = toAffine;
41
+ exports.equal = equal;
42
+ exports.encodePoint = encodePoint;
43
+ exports.isOnCurve = isOnCurve;
44
+ exports.isIdentity = isIdentity;
45
+ exports.hasPrimeOrder = hasPrimeOrder;
46
+ exports.isInSubgroup = isInSubgroup;
47
+ exports.assertInSubgroup = assertInSubgroup;
48
+ exports.schnorrProve = schnorrProve;
49
+ exports.schnorrVerify = schnorrVerify;
50
+ const node_crypto_1 = require("node:crypto");
51
+ /** Field prime q = 2^255 − 19. */
52
+ exports.Q = 2n ** 255n - 19n;
53
+ /** Prime order of the base-point subgroup. Scalars live in [0, L). */
54
+ exports.L = 2n ** 252n + 27742317777372353535851937790883648493n;
55
+ // d = −121665 / 121666 (mod q).
56
+ const D = modFq(-121665n * invFq(121666n));
57
+ /** The identity (neutral) element, affine (0, 1). */
58
+ exports.IDENTITY = { X: 0n, Y: 1n, Z: 1n, T: 0n };
59
+ /** The standard Ed25519 base point B (a generator of the order-L subgroup). */
60
+ exports.BASE = fromAffine(15112221349535400772501151409588531511454012693041857206046113283949847762202n, 46316835694926478169428394003475163141307993866256225615783033603165251855960n);
61
+ /** Canonical representative in [0, q). */
62
+ function modFq(x) {
63
+ const r = x % exports.Q;
64
+ return r >= 0n ? r : r + exports.Q;
65
+ }
66
+ /** Modular inverse in F_q via Fermat (q prime): a^(q−2). */
67
+ function invFq(a) {
68
+ return powFq(modFq(a), exports.Q - 2n);
69
+ }
70
+ function powFq(base, exp) {
71
+ let b = modFq(base);
72
+ let e = exp;
73
+ let acc = 1n;
74
+ while (e > 0n) {
75
+ if (e & 1n)
76
+ acc = (acc * b) % exports.Q;
77
+ b = (b * b) % exports.Q;
78
+ e >>= 1n;
79
+ }
80
+ return acc;
81
+ }
82
+ function fromAffine(x, y) {
83
+ const X = modFq(x);
84
+ const Y = modFq(y);
85
+ return { X, Y, Z: 1n, T: modFq(X * Y) };
86
+ }
87
+ /**
88
+ * Unified complete addition (twisted Edwards a=−1, "add-2008-hwcd-3"). Works for P=Q too (so doubling
89
+ * is just `add(P, P)`), and is complete on the prime-order subgroup — no exceptional cases.
90
+ */
91
+ function add(p1, p2) {
92
+ const A = (modFq(p1.Y - p1.X) * modFq(p2.Y - p2.X)) % exports.Q;
93
+ const B = (modFq(p1.Y + p1.X) * modFq(p2.Y + p2.X)) % exports.Q;
94
+ const C = (((p1.T * 2n) % exports.Q) * D % exports.Q) * p2.T % exports.Q;
95
+ const Dd = (((p1.Z * 2n) % exports.Q) * p2.Z) % exports.Q;
96
+ const E = modFq(B - A);
97
+ const F = modFq(Dd - C);
98
+ const G = modFq(Dd + C);
99
+ const H = modFq(B + A);
100
+ return {
101
+ X: (E * F) % exports.Q,
102
+ Y: (G * H) % exports.Q,
103
+ T: (E * H) % exports.Q,
104
+ Z: (F * G) % exports.Q,
105
+ };
106
+ }
107
+ /**
108
+ * Dedicated doubling (twisted Edwards a=−1, "dbl-2008-hwcd") — cheaper than the unified add, used to
109
+ * speed up the scalar ladder. Complete on the subgroup.
110
+ */
111
+ function dbl(p) {
112
+ const A = (p.X * p.X) % exports.Q;
113
+ const B = (p.Y * p.Y) % exports.Q;
114
+ const C = (2n * ((p.Z * p.Z) % exports.Q)) % exports.Q;
115
+ const Dd = modFq(-A); // a·A with a = −1
116
+ const s = modFq(p.X + p.Y);
117
+ const E = modFq((s * s) % exports.Q - A - B);
118
+ const G = modFq(Dd + B);
119
+ const F = modFq(G - C);
120
+ const H = modFq(Dd - B);
121
+ return {
122
+ X: (E * F) % exports.Q,
123
+ Y: (G * H) % exports.Q,
124
+ T: (E * H) % exports.Q,
125
+ Z: (F * G) % exports.Q,
126
+ };
127
+ }
128
+ /** Scalar multiplication [k]P (double-and-add). k is reduced mod L; k=0 ⇒ identity. */
129
+ function mul(k, p) {
130
+ let e = k % exports.L;
131
+ if (e < 0n)
132
+ e += exports.L;
133
+ let acc = exports.IDENTITY;
134
+ let base = p;
135
+ while (e > 0n) {
136
+ if (e & 1n)
137
+ acc = add(acc, base);
138
+ base = dbl(base);
139
+ e >>= 1n;
140
+ }
141
+ return acc;
142
+ }
143
+ /** [k]·BASE. */
144
+ function mulBase(k) {
145
+ return mul(k, exports.BASE);
146
+ }
147
+ /** P − Q. */
148
+ function sub(p1, p2) {
149
+ return add(p1, neg(p2));
150
+ }
151
+ /** −P = (−X : Y : Z : −T). */
152
+ function neg(p) {
153
+ return { X: modFq(-p.X), Y: p.Y, Z: p.Z, T: modFq(-p.T) };
154
+ }
155
+ /** Affine (x, y) of a point (one inversion). Identity ⇒ (0, 1). */
156
+ function toAffine(p) {
157
+ const zinv = invFq(p.Z);
158
+ return { x: modFq(p.X * zinv), y: modFq(p.Y * zinv) };
159
+ }
160
+ /** Whether two points are equal as group elements (compare in affine). */
161
+ function equal(p1, p2) {
162
+ // X1*Z2 == X2*Z1 and Y1*Z2 == Y2*Z1 (projective equality, no inversion).
163
+ return (modFq(p1.X * p2.Z) === modFq(p2.X * p1.Z) && modFq(p1.Y * p2.Z) === modFq(p2.Y * p1.Z));
164
+ }
165
+ /** 32-byte little-endian encoding of a field element (for hashing points deterministically). */
166
+ function feBytes(a) {
167
+ const out = new Uint8Array(32);
168
+ let v = modFq(a);
169
+ for (let i = 0; i < 32; i++) {
170
+ out[i] = Number(v & 0xffn);
171
+ v >>= 8n;
172
+ }
173
+ return out;
174
+ }
175
+ /** Canonical 64-byte encoding of a point (affine x‖y), the input to the OT key-derivation hash. */
176
+ function encodePoint(p) {
177
+ const { x, y } = toAffine(p);
178
+ const out = new Uint8Array(64);
179
+ out.set(feBytes(x), 0);
180
+ out.set(feBytes(y), 32);
181
+ return out;
182
+ }
183
+ // ==================================================================================================
184
+ // POINT VALIDATION (malicious-security hardening, docs §7.1 item b).
185
+ //
186
+ // A party must never trust a group element received from a (possibly malicious) peer. Three checks
187
+ // together reject every point that could enable a small-subgroup / invalid-curve attack:
188
+ // (1) on-curve: the extended coordinates satisfy the twisted-Edwards equation (and the T-invariant),
189
+ // (2) subgroup: [L]·P = O, the cofactor check — rejects small-order (order | 8) AND mixed-order
190
+ // points, so only genuine order-L (prime-order subgroup) points survive,
191
+ // (3) non-identity where the protocol forbids it (S = y·B with y = 0, or a degenerate R).
192
+ // These are wired into every OT point decode in `ot.ts`.
193
+ // ==================================================================================================
194
+ /** Raised when a received point fails on-curve / subgroup / identity validation. */
195
+ class PointValidationError extends Error {
196
+ constructor(message) {
197
+ super(message);
198
+ this.name = 'PointValidationError';
199
+ }
200
+ }
201
+ exports.PointValidationError = PointValidationError;
202
+ /**
203
+ * Scalar multiplication `[k]·P` WITHOUT the mod-L reduction that `mul` applies. `mul` reduces `k mod L`
204
+ * (correct for subgroup scalars, but it would turn `[L]·P` into `[0]·P = O` for every P and so cannot
205
+ * test subgroup membership). This raw ladder is used only by `hasPrimeOrder`.
206
+ */
207
+ function scalarMulRaw(k, p) {
208
+ let e = k < 0n ? -k : k;
209
+ let acc = exports.IDENTITY;
210
+ let base = p;
211
+ while (e > 0n) {
212
+ if (e & 1n)
213
+ acc = add(acc, base);
214
+ base = dbl(base);
215
+ e >>= 1n;
216
+ }
217
+ return acc;
218
+ }
219
+ /**
220
+ * Whether `p`'s extended coordinates lie on the Ed25519 curve. Checks projectively (no inversion):
221
+ * - `Z ≠ 0` (a valid projective point),
222
+ * - the T-invariant `T·Z ≡ X·Y`,
223
+ * - the twisted-Edwards equation (`a = −1`) cleared of denominators: `(Y² − X²)·Z² ≡ Z⁴ + d·X²·Y²`.
224
+ * An off-curve / malformed point fails here before any scalar work.
225
+ */
226
+ function isOnCurve(p) {
227
+ if (modFq(p.Z) === 0n)
228
+ return false;
229
+ if (modFq(p.T * p.Z) !== modFq(p.X * p.Y))
230
+ return false;
231
+ const X2 = modFq(p.X * p.X);
232
+ const Y2 = modFq(p.Y * p.Y);
233
+ const Z2 = modFq(p.Z * p.Z);
234
+ const lhs = modFq((Y2 - X2) * Z2);
235
+ const Z4 = modFq(Z2 * Z2);
236
+ const dxy = modFq(modFq(D * X2) * Y2);
237
+ const rhs = modFq(Z4 + dxy);
238
+ return lhs === rhs;
239
+ }
240
+ /** Whether `p` is the identity (neutral) element (affine `(0, 1)`). */
241
+ function isIdentity(p) {
242
+ return equal(p, exports.IDENTITY);
243
+ }
244
+ /**
245
+ * The cofactor check: whether `[L]·P = O`, i.e. `p` lies in the prime-order-`L` subgroup. For an
246
+ * on-curve point this is true iff `p` has order dividing `L`; since `L` is prime this means order `1`
247
+ * (identity) or order `L`. So on-curve ∧ `hasPrimeOrder` ∧ ¬identity ⟺ a genuine prime-order point.
248
+ * Rejects every small-order point (order | 8) and every mixed-order point (order `h·L`, `h | 8`, `h>1`).
249
+ */
250
+ function hasPrimeOrder(p) {
251
+ return equal(scalarMulRaw(exports.L, p), exports.IDENTITY);
252
+ }
253
+ /** Whether `p` is a valid non-identity point of the prime-order subgroup (the OT point contract). */
254
+ function isInSubgroup(p) {
255
+ return isOnCurve(p) && !isIdentity(p) && hasPrimeOrder(p);
256
+ }
257
+ /** Assert `p` is a valid non-identity prime-order-subgroup point, else throw `PointValidationError`. */
258
+ function assertInSubgroup(p, label = 'point') {
259
+ if (!isOnCurve(p))
260
+ throw new PointValidationError(`${label}: not on curve`);
261
+ if (isIdentity(p))
262
+ throw new PointValidationError(`${label}: identity element (forbidden here)`);
263
+ if (!hasPrimeOrder(p)) {
264
+ throw new PointValidationError(`${label}: not in the prime-order subgroup (small-order/cofactor)`);
265
+ }
266
+ }
267
+ const TAG_SCHNORR = new TextEncoder().encode('atlas-pca-mpc/schnorr-dlog');
268
+ /** Fiat–Shamir challenge `e = H(tag ‖ B ‖ S ‖ U) mod L` (64 hash bytes ⇒ negligible modular bias). */
269
+ function schnorrChallenge(S, U) {
270
+ const d = (0, node_crypto_1.createHash)('sha512')
271
+ .update(TAG_SCHNORR)
272
+ .update(encodePoint(exports.BASE))
273
+ .update(encodePoint(S))
274
+ .update(encodePoint(U))
275
+ .digest();
276
+ let acc = 0n;
277
+ for (const b of d)
278
+ acc = (acc << 8n) | BigInt(b);
279
+ return acc % exports.L;
280
+ }
281
+ /** Prove knowledge of `y` with `S = y·B`. `rnd` draws the (secret) nonce `r ∈ [1, L)`. */
282
+ function schnorrProve(y, S, rnd) {
283
+ // The nonce must be a non-zero subgroup scalar; `rnd` already draws from [1, L), the guard is belt-and-braces.
284
+ let r = ((rnd() % exports.L) + exports.L) % exports.L;
285
+ if (r === 0n)
286
+ r = 1n;
287
+ const U = mulBase(r);
288
+ const e = schnorrChallenge(S, U);
289
+ let z = (r + e * (((y % exports.L) + exports.L) % exports.L)) % exports.L;
290
+ if (z < 0n)
291
+ z += exports.L;
292
+ return { U, z };
293
+ }
294
+ /**
295
+ * Verify a Schnorr proof for `S`: `z` is in range, `U` is a valid subgroup point, and `z·B = U + e·S`
296
+ * for the recomputed challenge `e`. Returns false on any failure (the OT layer turns that into an abort).
297
+ */
298
+ function schnorrVerify(S, proof) {
299
+ if (proof.z < 0n || proof.z >= exports.L)
300
+ return false;
301
+ if (!isInSubgroup(proof.U))
302
+ return false;
303
+ const e = schnorrChallenge(S, proof.U);
304
+ return equal(mulBase(proof.z), add(proof.U, mul(e, S)));
305
+ }
306
+ //# sourceMappingURL=ec.js.map
package/dist/ec.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ec.js","sourceRoot":"","sources":["../src/ec.ts"],"names":[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AAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Arithmetic in the prime field F_p used for additive secret sharing.
3
+ *
4
+ * p = 2^61 - 1 (the Mersenne prime M61). It is wider than any value the composition ever shares
5
+ * (bits, thermometer bits, small sums), so no secret ever wraps; sharing randomness lives in the
6
+ * full field so that any single share is (information-theoretically) uniform and independent of the
7
+ * secret. All arithmetic is BigInt and exact — never floating point — so the protocol is
8
+ * bit-deterministic and verifier-reproducible.
9
+ *
10
+ * RANDOMNESS (docs §7.1 item "CSPRNG — done"): the `FieldRng` below is a deterministic SplitMix64, kept
11
+ * ONLY for bit-reproducible tests behind an explicit seed. It is NOT the default: the protocol draws
12
+ * all sharing/triple/MAC randomness from the CSPRNG `SecureFieldRng` / `secureOtRandom` in `csprng.ts`
13
+ * (`node:crypto.randomBytes`) unless a test explicitly asks for the seeded stream. `SecureFieldRng`
14
+ * extends this class and overrides `next()`, so it is a drop-in wherever a `FieldRng` is accepted.
15
+ */
16
+ export declare const PRIME: bigint;
17
+ /** Canonical representative in [0, p). */
18
+ export declare function mod(x: bigint): bigint;
19
+ export declare const fadd: (a: bigint, b: bigint) => bigint;
20
+ export declare const fsub: (a: bigint, b: bigint) => bigint;
21
+ export declare const fmul: (a: bigint, b: bigint) => bigint;
22
+ export declare const fneg: (a: bigint) => bigint;
23
+ /**
24
+ * Deterministic SplitMix64, drawing UNBIASED field elements by rejection sampling (reject the top
25
+ * 2^64 mod p = 8 residues so the modulo is exactly uniform). Deterministic for reproducible tests;
26
+ * see the security note above for production.
27
+ */
28
+ export declare class FieldRng {
29
+ private s;
30
+ constructor(seed?: bigint);
31
+ private nextU64;
32
+ /** Uniform element of F_p (unbiased). */
33
+ next(): bigint;
34
+ }
package/dist/field.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * Arithmetic in the prime field F_p used for additive secret sharing.
4
+ *
5
+ * p = 2^61 - 1 (the Mersenne prime M61). It is wider than any value the composition ever shares
6
+ * (bits, thermometer bits, small sums), so no secret ever wraps; sharing randomness lives in the
7
+ * full field so that any single share is (information-theoretically) uniform and independent of the
8
+ * secret. All arithmetic is BigInt and exact — never floating point — so the protocol is
9
+ * bit-deterministic and verifier-reproducible.
10
+ *
11
+ * RANDOMNESS (docs §7.1 item "CSPRNG — done"): the `FieldRng` below is a deterministic SplitMix64, kept
12
+ * ONLY for bit-reproducible tests behind an explicit seed. It is NOT the default: the protocol draws
13
+ * all sharing/triple/MAC randomness from the CSPRNG `SecureFieldRng` / `secureOtRandom` in `csprng.ts`
14
+ * (`node:crypto.randomBytes`) unless a test explicitly asks for the seeded stream. `SecureFieldRng`
15
+ * extends this class and overrides `next()`, so it is a drop-in wherever a `FieldRng` is accepted.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.FieldRng = exports.fneg = exports.fmul = exports.fsub = exports.fadd = exports.PRIME = void 0;
19
+ exports.mod = mod;
20
+ exports.PRIME = 2n ** 61n - 1n;
21
+ const MASK64 = (1n << 64n) - 1n;
22
+ /** Canonical representative in [0, p). */
23
+ function mod(x) {
24
+ const r = x % exports.PRIME;
25
+ return r >= 0n ? r : r + exports.PRIME;
26
+ }
27
+ const fadd = (a, b) => mod(a + b);
28
+ exports.fadd = fadd;
29
+ const fsub = (a, b) => mod(a - b);
30
+ exports.fsub = fsub;
31
+ const fmul = (a, b) => mod(a * b);
32
+ exports.fmul = fmul;
33
+ const fneg = (a) => mod(-a);
34
+ exports.fneg = fneg;
35
+ /**
36
+ * Deterministic SplitMix64, drawing UNBIASED field elements by rejection sampling (reject the top
37
+ * 2^64 mod p = 8 residues so the modulo is exactly uniform). Deterministic for reproducible tests;
38
+ * see the security note above for production.
39
+ */
40
+ class FieldRng {
41
+ s;
42
+ constructor(seed = 0x243f6a8885a308d3n) {
43
+ this.s = seed & MASK64;
44
+ }
45
+ nextU64() {
46
+ this.s = (this.s + 0x9e3779b97f4a7c15n) & MASK64;
47
+ let z = this.s;
48
+ z = ((z ^ (z >> 30n)) * 0xbf58476d1ce4e5b9n) & MASK64;
49
+ z = ((z ^ (z >> 27n)) * 0x94d049bb133111ebn) & MASK64;
50
+ z = (z ^ (z >> 31n)) & MASK64;
51
+ return z;
52
+ }
53
+ /** Uniform element of F_p (unbiased). */
54
+ next() {
55
+ // Largest multiple of p that fits in 64 bits; drop anything at or above it so `% PRIME` is uniform.
56
+ const limit = ((MASK64 + 1n) / exports.PRIME) * exports.PRIME;
57
+ for (;;) {
58
+ const u = this.nextU64();
59
+ if (u < limit)
60
+ return u % exports.PRIME;
61
+ }
62
+ }
63
+ }
64
+ exports.FieldRng = FieldRng;
65
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAOH,kBAGC;AARY,QAAA,KAAK,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC;AAEpC,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AAEhC,0CAA0C;AAC1C,SAAgB,GAAG,CAAC,CAAS;IAC3B,MAAM,CAAC,GAAG,CAAC,GAAG,aAAK,CAAC;IACpB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,aAAK,CAAC;AACjC,CAAC;AAEM,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAApD,QAAA,IAAI,QAAgD;AAC1D,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAApD,QAAA,IAAI,QAAgD;AAC1D,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,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-extension consistency check (KOS) folds every row of the extension matrix
5
+ * into a single random linear combination over GF(2^κ) with κ = 128, and verifies one field equation.
6
+ * A cheating receiver who deviates in the extension matrix passes that equation with probability at
7
+ * most `2^{-128}` (the field size), which is what upgrades IKNP from semi-honest to malicious-secure.
8
+ *
9
+ * We use the standard GF(2^128) with reduction polynomial `x^128 + x^7 + x^2 + x + 1` (the GCM /
10
+ * "0x87" polynomial). Elements are 128-bit `bigint`s, bit `i` = coefficient of `x^i`. Addition is XOR.
11
+ * Multiplication is schoolbook carryless multiply with reduction; `mulByXi` (multiply by `x^i`) is the
12
+ * repeated-shift form used by the column-domain check so the hot path pays no full 128×128 multiply
13
+ * per row. This is a textbook field (BigInt, not constant-time) — sound for the in-process prototype;
14
+ * see docs §7.1 for the constant-time boundary.
15
+ */
16
+ /** Field addition in GF(2^128): XOR (masked to 128 bits). */
17
+ export declare function gf128Add(a: bigint, b: bigint): bigint;
18
+ /** Multiply by `x` (one step of the LFSR): shift left 1, reduce if it overflowed bit 127. */
19
+ export declare function gf128MulX(v: bigint): bigint;
20
+ /** Multiply by `x^i` (i ≥ 0): i LFSR steps. Used by the column-domain KOS fold. */
21
+ export declare function gf128MulByXi(v: bigint, i: number): bigint;
22
+ /** Full GF(2^128) multiplication (carryless multiply + reduction), right-to-left over the bits of `b`. */
23
+ export declare function gf128Mul(a: bigint, b: bigint): bigint;
package/dist/gf128.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * GF(2^128) arithmetic — the field the KOS correlation check lives in (`ot.ts`).
4
+ *
5
+ * The malicious-secure OT-extension consistency check (KOS) folds every row of the extension matrix
6
+ * into a single random linear combination over GF(2^κ) with κ = 128, and verifies one field equation.
7
+ * A cheating receiver who deviates in the extension matrix passes that equation with probability at
8
+ * most `2^{-128}` (the field size), which is what upgrades IKNP from semi-honest to malicious-secure.
9
+ *
10
+ * We use the standard GF(2^128) with reduction polynomial `x^128 + x^7 + x^2 + x + 1` (the GCM /
11
+ * "0x87" polynomial). Elements are 128-bit `bigint`s, bit `i` = coefficient of `x^i`. Addition is XOR.
12
+ * Multiplication is schoolbook carryless multiply with reduction; `mulByXi` (multiply by `x^i`) is the
13
+ * repeated-shift form used by the column-domain check so the hot path pays no full 128×128 multiply
14
+ * per row. This is a textbook field (BigInt, not constant-time) — sound for the in-process prototype;
15
+ * see docs §7.1 for the constant-time boundary.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.gf128Add = gf128Add;
19
+ exports.gf128MulX = gf128MulX;
20
+ exports.gf128MulByXi = gf128MulByXi;
21
+ exports.gf128Mul = gf128Mul;
22
+ /** 128-bit mask. */
23
+ const MASK128 = (1n << 128n) - 1n;
24
+ /**
25
+ * The reduction tail for `x^128 + x^7 + x^2 + x + 1`: when a shift pushes a 1 past bit 127, we have
26
+ * `x^128 ≡ x^7 + x^2 + x + 1 = 0x87`, so we XOR `0x87` back in.
27
+ */
28
+ const GF128_RED = (1n << 7n) | (1n << 2n) | (1n << 1n) | 1n; // 0x87
29
+ /** Field addition in GF(2^128): XOR (masked to 128 bits). */
30
+ function gf128Add(a, b) {
31
+ return (a ^ b) & MASK128;
32
+ }
33
+ /** Multiply by `x` (one step of the LFSR): shift left 1, reduce if it overflowed bit 127. */
34
+ function gf128MulX(v) {
35
+ const carry = (v >> 127n) & 1n;
36
+ let r = (v << 1n) & MASK128;
37
+ if (carry)
38
+ r ^= GF128_RED;
39
+ return r;
40
+ }
41
+ /** Multiply by `x^i` (i ≥ 0): i LFSR steps. Used by the column-domain KOS fold. */
42
+ function gf128MulByXi(v, i) {
43
+ let r = v & MASK128;
44
+ for (let k = 0; k < i; k++)
45
+ r = gf128MulX(r);
46
+ return r;
47
+ }
48
+ /** Full GF(2^128) multiplication (carryless multiply + reduction), right-to-left over the bits of `b`. */
49
+ function gf128Mul(a, b) {
50
+ let res = 0n;
51
+ let v = a & MASK128;
52
+ for (let i = 0; i < 128; i++) {
53
+ if ((b >> BigInt(i)) & 1n)
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C,CAAS,EAAE,CAAS;IAC3C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE;YAAE,GAAG,IAAI,CAAC,CAAC;QACpC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,GAAG,OAAO,CAAC;AACvB,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @atlasauth/pca-mpc — PCA evolution B5 reference prototype.
3
+ *
4
+ * A multi-stakeholder Policy VM composed under secure multi-party computation, so user + org +
5
+ * regulator decide allow / threshold jointly WITHOUT any party revealing its own policy. Two layers:
6
+ * - SEMI-HONEST: additive secret sharing over a prime field + Beaver-triple multiplication
7
+ * (`sharing.ts`, `beaver.ts`, `runner.ts`).
8
+ * - MALICIOUS-WITH-ABORT (dishonest-majority): SPDZ-style authenticated sharing with
9
+ * information-theoretic MACs + a commit-then-open MAC-check that ABORTS on any deviation
10
+ * (`spdz.ts`, `spdz-runner.ts`). Result is correct, or an abort — never a silent wrong answer.
11
+ * See docs/specs/pca-mpc-policy-vm.md for the security model and the trusted-dealer / no-dealer boundary.
12
+ */
13
+ export * from './field';
14
+ export * from './sharing';
15
+ export * from './beaver';
16
+ export * from './thermometer';
17
+ export * from './party';
18
+ export * from './compose';
19
+ export * from './runner';
20
+ export * from './spdz';
21
+ export * from './spdz-runner';
22
+ export * from './ec';
23
+ export * from './gf128';
24
+ export * from './csprng';
25
+ export * from './ot';
26
+ export * from './kem-ot';
27
+ export * from './mascot';
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * @atlasauth/pca-mpc — PCA evolution B5 reference prototype.
4
+ *
5
+ * A multi-stakeholder Policy VM composed under secure multi-party computation, so user + org +
6
+ * regulator decide allow / threshold jointly WITHOUT any party revealing its own policy. Two layers:
7
+ * - SEMI-HONEST: additive secret sharing over a prime field + Beaver-triple multiplication
8
+ * (`sharing.ts`, `beaver.ts`, `runner.ts`).
9
+ * - MALICIOUS-WITH-ABORT (dishonest-majority): SPDZ-style authenticated sharing with
10
+ * information-theoretic MACs + a commit-then-open MAC-check that ABORTS on any deviation
11
+ * (`spdz.ts`, `spdz-runner.ts`). Result is correct, or an abort — never a silent wrong answer.
12
+ * See docs/specs/pca-mpc-policy-vm.md for the security model and the trusted-dealer / no-dealer boundary.
13
+ */
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ __exportStar(require("./field"), exports);
30
+ __exportStar(require("./sharing"), exports);
31
+ __exportStar(require("./beaver"), exports);
32
+ __exportStar(require("./thermometer"), exports);
33
+ __exportStar(require("./party"), exports);
34
+ __exportStar(require("./compose"), exports);
35
+ __exportStar(require("./runner"), exports);
36
+ __exportStar(require("./spdz"), exports);
37
+ __exportStar(require("./spdz-runner"), exports);
38
+ __exportStar(require("./ec"), exports);
39
+ __exportStar(require("./gf128"), exports);
40
+ __exportStar(require("./csprng"), exports);
41
+ __exportStar(require("./ot"), exports);
42
+ __exportStar(require("./kem-ot"), exports);
43
+ __exportStar(require("./mascot"), exports);
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,4CAA0B;AAC1B,2CAAyB;AACzB,gDAA8B;AAC9B,0CAAwB;AACxB,4CAA0B;AAC1B,2CAAyB;AACzB,yCAAuB;AACvB,gDAA8B;AAC9B,uCAAqB;AACrB,0CAAwB;AACxB,2CAAyB;AACzB,uCAAqB;AACrB,2CAAyB;AACzB,2CAAyB"}