author | wenzelm |
Tue, 05 Apr 2011 14:25:18 +0200 | |
changeset 42224 | 578a51fae383 |
parent 42103 | 6066a35f6678 |
child 42463 | f270e3e18be5 |
permissions | -rw-r--r-- |
41141
ad923cdd4a5d
added example to exercise higher-order reasoning with Sledgehammer and Metis
blanchet
parents:
39260
diff
changeset
|
1 |
(* Title: HOL/Metis_Examples/Message.thy |
23449 | 2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
41144 | 3 |
Author: Jasmin Blanchette, TU Muenchen |
23449 | 4 |
|
41144 | 5 |
Testing Metis. |
23449 | 6 |
*) |
7 |
||
36553 | 8 |
theory Message |
9 |
imports Main |
|
10 |
begin |
|
23449 | 11 |
|
42103
6066a35f6678
Metis examples use the new Skolemizer to test it
blanchet
parents:
41144
diff
changeset
|
12 |
declare [[metis_new_skolemizer]] |
6066a35f6678
Metis examples use the new Skolemizer to test it
blanchet
parents:
41144
diff
changeset
|
13 |
|
23449 | 14 |
lemma strange_Un_eq [simp]: "A \<union> (B \<union> A) = B \<union> A" |
36911 | 15 |
by (metis Un_commute Un_left_absorb) |
23449 | 16 |
|
17 |
types |
|
18 |
key = nat |
|
19 |
||
20 |
consts |
|
21 |
all_symmetric :: bool --{*true if all keys are symmetric*} |
|
22 |
invKey :: "key=>key" --{*inverse of a symmetric key*} |
|
23 |
||
24 |
specification (invKey) |
|
25 |
invKey [simp]: "invKey (invKey K) = K" |
|
26 |
invKey_symmetric: "all_symmetric --> invKey = id" |
|
36553 | 27 |
by (metis id_apply) |
23449 | 28 |
|
29 |
||
30 |
text{*The inverse of a symmetric key is itself; that of a public key |
|
31 |
is the private key and vice versa*} |
|
32 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35109
diff
changeset
|
33 |
definition symKeys :: "key set" where |
23449 | 34 |
"symKeys == {K. invKey K = K}" |
35 |
||
36 |
datatype --{*We allow any number of friendly agents*} |
|
37 |
agent = Server | Friend nat | Spy |
|
38 |
||
39 |
datatype |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32864
diff
changeset
|
40 |
msg = Agent agent --{*Agent names*} |
23449 | 41 |
| Number nat --{*Ordinary integers, timestamps, ...*} |
42 |
| Nonce nat --{*Unguessable nonces*} |
|
43 |
| Key key --{*Crypto keys*} |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32864
diff
changeset
|
44 |
| Hash msg --{*Hashing*} |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32864
diff
changeset
|
45 |
| MPair msg msg --{*Compound messages*} |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32864
diff
changeset
|
46 |
| Crypt key msg --{*Encryption, public- or shared-key*} |
23449 | 47 |
|
48 |
||
49 |
text{*Concrete syntax: messages appear as {|A,B,NA|}, etc...*} |
|
50 |
syntax |
|
35109 | 51 |
"_MTuple" :: "['a, args] => 'a * 'b" ("(2{|_,/ _|})") |
23449 | 52 |
|
53 |
syntax (xsymbols) |
|
35109 | 54 |
"_MTuple" :: "['a, args] => 'a * 'b" ("(2\<lbrace>_,/ _\<rbrace>)") |
23449 | 55 |
|
56 |
translations |
|
57 |
"{|x, y, z|}" == "{|x, {|y, z|}|}" |
|
35054 | 58 |
"{|x, y|}" == "CONST MPair x y" |
23449 | 59 |
|
60 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35109
diff
changeset
|
61 |
definition HPair :: "[msg,msg] => msg" ("(4Hash[_] /_)" [0, 1000]) where |
23449 | 62 |
--{*Message Y paired with a MAC computed with the help of X*} |
63 |
"Hash[X] Y == {| Hash{|X,Y|}, Y|}" |
|
64 |
||
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35109
diff
changeset
|
65 |
definition keysFor :: "msg set => key set" where |
23449 | 66 |
--{*Keys useful to decrypt elements of a message set*} |
67 |
"keysFor H == invKey ` {K. \<exists>X. Crypt K X \<in> H}" |
|
68 |
||
69 |
||
70 |
subsubsection{*Inductive Definition of All Parts" of a Message*} |
|
71 |
||
23755 | 72 |
inductive_set |
73 |
parts :: "msg set => msg set" |
|
74 |
for H :: "msg set" |
|
75 |
where |
|
23449 | 76 |
Inj [intro]: "X \<in> H ==> X \<in> parts H" |
23755 | 77 |
| Fst: "{|X,Y|} \<in> parts H ==> X \<in> parts H" |
78 |
| Snd: "{|X,Y|} \<in> parts H ==> Y \<in> parts H" |
|
79 |
| Body: "Crypt K X \<in> parts H ==> X \<in> parts H" |
|
23449 | 80 |
|
81 |
lemma parts_mono: "G \<subseteq> H ==> parts(G) \<subseteq> parts(H)" |
|
82 |
apply auto |
|
36553 | 83 |
apply (erule parts.induct) |
84 |
apply (metis parts.Inj set_rev_mp) |
|
85 |
apply (metis parts.Fst) |
|
86 |
apply (metis parts.Snd) |
|
87 |
by (metis parts.Body) |
|
23449 | 88 |
|
89 |
text{*Equations hold because constructors are injective.*} |
|
90 |
lemma Friend_image_eq [simp]: "(Friend x \<in> Friend`A) = (x:A)" |
|
39260 | 91 |
by (metis agent.inject image_iff) |
23449 | 92 |
|
36553 | 93 |
lemma Key_image_eq [simp]: "(Key x \<in> Key`A) = (x \<in> A)" |
94 |
by (metis image_iff msg.inject(4)) |
|
23449 | 95 |
|
36553 | 96 |
lemma Nonce_Key_image_eq [simp]: "Nonce x \<notin> Key`A" |
97 |
by (metis image_iff msg.distinct(23)) |
|
23449 | 98 |
|
99 |
||
100 |
subsubsection{*Inverse of keys *} |
|
101 |
||
36553 | 102 |
lemma invKey_eq [simp]: "(invKey K = invKey K') = (K = K')" |
23449 | 103 |
by (metis invKey) |
104 |
||
105 |
||
106 |
subsection{*keysFor operator*} |
|
107 |
||
108 |
lemma keysFor_empty [simp]: "keysFor {} = {}" |
|
109 |
by (unfold keysFor_def, blast) |
|
110 |
||
111 |
lemma keysFor_Un [simp]: "keysFor (H \<union> H') = keysFor H \<union> keysFor H'" |
|
112 |
by (unfold keysFor_def, blast) |
|
113 |
||
114 |
lemma keysFor_UN [simp]: "keysFor (\<Union>i\<in>A. H i) = (\<Union>i\<in>A. keysFor (H i))" |
|
115 |
by (unfold keysFor_def, blast) |
|
116 |
||
117 |
text{*Monotonicity*} |
|
118 |
lemma keysFor_mono: "G \<subseteq> H ==> keysFor(G) \<subseteq> keysFor(H)" |
|
119 |
by (unfold keysFor_def, blast) |
|
120 |
||
121 |
lemma keysFor_insert_Agent [simp]: "keysFor (insert (Agent A) H) = keysFor H" |
|
122 |
by (unfold keysFor_def, auto) |
|
123 |
||
124 |
lemma keysFor_insert_Nonce [simp]: "keysFor (insert (Nonce N) H) = keysFor H" |
|
125 |
by (unfold keysFor_def, auto) |
|
126 |
||
127 |
lemma keysFor_insert_Number [simp]: "keysFor (insert (Number N) H) = keysFor H" |
|
128 |
by (unfold keysFor_def, auto) |
|
129 |
||
130 |
lemma keysFor_insert_Key [simp]: "keysFor (insert (Key K) H) = keysFor H" |
|
131 |
by (unfold keysFor_def, auto) |
|
132 |
||
133 |
lemma keysFor_insert_Hash [simp]: "keysFor (insert (Hash X) H) = keysFor H" |
|
134 |
by (unfold keysFor_def, auto) |
|
135 |
||
136 |
lemma keysFor_insert_MPair [simp]: "keysFor (insert {|X,Y|} H) = keysFor H" |
|
137 |
by (unfold keysFor_def, auto) |
|
138 |
||
139 |
lemma keysFor_insert_Crypt [simp]: |
|
140 |
"keysFor (insert (Crypt K X) H) = insert (invKey K) (keysFor H)" |
|
141 |
by (unfold keysFor_def, auto) |
|
142 |
||
143 |
lemma keysFor_image_Key [simp]: "keysFor (Key`E) = {}" |
|
144 |
by (unfold keysFor_def, auto) |
|
145 |
||
146 |
lemma Crypt_imp_invKey_keysFor: "Crypt K X \<in> H ==> invKey K \<in> keysFor H" |
|
147 |
by (unfold keysFor_def, blast) |
|
148 |
||
149 |
||
150 |
subsection{*Inductive relation "parts"*} |
|
151 |
||
152 |
lemma MPair_parts: |
|
153 |
"[| {|X,Y|} \<in> parts H; |
|
154 |
[| X \<in> parts H; Y \<in> parts H |] ==> P |] ==> P" |
|
155 |
by (blast dest: parts.Fst parts.Snd) |
|
156 |
||
36553 | 157 |
declare MPair_parts [elim!] parts.Body [dest!] |
23449 | 158 |
text{*NB These two rules are UNSAFE in the formal sense, as they discard the |
159 |
compound message. They work well on THIS FILE. |
|
160 |
@{text MPair_parts} is left as SAFE because it speeds up proofs. |
|
161 |
The Crypt rule is normally kept UNSAFE to avoid breaking up certificates.*} |
|
162 |
||
163 |
lemma parts_increasing: "H \<subseteq> parts(H)" |
|
164 |
by blast |
|
165 |
||
166 |
lemmas parts_insertI = subset_insertI [THEN parts_mono, THEN subsetD, standard] |
|
167 |
||
168 |
lemma parts_empty [simp]: "parts{} = {}" |
|
169 |
apply safe |
|
170 |
apply (erule parts.induct) |
|
171 |
apply blast+ |
|
172 |
done |
|
173 |
||
174 |
lemma parts_emptyE [elim!]: "X\<in> parts{} ==> P" |
|
175 |
by simp |
|
176 |
||
177 |
text{*WARNING: loops if H = {Y}, therefore must not be repeated!*} |
|
178 |
lemma parts_singleton: "X\<in> parts H ==> \<exists>Y\<in>H. X\<in> parts {Y}" |
|
179 |
apply (erule parts.induct) |
|
26807
4cd176ea28dc
Replaced blast by fast in proof of parts_singleton, since blast looped
berghofe
parents:
25710
diff
changeset
|
180 |
apply fast+ |
23449 | 181 |
done |
182 |
||
183 |
||
184 |
subsubsection{*Unions *} |
|
185 |
||
186 |
lemma parts_Un_subset1: "parts(G) \<union> parts(H) \<subseteq> parts(G \<union> H)" |
|
187 |
by (intro Un_least parts_mono Un_upper1 Un_upper2) |
|
188 |
||
189 |
lemma parts_Un_subset2: "parts(G \<union> H) \<subseteq> parts(G) \<union> parts(H)" |
|
190 |
apply (rule subsetI) |
|
191 |
apply (erule parts.induct, blast+) |
|
192 |
done |
|
193 |
||
194 |
lemma parts_Un [simp]: "parts(G \<union> H) = parts(G) \<union> parts(H)" |
|
195 |
by (intro equalityI parts_Un_subset1 parts_Un_subset2) |
|
196 |
||
197 |
lemma parts_insert: "parts (insert X H) = parts {X} \<union> parts H" |
|
198 |
apply (subst insert_is_Un [of _ H]) |
|
199 |
apply (simp only: parts_Un) |
|
200 |
done |
|
201 |
||
202 |
lemma parts_insert2: |
|
203 |
"parts (insert X (insert Y H)) = parts {X} \<union> parts {Y} \<union> parts H" |
|
25710
4cdf7de81e1b
Replaced refs by config params; finer critical section in mets method
paulson
parents:
25457
diff
changeset
|
204 |
by (metis Un_commute Un_empty_left Un_empty_right Un_insert_left Un_insert_right parts_Un) |
23449 | 205 |
|
206 |
||
207 |
lemma parts_UN_subset1: "(\<Union>x\<in>A. parts(H x)) \<subseteq> parts(\<Union>x\<in>A. H x)" |
|
208 |
by (intro UN_least parts_mono UN_upper) |
|
209 |
||
210 |
lemma parts_UN_subset2: "parts(\<Union>x\<in>A. H x) \<subseteq> (\<Union>x\<in>A. parts(H x))" |
|
211 |
apply (rule subsetI) |
|
212 |
apply (erule parts.induct, blast+) |
|
213 |
done |
|
214 |
||
215 |
lemma parts_UN [simp]: "parts(\<Union>x\<in>A. H x) = (\<Union>x\<in>A. parts(H x))" |
|
216 |
by (intro equalityI parts_UN_subset1 parts_UN_subset2) |
|
217 |
||
218 |
text{*Added to simplify arguments to parts, analz and synth. |
|
219 |
NOTE: the UN versions are no longer used!*} |
|
220 |
||
221 |
||
222 |
text{*This allows @{text blast} to simplify occurrences of |
|
223 |
@{term "parts(G\<union>H)"} in the assumption.*} |
|
224 |
lemmas in_parts_UnE = parts_Un [THEN equalityD1, THEN subsetD, THEN UnE] |
|
225 |
declare in_parts_UnE [elim!] |
|
226 |
||
227 |
lemma parts_insert_subset: "insert X (parts H) \<subseteq> parts(insert X H)" |
|
228 |
by (blast intro: parts_mono [THEN [2] rev_subsetD]) |
|
229 |
||
230 |
subsubsection{*Idempotence and transitivity *} |
|
231 |
||
232 |
lemma parts_partsD [dest!]: "X\<in> parts (parts H) ==> X\<in> parts H" |
|
233 |
by (erule parts.induct, blast+) |
|
234 |
||
235 |
lemma parts_idem [simp]: "parts (parts H) = parts H" |
|
236 |
by blast |
|
237 |
||
238 |
lemma parts_subset_iff [simp]: "(parts G \<subseteq> parts H) = (G \<subseteq> parts H)" |
|
239 |
apply (rule iffI) |
|
240 |
apply (metis Un_absorb1 Un_subset_iff parts_Un parts_increasing) |
|
25710
4cdf7de81e1b
Replaced refs by config params; finer critical section in mets method
paulson
parents:
25457
diff
changeset
|
241 |
apply (metis parts_idem parts_mono) |
23449 | 242 |
done |
243 |
||
244 |
lemma parts_trans: "[| X\<in> parts G; G \<subseteq> parts H |] ==> X\<in> parts H" |
|
245 |
by (blast dest: parts_mono); |
|
246 |
||
39260 | 247 |
lemma parts_cut: "[|Y\<in> parts (insert X G); X\<in> parts H|] ==> Y\<in> parts(G \<union> H)" |
35095 | 248 |
by (metis Un_insert_left Un_insert_right insert_absorb mem_def parts_Un parts_idem sup1CI) |
23449 | 249 |
|
250 |
||
251 |
subsubsection{*Rewrite rules for pulling out atomic messages *} |
|
252 |
||
253 |
lemmas parts_insert_eq_I = equalityI [OF subsetI parts_insert_subset] |
|
254 |
||
255 |
||
256 |
lemma parts_insert_Agent [simp]: |
|
257 |
"parts (insert (Agent agt) H) = insert (Agent agt) (parts H)" |
|
258 |
apply (rule parts_insert_eq_I) |
|
259 |
apply (erule parts.induct, auto) |
|
260 |
done |
|
261 |
||
262 |
lemma parts_insert_Nonce [simp]: |
|
263 |
"parts (insert (Nonce N) H) = insert (Nonce N) (parts H)" |
|
264 |
apply (rule parts_insert_eq_I) |
|
265 |
apply (erule parts.induct, auto) |
|
266 |
done |
|
267 |
||
268 |
lemma parts_insert_Number [simp]: |
|
269 |
"parts (insert (Number N) H) = insert (Number N) (parts H)" |
|
270 |
apply (rule parts_insert_eq_I) |
|
271 |
apply (erule parts.induct, auto) |
|
272 |
done |
|
273 |
||
274 |
lemma parts_insert_Key [simp]: |
|
275 |
"parts (insert (Key K) H) = insert (Key K) (parts H)" |
|
276 |
apply (rule parts_insert_eq_I) |
|
277 |
apply (erule parts.induct, auto) |
|
278 |
done |
|
279 |
||
280 |
lemma parts_insert_Hash [simp]: |
|
281 |
"parts (insert (Hash X) H) = insert (Hash X) (parts H)" |
|
282 |
apply (rule parts_insert_eq_I) |
|
283 |
apply (erule parts.induct, auto) |
|
284 |
done |
|
285 |
||
286 |
lemma parts_insert_Crypt [simp]: |
|
287 |
"parts (insert (Crypt K X) H) = |
|
288 |
insert (Crypt K X) (parts (insert X H))" |
|
289 |
apply (rule equalityI) |
|
290 |
apply (rule subsetI) |
|
291 |
apply (erule parts.induct, auto) |
|
292 |
apply (blast intro: parts.Body) |
|
293 |
done |
|
294 |
||
295 |
lemma parts_insert_MPair [simp]: |
|
296 |
"parts (insert {|X,Y|} H) = |
|
297 |
insert {|X,Y|} (parts (insert X (insert Y H)))" |
|
298 |
apply (rule equalityI) |
|
299 |
apply (rule subsetI) |
|
300 |
apply (erule parts.induct, auto) |
|
301 |
apply (blast intro: parts.Fst parts.Snd)+ |
|
302 |
done |
|
303 |
||
304 |
lemma parts_image_Key [simp]: "parts (Key`N) = Key`N" |
|
305 |
apply auto |
|
306 |
apply (erule parts.induct, auto) |
|
307 |
done |
|
308 |
||
309 |
lemma msg_Nonce_supply: "\<exists>N. \<forall>n. N\<le>n --> Nonce n \<notin> parts {msg}" |
|
310 |
apply (induct_tac "msg") |
|
311 |
apply (simp_all add: parts_insert2) |
|
312 |
apply (metis Suc_n_not_le_n) |
|
313 |
apply (metis le_trans linorder_linear) |
|
314 |
done |
|
315 |
||
316 |
subsection{*Inductive relation "analz"*} |
|
317 |
||
318 |
text{*Inductive definition of "analz" -- what can be broken down from a set of |
|
319 |
messages, including keys. A form of downward closure. Pairs can |
|
320 |
be taken apart; messages decrypted with known keys. *} |
|
321 |
||
23755 | 322 |
inductive_set |
323 |
analz :: "msg set => msg set" |
|
324 |
for H :: "msg set" |
|
325 |
where |
|
23449 | 326 |
Inj [intro,simp] : "X \<in> H ==> X \<in> analz H" |
23755 | 327 |
| Fst: "{|X,Y|} \<in> analz H ==> X \<in> analz H" |
328 |
| Snd: "{|X,Y|} \<in> analz H ==> Y \<in> analz H" |
|
329 |
| Decrypt [dest]: |
|
23449 | 330 |
"[|Crypt K X \<in> analz H; Key(invKey K): analz H|] ==> X \<in> analz H" |
331 |
||
332 |
||
333 |
text{*Monotonicity; Lemma 1 of Lowe's paper*} |
|
334 |
lemma analz_mono: "G\<subseteq>H ==> analz(G) \<subseteq> analz(H)" |
|
335 |
apply auto |
|
336 |
apply (erule analz.induct) |
|
337 |
apply (auto dest: analz.Fst analz.Snd) |
|
338 |
done |
|
339 |
||
340 |
text{*Making it safe speeds up proofs*} |
|
341 |
lemma MPair_analz [elim!]: |
|
342 |
"[| {|X,Y|} \<in> analz H; |
|
343 |
[| X \<in> analz H; Y \<in> analz H |] ==> P |
|
344 |
|] ==> P" |
|
345 |
by (blast dest: analz.Fst analz.Snd) |
|
346 |
||
347 |
lemma analz_increasing: "H \<subseteq> analz(H)" |
|
348 |
by blast |
|
349 |
||
350 |
lemma analz_subset_parts: "analz H \<subseteq> parts H" |
|
351 |
apply (rule subsetI) |
|
352 |
apply (erule analz.induct, blast+) |
|
353 |
done |
|
354 |
||
355 |
lemmas analz_into_parts = analz_subset_parts [THEN subsetD, standard] |
|
356 |
||
357 |
lemmas not_parts_not_analz = analz_subset_parts [THEN contra_subsetD, standard] |
|
358 |
||
359 |
lemma parts_analz [simp]: "parts (analz H) = parts H" |
|
360 |
apply (rule equalityI) |
|
361 |
apply (metis analz_subset_parts parts_subset_iff) |
|
362 |
apply (metis analz_increasing parts_mono) |
|
363 |
done |
|
364 |
||
365 |
||
366 |
lemma analz_parts [simp]: "analz (parts H) = parts H" |
|
367 |
apply auto |
|
368 |
apply (erule analz.induct, auto) |
|
369 |
done |
|
370 |
||
371 |
lemmas analz_insertI = subset_insertI [THEN analz_mono, THEN [2] rev_subsetD, standard] |
|
372 |
||
373 |
subsubsection{*General equational properties *} |
|
374 |
||
375 |
lemma analz_empty [simp]: "analz{} = {}" |
|
376 |
apply safe |
|
377 |
apply (erule analz.induct, blast+) |
|
378 |
done |
|
379 |
||
380 |
text{*Converse fails: we can analz more from the union than from the |
|
381 |
separate parts, as a key in one might decrypt a message in the other*} |
|
382 |
lemma analz_Un: "analz(G) \<union> analz(H) \<subseteq> analz(G \<union> H)" |
|
383 |
by (intro Un_least analz_mono Un_upper1 Un_upper2) |
|
384 |
||
385 |
lemma analz_insert: "insert X (analz H) \<subseteq> analz(insert X H)" |
|
386 |
by (blast intro: analz_mono [THEN [2] rev_subsetD]) |
|
387 |
||
388 |
subsubsection{*Rewrite rules for pulling out atomic messages *} |
|
389 |
||
390 |
lemmas analz_insert_eq_I = equalityI [OF subsetI analz_insert] |
|
391 |
||
392 |
lemma analz_insert_Agent [simp]: |
|
393 |
"analz (insert (Agent agt) H) = insert (Agent agt) (analz H)" |
|
394 |
apply (rule analz_insert_eq_I) |
|
395 |
apply (erule analz.induct, auto) |
|
396 |
done |
|
397 |
||
398 |
lemma analz_insert_Nonce [simp]: |
|
399 |
"analz (insert (Nonce N) H) = insert (Nonce N) (analz H)" |
|
400 |
apply (rule analz_insert_eq_I) |
|
401 |
apply (erule analz.induct, auto) |
|
402 |
done |
|
403 |
||
404 |
lemma analz_insert_Number [simp]: |
|
405 |
"analz (insert (Number N) H) = insert (Number N) (analz H)" |
|
406 |
apply (rule analz_insert_eq_I) |
|
407 |
apply (erule analz.induct, auto) |
|
408 |
done |
|
409 |
||
410 |
lemma analz_insert_Hash [simp]: |
|
411 |
"analz (insert (Hash X) H) = insert (Hash X) (analz H)" |
|
412 |
apply (rule analz_insert_eq_I) |
|
413 |
apply (erule analz.induct, auto) |
|
414 |
done |
|
415 |
||
416 |
text{*Can only pull out Keys if they are not needed to decrypt the rest*} |
|
417 |
lemma analz_insert_Key [simp]: |
|
418 |
"K \<notin> keysFor (analz H) ==> |
|
419 |
analz (insert (Key K) H) = insert (Key K) (analz H)" |
|
420 |
apply (unfold keysFor_def) |
|
421 |
apply (rule analz_insert_eq_I) |
|
422 |
apply (erule analz.induct, auto) |
|
423 |
done |
|
424 |
||
425 |
lemma analz_insert_MPair [simp]: |
|
426 |
"analz (insert {|X,Y|} H) = |
|
427 |
insert {|X,Y|} (analz (insert X (insert Y H)))" |
|
428 |
apply (rule equalityI) |
|
429 |
apply (rule subsetI) |
|
430 |
apply (erule analz.induct, auto) |
|
431 |
apply (erule analz.induct) |
|
432 |
apply (blast intro: analz.Fst analz.Snd)+ |
|
433 |
done |
|
434 |
||
435 |
text{*Can pull out enCrypted message if the Key is not known*} |
|
436 |
lemma analz_insert_Crypt: |
|
437 |
"Key (invKey K) \<notin> analz H |
|
438 |
==> analz (insert (Crypt K X) H) = insert (Crypt K X) (analz H)" |
|
439 |
apply (rule analz_insert_eq_I) |
|
440 |
apply (erule analz.induct, auto) |
|
441 |
||
442 |
done |
|
443 |
||
444 |
lemma lemma1: "Key (invKey K) \<in> analz H ==> |
|
445 |
analz (insert (Crypt K X) H) \<subseteq> |
|
446 |
insert (Crypt K X) (analz (insert X H))" |
|
447 |
apply (rule subsetI) |
|
23755 | 448 |
apply (erule_tac x = x in analz.induct, auto) |
23449 | 449 |
done |
450 |
||
451 |
lemma lemma2: "Key (invKey K) \<in> analz H ==> |
|
452 |
insert (Crypt K X) (analz (insert X H)) \<subseteq> |
|
453 |
analz (insert (Crypt K X) H)" |
|
454 |
apply auto |
|
23755 | 455 |
apply (erule_tac x = x in analz.induct, auto) |
23449 | 456 |
apply (blast intro: analz_insertI analz.Decrypt) |
457 |
done |
|
458 |
||
459 |
lemma analz_insert_Decrypt: |
|
460 |
"Key (invKey K) \<in> analz H ==> |
|
461 |
analz (insert (Crypt K X) H) = |
|
462 |
insert (Crypt K X) (analz (insert X H))" |
|
463 |
by (intro equalityI lemma1 lemma2) |
|
464 |
||
465 |
text{*Case analysis: either the message is secure, or it is not! Effective, |
|
466 |
but can cause subgoals to blow up! Use with @{text "split_if"}; apparently |
|
467 |
@{text "split_tac"} does not cope with patterns such as @{term"analz (insert |
|
468 |
(Crypt K X) H)"} *} |
|
469 |
lemma analz_Crypt_if [simp]: |
|
470 |
"analz (insert (Crypt K X) H) = |
|
471 |
(if (Key (invKey K) \<in> analz H) |
|
472 |
then insert (Crypt K X) (analz (insert X H)) |
|
473 |
else insert (Crypt K X) (analz H))" |
|
474 |
by (simp add: analz_insert_Crypt analz_insert_Decrypt) |
|
475 |
||
476 |
||
477 |
text{*This rule supposes "for the sake of argument" that we have the key.*} |
|
478 |
lemma analz_insert_Crypt_subset: |
|
479 |
"analz (insert (Crypt K X) H) \<subseteq> |
|
480 |
insert (Crypt K X) (analz (insert X H))" |
|
481 |
apply (rule subsetI) |
|
482 |
apply (erule analz.induct, auto) |
|
483 |
done |
|
484 |
||
485 |
||
486 |
lemma analz_image_Key [simp]: "analz (Key`N) = Key`N" |
|
487 |
apply auto |
|
488 |
apply (erule analz.induct, auto) |
|
489 |
done |
|
490 |
||
491 |
||
492 |
subsubsection{*Idempotence and transitivity *} |
|
493 |
||
494 |
lemma analz_analzD [dest!]: "X\<in> analz (analz H) ==> X\<in> analz H" |
|
495 |
by (erule analz.induct, blast+) |
|
496 |
||
497 |
lemma analz_idem [simp]: "analz (analz H) = analz H" |
|
498 |
by blast |
|
499 |
||
500 |
lemma analz_subset_iff [simp]: "(analz G \<subseteq> analz H) = (G \<subseteq> analz H)" |
|
501 |
apply (rule iffI) |
|
502 |
apply (iprover intro: subset_trans analz_increasing) |
|
503 |
apply (frule analz_mono, simp) |
|
504 |
done |
|
505 |
||
506 |
lemma analz_trans: "[| X\<in> analz G; G \<subseteq> analz H |] ==> X\<in> analz H" |
|
507 |
by (drule analz_mono, blast) |
|
508 |
||
509 |
||
36553 | 510 |
declare analz_trans[intro] |
511 |
||
23449 | 512 |
lemma analz_cut: "[| Y\<in> analz (insert X H); X\<in> analz H |] ==> Y\<in> analz H" |
513 |
(*TOO SLOW |
|
514 |
by (metis analz_idem analz_increasing analz_mono insert_absorb insert_mono insert_subset) --{*317s*} |
|
515 |
??*) |
|
516 |
by (erule analz_trans, blast) |
|
517 |
||
518 |
||
519 |
text{*This rewrite rule helps in the simplification of messages that involve |
|
520 |
the forwarding of unknown components (X). Without it, removing occurrences |
|
521 |
of X can be very complicated. *} |
|
522 |
lemma analz_insert_eq: "X\<in> analz H ==> analz (insert X H) = analz H" |
|
523 |
by (blast intro: analz_cut analz_insertI) |
|
524 |
||
525 |
||
526 |
text{*A congruence rule for "analz" *} |
|
527 |
||
528 |
lemma analz_subset_cong: |
|
529 |
"[| analz G \<subseteq> analz G'; analz H \<subseteq> analz H' |] |
|
530 |
==> analz (G \<union> H) \<subseteq> analz (G' \<union> H')" |
|
531 |
apply simp |
|
532 |
apply (metis Un_absorb2 Un_commute Un_subset_iff Un_upper1 Un_upper2 analz_mono) |
|
533 |
done |
|
534 |
||
535 |
||
536 |
lemma analz_cong: |
|
537 |
"[| analz G = analz G'; analz H = analz H' |
|
538 |
|] ==> analz (G \<union> H) = analz (G' \<union> H')" |
|
539 |
by (intro equalityI analz_subset_cong, simp_all) |
|
540 |
||
541 |
lemma analz_insert_cong: |
|
542 |
"analz H = analz H' ==> analz(insert X H) = analz(insert X H')" |
|
543 |
by (force simp only: insert_def intro!: analz_cong) |
|
544 |
||
545 |
text{*If there are no pairs or encryptions then analz does nothing*} |
|
546 |
lemma analz_trivial: |
|
547 |
"[| \<forall>X Y. {|X,Y|} \<notin> H; \<forall>X K. Crypt K X \<notin> H |] ==> analz H = H" |
|
548 |
apply safe |
|
549 |
apply (erule analz.induct, blast+) |
|
550 |
done |
|
551 |
||
552 |
text{*These two are obsolete (with a single Spy) but cost little to prove...*} |
|
553 |
lemma analz_UN_analz_lemma: |
|
554 |
"X\<in> analz (\<Union>i\<in>A. analz (H i)) ==> X\<in> analz (\<Union>i\<in>A. H i)" |
|
555 |
apply (erule analz.induct) |
|
556 |
apply (blast intro: analz_mono [THEN [2] rev_subsetD])+ |
|
557 |
done |
|
558 |
||
559 |
lemma analz_UN_analz [simp]: "analz (\<Union>i\<in>A. analz (H i)) = analz (\<Union>i\<in>A. H i)" |
|
560 |
by (blast intro: analz_UN_analz_lemma analz_mono [THEN [2] rev_subsetD]) |
|
561 |
||
562 |
||
563 |
subsection{*Inductive relation "synth"*} |
|
564 |
||
565 |
text{*Inductive definition of "synth" -- what can be built up from a set of |
|
566 |
messages. A form of upward closure. Pairs can be built, messages |
|
567 |
encrypted with known keys. Agent names are public domain. |
|
568 |
Numbers can be guessed, but Nonces cannot be. *} |
|
569 |
||
23755 | 570 |
inductive_set |
571 |
synth :: "msg set => msg set" |
|
572 |
for H :: "msg set" |
|
573 |
where |
|
23449 | 574 |
Inj [intro]: "X \<in> H ==> X \<in> synth H" |
23755 | 575 |
| Agent [intro]: "Agent agt \<in> synth H" |
576 |
| Number [intro]: "Number n \<in> synth H" |
|
577 |
| Hash [intro]: "X \<in> synth H ==> Hash X \<in> synth H" |
|
578 |
| MPair [intro]: "[|X \<in> synth H; Y \<in> synth H|] ==> {|X,Y|} \<in> synth H" |
|
579 |
| Crypt [intro]: "[|X \<in> synth H; Key(K) \<in> H|] ==> Crypt K X \<in> synth H" |
|
23449 | 580 |
|
581 |
text{*Monotonicity*} |
|
582 |
lemma synth_mono: "G\<subseteq>H ==> synth(G) \<subseteq> synth(H)" |
|
583 |
by (auto, erule synth.induct, auto) |
|
584 |
||
585 |
text{*NO @{text Agent_synth}, as any Agent name can be synthesized. |
|
586 |
The same holds for @{term Number}*} |
|
587 |
inductive_cases Nonce_synth [elim!]: "Nonce n \<in> synth H" |
|
588 |
inductive_cases Key_synth [elim!]: "Key K \<in> synth H" |
|
589 |
inductive_cases Hash_synth [elim!]: "Hash X \<in> synth H" |
|
590 |
inductive_cases MPair_synth [elim!]: "{|X,Y|} \<in> synth H" |
|
591 |
inductive_cases Crypt_synth [elim!]: "Crypt K X \<in> synth H" |
|
592 |
||
593 |
||
594 |
lemma synth_increasing: "H \<subseteq> synth(H)" |
|
595 |
by blast |
|
596 |
||
597 |
subsubsection{*Unions *} |
|
598 |
||
599 |
text{*Converse fails: we can synth more from the union than from the |
|
600 |
separate parts, building a compound message using elements of each.*} |
|
601 |
lemma synth_Un: "synth(G) \<union> synth(H) \<subseteq> synth(G \<union> H)" |
|
602 |
by (intro Un_least synth_mono Un_upper1 Un_upper2) |
|
603 |
||
604 |
lemma synth_insert: "insert X (synth H) \<subseteq> synth(insert X H)" |
|
605 |
by (metis insert_iff insert_subset subset_insertI synth.Inj synth_mono) |
|
606 |
||
607 |
subsubsection{*Idempotence and transitivity *} |
|
608 |
||
609 |
lemma synth_synthD [dest!]: "X\<in> synth (synth H) ==> X\<in> synth H" |
|
610 |
by (erule synth.induct, blast+) |
|
611 |
||
612 |
lemma synth_idem: "synth (synth H) = synth H" |
|
613 |
by blast |
|
614 |
||
615 |
lemma synth_subset_iff [simp]: "(synth G \<subseteq> synth H) = (G \<subseteq> synth H)" |
|
616 |
apply (rule iffI) |
|
617 |
apply (iprover intro: subset_trans synth_increasing) |
|
618 |
apply (frule synth_mono, simp add: synth_idem) |
|
619 |
done |
|
620 |
||
621 |
lemma synth_trans: "[| X\<in> synth G; G \<subseteq> synth H |] ==> X\<in> synth H" |
|
622 |
by (drule synth_mono, blast) |
|
623 |
||
624 |
lemma synth_cut: "[| Y\<in> synth (insert X H); X\<in> synth H |] ==> Y\<in> synth H" |
|
625 |
(*TOO SLOW |
|
626 |
by (metis insert_absorb insert_mono insert_subset synth_idem synth_increasing synth_mono) |
|
627 |
*) |
|
628 |
by (erule synth_trans, blast) |
|
629 |
||
630 |
||
631 |
lemma Agent_synth [simp]: "Agent A \<in> synth H" |
|
632 |
by blast |
|
633 |
||
634 |
lemma Number_synth [simp]: "Number n \<in> synth H" |
|
635 |
by blast |
|
636 |
||
637 |
lemma Nonce_synth_eq [simp]: "(Nonce N \<in> synth H) = (Nonce N \<in> H)" |
|
638 |
by blast |
|
639 |
||
640 |
lemma Key_synth_eq [simp]: "(Key K \<in> synth H) = (Key K \<in> H)" |
|
641 |
by blast |
|
642 |
||
643 |
lemma Crypt_synth_eq [simp]: |
|
644 |
"Key K \<notin> H ==> (Crypt K X \<in> synth H) = (Crypt K X \<in> H)" |
|
645 |
by blast |
|
646 |
||
647 |
||
648 |
lemma keysFor_synth [simp]: |
|
649 |
"keysFor (synth H) = keysFor H \<union> invKey`{K. Key K \<in> H}" |
|
650 |
by (unfold keysFor_def, blast) |
|
651 |
||
652 |
||
653 |
subsubsection{*Combinations of parts, analz and synth *} |
|
654 |
||
655 |
lemma parts_synth [simp]: "parts (synth H) = parts H \<union> synth H" |
|
656 |
apply (rule equalityI) |
|
657 |
apply (rule subsetI) |
|
658 |
apply (erule parts.induct) |
|
659 |
apply (metis UnCI) |
|
660 |
apply (metis MPair_synth UnCI UnE insert_absorb insert_subset parts.Fst parts_increasing) |
|
661 |
apply (metis MPair_synth UnCI UnE insert_absorb insert_subset parts.Snd parts_increasing) |
|
662 |
apply (metis Body Crypt_synth UnCI UnE insert_absorb insert_subset parts_increasing) |
|
663 |
apply (metis Un_subset_iff parts_increasing parts_mono synth_increasing) |
|
664 |
done |
|
665 |
||
666 |
lemma analz_analz_Un [simp]: "analz (analz G \<union> H) = analz (G \<union> H)" |
|
667 |
apply (rule equalityI); |
|
668 |
apply (metis analz_idem analz_subset_cong order_eq_refl) |
|
669 |
apply (metis analz_increasing analz_subset_cong order_eq_refl) |
|
670 |
done |
|
671 |
||
36553 | 672 |
declare analz_mono [intro] analz.Fst [intro] analz.Snd [intro] Un_least [intro] |
673 |
||
23449 | 674 |
lemma analz_synth_Un [simp]: "analz (synth G \<union> H) = analz (G \<union> H) \<union> synth G" |
675 |
apply (rule equalityI) |
|
676 |
apply (rule subsetI) |
|
677 |
apply (erule analz.induct) |
|
678 |
apply (metis UnCI UnE Un_commute analz.Inj) |
|
35095 | 679 |
apply (metis MPair_synth UnCI UnE Un_commute analz.Fst analz.Inj mem_def) |
680 |
apply (metis MPair_synth UnCI UnE Un_commute analz.Inj analz.Snd mem_def) |
|
23449 | 681 |
apply (blast intro: analz.Decrypt) |
24759 | 682 |
apply blast |
23449 | 683 |
done |
684 |
||
685 |
lemma analz_synth [simp]: "analz (synth H) = analz H \<union> synth H" |
|
36553 | 686 |
proof - |
36911 | 687 |
have "\<forall>x\<^isub>2 x\<^isub>1. synth x\<^isub>1 \<union> analz (x\<^isub>1 \<union> x\<^isub>2) = analz (synth x\<^isub>1 \<union> x\<^isub>2)" by (metis Un_commute analz_synth_Un) |
688 |
hence "\<forall>x\<^isub>1. synth x\<^isub>1 \<union> analz x\<^isub>1 = analz (synth x\<^isub>1 \<union> {})" by (metis Un_empty_right) |
|
689 |
hence "\<forall>x\<^isub>1. synth x\<^isub>1 \<union> analz x\<^isub>1 = analz (synth x\<^isub>1)" by (metis Un_empty_right) |
|
690 |
hence "\<forall>x\<^isub>1. analz x\<^isub>1 \<union> synth x\<^isub>1 = analz (synth x\<^isub>1)" by (metis Un_commute) |
|
36553 | 691 |
thus "analz (synth H) = analz H \<union> synth H" by metis |
23449 | 692 |
qed |
693 |
||
694 |
||
695 |
subsubsection{*For reasoning about the Fake rule in traces *} |
|
696 |
||
697 |
lemma parts_insert_subset_Un: "X\<in> G ==> parts(insert X H) \<subseteq> parts G \<union> parts H" |
|
36553 | 698 |
proof - |
699 |
assume "X \<in> G" |
|
36911 | 700 |
hence "G X" by (metis mem_def) |
701 |
hence "\<forall>x\<^isub>1. G \<subseteq> x\<^isub>1 \<longrightarrow> x\<^isub>1 X" by (metis predicate1D) |
|
702 |
hence "\<forall>x\<^isub>1. (G \<union> x\<^isub>1) X" by (metis Un_upper1) |
|
703 |
hence "\<forall>x\<^isub>1. X \<in> G \<union> x\<^isub>1" by (metis mem_def) |
|
704 |
hence "insert X H \<subseteq> G \<union> H" by (metis Un_upper2 insert_subset) |
|
705 |
hence "parts (insert X H) \<subseteq> parts (G \<union> H)" by (metis parts_mono) |
|
706 |
thus "parts (insert X H) \<subseteq> parts G \<union> parts H" by (metis parts_Un) |
|
23449 | 707 |
qed |
708 |
||
709 |
lemma Fake_parts_insert: |
|
710 |
"X \<in> synth (analz H) ==> |
|
711 |
parts (insert X H) \<subseteq> synth (analz H) \<union> parts H" |
|
36553 | 712 |
proof - |
713 |
assume A1: "X \<in> synth (analz H)" |
|
714 |
have F1: "\<forall>x\<^isub>1. analz x\<^isub>1 \<union> synth (analz x\<^isub>1) = analz (synth (analz x\<^isub>1))" |
|
715 |
by (metis analz_idem analz_synth) |
|
716 |
have F2: "\<forall>x\<^isub>1. parts x\<^isub>1 \<union> synth (analz x\<^isub>1) = parts (synth (analz x\<^isub>1))" |
|
717 |
by (metis parts_analz parts_synth) |
|
718 |
have F3: "synth (analz H) X" using A1 by (metis mem_def) |
|
719 |
have "\<forall>x\<^isub>2 x\<^isub>1\<Colon>msg set. x\<^isub>1 \<le> sup x\<^isub>1 x\<^isub>2" by (metis inf_sup_ord(3)) |
|
720 |
hence F4: "\<forall>x\<^isub>1. analz x\<^isub>1 \<subseteq> analz (synth x\<^isub>1)" by (metis analz_synth) |
|
721 |
have F5: "X \<in> synth (analz H)" using F3 by (metis mem_def) |
|
722 |
have "\<forall>x\<^isub>1. analz x\<^isub>1 \<subseteq> synth (analz x\<^isub>1) |
|
723 |
\<longrightarrow> analz (synth (analz x\<^isub>1)) = synth (analz x\<^isub>1)" |
|
724 |
using F1 by (metis subset_Un_eq) |
|
725 |
hence F6: "\<forall>x\<^isub>1. analz (synth (analz x\<^isub>1)) = synth (analz x\<^isub>1)" |
|
726 |
by (metis synth_increasing) |
|
727 |
have "\<forall>x\<^isub>1. x\<^isub>1 \<subseteq> analz (synth x\<^isub>1)" using F4 by (metis analz_subset_iff) |
|
728 |
hence "\<forall>x\<^isub>1. x\<^isub>1 \<subseteq> analz (synth (analz x\<^isub>1))" by (metis analz_subset_iff) |
|
729 |
hence "\<forall>x\<^isub>1. x\<^isub>1 \<subseteq> synth (analz x\<^isub>1)" using F6 by metis |
|
730 |
hence "H \<subseteq> synth (analz H)" by metis |
|
731 |
hence "H \<subseteq> synth (analz H) \<and> X \<in> synth (analz H)" using F5 by metis |
|
732 |
hence "insert X H \<subseteq> synth (analz H)" by (metis insert_subset) |
|
733 |
hence "parts (insert X H) \<subseteq> parts (synth (analz H))" by (metis parts_mono) |
|
734 |
hence "parts (insert X H) \<subseteq> parts H \<union> synth (analz H)" using F2 by metis |
|
735 |
thus "parts (insert X H) \<subseteq> synth (analz H) \<union> parts H" by (metis Un_commute) |
|
23449 | 736 |
qed |
737 |
||
738 |
lemma Fake_parts_insert_in_Un: |
|
739 |
"[|Z \<in> parts (insert X H); X: synth (analz H)|] |
|
740 |
==> Z \<in> synth (analz H) \<union> parts H"; |
|
36553 | 741 |
by (blast dest: Fake_parts_insert [THEN subsetD, dest]) |
23449 | 742 |
|
36553 | 743 |
declare analz_mono [intro] synth_mono [intro] |
744 |
||
23449 | 745 |
lemma Fake_analz_insert: |
36553 | 746 |
"X \<in> synth (analz G) ==> |
23449 | 747 |
analz (insert X H) \<subseteq> synth (analz G) \<union> analz (G \<union> H)" |
36553 | 748 |
by (metis Un_commute Un_insert_left Un_insert_right Un_upper1 analz_analz_Un |
749 |
analz_mono analz_synth_Un insert_absorb) |
|
23449 | 750 |
|
751 |
lemma Fake_analz_insert_simpler: |
|
36553 | 752 |
"X \<in> synth (analz G) ==> |
23449 | 753 |
analz (insert X H) \<subseteq> synth (analz G) \<union> analz (G \<union> H)" |
754 |
apply (rule subsetI) |
|
755 |
apply (subgoal_tac "x \<in> analz (synth (analz G) \<union> H) ") |
|
756 |
apply (metis Un_commute analz_analz_Un analz_synth_Un) |
|
39260 | 757 |
by (metis Un_upper1 Un_upper2 analz_mono insert_absorb insert_subset) |
23449 | 758 |
|
759 |
end |