@stevenvo780/st-lang 4.8.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/logic/profiles/quantum/index.d.ts +153 -0
- package/dist/logic/profiles/quantum/index.d.ts.map +1 -0
- package/dist/logic/profiles/quantum/index.js +788 -0
- package/dist/logic/profiles/quantum/index.js.map +1 -0
- package/dist/namespaces/reasoning.d.ts +2 -1
- package/dist/namespaces/reasoning.d.ts.map +1 -1
- package/dist/namespaces/reasoning.js +3 -1
- package/dist/namespaces/reasoning.js.map +1 -1
- package/dist/proof-systems/certificate/canonical.d.ts +18 -0
- package/dist/proof-systems/certificate/canonical.d.ts.map +1 -0
- package/dist/proof-systems/certificate/canonical.js +79 -0
- package/dist/proof-systems/certificate/canonical.js.map +1 -0
- package/dist/proof-systems/certificate/generate.d.ts +39 -0
- package/dist/proof-systems/certificate/generate.d.ts.map +1 -0
- package/dist/proof-systems/certificate/generate.js +259 -0
- package/dist/proof-systems/certificate/generate.js.map +1 -0
- package/dist/proof-systems/certificate/index.d.ts +7 -0
- package/dist/proof-systems/certificate/index.d.ts.map +1 -0
- package/dist/proof-systems/certificate/index.js +23 -0
- package/dist/proof-systems/certificate/index.js.map +1 -0
- package/dist/proof-systems/certificate/lfsc.d.ts +15 -0
- package/dist/proof-systems/certificate/lfsc.d.ts.map +1 -0
- package/dist/proof-systems/certificate/lfsc.js +395 -0
- package/dist/proof-systems/certificate/lfsc.js.map +1 -0
- package/dist/proof-systems/certificate/rules.d.ts +8 -0
- package/dist/proof-systems/certificate/rules.d.ts.map +1 -0
- package/dist/proof-systems/certificate/rules.js +369 -0
- package/dist/proof-systems/certificate/rules.js.map +1 -0
- package/dist/proof-systems/certificate/types.d.ts +114 -0
- package/dist/proof-systems/certificate/types.d.ts.map +1 -0
- package/dist/proof-systems/certificate/types.js +18 -0
- package/dist/proof-systems/certificate/types.js.map +1 -0
- package/dist/proof-systems/certificate/verify.d.ts +20 -0
- package/dist/proof-systems/certificate/verify.d.ts.map +1 -0
- package/dist/proof-systems/certificate/verify.js +171 -0
- package/dist/proof-systems/certificate/verify.js.map +1 -0
- package/dist/reasoning/ban-logic/analyze.d.ts +31 -0
- package/dist/reasoning/ban-logic/analyze.d.ts.map +1 -0
- package/dist/reasoning/ban-logic/analyze.js +113 -0
- package/dist/reasoning/ban-logic/analyze.js.map +1 -0
- package/dist/reasoning/ban-logic/index.d.ts +7 -0
- package/dist/reasoning/ban-logic/index.d.ts.map +1 -0
- package/dist/reasoning/ban-logic/index.js +66 -0
- package/dist/reasoning/ban-logic/index.js.map +1 -0
- package/dist/reasoning/ban-logic/protocols.d.ts +54 -0
- package/dist/reasoning/ban-logic/protocols.d.ts.map +1 -0
- package/dist/reasoning/ban-logic/protocols.js +219 -0
- package/dist/reasoning/ban-logic/protocols.js.map +1 -0
- package/dist/reasoning/ban-logic/rules.d.ts +83 -0
- package/dist/reasoning/ban-logic/rules.d.ts.map +1 -0
- package/dist/reasoning/ban-logic/rules.js +409 -0
- package/dist/reasoning/ban-logic/rules.js.map +1 -0
- package/dist/reasoning/ban-logic/terms.d.ts +26 -0
- package/dist/reasoning/ban-logic/terms.d.ts.map +1 -0
- package/dist/reasoning/ban-logic/terms.js +262 -0
- package/dist/reasoning/ban-logic/terms.js.map +1 -0
- package/dist/reasoning/ban-logic/types.d.ts +107 -0
- package/dist/reasoning/ban-logic/types.d.ts.map +1 -0
- package/dist/reasoning/ban-logic/types.js +27 -0
- package/dist/reasoning/ban-logic/types.js.map +1 -0
- package/dist/reasoning/differential-privacy/index.d.ts +121 -0
- package/dist/reasoning/differential-privacy/index.d.ts.map +1 -0
- package/dist/reasoning/differential-privacy/index.js +417 -0
- package/dist/reasoning/differential-privacy/index.js.map +1 -0
- package/dist/tests/logic/profiles/quantum/quantum.test.d.ts +2 -0
- package/dist/tests/logic/profiles/quantum/quantum.test.d.ts.map +1 -0
- package/dist/tests/logic/profiles/quantum/quantum.test.js +209 -0
- package/dist/tests/logic/profiles/quantum/quantum.test.js.map +1 -0
- package/dist/tests/proof-systems/certificate/certificate.test.d.ts +2 -0
- package/dist/tests/proof-systems/certificate/certificate.test.d.ts.map +1 -0
- package/dist/tests/proof-systems/certificate/certificate.test.js +449 -0
- package/dist/tests/proof-systems/certificate/certificate.test.js.map +1 -0
- package/dist/tests/reasoning/ban-logic/ban-logic.test.d.ts +2 -0
- package/dist/tests/reasoning/ban-logic/ban-logic.test.d.ts.map +1 -0
- package/dist/tests/reasoning/ban-logic/ban-logic.test.js +270 -0
- package/dist/tests/reasoning/ban-logic/ban-logic.test.js.map +1 -0
- package/dist/tests/reasoning/differential-privacy/differential-privacy.test.d.ts +2 -0
- package/dist/tests/reasoning/differential-privacy/differential-privacy.test.d.ts.map +1 -0
- package/dist/tests/reasoning/differential-privacy/differential-privacy.test.js +388 -0
- package/dist/tests/reasoning/differential-privacy/differential-privacy.test.js.map +1 -0
- package/dist/tests/tooling/mathlib/mathlib.test.d.ts +2 -0
- package/dist/tests/tooling/mathlib/mathlib.test.d.ts.map +1 -0
- package/dist/tests/tooling/mathlib/mathlib.test.js +214 -0
- package/dist/tests/tooling/mathlib/mathlib.test.js.map +1 -0
- package/dist/tests/type-theory/effects/effects.test.d.ts +2 -0
- package/dist/tests/type-theory/effects/effects.test.d.ts.map +1 -0
- package/dist/tests/type-theory/effects/effects.test.js +242 -0
- package/dist/tests/type-theory/effects/effects.test.js.map +1 -0
- package/dist/tooling/mathlib/group.d.ts +27 -0
- package/dist/tooling/mathlib/group.d.ts.map +1 -0
- package/dist/tooling/mathlib/group.js +89 -0
- package/dist/tooling/mathlib/group.js.map +1 -0
- package/dist/tooling/mathlib/index.d.ts +8 -0
- package/dist/tooling/mathlib/index.d.ts.map +1 -0
- package/dist/tooling/mathlib/index.js +40 -0
- package/dist/tooling/mathlib/index.js.map +1 -0
- package/dist/tooling/mathlib/instances.d.ts +29 -0
- package/dist/tooling/mathlib/instances.d.ts.map +1 -0
- package/dist/tooling/mathlib/instances.js +139 -0
- package/dist/tooling/mathlib/instances.js.map +1 -0
- package/dist/tooling/mathlib/lemmas.d.ts +3 -0
- package/dist/tooling/mathlib/lemmas.d.ts.map +1 -0
- package/dist/tooling/mathlib/lemmas.js +72 -0
- package/dist/tooling/mathlib/lemmas.js.map +1 -0
- package/dist/tooling/mathlib/order.d.ts +29 -0
- package/dist/tooling/mathlib/order.d.ts.map +1 -0
- package/dist/tooling/mathlib/order.js +91 -0
- package/dist/tooling/mathlib/order.js.map +1 -0
- package/dist/tooling/mathlib/ring.d.ts +15 -0
- package/dist/tooling/mathlib/ring.d.ts.map +1 -0
- package/dist/tooling/mathlib/ring.js +91 -0
- package/dist/tooling/mathlib/ring.js.map +1 -0
- package/dist/tooling/mathlib/types.d.ts +62 -0
- package/dist/tooling/mathlib/types.d.ts.map +1 -0
- package/dist/tooling/mathlib/types.js +7 -0
- package/dist/tooling/mathlib/types.js.map +1 -0
- package/dist/type-theory/effects/core.d.ts +27 -0
- package/dist/type-theory/effects/core.d.ts.map +1 -0
- package/dist/type-theory/effects/core.js +79 -0
- package/dist/type-theory/effects/core.js.map +1 -0
- package/dist/type-theory/effects/exception.d.ts +18 -0
- package/dist/type-theory/effects/exception.d.ts.map +1 -0
- package/dist/type-theory/effects/exception.js +59 -0
- package/dist/type-theory/effects/exception.js.map +1 -0
- package/dist/type-theory/effects/index.d.ts +11 -0
- package/dist/type-theory/effects/index.d.ts.map +1 -0
- package/dist/type-theory/effects/index.js +50 -0
- package/dist/type-theory/effects/index.js.map +1 -0
- package/dist/type-theory/effects/reader.d.ts +20 -0
- package/dist/type-theory/effects/reader.d.ts.map +1 -0
- package/dist/type-theory/effects/reader.js +62 -0
- package/dist/type-theory/effects/reader.js.map +1 -0
- package/dist/type-theory/effects/state.d.ts +31 -0
- package/dist/type-theory/effects/state.d.ts.map +1 -0
- package/dist/type-theory/effects/state.js +91 -0
- package/dist/type-theory/effects/state.js.map +1 -0
- package/dist/type-theory/effects/types.d.ts +45 -0
- package/dist/type-theory/effects/types.d.ts.map +1 -0
- package/dist/type-theory/effects/types.js +21 -0
- package/dist/type-theory/effects/types.js.map +1 -0
- package/dist/type-theory/effects/writer.d.ts +30 -0
- package/dist/type-theory/effects/writer.d.ts.map +1 -0
- package/dist/type-theory/effects/writer.js +79 -0
- package/dist/type-theory/effects/writer.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// ST Proof Certificate — Check-only verifier
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// El verificador NO hace búsqueda de prueba. Asume que el
|
|
7
|
+
// certificado declara cada paso con su regla y premisas, y se
|
|
8
|
+
// limita a:
|
|
9
|
+
// 1. validar integridad (hash + estructura);
|
|
10
|
+
// 2. validar acíclicidad de `depends`;
|
|
11
|
+
// 3. resolver premisas y delegar al `CertRuleChecker` de la regla;
|
|
12
|
+
// 4. comprobar que el goal aparece como conclusión.
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.canonicalize = void 0;
|
|
15
|
+
exports.verifyCertificate = verifyCertificate;
|
|
16
|
+
const canonical_1 = require("./canonical");
|
|
17
|
+
Object.defineProperty(exports, "canonicalize", { enumerable: true, get: function () { return canonical_1.canonicalize; } });
|
|
18
|
+
const rules_1 = require("./rules");
|
|
19
|
+
function detectCycle(steps) {
|
|
20
|
+
const byId = new Map();
|
|
21
|
+
for (const s of steps)
|
|
22
|
+
byId.set(s.id, s);
|
|
23
|
+
const WHITE = 0;
|
|
24
|
+
const GRAY = 1;
|
|
25
|
+
const BLACK = 2;
|
|
26
|
+
const color = new Map();
|
|
27
|
+
for (const s of steps)
|
|
28
|
+
color.set(s.id, WHITE);
|
|
29
|
+
let cyclePath = null;
|
|
30
|
+
function dfs(id, path) {
|
|
31
|
+
color.set(id, GRAY);
|
|
32
|
+
const step = byId.get(id);
|
|
33
|
+
if (!step)
|
|
34
|
+
return false;
|
|
35
|
+
for (const dep of step.depends) {
|
|
36
|
+
const cdep = color.get(dep);
|
|
37
|
+
if (cdep === undefined)
|
|
38
|
+
continue; // missing deps reportadas aparte
|
|
39
|
+
if (cdep === GRAY) {
|
|
40
|
+
const cycleStart = path.indexOf(dep);
|
|
41
|
+
cyclePath = cycleStart >= 0 ? path.slice(cycleStart).concat(dep) : [...path, id, dep];
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (cdep === WHITE) {
|
|
45
|
+
if (dfs(dep, [...path, id]))
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
color.set(id, BLACK);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
for (const s of steps) {
|
|
53
|
+
if (color.get(s.id) === WHITE) {
|
|
54
|
+
if (dfs(s.id, []))
|
|
55
|
+
return cyclePath;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Verifica un certificado en modo check-only.
|
|
62
|
+
*
|
|
63
|
+
* Las reglas custom (parámetro `rules`) se prueban PRIMERO; si no
|
|
64
|
+
* está la regla, se busca en `STANDARD_RULES`. Esto permite a
|
|
65
|
+
* profiles externos extender el conjunto sin tocar el core.
|
|
66
|
+
*/
|
|
67
|
+
async function verifyCertificate(cert, rules = rules_1.STANDARD_RULES) {
|
|
68
|
+
const errors = [];
|
|
69
|
+
const totalSteps = cert.steps.length;
|
|
70
|
+
let stepsVerified = 0;
|
|
71
|
+
// 1. Versión.
|
|
72
|
+
if (cert.version !== '1.0') {
|
|
73
|
+
errors.push(`unsupported certificate version: ${String(cert.version)}`);
|
|
74
|
+
}
|
|
75
|
+
// 2. Hash.
|
|
76
|
+
try {
|
|
77
|
+
const expected = await (0, canonical_1.hashCertificate)({
|
|
78
|
+
version: cert.version,
|
|
79
|
+
goal: cert.goal,
|
|
80
|
+
profile: cert.profile,
|
|
81
|
+
axioms: cert.axioms,
|
|
82
|
+
steps: cert.steps,
|
|
83
|
+
});
|
|
84
|
+
if (expected !== cert.hash) {
|
|
85
|
+
errors.push(`hash mismatch: expected ${expected}, got ${cert.hash}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
errors.push(`hash computation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
90
|
+
}
|
|
91
|
+
// 3. Ids únicos.
|
|
92
|
+
const seenIds = new Set();
|
|
93
|
+
for (const step of cert.steps) {
|
|
94
|
+
if (seenIds.has(step.id)) {
|
|
95
|
+
errors.push(`duplicate step id: ${step.id}`);
|
|
96
|
+
}
|
|
97
|
+
seenIds.add(step.id);
|
|
98
|
+
}
|
|
99
|
+
// 4. Referencias existentes.
|
|
100
|
+
const byId = new Map();
|
|
101
|
+
for (const s of cert.steps)
|
|
102
|
+
byId.set(s.id, s);
|
|
103
|
+
for (const step of cert.steps) {
|
|
104
|
+
for (const dep of step.depends) {
|
|
105
|
+
if (!byId.has(dep)) {
|
|
106
|
+
errors.push(`step "${step.id}" depends on missing step "${dep}"`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// 5. Acíclicidad.
|
|
111
|
+
const cycle = detectCycle(cert.steps);
|
|
112
|
+
if (cycle) {
|
|
113
|
+
errors.push(`cycle detected in depends: ${cycle.join(' -> ')}`);
|
|
114
|
+
}
|
|
115
|
+
// 6. Orden topológico (deps deben aparecer antes que dependientes).
|
|
116
|
+
const indexOf = new Map();
|
|
117
|
+
cert.steps.forEach((s, i) => indexOf.set(s.id, i));
|
|
118
|
+
for (const step of cert.steps) {
|
|
119
|
+
const myIdx = indexOf.get(step.id) ?? -1;
|
|
120
|
+
for (const dep of step.depends) {
|
|
121
|
+
const depIdx = indexOf.get(dep);
|
|
122
|
+
if (depIdx !== undefined && depIdx >= myIdx) {
|
|
123
|
+
errors.push(`step "${step.id}" references "${dep}" out of topological order`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// 7. Goal aparece como conclusión.
|
|
128
|
+
const normalizedGoal = (0, canonical_1.normalizeFormula)(cert.goal);
|
|
129
|
+
const goalFound = cert.steps.some((s) => (0, canonical_1.normalizeFormula)(s.conclusion) === normalizedGoal);
|
|
130
|
+
if (!goalFound && cert.steps.length > 0) {
|
|
131
|
+
errors.push(`goal "${cert.goal}" not produced by any step`);
|
|
132
|
+
}
|
|
133
|
+
// 8. Chequeo regla a regla.
|
|
134
|
+
if (!cycle) {
|
|
135
|
+
for (const step of cert.steps) {
|
|
136
|
+
const checker = rules.get(step.rule) ?? rules_1.STANDARD_RULES.get(step.rule);
|
|
137
|
+
if (!checker) {
|
|
138
|
+
errors.push(`step "${step.id}": unknown rule "${step.rule}"`);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// Resolver premisas: las conclusiones de los pasos referenciados
|
|
142
|
+
// en depends, en el orden declarado. Si alguna referencia falta,
|
|
143
|
+
// ya fue reportada en chequeo #4; aquí evitamos crashear.
|
|
144
|
+
const premises = step.depends.map((d) => {
|
|
145
|
+
const ref = byId.get(d);
|
|
146
|
+
return ref ? ref.conclusion : '';
|
|
147
|
+
});
|
|
148
|
+
let ok;
|
|
149
|
+
try {
|
|
150
|
+
ok = checker(step.args, step.conclusion, premises);
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
errors.push(`step "${step.id}": checker for "${step.rule}" threw ${err instanceof Error ? err.message : String(err)}`);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (!ok) {
|
|
157
|
+
errors.push(`step "${step.id}": rule "${step.rule}" does not justify conclusion "${step.conclusion}"`);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
stepsVerified++;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
valid: errors.length === 0,
|
|
166
|
+
errors,
|
|
167
|
+
stepsVerified,
|
|
168
|
+
totalSteps,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../src/proof-systems/certificate/verify.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,6CAA6C;AAC7C,+DAA+D;AAC/D,EAAE;AACF,0DAA0D;AAC1D,8DAA8D;AAC9D,YAAY;AACZ,+CAA+C;AAC/C,yCAAyC;AACzC,qEAAqE;AACrE,sDAAsD;;;AAoDtD,8CAqHC;AAvKD,2CAA8E;AAiLrE,6FAjLA,wBAAY,OAiLA;AAhLrB,mCAAyC;AAGzC,SAAS,WAAW,CAAC,KAAiB;IACpC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAoB,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,CAAC,CAAC;IAChB,MAAM,IAAI,GAAG,CAAC,CAAC;IACf,MAAM,KAAK,GAAG,CAAC,CAAC;IAChB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAE9C,IAAI,SAAS,GAAoB,IAAI,CAAC;IAEtC,SAAS,GAAG,CAAC,EAAU,EAAE,IAAc;QACrC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QACxB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC/B,MAAM,IAAI,GA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C;gBACH,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACrD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,IAAI,CACT,SAAS,IAAI,CAAC,EAAE,mBAAmB,IAAI,CAAC,IAAI,WAC1C,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CACjD,EAAE,CACH,CAAC;gBACF,SAAS;YACX,CAAC;YACD,IAAI,CAAC,EAAE,EAAE,CAAC;gBACR,MAAM,CAAC,IAAI,CACT,SAAS,IAAI,CAAC,EAAE,YAAY,IAAI,CAAC,IAAI,kCAAkC,IAAI,CAAC,UAAU,GAAG,CAC1F,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,aAAa,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;QACN,aAAa;QACb,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BANFormula, Protocol, ProtocolAnalysis } from './types';
|
|
2
|
+
export interface SaturateOptions {
|
|
3
|
+
/** Máximo de iteraciones del punto fijo. Default: 200. */
|
|
4
|
+
maxIterations?: number;
|
|
5
|
+
/** Máximo de fórmulas nuevas a derivar. Default: 1024. */
|
|
6
|
+
maxDerivations?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Aplica las reglas BAN al estado hasta punto fijo. Devuelve el estado
|
|
10
|
+
* saturado y la lista de derivaciones nuevas (no incluye las iniciales).
|
|
11
|
+
*/
|
|
12
|
+
export declare function saturate(initial: ReadonlyArray<BANFormula>, opts?: SaturateOptions): {
|
|
13
|
+
state: BANFormula[];
|
|
14
|
+
trace: BANFormula[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Idealización mínima: cada step `from → to: msg` produce la
|
|
18
|
+
* fórmula `to ◁ msg`. Asumimos que el receptor literalmente ve el
|
|
19
|
+
* mensaje que se le envía.
|
|
20
|
+
*
|
|
21
|
+
* (BAN tradicional pide idealización manual para descartar texto
|
|
22
|
+
* inseguro como nombres en claro; aquí preservamos todos los
|
|
23
|
+
* subtérminos, que es la lectura conservadora.)
|
|
24
|
+
*/
|
|
25
|
+
export declare function idealize(p: Protocol): BANFormula[];
|
|
26
|
+
/**
|
|
27
|
+
* Analiza un protocolo: parte de las assumptions + idealización,
|
|
28
|
+
* satura, y verifica goals.
|
|
29
|
+
*/
|
|
30
|
+
export declare function analyzeProtocol(p: Protocol, opts?: SaturateOptions): ProtocolAnalysis;
|
|
31
|
+
//# sourceMappingURL=analyze.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../../src/reasoning/ban-logic/analyze.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEtE,MAAM,WAAW,eAAe;IAC9B,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAwBD;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,EAClC,IAAI,CAAC,EAAE,eAAe,GACrB;IAAE,KAAK,EAAE,UAAU,EAAE,CAAC;IAAC,KAAK,EAAE,UAAU,EAAE,CAAA;CAAE,CA4C9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,UAAU,EAAE,CAElD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,gBAAgB,CAYrF"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// BAN Logic — Saturación de estado + análisis de protocolos
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// `saturate(state)` aplica las reglas R1-R10 en forward-chaining
|
|
7
|
+
// hasta punto fijo (o cota de iteraciones). Devuelve la lista de
|
|
8
|
+
// fórmulas inferidas en orden de derivación (trace).
|
|
9
|
+
//
|
|
10
|
+
// `analyzeProtocol(p)` toma un Protocol con assumptions, steps y goals;
|
|
11
|
+
// idealiza los mensajes (cada step produce `P ◁ msg` para el receptor),
|
|
12
|
+
// satura, y reporta cuáles goals quedaron satisfechos.
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.saturate = saturate;
|
|
15
|
+
exports.idealize = idealize;
|
|
16
|
+
exports.analyzeProtocol = analyzeProtocol;
|
|
17
|
+
const rules_1 = require("./rules");
|
|
18
|
+
const terms_1 = require("./terms");
|
|
19
|
+
const STATE_RULES = [
|
|
20
|
+
{ name: 'message-meaning-shared', apply: rules_1.applyMessageMeaningShared },
|
|
21
|
+
{ name: 'message-meaning-public', apply: rules_1.applyMessageMeaningPublic },
|
|
22
|
+
{ name: 'message-meaning-secret', apply: rules_1.applyMessageMeaningSecret },
|
|
23
|
+
{ name: 'nonce-verification', apply: rules_1.applyNonceVerification },
|
|
24
|
+
{ name: 'jurisdiction', apply: rules_1.applyJurisdiction },
|
|
25
|
+
{ name: 'seeing-encrypted', apply: rules_1.applySeeingEncrypted },
|
|
26
|
+
{ name: 'sees-compound', apply: rules_1.applySeesCompound },
|
|
27
|
+
{ name: 'freshness-propagation', apply: rules_1.applyFreshnessPropagation },
|
|
28
|
+
];
|
|
29
|
+
const FOCUS_ONLY_RULES = [
|
|
30
|
+
{ name: 'belief-conj-left', apply: rules_1.applyBeliefConjunction },
|
|
31
|
+
{ name: 'belief-conj-right', apply: rules_1.applyBeliefConjunctionRight },
|
|
32
|
+
{ name: 'said-conj', apply: rules_1.applySaidConjunction },
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* Aplica las reglas BAN al estado hasta punto fijo. Devuelve el estado
|
|
36
|
+
* saturado y la lista de derivaciones nuevas (no incluye las iniciales).
|
|
37
|
+
*/
|
|
38
|
+
function saturate(initial, opts) {
|
|
39
|
+
const maxIter = opts?.maxIterations ?? 200;
|
|
40
|
+
const maxDeriv = opts?.maxDerivations ?? 1024;
|
|
41
|
+
const state = [];
|
|
42
|
+
const trace = [];
|
|
43
|
+
const tryAdd = (f) => {
|
|
44
|
+
if (state.some((g) => (0, terms_1.formulaEquals)(g, f)))
|
|
45
|
+
return false;
|
|
46
|
+
state.push(f);
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
for (const f of initial)
|
|
50
|
+
tryAdd(f);
|
|
51
|
+
let iter = 0;
|
|
52
|
+
let changed = true;
|
|
53
|
+
while (changed && iter < maxIter && trace.length < maxDeriv) {
|
|
54
|
+
changed = false;
|
|
55
|
+
iter++;
|
|
56
|
+
// Snapshot del estado para iterar de forma estable.
|
|
57
|
+
const snapshot = state.slice();
|
|
58
|
+
for (const focus of snapshot) {
|
|
59
|
+
// Reglas state+focus.
|
|
60
|
+
for (const rule of STATE_RULES) {
|
|
61
|
+
const out = rule.apply(snapshot, focus);
|
|
62
|
+
if (out && tryAdd(out)) {
|
|
63
|
+
trace.push(out);
|
|
64
|
+
changed = true;
|
|
65
|
+
if (trace.length >= maxDeriv)
|
|
66
|
+
return { state, trace };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Reglas focus-only.
|
|
70
|
+
for (const rule of FOCUS_ONLY_RULES) {
|
|
71
|
+
const out = rule.apply(focus);
|
|
72
|
+
if (out && tryAdd(out)) {
|
|
73
|
+
trace.push(out);
|
|
74
|
+
changed = true;
|
|
75
|
+
if (trace.length >= maxDeriv)
|
|
76
|
+
return { state, trace };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { state, trace };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Idealización mínima: cada step `from → to: msg` produce la
|
|
85
|
+
* fórmula `to ◁ msg`. Asumimos que el receptor literalmente ve el
|
|
86
|
+
* mensaje que se le envía.
|
|
87
|
+
*
|
|
88
|
+
* (BAN tradicional pide idealización manual para descartar texto
|
|
89
|
+
* inseguro como nombres en claro; aquí preservamos todos los
|
|
90
|
+
* subtérminos, que es la lectura conservadora.)
|
|
91
|
+
*/
|
|
92
|
+
function idealize(p) {
|
|
93
|
+
return p.steps.map((s) => (0, terms_1.sees)((0, terms_1.principal)(s.to), s.message));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Analiza un protocolo: parte de las assumptions + idealización,
|
|
97
|
+
* satura, y verifica goals.
|
|
98
|
+
*/
|
|
99
|
+
function analyzeProtocol(p, opts) {
|
|
100
|
+
const idealized = idealize(p);
|
|
101
|
+
const initial = [...p.initialAssumptions, ...idealized];
|
|
102
|
+
const { state, trace } = saturate(initial, opts);
|
|
103
|
+
const satisfied = [];
|
|
104
|
+
const unsatisfied = [];
|
|
105
|
+
for (const g of p.goals) {
|
|
106
|
+
if ((0, terms_1.hasFormula)(state, g))
|
|
107
|
+
satisfied.push(g);
|
|
108
|
+
else
|
|
109
|
+
unsatisfied.push(g);
|
|
110
|
+
}
|
|
111
|
+
return { satisfied, unsatisfied, trace };
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=analyze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../../src/reasoning/ban-logic/analyze.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,+DAA+D;AAC/D,EAAE;AACF,iEAAiE;AACjE,iEAAiE;AACjE,qDAAqD;AACrD,EAAE;AACF,wEAAw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ocol, ProtocolAnalysis, ProtocolStep, } from './types';
|
|
2
|
+
export { atom, compound, encrypted, hashed, key, message, nonce, principal, believes, controls, formulaAnd, fresh, jurisdiction, publicKey, said, saidMessage, sees, sharedKey, sharedSecret, formulaEquals, formulaToString, hasFormula, termEquals, termToString, } from './terms';
|
|
3
|
+
export { applyBeliefConjunction, applyBeliefConjunctionRight, applyFreshnessPropagation, applyJurisdiction, applyMessageMeaningPublic, applyMessageMeaningSecret, applyMessageMeaningShared, applyNonceVerification, applySaidConjunction, applySeeingEncrypted, applySeesCompound, RULES_REGISTRY, } from './rules';
|
|
4
|
+
export type { SaturateOptions } from './analyze';
|
|
5
|
+
export { analyzeProtocol, idealize, saturate } from './analyze';
|
|
6
|
+
export { kerberos, needhamSchroederPublicKey, needhamSchroederSymmetric } from './protocols';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reasoning/ban-logic/index.ts"],"names":[],"mappings":"AAcA,YAAY,EACV,UAAU,EACV,OAAO,EACP,OAAO,EACP,QAAQ,EACR,gBAAgB,EAChB,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAEL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,MAAM,EACN,GAAG,EACH,OAAO,EACP,KAAK,EACL,SAAS,EAET,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,KAAK,EACL,YAAY,EACZ,SAAS,EACT,IAAI,EACJ,WAAW,EACX,IAAI,EACJ,SAAS,EACT,YAAY,EAEZ,aAAa,EACb,eAAe,EACf,UAAU,EACV,UAAU,EACV,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,EACzB,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// BAN Logic — Barrel export
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Burrows-Abadi-Needham logic para verificación de protocolos
|
|
7
|
+
// criptográficos de autenticación.
|
|
8
|
+
//
|
|
9
|
+
// API pública:
|
|
10
|
+
// - Constructores de términos y fórmulas (`principal`, `key`, ...)
|
|
11
|
+
// - Reglas de inferencia (R1-R10 y variantes)
|
|
12
|
+
// - `saturate(initial)` para cerrar un estado bajo las reglas
|
|
13
|
+
// - `analyzeProtocol(p)` para evaluar goals de un Protocol
|
|
14
|
+
// - Protocolos pre-armados: Needham-Schroeder symmetric / PK / Kerberos
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.needhamSchroederSymmetric = exports.needhamSchroederPublicKey = exports.kerberos = exports.saturate = exports.idealize = exports.analyzeProtocol = exports.RULES_REGISTRY = exports.applySeesCompound = exports.applySeeingEncrypted = exports.applySaidConjunction = exports.applyNonceVerification = exports.applyMessageMeaningShared = exports.applyMessageMeaningSecret = exports.applyMessageMeaningPublic = exports.applyJurisdiction = exports.applyFreshnessPropagation = exports.applyBeliefConjunctionRight = exports.applyBeliefConjunction = exports.termToString = exports.termEquals = exports.hasFormula = exports.formulaToString = exports.formulaEquals = exports.sharedSecret = exports.sharedKey = exports.sees = exports.saidMessage = exports.said = exports.publicKey = exports.jurisdiction = exports.fresh = exports.formulaAnd = exports.controls = exports.believes = exports.principal = exports.nonce = exports.message = exports.key = exports.hashed = exports.encrypted = exports.compound = exports.atom = void 0;
|
|
17
|
+
var terms_1 = require("./terms");
|
|
18
|
+
// Constructores de términos
|
|
19
|
+
Object.defineProperty(exports, "atom", { enumerable: true, get: function () { return terms_1.atom; } });
|
|
20
|
+
Object.defineProperty(exports, "compound", { enumerable: true, get: function () { return terms_1.compound; } });
|
|
21
|
+
Object.defineProperty(exports, "encrypted", { enumerable: true, get: function () { return terms_1.encrypted; } });
|
|
22
|
+
Object.defineProperty(exports, "hashed", { enumerable: true, get: function () { return terms_1.hashed; } });
|
|
23
|
+
Object.defineProperty(exports, "key", { enumerable: true, get: function () { return terms_1.key; } });
|
|
24
|
+
Object.defineProperty(exports, "message", { enumerable: true, get: function () { return terms_1.message; } });
|
|
25
|
+
Object.defineProperty(exports, "nonce", { enumerable: true, get: function () { return terms_1.nonce; } });
|
|
26
|
+
Object.defineProperty(exports, "principal", { enumerable: true, get: function () { return terms_1.principal; } });
|
|
27
|
+
// Constructores de fórmulas
|
|
28
|
+
Object.defineProperty(exports, "believes", { enumerable: true, get: function () { return terms_1.believes; } });
|
|
29
|
+
Object.defineProperty(exports, "controls", { enumerable: true, get: function () { return terms_1.controls; } });
|
|
30
|
+
Object.defineProperty(exports, "formulaAnd", { enumerable: true, get: function () { return terms_1.formulaAnd; } });
|
|
31
|
+
Object.defineProperty(exports, "fresh", { enumerable: true, get: function () { return terms_1.fresh; } });
|
|
32
|
+
Object.defineProperty(exports, "jurisdiction", { enumerable: true, get: function () { return terms_1.jurisdiction; } });
|
|
33
|
+
Object.defineProperty(exports, "publicKey", { enumerable: true, get: function () { return terms_1.publicKey; } });
|
|
34
|
+
Object.defineProperty(exports, "said", { enumerable: true, get: function () { return terms_1.said; } });
|
|
35
|
+
Object.defineProperty(exports, "saidMessage", { enumerable: true, get: function () { return terms_1.saidMessage; } });
|
|
36
|
+
Object.defineProperty(exports, "sees", { enumerable: true, get: function () { return terms_1.sees; } });
|
|
37
|
+
Object.defineProperty(exports, "sharedKey", { enumerable: true, get: function () { return terms_1.sharedKey; } });
|
|
38
|
+
Object.defineProperty(exports, "sharedSecret", { enumerable: true, get: function () { return terms_1.sharedSecret; } });
|
|
39
|
+
// Equality + printing
|
|
40
|
+
Object.defineProperty(exports, "formulaEquals", { enumerable: true, get: function () { return terms_1.formulaEquals; } });
|
|
41
|
+
Object.defineProperty(exports, "formulaToString", { enumerable: true, get: function () { return terms_1.formulaToString; } });
|
|
42
|
+
Object.defineProperty(exports, "hasFormula", { enumerable: true, get: function () { return terms_1.hasFormula; } });
|
|
43
|
+
Object.defineProperty(exports, "termEquals", { enumerable: true, get: function () { return terms_1.termEquals; } });
|
|
44
|
+
Object.defineProperty(exports, "termToString", { enumerable: true, get: function () { return terms_1.termToString; } });
|
|
45
|
+
var rules_1 = require("./rules");
|
|
46
|
+
Object.defineProperty(exports, "applyBeliefConjunction", { enumerable: true, get: function () { return rules_1.applyBeliefConjunction; } });
|
|
47
|
+
Object.defineProperty(exports, "applyBeliefConjunctionRight", { enumerable: true, get: function () { return rules_1.applyBeliefConjunctionRight; } });
|
|
48
|
+
Object.defineProperty(exports, "applyFreshnessPropagation", { enumerable: true, get: function () { return rules_1.applyFreshnessPropagation; } });
|
|
49
|
+
Object.defineProperty(exports, "applyJurisdiction", { enumerable: true, get: function () { return rules_1.applyJurisdiction; } });
|
|
50
|
+
Object.defineProperty(exports, "applyMessageMeaningPublic", { enumerable: true, get: function () { return rules_1.applyMessageMeaningPublic; } });
|
|
51
|
+
Object.defineProperty(exports, "applyMessageMeaningSecret", { enumerable: true, get: function () { return rules_1.applyMessageMeaningSecret; } });
|
|
52
|
+
Object.defineProperty(exports, "applyMessageMeaningShared", { enumerable: true, get: function () { return rules_1.applyMessageMeaningShared; } });
|
|
53
|
+
Object.defineProperty(exports, "applyNonceVerification", { enumerable: true, get: function () { return rules_1.applyNonceVerification; } });
|
|
54
|
+
Object.defineProperty(exports, "applySaidConjunction", { enumerable: true, get: function () { return rules_1.applySaidConjunction; } });
|
|
55
|
+
Object.defineProperty(exports, "applySeeingEncrypted", { enumerable: true, get: function () { return rules_1.applySeeingEncrypted; } });
|
|
56
|
+
Object.defineProperty(exports, "applySeesCompound", { enumerable: true, get: function () { return rules_1.applySeesCompound; } });
|
|
57
|
+
Object.defineProperty(exports, "RULES_REGISTRY", { enumerable: true, get: function () { return rules_1.RULES_REGISTRY; } });
|
|
58
|
+
var analyze_1 = require("./analyze");
|
|
59
|
+
Object.defineProperty(exports, "analyzeProtocol", { enumerable: true, get: function () { return analyze_1.analyzeProtocol; } });
|
|
60
|
+
Object.defineProperty(exports, "idealize", { enumerable: true, get: function () { return analyze_1.idealize; } });
|
|
61
|
+
Object.defineProperty(exports, "saturate", { enumerable: true, get: function () { return analyze_1.saturate; } });
|
|
62
|
+
var protocols_1 = require("./protocols");
|
|
63
|
+
Object.defineProperty(exports, "kerberos", { enumerable: true, get: function () { return protocols_1.kerberos; } });
|
|
64
|
+
Object.defineProperty(exports, "needhamSchroederPublicKey", { enumerable: true, get: function () { return protocols_1.needhamSchroederPublicKey; } });
|
|
65
|
+
Object.defineProperty(exports, "needhamSchroederSymmetric", { enumerable: true, get: function () { return protocols_1.needhamSchroederSymmetric; } });
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reasoning/ban-logic/index.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,4BAA4B;AAC5B,+DAA+D;AAC/D,EAAE;AACF,8DAA8D;AAC9D,mCAAmC;AACnC,EAAE;AACF,eAAe;AACf,qEAAqE;AACrE,gDAAgD;AAChD,gEAAgE;AAChE,6DAA6D;AAC7D,0EAA0E;;;AAW1E,iCA4BiB;AA3Bf,4BAA4B;AAC5B,6FAAA,IAAI,OAAA;AACJ,iGAAA,QAAQ,OAAA;AACR,kGAAA,SAAS,OAAA;AACT,+FAAA,MAAM,OAAA;AACN,4FAAA,GAAG,OAAA;AACH,gGAAA,OAAO,OAAA;AACP,8FAAA,KAAK,OAAA;AACL,kGAAA,SAAS,OAAA;AACT,4BAA4B;AAC5B,iGAAA,QAAQ,OAAA;AACR,iGAAA,QAAQ,OAAA;AACR,mGAAA,UAAU,OAAA;AACV,8FAAA,KAAK,OAAA;AACL,qGAAA,YAAY,OAAA;AACZ,kGAAA,SAAS,OAAA;AACT,6FAAA,IAAI,OAAA;AACJ,oGAAA,WAAW,OAAA;AACX,6FAAA,IAAI,OAAA;AACJ,kGAAA,SAAS,OAAA;AACT,qGAAA,YAAY,OAAA;AACZ,sBAAsB;AACtB,sGAAA,aAAa,OAAA;AACb,wGAAA,eAAe,OAAA;AACf,mGAAA,UAAU,OAAA;AACV,mGAAA,UAAU,OAAA;AACV,qGAAA,YAAY,OAAA;AAGd,iCAaiB;AAZf,+GAAA,sBAAsB,OAAA;AACtB,oHAAA,2BAA2B,OAAA;AAC3B,kHAAA,yBAAyB,OAAA;AACzB,0GAAA,iBAAiB,OAAA;AACjB,kHAAA,yBAAyB,OAAA;AACzB,kHAAA,yBAAyB,OAAA;AACzB,kHAAA,yBAAyB,OAAA;AACzB,+GAAA,sBAAsB,OAAA;AACtB,6GAAA,oBAAoB,OAAA;AACpB,6GAAA,oBAAoB,OAAA;AACpB,0GAAA,iBAAiB,OAAA;AACjB,uGAAA,cAAc,OAAA;AAIhB,qCAAgE;AAAvD,0GAAA,eAAe,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAE5C,yCAA6F;AAApF,qGAAA,QAAQ,OAAA;AAAE,sHAAA,yBAAyB,OAAA;AAAE,sHAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { key, principal } from './terms';
|
|
2
|
+
import type { BANFormula, Protocol } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Needham-Schroeder shared-key (simplificado para BAN).
|
|
5
|
+
*
|
|
6
|
+
* 1. A → S : A, B, N_a
|
|
7
|
+
* 2. S → A : {N_a, K_ab, B, {K_ab, A}_{K_bs}}_{K_as}
|
|
8
|
+
* 3. A → B : {K_ab, A}_{K_bs}
|
|
9
|
+
* 4. B → A : {N_b}_{K_ab}
|
|
10
|
+
* 5. A → B : {N_b - 1}_{K_ab} (representamos como nonce(N_b'))
|
|
11
|
+
*/
|
|
12
|
+
export declare function needhamSchroederSymmetric(): Protocol;
|
|
13
|
+
/**
|
|
14
|
+
* Needham-Schroeder public-key (Lowe attack territory).
|
|
15
|
+
*
|
|
16
|
+
* Original:
|
|
17
|
+
* 1. A → B : {N_a, A}_{K_b}
|
|
18
|
+
* 2. B → A : {N_a, N_b}_{K_a}
|
|
19
|
+
* 3. A → B : {N_b}_{K_b}
|
|
20
|
+
*
|
|
21
|
+
* El "Lowe attack" (1995) muestra que un atacante M puede intercalar
|
|
22
|
+
* y hacer creer a B que está hablando con A cuando en realidad A
|
|
23
|
+
* habla con M. Modelamos el protocolo TAL CUAL, sin la corrección
|
|
24
|
+
* de Lowe; el resultado: el goal "B|≡A|≡(sesión con B)" NO se
|
|
25
|
+
* deriva.
|
|
26
|
+
*/
|
|
27
|
+
export declare function needhamSchroederPublicKey(): Protocol;
|
|
28
|
+
/**
|
|
29
|
+
* Kerberos (simplificación BAN).
|
|
30
|
+
*
|
|
31
|
+
* 1. C → S : C, T, N_c
|
|
32
|
+
* 2. S → C : {N_c, T_C, K_ct}_{K_cs}, {C, T_C, K_ct}_{K_ts}
|
|
33
|
+
* 3. C → T : {C, T_C, K_ct}_{K_ts}, {C, t}_{K_ct}
|
|
34
|
+
* 4. T → C : {t + 1}_{K_ct}
|
|
35
|
+
*
|
|
36
|
+
* Goal: C cree que T comparte K_ct con C; T cree lo mismo.
|
|
37
|
+
*/
|
|
38
|
+
export declare function kerberos(): Protocol;
|
|
39
|
+
export declare const protocolUtils: {
|
|
40
|
+
believes: (p: import("./types").BANTerm, f: BANFormula) => BANFormula;
|
|
41
|
+
sharedKey: (a: import("./types").BANTerm, b: import("./types").BANTerm, k: import("./types").BANTerm) => BANFormula;
|
|
42
|
+
publicKey: (p: ReturnType<typeof principal>, k: ReturnType<typeof key>) => BANFormula;
|
|
43
|
+
jurisdiction: (p: import("./types").BANTerm, f: BANFormula) => BANFormula;
|
|
44
|
+
saidMessage: (p: import("./types").BANTerm, w: import("./types").BANTerm) => BANFormula;
|
|
45
|
+
fresh: (w: import("./types").BANTerm) => BANFormula;
|
|
46
|
+
encrypted: (msg: import("./types").BANTerm, k: import("./types").BANTerm) => import("./types").BANTerm;
|
|
47
|
+
sees: (p: import("./types").BANTerm, w: import("./types").BANTerm) => BANFormula;
|
|
48
|
+
message: (...content: import("./types").BANTerm[]) => import("./types").BANTerm;
|
|
49
|
+
nonce: (name: string) => import("./types").BANTerm;
|
|
50
|
+
key: (name: string, shared?: [string, string]) => import("./types").BANTerm;
|
|
51
|
+
principal: (name: string) => import("./types").BANTerm;
|
|
52
|
+
controls: (p: import("./types").BANTerm, f: BANFormula) => BANFormula;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=protocols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocols.d.ts","sourceRoot":"","sources":["../../../src/reasoning/ban-logic/protocols.ts"],"names":[],"mappings":"AAkBA,OAAO,EAML,GAAG,EAGH,SAAS,EAIV,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,IAAI,QAAQ,CAoEpD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,IAAI,QAAQ,CAuCpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,IAAI,QAAQ,CAwCnC;AAGD,eAAO,MAAM,aAAa;;;mBAGT,UAAU,CAAC,OAAO,SAAS,CAAC,KAAK,UAAU,CAAC,OAAO,GAAG,CAAC,KAAG,UAAU;;;;;;;;;;;CAepF,CAAC"}
|