-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeedhamSchroeder.scala
95 lines (88 loc) · 3.39 KB
/
NeedhamSchroeder.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import Term._
import Derivation.resolution
import Derivation.saturate
import pprint.pprintln
import Derivation.derivable
import Derivation.basicResolution
class NeedhamSchroeder extends munit.FunSuite {
test("derivable needham schroeder") {
val pair = Func.Def("pair", 2)
val aenc = Func.Def("aenc", 2)
val pk = Func.Def("pk", 1)
val na = Name.Def("na", arity = 1)
val nb = Name.Def("nb", arity = 2)
val x = Var("x")
val y = Var("y")
val z = Var("z")
val ska = Name("ska")
val skb = Name("skb")
val skc = Name("skc")
val att = Fact.Def("att")
val rs = Set(
// pair
Clause(Set(att(x), att(y)), att(pair(x, y))),
Clause(Set(att(pair(x, y))), att(x)),
Clause(Set(att(pair(x, y))), att(y)),
// aenc
Clause(Set(att(x), att(y)), att(aenc(x, y))),
Clause(Set(att(aenc(x, pk(y))), att(y)), att(x)),
// pk
Clause(Set(att(x)), att(pk(x))),
// inital knowledge
Clause(Set(), att(skc)),
Clause(Set(), att(pk(ska))),
Clause(Set(), att(pk(skb))),
// protocol
Clause(
Set(att(x)),
att(aenc(pair(pk(ska), na(x)), x)),
label = Some("1")
),
Clause(
Set(att(aenc(pair(x, y), pk(skb)))),
att(aenc(pair(y, nb(y, x)), x)),
label = Some("2")
),
Clause(
Set(att(x), att(aenc(pair(na(x), y), z))),
att(aenc(y, x)),
label = Some("3")
)
)
// expected attack:
// C gets aenc(<pka, na>, pkc) with 1
// C gets aenc(<na,nb>, pka) with 2
// using previous, C gets aenc(nb, pkc)
// C applies adec to get nb
assert(derivable(att(nb(x, y)), rs))
// ┌{att(x)} => att(pk(x))
// │ ┌{att(x)} => att(pk(x))
// │ │┌{att(x)} => att(aenc(pair(pk(ska()),na(x)),x)) [1]
// │ │├{att(aenc(x,pk(y))),att(y)} => att(x)
// │ ├{att(pk(y)),att(y)} => att(pair(pk(ska()),na(pk(y))))
// │ ┌{att(x)} => att(pair(pk(ska()),na(pk(x))))
// │ ├{att(pair(x,y))} => att(y)
// │┌{att(x)} => att(na(pk(x)))
// ││ ┌{att(x)} => att(pk(x))
// ││ │ ┌{} => att(pk(skb()))
// ││ │ │┌{att(x),att(y)} => att(pair(x,y))
// ││ │ ││┌{att(x),att(y)} => att(aenc(x,y))
// ││ │ ││├{att(aenc(pair(x,y),pk(skb())))} => att(aenc(pair(y,nb(y,x)),x)) [2]
// ││ │ │├{att(pair(x_1,y_1)),att(pk(skb()))} => att(aenc(pair(y_1,nb(y_1,x_1)),x_1))
// ││ │ ├{att(x),att(y),att(pk(skb()))} => att(aenc(pair(y,nb(y,x)),x))
// ││ │┌{att(x),att(y)} => att(aenc(pair(y,nb(y,x)),x))
// ││ │├{att(aenc(x,pk(y))),att(y)} => att(x)
// ││ ├{att(pk(y_1)),att(y),att(y_1)} => att(pair(y,nb(y,pk(y_1))))
// ││┌{att(x),att(y)} => att(pair(y,nb(y,pk(x))))
// │││┌{att(x),att(y)} => att(aenc(x,y))
// │││├{att(x),att(aenc(pair(na(x),y),z))} => att(aenc(y,x)) [3]
// ││├{att(pair(na(x_1),y_1)),att(y),att(x_1)} => att(aenc(y_1,x_1))
// │├{att(x),att(na(x_1)),att(y_2),att(x_1)} => att(aenc(nb(na(x_1),pk(x)),x_1))
// ├{att(x),att(x_2),att(y_2),att(pk(x))} => att(aenc(nb(na(pk(x)),pk(x_2)),pk(x)))
// ┌{att(x),att(x_2),att(y_2)} => att(aenc(nb(na(pk(x)),pk(x_2)),pk(x)))
// ├{att(aenc(x,pk(y))),att(y)} => att(x)
// ┌{att(x),att(x_2),att(y_2)} => att(nb(na(pk(x)),pk(x_2)))
// ├{att(nb(x,y))} => att(nb(x,y))
// {att(x),att(x_2),att(y_2)} => att(nb(na(pk(x)),pk(x_2)))
}
}