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