author  paulson 
Wed, 24 Jun 1998 11:24:52 +0200  
changeset 5076  fbc9d95b62ba 
parent 5055  546d6d62aeab 
child 5102  8c782c25a11e 
permissions  rwrr 
1839  1 
(* Title: HOL/Auth/Message 
2 
ID: $Id$ 

3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 

4 
Copyright 1996 University of Cambridge 

5 

6 
Datatypes of agents and messages; 

1913  7 
Inductive relations "parts", "analz" and "synth" 
1839  8 
*) 
9 

3702  10 

11 
(*Eliminates a commonlyoccurring expression*) 

12 
goal HOL.thy "~ (ALL x. x~=y)"; 

13 
by (Blast_tac 1); 

14 
Addsimps [result()]; 

15 

1839  16 
open Message; 
17 

3668  18 
AddIffs atomic.inject; 
19 
AddIffs msg.inject; 

1839  20 

4422
21238c9d363e
Simplified proofs using rewrites for f``A where f is injective
paulson
parents:
4157
diff
changeset

21 
(*Equations hold because constructors are injective; cannot prove for all f*) 
5076  22 
Goal "(Friend x : Friend``A) = (x:A)"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

23 
by Auto_tac; 
3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

24 
qed "Friend_image_eq"; 
4422
21238c9d363e
Simplified proofs using rewrites for f``A where f is injective
paulson
parents:
4157
diff
changeset

25 

5076  26 
Goal "(Key x : Key``A) = (x:A)"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

27 
by Auto_tac; 
4422
21238c9d363e
Simplified proofs using rewrites for f``A where f is injective
paulson
parents:
4157
diff
changeset

28 
qed "Key_image_eq"; 
21238c9d363e
Simplified proofs using rewrites for f``A where f is injective
paulson
parents:
4157
diff
changeset

29 

5076  30 
Goal "(Nonce x ~: Key``A)"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

31 
by Auto_tac; 
4422
21238c9d363e
Simplified proofs using rewrites for f``A where f is injective
paulson
parents:
4157
diff
changeset

32 
qed "Nonce_Key_image_eq"; 
21238c9d363e
Simplified proofs using rewrites for f``A where f is injective
paulson
parents:
4157
diff
changeset

33 
Addsimps [Friend_image_eq, Key_image_eq, Nonce_Key_image_eq]; 
3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

34 

eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

35 

1839  36 
(** Inverse of keys **) 
37 

5076  38 
Goal "!!K K'. (invKey K = invKey K') = (K=K')"; 
3730  39 
by Safe_tac; 
2032  40 
by (rtac box_equals 1); 
1839  41 
by (REPEAT (rtac invKey 2)); 
42 
by (Asm_simp_tac 1); 

43 
qed "invKey_eq"; 

44 

45 
Addsimps [invKey, invKey_eq]; 

46 

47 

48 
(**** keysFor operator ****) 

49 

5076  50 
Goalw [keysFor_def] "keysFor {} = {}"; 
2891  51 
by (Blast_tac 1); 
1839  52 
qed "keysFor_empty"; 
53 

5076  54 
Goalw [keysFor_def] "keysFor (H Un H') = keysFor H Un keysFor H'"; 
2891  55 
by (Blast_tac 1); 
1839  56 
qed "keysFor_Un"; 
57 

5076  58 
Goalw [keysFor_def] "keysFor (UN i:A. H i) = (UN i:A. keysFor (H i))"; 
2891  59 
by (Blast_tac 1); 
4157  60 
qed "keysFor_UN"; 
1839  61 

62 
(*Monotonicity*) 

5076  63 
Goalw [keysFor_def] "!!G H. G<=H ==> keysFor(G) <= keysFor(H)"; 
2891  64 
by (Blast_tac 1); 
1839  65 
qed "keysFor_mono"; 
66 

5076  67 
Goalw [keysFor_def] "keysFor (insert (Agent A) H) = keysFor H"; 
3102  68 
by (Blast_tac 1); 
1839  69 
qed "keysFor_insert_Agent"; 
70 

5076  71 
Goalw [keysFor_def] "keysFor (insert (Nonce N) H) = keysFor H"; 
3102  72 
by (Blast_tac 1); 
1839  73 
qed "keysFor_insert_Nonce"; 
74 

5076  75 
Goalw [keysFor_def] "keysFor (insert (Number N) H) = keysFor H"; 
3668  76 
by (Blast_tac 1); 
77 
qed "keysFor_insert_Number"; 

78 

5076  79 
Goalw [keysFor_def] "keysFor (insert (Key K) H) = keysFor H"; 
3102  80 
by (Blast_tac 1); 
1839  81 
qed "keysFor_insert_Key"; 
82 

5076  83 
Goalw [keysFor_def] "keysFor (insert (Hash X) H) = keysFor H"; 
3102  84 
by (Blast_tac 1); 
2373  85 
qed "keysFor_insert_Hash"; 
86 

5076  87 
Goalw [keysFor_def] "keysFor (insert {X,Y} H) = keysFor H"; 
3102  88 
by (Blast_tac 1); 
1839  89 
qed "keysFor_insert_MPair"; 
90 

5076  91 
Goalw [keysFor_def] 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

92 
"keysFor (insert (Crypt K X) H) = insert (invKey K) (keysFor H)"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

93 
by Auto_tac; 
1839  94 
qed "keysFor_insert_Crypt"; 
95 

4157  96 
Addsimps [keysFor_empty, keysFor_Un, keysFor_UN, 
3668  97 
keysFor_insert_Agent, keysFor_insert_Nonce, 
98 
keysFor_insert_Number, keysFor_insert_Key, 

2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

99 
keysFor_insert_Hash, keysFor_insert_MPair, keysFor_insert_Crypt]; 
3121
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

100 
AddSEs [keysFor_Un RS equalityD1 RS subsetD RS UnE, 
4157  101 
keysFor_UN RS equalityD1 RS subsetD RS UN_E]; 
1839  102 

5076  103 
Goalw [keysFor_def] "keysFor (Key``E) = {}"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

104 
by Auto_tac; 
3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

105 
qed "keysFor_image_Key"; 
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

106 
Addsimps [keysFor_image_Key]; 
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

107 

5076  108 
Goalw [keysFor_def] "!!H. Crypt K X : H ==> invKey K : keysFor H"; 
2891  109 
by (Blast_tac 1); 
2068  110 
qed "Crypt_imp_invKey_keysFor"; 
111 

1839  112 

113 
(**** Inductive relation "parts" ****) 

114 

115 
val major::prems = 

5076  116 
Goal "[ {X,Y} : parts H; \ 
1839  117 
\ [ X : parts H; Y : parts H ] ==> P \ 
118 
\ ] ==> P"; 

119 
by (cut_facts_tac [major] 1); 

2032  120 
by (resolve_tac prems 1); 
1839  121 
by (REPEAT (eresolve_tac [asm_rl, parts.Fst, parts.Snd] 1)); 
122 
qed "MPair_parts"; 

123 

124 
AddIs [parts.Inj]; 

1929
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

125 

f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

126 
val partsEs = [MPair_parts, make_elim parts.Body]; 
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

127 

f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

128 
AddSEs partsEs; 
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

129 
(*NB These two rules are UNSAFE in the formal sense, as they discard the 
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

130 
compound message. They work well on THIS FILE, perhaps because its 
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

131 
proofs concern only atomic messages.*) 
1839  132 

5076  133 
Goal "H <= parts(H)"; 
2891  134 
by (Blast_tac 1); 
1839  135 
qed "parts_increasing"; 
136 

137 
(*Monotonicity*) 

5076  138 
Goalw parts.defs "!!G H. G<=H ==> parts(G) <= parts(H)"; 
1839  139 
by (rtac lfp_mono 1); 
140 
by (REPEAT (ares_tac basic_monos 1)); 

141 
qed "parts_mono"; 

142 

2373  143 
val parts_insertI = impOfSubs (subset_insertI RS parts_mono); 
144 

5076  145 
Goal "parts{} = {}"; 
3730  146 
by Safe_tac; 
2032  147 
by (etac parts.induct 1); 
2891  148 
by (ALLGOALS Blast_tac); 
1839  149 
qed "parts_empty"; 
150 
Addsimps [parts_empty]; 

151 

5076  152 
Goal "!!X. X: parts{} ==> P"; 
1839  153 
by (Asm_full_simp_tac 1); 
154 
qed "parts_emptyE"; 

155 
AddSEs [parts_emptyE]; 

156 

1893  157 
(*WARNING: loops if H = {Y}, therefore must not be repeated!*) 
5076  158 
Goal "!!H. X: parts H ==> EX Y:H. X: parts {Y}"; 
2032  159 
by (etac parts.induct 1); 
2891  160 
by (ALLGOALS Blast_tac); 
1893  161 
qed "parts_singleton"; 
162 

1839  163 

164 
(** Unions **) 

165 

5076  166 
Goal "parts(G) Un parts(H) <= parts(G Un H)"; 
1839  167 
by (REPEAT (ares_tac [Un_least, parts_mono, Un_upper1, Un_upper2] 1)); 
168 
val parts_Un_subset1 = result(); 

169 

5076  170 
Goal "parts(G Un H) <= parts(G) Un parts(H)"; 
2032  171 
by (rtac subsetI 1); 
172 
by (etac parts.induct 1); 

2891  173 
by (ALLGOALS Blast_tac); 
1839  174 
val parts_Un_subset2 = result(); 
175 

5076  176 
Goal "parts(G Un H) = parts(G) Un parts(H)"; 
1839  177 
by (REPEAT (ares_tac [equalityI, parts_Un_subset1, parts_Un_subset2] 1)); 
178 
qed "parts_Un"; 

179 

5076  180 
Goal "parts (insert X H) = parts {X} Un parts H"; 
1852  181 
by (stac (read_instantiate [("A","H")] insert_is_Un) 1); 
2011  182 
by (simp_tac (HOL_ss addsimps [parts_Un]) 1); 
183 
qed "parts_insert"; 

184 

185 
(*TWO inserts to avoid looping. This rewrite is better than nothing. 

186 
Not suitable for Addsimps: its behaviour can be strange.*) 

5076  187 
Goal "parts (insert X (insert Y H)) = parts {X} Un parts {Y} Un parts H"; 
4091  188 
by (simp_tac (simpset() addsimps [Un_assoc]) 1); 
189 
by (simp_tac (simpset() addsimps [parts_insert RS sym]) 1); 

1852  190 
qed "parts_insert2"; 
191 

5076  192 
Goal "(UN x:A. parts(H x)) <= parts(UN x:A. H x)"; 
1839  193 
by (REPEAT (ares_tac [UN_least, parts_mono, UN_upper] 1)); 
194 
val parts_UN_subset1 = result(); 

195 

5076  196 
Goal "parts(UN x:A. H x) <= (UN x:A. parts(H x))"; 
2032  197 
by (rtac subsetI 1); 
198 
by (etac parts.induct 1); 

2891  199 
by (ALLGOALS Blast_tac); 
1839  200 
val parts_UN_subset2 = result(); 
201 

5076  202 
Goal "parts(UN x:A. H x) = (UN x:A. parts(H x))"; 
1839  203 
by (REPEAT (ares_tac [equalityI, parts_UN_subset1, parts_UN_subset2] 1)); 
204 
qed "parts_UN"; 

205 

3121
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

206 
(*Added to simplify arguments to parts, analz and synth. 
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

207 
NOTE: the UN versions are no longer used!*) 
4157  208 
Addsimps [parts_Un, parts_UN]; 
3121
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

209 
AddSEs [parts_Un RS equalityD1 RS subsetD RS UnE, 
4157  210 
parts_UN RS equalityD1 RS subsetD RS UN_E]; 
1839  211 

5076  212 
Goal "insert X (parts H) <= parts(insert X H)"; 
4091  213 
by (blast_tac (claset() addIs [impOfSubs parts_mono]) 1); 
1839  214 
qed "parts_insert_subset"; 
215 

216 
(** Idempotence and transitivity **) 

217 

5076  218 
Goal "!!H. X: parts (parts H) ==> X: parts H"; 
2032  219 
by (etac parts.induct 1); 
2891  220 
by (ALLGOALS Blast_tac); 
2922  221 
qed "parts_partsD"; 
222 
AddSDs [parts_partsD]; 

1839  223 

5076  224 
Goal "parts (parts H) = parts H"; 
2891  225 
by (Blast_tac 1); 
1839  226 
qed "parts_idem"; 
227 
Addsimps [parts_idem]; 

228 

5076  229 
Goal "!!H. [ X: parts G; G <= parts H ] ==> X: parts H"; 
1839  230 
by (dtac parts_mono 1); 
2891  231 
by (Blast_tac 1); 
1839  232 
qed "parts_trans"; 
233 

234 
(*Cut*) 

5076  235 
Goal "!!H. [ Y: parts (insert X G); X: parts H ] \ 
2373  236 
\ ==> Y: parts (G Un H)"; 
2032  237 
by (etac parts_trans 1); 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

238 
by Auto_tac; 
1839  239 
qed "parts_cut"; 
240 

5076  241 
Goal "!!H. X: parts H ==> parts (insert X H) = parts H"; 
4091  242 
by (fast_tac (claset() addSDs [parts_cut] 
4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

243 
addIs [parts_insertI] 
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

244 
addss (simpset())) 1); 
1929
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

245 
qed "parts_cut_eq"; 
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

246 

2028
738bb98d65ec
Last working version prior to addition of "lost" component
paulson
parents:
2026
diff
changeset

247 
Addsimps [parts_cut_eq]; 
738bb98d65ec
Last working version prior to addition of "lost" component
paulson
parents:
2026
diff
changeset

248 

1839  249 

250 
(** Rewrite rules for pulling out atomic messages **) 

251 

2373  252 
fun parts_tac i = 
253 
EVERY [rtac ([subsetI, parts_insert_subset] MRS equalityI) i, 

2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

254 
etac parts.induct i, 
3102  255 
REPEAT (Blast_tac i)]; 
2373  256 

5076  257 
Goal "parts (insert (Agent agt) H) = insert (Agent agt) (parts H)"; 
2373  258 
by (parts_tac 1); 
1839  259 
qed "parts_insert_Agent"; 
260 

5076  261 
Goal "parts (insert (Nonce N) H) = insert (Nonce N) (parts H)"; 
2373  262 
by (parts_tac 1); 
1839  263 
qed "parts_insert_Nonce"; 
264 

5076  265 
Goal "parts (insert (Number N) H) = insert (Number N) (parts H)"; 
3668  266 
by (parts_tac 1); 
267 
qed "parts_insert_Number"; 

268 

5076  269 
Goal "parts (insert (Key K) H) = insert (Key K) (parts H)"; 
2373  270 
by (parts_tac 1); 
1839  271 
qed "parts_insert_Key"; 
272 

5076  273 
Goal "parts (insert (Hash X) H) = insert (Hash X) (parts H)"; 
2373  274 
by (parts_tac 1); 
275 
qed "parts_insert_Hash"; 

276 

5076  277 
Goal "parts (insert (Crypt K X) H) = \ 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

278 
\ insert (Crypt K X) (parts (insert X H))"; 
2032  279 
by (rtac equalityI 1); 
280 
by (rtac subsetI 1); 

281 
by (etac parts.induct 1); 

4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

282 
by Auto_tac; 
2032  283 
by (etac parts.induct 1); 
4091  284 
by (ALLGOALS (blast_tac (claset() addIs [parts.Body]))); 
1839  285 
qed "parts_insert_Crypt"; 
286 

5076  287 
Goal "parts (insert {X,Y} H) = \ 
1839  288 
\ insert {X,Y} (parts (insert X (insert Y H)))"; 
2032  289 
by (rtac equalityI 1); 
290 
by (rtac subsetI 1); 

291 
by (etac parts.induct 1); 

4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

292 
by Auto_tac; 
2032  293 
by (etac parts.induct 1); 
4091  294 
by (ALLGOALS (blast_tac (claset() addIs [parts.Fst, parts.Snd]))); 
1839  295 
qed "parts_insert_MPair"; 
296 

3668  297 
Addsimps [parts_insert_Agent, parts_insert_Nonce, 
298 
parts_insert_Number, parts_insert_Key, 

2373  299 
parts_insert_Hash, parts_insert_Crypt, parts_insert_MPair]; 
1839  300 

301 

5076  302 
Goal "parts (Key``N) = Key``N"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

303 
by Auto_tac; 
2032  304 
by (etac parts.induct 1); 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

305 
by Auto_tac; 
2026
0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

306 
qed "parts_image_Key"; 
3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

307 
Addsimps [parts_image_Key]; 
2026
0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

308 

3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

309 

eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

310 
(*In any message, there is an upper bound N on its greatest nonce.*) 
5076  311 
Goal "EX N. ALL n. N<=n > Nonce n ~: parts {msg}"; 
3668  312 
by (induct_tac "msg" 1); 
313 
by (induct_tac "atomic" 1); 

4091  314 
by (ALLGOALS (asm_simp_tac (simpset() addsimps [exI, parts_insert2]))); 
3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

315 
(*MPair case: blast_tac works out the necessary sum itself!*) 
4091  316 
by (blast_tac (claset() addSEs [add_leE]) 2); 
3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

317 
(*Nonce case*) 
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

318 
by (res_inst_tac [("x","N + Suc nat")] exI 1); 
4651  319 
by (fast_tac (claset() addSEs [add_leE] addaltern ("trans_tac",trans_tac)) 1); 
3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

320 
qed "msg_Nonce_supply"; 
2026
0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

321 

0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

322 

1913  323 
(**** Inductive relation "analz" ****) 
1839  324 

325 
val major::prems = 

5076  326 
Goal "[ {X,Y} : analz H; \ 
1913  327 
\ [ X : analz H; Y : analz H ] ==> P \ 
1839  328 
\ ] ==> P"; 
329 
by (cut_facts_tac [major] 1); 

2032  330 
by (resolve_tac prems 1); 
1913  331 
by (REPEAT (eresolve_tac [asm_rl, analz.Fst, analz.Snd] 1)); 
332 
qed "MPair_analz"; 

1839  333 

1913  334 
AddIs [analz.Inj]; 
2011  335 
AddSEs [MPair_analz]; (*Perhaps it should NOT be deemed safe!*) 
1913  336 
AddDs [analz.Decrypt]; 
1839  337 

1913  338 
Addsimps [analz.Inj]; 
1885  339 

5076  340 
Goal "H <= analz(H)"; 
2891  341 
by (Blast_tac 1); 
1913  342 
qed "analz_increasing"; 
1839  343 

5076  344 
Goal "analz H <= parts H"; 
1839  345 
by (rtac subsetI 1); 
2032  346 
by (etac analz.induct 1); 
2891  347 
by (ALLGOALS Blast_tac); 
1913  348 
qed "analz_subset_parts"; 
1839  349 

1913  350 
bind_thm ("not_parts_not_analz", analz_subset_parts RS contra_subsetD); 
1839  351 

352 

5076  353 
Goal "parts (analz H) = parts H"; 
2032  354 
by (rtac equalityI 1); 
355 
by (rtac (analz_subset_parts RS parts_mono RS subset_trans) 1); 

1839  356 
by (Simp_tac 1); 
4091  357 
by (blast_tac (claset() addIs [analz_increasing RS parts_mono RS subsetD]) 1); 
1913  358 
qed "parts_analz"; 
359 
Addsimps [parts_analz]; 

1839  360 

5076  361 
Goal "analz (parts H) = parts H"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

362 
by Auto_tac; 
2032  363 
by (etac analz.induct 1); 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

364 
by Auto_tac; 
1913  365 
qed "analz_parts"; 
366 
Addsimps [analz_parts]; 

1885  367 

1839  368 
(*Monotonicity; Lemma 1 of Lowe*) 
5076  369 
Goalw analz.defs "!!G H. G<=H ==> analz(G) <= analz(H)"; 
1839  370 
by (rtac lfp_mono 1); 
371 
by (REPEAT (ares_tac basic_monos 1)); 

1913  372 
qed "analz_mono"; 
1839  373 

2373  374 
val analz_insertI = impOfSubs (subset_insertI RS analz_mono); 
375 

1839  376 
(** General equational properties **) 
377 

5076  378 
Goal "analz{} = {}"; 
3730  379 
by Safe_tac; 
2032  380 
by (etac analz.induct 1); 
2891  381 
by (ALLGOALS Blast_tac); 
1913  382 
qed "analz_empty"; 
383 
Addsimps [analz_empty]; 

1839  384 

1913  385 
(*Converse fails: we can analz more from the union than from the 
1839  386 
separate parts, as a key in one might decrypt a message in the other*) 
5076  387 
Goal "analz(G) Un analz(H) <= analz(G Un H)"; 
1913  388 
by (REPEAT (ares_tac [Un_least, analz_mono, Un_upper1, Un_upper2] 1)); 
389 
qed "analz_Un"; 

1839  390 

5076  391 
Goal "insert X (analz H) <= analz(insert X H)"; 
4091  392 
by (blast_tac (claset() addIs [impOfSubs analz_mono]) 1); 
1913  393 
qed "analz_insert"; 
1839  394 

395 
(** Rewrite rules for pulling out atomic messages **) 

396 

2373  397 
fun analz_tac i = 
398 
EVERY [rtac ([subsetI, analz_insert] MRS equalityI) i, 

2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

399 
etac analz.induct i, 
3102  400 
REPEAT (Blast_tac i)]; 
2373  401 

5076  402 
Goal "analz (insert (Agent agt) H) = insert (Agent agt) (analz H)"; 
2373  403 
by (analz_tac 1); 
1913  404 
qed "analz_insert_Agent"; 
1839  405 

5076  406 
Goal "analz (insert (Nonce N) H) = insert (Nonce N) (analz H)"; 
2373  407 
by (analz_tac 1); 
1913  408 
qed "analz_insert_Nonce"; 
1839  409 

5076  410 
Goal "analz (insert (Number N) H) = insert (Number N) (analz H)"; 
3668  411 
by (analz_tac 1); 
412 
qed "analz_insert_Number"; 

413 

5076  414 
Goal "analz (insert (Hash X) H) = insert (Hash X) (analz H)"; 
2373  415 
by (analz_tac 1); 
416 
qed "analz_insert_Hash"; 

417 

1839  418 
(*Can only pull out Keys if they are not needed to decrypt the rest*) 
5076  419 
Goalw [keysFor_def] 
1913  420 
"!!K. K ~: keysFor (analz H) ==> \ 
421 
\ analz (insert (Key K) H) = insert (Key K) (analz H)"; 

2373  422 
by (analz_tac 1); 
1913  423 
qed "analz_insert_Key"; 
1839  424 

5076  425 
Goal "analz (insert {X,Y} H) = \ 
1913  426 
\ insert {X,Y} (analz (insert X (insert Y H)))"; 
2032  427 
by (rtac equalityI 1); 
428 
by (rtac subsetI 1); 

429 
by (etac analz.induct 1); 

4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

430 
by Auto_tac; 
2032  431 
by (etac analz.induct 1); 
4091  432 
by (ALLGOALS (blast_tac (claset() addIs [analz.Fst, analz.Snd]))); 
1913  433 
qed "analz_insert_MPair"; 
1885  434 

435 
(*Can pull out enCrypted message if the Key is not known*) 

5076  436 
Goal "!!H. Key (invKey K) ~: analz H ==> \ 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

437 
\ analz (insert (Crypt K X) H) = \ 
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

438 
\ insert (Crypt K X) (analz H)"; 
2373  439 
by (analz_tac 1); 
1913  440 
qed "analz_insert_Crypt"; 
1839  441 

5076  442 
Goal "!!H. Key (invKey K) : analz H ==> \ 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

443 
\ analz (insert (Crypt K X) H) <= \ 
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

444 
\ insert (Crypt K X) (analz (insert X H))"; 
2032  445 
by (rtac subsetI 1); 
1913  446 
by (eres_inst_tac [("za","x")] analz.induct 1); 
3102  447 
by (ALLGOALS (Blast_tac)); 
1839  448 
val lemma1 = result(); 
449 

5076  450 
Goal "!!H. Key (invKey K) : analz H ==> \ 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

451 
\ insert (Crypt K X) (analz (insert X H)) <= \ 
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

452 
\ analz (insert (Crypt K X) H)"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

453 
by Auto_tac; 
1913  454 
by (eres_inst_tac [("za","x")] analz.induct 1); 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

455 
by Auto_tac; 
4091  456 
by (blast_tac (claset() addIs [analz_insertI, analz.Decrypt]) 1); 
1839  457 
val lemma2 = result(); 
458 

5076  459 
Goal "!!H. Key (invKey K) : analz H ==> \ 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

460 
\ analz (insert (Crypt K X) H) = \ 
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

461 
\ insert (Crypt K X) (analz (insert X H))"; 
1839  462 
by (REPEAT (ares_tac [equalityI, lemma1, lemma2] 1)); 
1913  463 
qed "analz_insert_Decrypt"; 
1839  464 

1885  465 
(*Case analysis: either the message is secure, or it is not! 
1946  466 
Effective, but can cause subgoals to blow up! 
5055  467 
Use with split_if; apparently split_tac does not cope with patterns 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

468 
such as "analz (insert (Crypt K X) H)" *) 
5076  469 
Goal "analz (insert (Crypt K X) H) = \ 
2154  470 
\ (if (Key (invKey K) : analz H) \ 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

471 
\ then insert (Crypt K X) (analz (insert X H)) \ 
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

472 
\ else insert (Crypt K X) (analz H))"; 
2102  473 
by (case_tac "Key (invKey K) : analz H " 1); 
4091  474 
by (ALLGOALS (asm_simp_tac (simpset() addsimps [analz_insert_Crypt, 
4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

475 
analz_insert_Decrypt]))); 
1913  476 
qed "analz_Crypt_if"; 
1885  477 

3668  478 
Addsimps [analz_insert_Agent, analz_insert_Nonce, 
479 
analz_insert_Number, analz_insert_Key, 

2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

480 
analz_insert_Hash, analz_insert_MPair, analz_Crypt_if]; 
1839  481 

482 
(*This rule supposes "for the sake of argument" that we have the key.*) 

5076  483 
Goal "analz (insert (Crypt K X) H) <= \ 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

484 
\ insert (Crypt K X) (analz (insert X H))"; 
2032  485 
by (rtac subsetI 1); 
486 
by (etac analz.induct 1); 

4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

487 
by Auto_tac; 
1913  488 
qed "analz_insert_Crypt_subset"; 
1839  489 

490 

5076  491 
Goal "analz (Key``N) = Key``N"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

492 
by Auto_tac; 
2032  493 
by (etac analz.induct 1); 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

494 
by Auto_tac; 
2026
0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

495 
qed "analz_image_Key"; 
0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

496 

0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

497 
Addsimps [analz_image_Key]; 
0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

498 

0df5a96bf77e
Last working version prior to introduction of "lost"
paulson
parents:
2011
diff
changeset

499 

1839  500 
(** Idempotence and transitivity **) 
501 

5076  502 
Goal "!!H. X: analz (analz H) ==> X: analz H"; 
2032  503 
by (etac analz.induct 1); 
2891  504 
by (ALLGOALS Blast_tac); 
2922  505 
qed "analz_analzD"; 
506 
AddSDs [analz_analzD]; 

1839  507 

5076  508 
Goal "analz (analz H) = analz H"; 
2891  509 
by (Blast_tac 1); 
1913  510 
qed "analz_idem"; 
511 
Addsimps [analz_idem]; 

1839  512 

5076  513 
Goal "!!H. [ X: analz G; G <= analz H ] ==> X: analz H"; 
1913  514 
by (dtac analz_mono 1); 
2891  515 
by (Blast_tac 1); 
1913  516 
qed "analz_trans"; 
1839  517 

518 
(*Cut; Lemma 2 of Lowe*) 

5076  519 
Goal "!!H. [ Y: analz (insert X H); X: analz H ] ==> Y: analz H"; 
2032  520 
by (etac analz_trans 1); 
2891  521 
by (Blast_tac 1); 
1913  522 
qed "analz_cut"; 
1839  523 

524 
(*Cut can be proved easily by induction on 

1913  525 
"!!H. Y: analz (insert X H) ==> X: analz H > Y: analz H" 
1839  526 
*) 
527 

3449  528 
(*This rewrite rule helps in the simplification of messages that involve 
529 
the forwarding of unknown components (X). Without it, removing occurrences 

530 
of X can be very complicated. *) 

5076  531 
Goal "!!H. X: analz H ==> analz (insert X H) = analz H"; 
4091  532 
by (blast_tac (claset() addIs [analz_cut, analz_insertI]) 1); 
3431  533 
qed "analz_insert_eq"; 
534 

1885  535 

1913  536 
(** A congruence rule for "analz" **) 
1885  537 

5076  538 
Goal "!!H. [ analz G <= analz G'; analz H <= analz H' \ 
1913  539 
\ ] ==> analz (G Un H) <= analz (G' Un H')"; 
3714  540 
by (Clarify_tac 1); 
2032  541 
by (etac analz.induct 1); 
4091  542 
by (ALLGOALS (best_tac (claset() addIs [analz_mono RS subsetD]))); 
1913  543 
qed "analz_subset_cong"; 
1885  544 

5076  545 
Goal "!!H. [ analz G = analz G'; analz H = analz H' \ 
1913  546 
\ ] ==> analz (G Un H) = analz (G' Un H')"; 
547 
by (REPEAT_FIRST (ares_tac [equalityI, analz_subset_cong] 

2032  548 
ORELSE' etac equalityE)); 
1913  549 
qed "analz_cong"; 
1885  550 

551 

5076  552 
Goal "!!H. analz H = analz H' ==> analz(insert X H) = analz(insert X H')"; 
4091  553 
by (asm_simp_tac (simpset() addsimps [insert_def] delsimps [singleton_conv] 
4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

554 
setloop (rtac analz_cong)) 1); 
1913  555 
qed "analz_insert_cong"; 
1885  556 

1913  557 
(*If there are no pairs or encryptions then analz does nothing*) 
5076  558 
Goal "!!H. [ ALL X Y. {X,Y} ~: H; ALL X K. Crypt K X ~: H ] ==> \ 
1913  559 
\ analz H = H"; 
3730  560 
by Safe_tac; 
2032  561 
by (etac analz.induct 1); 
2891  562 
by (ALLGOALS Blast_tac); 
1913  563 
qed "analz_trivial"; 
1839  564 

4157  565 
(*These two are obsolete (with a single Spy) but cost little to prove...*) 
5076  566 
Goal "!!X. X: analz (UN i:A. analz (H i)) ==> X: analz (UN i:A. H i)"; 
2032  567 
by (etac analz.induct 1); 
4091  568 
by (ALLGOALS (blast_tac (claset() addIs [impOfSubs analz_mono]))); 
1839  569 
val lemma = result(); 
570 

5076  571 
Goal "analz (UN i:A. analz (H i)) = analz (UN i:A. H i)"; 
4091  572 
by (blast_tac (claset() addIs [lemma, impOfSubs analz_mono]) 1); 
1913  573 
qed "analz_UN_analz"; 
574 
Addsimps [analz_UN_analz]; 

1839  575 

576 

1913  577 
(**** Inductive relation "synth" ****) 
1839  578 

1913  579 
AddIs synth.intrs; 
1839  580 

2011  581 
(*Can only produce a nonce or key if it is already known, 
582 
but can synth a pair or encryption from its components...*) 

3668  583 
val mk_cases = synth.mk_cases (atomic.simps @ msg.simps); 
2011  584 

3668  585 
(*NO Agent_synth, as any Agent name can be synthesized. Ditto for Number*) 
2011  586 
val Nonce_synth = mk_cases "Nonce n : synth H"; 
587 
val Key_synth = mk_cases "Key K : synth H"; 

2373  588 
val Hash_synth = mk_cases "Hash X : synth H"; 
2011  589 
val MPair_synth = mk_cases "{X,Y} : synth H"; 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

590 
val Crypt_synth = mk_cases "Crypt K X : synth H"; 
2011  591 

2373  592 
AddSEs [Nonce_synth, Key_synth, Hash_synth, MPair_synth, Crypt_synth]; 
2011  593 

5076  594 
Goal "H <= synth(H)"; 
2891  595 
by (Blast_tac 1); 
1913  596 
qed "synth_increasing"; 
1839  597 

598 
(*Monotonicity*) 

5076  599 
Goalw synth.defs "!!G H. G<=H ==> synth(G) <= synth(H)"; 
1839  600 
by (rtac lfp_mono 1); 
601 
by (REPEAT (ares_tac basic_monos 1)); 

1913  602 
qed "synth_mono"; 
1839  603 

604 
(** Unions **) 

605 

1913  606 
(*Converse fails: we can synth more from the union than from the 
1839  607 
separate parts, building a compound message using elements of each.*) 
5076  608 
Goal "synth(G) Un synth(H) <= synth(G Un H)"; 
1913  609 
by (REPEAT (ares_tac [Un_least, synth_mono, Un_upper1, Un_upper2] 1)); 
610 
qed "synth_Un"; 

1839  611 

5076  612 
Goal "insert X (synth H) <= synth(insert X H)"; 
4091  613 
by (blast_tac (claset() addIs [impOfSubs synth_mono]) 1); 
1913  614 
qed "synth_insert"; 
1885  615 

1839  616 
(** Idempotence and transitivity **) 
617 

5076  618 
Goal "!!H. X: synth (synth H) ==> X: synth H"; 
2032  619 
by (etac synth.induct 1); 
2891  620 
by (ALLGOALS Blast_tac); 
2922  621 
qed "synth_synthD"; 
622 
AddSDs [synth_synthD]; 

1839  623 

5076  624 
Goal "synth (synth H) = synth H"; 
2891  625 
by (Blast_tac 1); 
1913  626 
qed "synth_idem"; 
1839  627 

5076  628 
Goal "!!H. [ X: synth G; G <= synth H ] ==> X: synth H"; 
1913  629 
by (dtac synth_mono 1); 
2891  630 
by (Blast_tac 1); 
1913  631 
qed "synth_trans"; 
1839  632 

633 
(*Cut; Lemma 2 of Lowe*) 

5076  634 
Goal "!!H. [ Y: synth (insert X H); X: synth H ] ==> Y: synth H"; 
2032  635 
by (etac synth_trans 1); 
2891  636 
by (Blast_tac 1); 
1913  637 
qed "synth_cut"; 
1839  638 

5076  639 
Goal "Agent A : synth H"; 
2891  640 
by (Blast_tac 1); 
1946  641 
qed "Agent_synth"; 
642 

5076  643 
Goal "Number n : synth H"; 
3668  644 
by (Blast_tac 1); 
645 
qed "Number_synth"; 

646 

5076  647 
Goal "(Nonce N : synth H) = (Nonce N : H)"; 
2891  648 
by (Blast_tac 1); 
1913  649 
qed "Nonce_synth_eq"; 
1839  650 

5076  651 
Goal "(Key K : synth H) = (Key K : H)"; 
2891  652 
by (Blast_tac 1); 
1913  653 
qed "Key_synth_eq"; 
1839  654 

5076  655 
Goal "!!K. Key K ~: H ==> (Crypt K X : synth H) = (Crypt K X : H)"; 
2891  656 
by (Blast_tac 1); 
2011  657 
qed "Crypt_synth_eq"; 
658 

3668  659 
Addsimps [Agent_synth, Number_synth, 
660 
Nonce_synth_eq, Key_synth_eq, Crypt_synth_eq]; 

1839  661 

662 

5076  663 
Goalw [keysFor_def] 
1913  664 
"keysFor (synth H) = keysFor H Un invKey``{K. Key K : H}"; 
2891  665 
by (Blast_tac 1); 
1913  666 
qed "keysFor_synth"; 
667 
Addsimps [keysFor_synth]; 

1839  668 

669 

1913  670 
(*** Combinations of parts, analz and synth ***) 
1839  671 

5076  672 
Goal "parts (synth H) = parts H Un synth H"; 
2032  673 
by (rtac equalityI 1); 
674 
by (rtac subsetI 1); 

675 
by (etac parts.induct 1); 

1839  676 
by (ALLGOALS 
4091  677 
(blast_tac (claset() addIs ((synth_increasing RS parts_mono RS subsetD) 
4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

678 
::parts.intrs)))); 
1913  679 
qed "parts_synth"; 
680 
Addsimps [parts_synth]; 

1839  681 

5076  682 
Goal "analz (analz G Un H) = analz (G Un H)"; 
2373  683 
by (REPEAT_FIRST (resolve_tac [equalityI, analz_subset_cong])); 
684 
by (ALLGOALS Simp_tac); 

685 
qed "analz_analz_Un"; 

686 

5076  687 
Goal "analz (synth G Un H) = analz (G Un H) Un synth G"; 
2032  688 
by (rtac equalityI 1); 
689 
by (rtac subsetI 1); 

690 
by (etac analz.induct 1); 

4091  691 
by (blast_tac (claset() addIs [impOfSubs analz_mono]) 5); 
692 
by (ALLGOALS (blast_tac (claset() addIs analz.intrs))); 

2373  693 
qed "analz_synth_Un"; 
694 

5076  695 
Goal "analz (synth H) = analz H Un synth H"; 
2373  696 
by (cut_inst_tac [("H","{}")] analz_synth_Un 1); 
697 
by (Full_simp_tac 1); 

1913  698 
qed "analz_synth"; 
2373  699 
Addsimps [analz_analz_Un, analz_synth_Un, analz_synth]; 
1839  700 

1946  701 

702 
(** For reasoning about the Fake rule in traces **) 

703 

5076  704 
Goal "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H"; 
2032  705 
by (rtac ([parts_mono, parts_Un_subset2] MRS subset_trans) 1); 
2891  706 
by (Blast_tac 1); 
1929
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

707 
qed "parts_insert_subset_Un"; 
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

708 

4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

709 
(*More specifically for Fake. Very occasionally we could do with a version 
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

710 
of the form parts{X} <= synth (analz H) Un parts H *) 
5076  711 
Goal "!!H. X: synth (analz H) ==> \ 
4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

712 
\ parts (insert X H) <= synth (analz H) Un parts H"; 
2032  713 
by (dtac parts_insert_subset_Un 1); 
1946  714 
by (Full_simp_tac 1); 
2891  715 
by (Blast_tac 1); 
1946  716 
qed "Fake_parts_insert"; 
717 

4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

718 
(*H is sometimes (Key `` KK Un spies evs), so can't put G=H*) 
5076  719 
Goal "!!H. X: synth (analz G) ==> \ 
2373  720 
\ analz (insert X H) <= synth (analz G) Un analz (G Un H)"; 
721 
by (rtac subsetI 1); 

722 
by (subgoal_tac "x : analz (synth (analz G) Un H)" 1); 

4091  723 
by (blast_tac (claset() addIs [impOfSubs analz_mono, 
4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

724 
impOfSubs (analz_mono RS synth_mono)]) 2); 
2373  725 
by (Full_simp_tac 1); 
2891  726 
by (Blast_tac 1); 
2373  727 
qed "Fake_analz_insert"; 
728 

5076  729 
Goal "(X: analz H & X: parts H) = (X: analz H)"; 
4091  730 
by (blast_tac (claset() addIs [impOfSubs analz_subset_parts]) 1); 
2011  731 
val analz_conj_parts = result(); 
732 

5076  733 
Goal "(X: analz H  X: parts H) = (X: parts H)"; 
4091  734 
by (blast_tac (claset() addIs [impOfSubs analz_subset_parts]) 1); 
2011  735 
val analz_disj_parts = result(); 
736 

737 
AddIffs [analz_conj_parts, analz_disj_parts]; 

738 

1998
f8230821f1e8
Reordering of premises for cut theorems, and new law MPair_synth_analz
paulson
parents:
1994
diff
changeset

739 
(*Without this equation, other rules for synth and analz would yield 
f8230821f1e8
Reordering of premises for cut theorems, and new law MPair_synth_analz
paulson
parents:
1994
diff
changeset

740 
redundant cases*) 
5076  741 
Goal "({X,Y} : synth (analz H)) = \ 
1998
f8230821f1e8
Reordering of premises for cut theorems, and new law MPair_synth_analz
paulson
parents:
1994
diff
changeset

742 
\ (X : synth (analz H) & Y : synth (analz H))"; 
2891  743 
by (Blast_tac 1); 
1998
f8230821f1e8
Reordering of premises for cut theorems, and new law MPair_synth_analz
paulson
parents:
1994
diff
changeset

744 
qed "MPair_synth_analz"; 
f8230821f1e8
Reordering of premises for cut theorems, and new law MPair_synth_analz
paulson
parents:
1994
diff
changeset

745 

f8230821f1e8
Reordering of premises for cut theorems, and new law MPair_synth_analz
paulson
parents:
1994
diff
changeset

746 
AddIffs [MPair_synth_analz]; 
1929
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

747 

5076  748 
Goal "!!K. [ Key K : analz H; Key (invKey K) : analz H ] \ 
2284
80ebd1a213fd
Swapped arguments of Crypt (for clarity and because it is conventional)
paulson
parents:
2170
diff
changeset

749 
\ ==> (Crypt K X : synth (analz H)) = (X : synth (analz H))"; 
2891  750 
by (Blast_tac 1); 
2154  751 
qed "Crypt_synth_analz"; 
752 

1929
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

753 

5076  754 
Goal "!!K. X ~: synth (analz H) \ 
2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

755 
\ ==> (Hash{X,Y} : synth (analz H)) = (Hash{X,Y} : analz H)"; 
2891  756 
by (Blast_tac 1); 
2373  757 
qed "Hash_synth_analz"; 
758 
Addsimps [Hash_synth_analz]; 

759 

760 

2484  761 
(**** HPair: a combination of Hash and MPair ****) 
762 

763 
(*** Freeness ***) 

764 

5076  765 
Goalw [HPair_def] "Agent A ~= Hash[X] Y"; 
2484  766 
by (Simp_tac 1); 
767 
qed "Agent_neq_HPair"; 

768 

5076  769 
Goalw [HPair_def] "Nonce N ~= Hash[X] Y"; 
2484  770 
by (Simp_tac 1); 
771 
qed "Nonce_neq_HPair"; 

772 

5076  773 
Goalw [HPair_def] "Number N ~= Hash[X] Y"; 
3668  774 
by (Simp_tac 1); 
775 
qed "Number_neq_HPair"; 

776 

5076  777 
Goalw [HPair_def] "Key K ~= Hash[X] Y"; 
2484  778 
by (Simp_tac 1); 
779 
qed "Key_neq_HPair"; 

780 

5076  781 
Goalw [HPair_def] "Hash Z ~= Hash[X] Y"; 
2484  782 
by (Simp_tac 1); 
783 
qed "Hash_neq_HPair"; 

784 

5076  785 
Goalw [HPair_def] "Crypt K X' ~= Hash[X] Y"; 
2484  786 
by (Simp_tac 1); 
787 
qed "Crypt_neq_HPair"; 

788 

3668  789 
val HPair_neqs = [Agent_neq_HPair, Nonce_neq_HPair, Number_neq_HPair, 
2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

790 
Key_neq_HPair, Hash_neq_HPair, Crypt_neq_HPair]; 
2484  791 

792 
AddIffs HPair_neqs; 

793 
AddIffs (HPair_neqs RL [not_sym]); 

794 

5076  795 
Goalw [HPair_def] "(Hash[X'] Y' = Hash[X] Y) = (X' = X & Y'=Y)"; 
2484  796 
by (Simp_tac 1); 
797 
qed "HPair_eq"; 

798 

5076  799 
Goalw [HPair_def] "({X',Y'} = Hash[X] Y) = (X' = Hash{X,Y} & Y'=Y)"; 
2484  800 
by (Simp_tac 1); 
801 
qed "MPair_eq_HPair"; 

802 

5076  803 
Goalw [HPair_def] "(Hash[X] Y = {X',Y'}) = (X' = Hash{X,Y} & Y'=Y)"; 
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4422
diff
changeset

804 
by Auto_tac; 
2484  805 
qed "HPair_eq_MPair"; 
806 

807 
AddIffs [HPair_eq, MPair_eq_HPair, HPair_eq_MPair]; 

808 

809 

810 
(*** Specialized laws, proved in terms of those for Hash and MPair ***) 

811 

5076  812 
Goalw [HPair_def] "keysFor (insert (Hash[X] Y) H) = keysFor H"; 
2484  813 
by (Simp_tac 1); 
814 
qed "keysFor_insert_HPair"; 

815 

5076  816 
Goalw [HPair_def] 
2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

817 
"parts (insert (Hash[X] Y) H) = \ 
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

818 
\ insert (Hash[X] Y) (insert (Hash{X,Y}) (parts (insert Y H)))"; 
2484  819 
by (Simp_tac 1); 
820 
qed "parts_insert_HPair"; 

821 

5076  822 
Goalw [HPair_def] 
2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

823 
"analz (insert (Hash[X] Y) H) = \ 
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

824 
\ insert (Hash[X] Y) (insert (Hash{X,Y}) (analz (insert Y H)))"; 
2484  825 
by (Simp_tac 1); 
826 
qed "analz_insert_HPair"; 

827 

5076  828 
Goalw [HPair_def] "!!H. X ~: synth (analz H) \ 
2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

829 
\ ==> (Hash[X] Y : synth (analz H)) = \ 
2484  830 
\ (Hash {X, Y} : analz H & Y : synth (analz H))"; 
831 
by (Simp_tac 1); 

2891  832 
by (Blast_tac 1); 
2484  833 
qed "HPair_synth_analz"; 
834 

835 
Addsimps [keysFor_insert_HPair, parts_insert_HPair, analz_insert_HPair, 

2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

836 
HPair_synth_analz, HPair_synth_analz]; 
2484  837 

838 

1929
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

839 
(*We do NOT want Crypt... messages broken up in protocols!!*) 
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

840 
Delrules partsEs; 
f0839bab4b00
Working version of NS, messages 13, WITH INTERLEAVING
paulson
parents:
1913
diff
changeset

841 

2327  842 

843 
(** Rewrites to push in Key and Crypt messages, so that other messages can 

844 
be pulled out using the analz_insert rules **) 

845 

846 
fun insComm thy x y = read_instantiate_sg (sign_of thy) [("x",x), ("y",y)] 

847 
insert_commute; 

848 

849 
val pushKeys = map (insComm thy "Key ?K") 

3668  850 
["Agent ?C", "Nonce ?N", "Number ?N", 
851 
"Hash ?X", "MPair ?X ?Y", "Crypt ?X ?K'"]; 

2327  852 

853 
val pushCrypts = map (insComm thy "Crypt ?X ?K") 

3668  854 
["Agent ?C", "Nonce ?N", "Number ?N", 
855 
"Hash ?X'", "MPair ?X' ?Y"]; 

2327  856 

857 
(*Cannot be added with Addsimps  we don't always want to reorder messages*) 

858 
val pushes = pushKeys@pushCrypts; 

859 

3121
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

860 

cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

861 
(*** Tactics useful for many protocol proofs ***) 
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

862 

3470  863 
(*Prove base case (subgoal i) and simplify others. A typical base case 
3683  864 
concerns Crypt K X ~: Key``shrK``bad and cannot be proved by rewriting 
3470  865 
alone.*) 
3121
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

866 
fun prove_simple_subgoals_tac i = 
4091  867 
fast_tac (claset() addss (simpset())) i THEN 
3121
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

868 
ALLGOALS Asm_simp_tac; 
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

869 

cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

870 
fun Fake_parts_insert_tac i = 
4556
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

871 
blast_tac (claset() addIs [parts_insertI] 
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

872 
addDs [impOfSubs analz_subset_parts, 
e7a4683c0026
Tidying, mostly to do with handling a more specific version of Fake_parts_insert
paulson
parents:
4477
diff
changeset

873 
impOfSubs Fake_parts_insert]) i; 
3121
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

874 

cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

875 
(*Apply rules to break down assumptions of the form 
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

876 
Y : parts(insert X H) and Y : analz(insert X H) 
cbb6c0c1c58a
Conversion to use blast_tac (with other improvements)
paulson
parents:
3102
diff
changeset

877 
*) 
2373  878 
val Fake_insert_tac = 
879 
dresolve_tac [impOfSubs Fake_analz_insert, 

2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

880 
impOfSubs Fake_parts_insert] THEN' 
2373  881 
eresolve_tac [asm_rl, synth.Inj]; 
882 

3702  883 
fun Fake_insert_simp_tac i = 
884 
REPEAT (Fake_insert_tac i) THEN Asm_full_simp_tac i; 

885 

886 

3449  887 
(*Analysis of Fake cases. Also works for messages that forward unknown parts, 
888 
but this application is no longer necessary if analz_insert_eq is used. 

2327  889 
Abstraction over i is ESSENTIAL: it delays the dereferencing of claset 
890 
DEPENDS UPON "X" REFERRING TO THE FRADULENT MESSAGE *) 

4735
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

891 

6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

892 
val atomic_spy_analz_tac = SELECT_GOAL 
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

893 
(Fake_insert_simp_tac 1 
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

894 
THEN 
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

895 
IF_UNSOLVED (Blast.depth_tac 
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

896 
(claset() addIs [analz_insertI, 
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

897 
impOfSubs analz_subset_parts]) 4 1)); 
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

898 

2327  899 
fun spy_analz_tac i = 
2373  900 
DETERM 
901 
(SELECT_GOAL 

902 
(EVERY 

903 
[ (*push in occurrences of X...*) 

904 
(REPEAT o CHANGED) 

905 
(res_inst_tac [("x1","X")] (insert_commute RS ssubst) 1), 

906 
(*...allowing further simplifications*) 

4686  907 
Simp_tac 1, 
3476
1be4fee7606b
spy_analz_tac: Restored iffI to the list of rules used to break down
paulson
parents:
3470
diff
changeset

908 
REPEAT (FIRSTGOAL (resolve_tac [allI,impI,notI,conjI,iffI])), 
4735
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

909 
DEPTH_SOLVE (atomic_spy_analz_tac 1)]) i); 
6d544b44a70e
spy_analz_tac now handles individual conjuncts properly
paulson
parents:
4686
diff
changeset

910 

2327  911 

2415  912 
(** Useful in many uniqueness proofs **) 
2327  913 
fun ex_strip_tac i = REPEAT (swap_res_tac [exI, conjI] i) THEN 
914 
assume_tac (i+1); 

915 

2415  916 
(*Apply the EXALL quantifification to prove uniqueness theorems in 
917 
their standard form*) 

918 
fun prove_unique_tac lemma = 

919 
EVERY' [dtac lemma, 

2516
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

920 
REPEAT o (mp_tac ORELSE' eresolve_tac [asm_rl,exE]), 
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

921 
(*Duplicate the assumption*) 
4d68fbe6378b
Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents:
2484
diff
changeset

922 
forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl, 
4091  923 
Blast.depth_tac (claset() addSDs [spec]) 0]; 
2415  924 

2373  925 

926 
(*Needed occasionally with spy_analz_tac, e.g. in analz_insert_Key_newK*) 

927 
goal Set.thy "A Un (B Un A) = B Un A"; 

2891  928 
by (Blast_tac 1); 
2373  929 
val Un_absorb3 = result(); 
930 
Addsimps [Un_absorb3]; 

3514
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

931 

eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

932 
(*By default only o_apply is builtin. But in the presence of etaexpansion 
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

933 
this means that some terms displayed as (f o g) will be rewritten, and others 
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

934 
will not!*) 
eb16b8e8d872
Moved some declarations to Message from Public and Shared
paulson
parents:
3476
diff
changeset

935 
Addsimps [o_def]; 