src/HOL/Auth/Message.ML
author paulson
Tue Sep 03 19:07:00 1996 +0200 (1996-09-03)
changeset 1946 b59a3d686436
parent 1929 f0839bab4b00
child 1964 d551e68b7a36
permissions -rw-r--r--
New theorems for Fake case
paulson@1839
     1
(*  Title:      HOL/Auth/Message
paulson@1839
     2
    ID:         $Id$
paulson@1839
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@1839
     4
    Copyright   1996  University of Cambridge
paulson@1839
     5
paulson@1839
     6
Datatypes of agents and messages;
paulson@1913
     7
Inductive relations "parts", "analz" and "synth"
paulson@1839
     8
*)
paulson@1839
     9
paulson@1839
    10
open Message;
paulson@1839
    11
paulson@1839
    12
paulson@1839
    13
(** Inverse of keys **)
paulson@1839
    14
paulson@1839
    15
goal thy "!!K K'. (invKey K = invKey K') = (K=K')";
paulson@1839
    16
by (Step_tac 1);
paulson@1839
    17
br box_equals 1;
paulson@1839
    18
by (REPEAT (rtac invKey 2));
paulson@1839
    19
by (Asm_simp_tac 1);
paulson@1839
    20
qed "invKey_eq";
paulson@1839
    21
paulson@1839
    22
Addsimps [invKey, invKey_eq];
paulson@1839
    23
paulson@1839
    24
paulson@1839
    25
(**** keysFor operator ****)
paulson@1839
    26
paulson@1839
    27
goalw thy [keysFor_def] "keysFor {} = {}";
paulson@1839
    28
by (Fast_tac 1);
paulson@1839
    29
qed "keysFor_empty";
paulson@1839
    30
paulson@1839
    31
goalw thy [keysFor_def] "keysFor (H Un H') = keysFor H Un keysFor H'";
paulson@1839
    32
by (Fast_tac 1);
paulson@1839
    33
qed "keysFor_Un";
paulson@1839
    34
paulson@1839
    35
goalw thy [keysFor_def] "keysFor (UN i. H i) = (UN i. keysFor (H i))";
paulson@1839
    36
by (Fast_tac 1);
paulson@1839
    37
qed "keysFor_UN";
paulson@1839
    38
paulson@1839
    39
(*Monotonicity*)
paulson@1839
    40
goalw thy [keysFor_def] "!!G H. G<=H ==> keysFor(G) <= keysFor(H)";
paulson@1839
    41
by (Fast_tac 1);
paulson@1839
    42
qed "keysFor_mono";
paulson@1839
    43
paulson@1839
    44
goalw thy [keysFor_def] "keysFor (insert (Agent A) H) = keysFor H";
paulson@1839
    45
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    46
qed "keysFor_insert_Agent";
paulson@1839
    47
paulson@1839
    48
goalw thy [keysFor_def] "keysFor (insert (Nonce N) H) = keysFor H";
paulson@1839
    49
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    50
qed "keysFor_insert_Nonce";
paulson@1839
    51
paulson@1839
    52
goalw thy [keysFor_def] "keysFor (insert (Key K) H) = keysFor H";
paulson@1839
    53
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    54
qed "keysFor_insert_Key";
paulson@1839
    55
paulson@1839
    56
goalw thy [keysFor_def] "keysFor (insert {|X,Y|} H) = keysFor H";
paulson@1839
    57
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    58
qed "keysFor_insert_MPair";
paulson@1839
    59
paulson@1839
    60
goalw thy [keysFor_def]
paulson@1839
    61
    "keysFor (insert (Crypt X K) H) = insert (invKey K) (keysFor H)";
paulson@1839
    62
by (Auto_tac());
paulson@1839
    63
qed "keysFor_insert_Crypt";
paulson@1839
    64
paulson@1839
    65
Addsimps [keysFor_empty, keysFor_Un, keysFor_UN, 
paulson@1839
    66
	  keysFor_insert_Agent, keysFor_insert_Nonce,
paulson@1839
    67
	  keysFor_insert_Key, keysFor_insert_MPair,
paulson@1839
    68
	  keysFor_insert_Crypt];
paulson@1839
    69
paulson@1839
    70
paulson@1839
    71
(**** Inductive relation "parts" ****)
paulson@1839
    72
paulson@1839
    73
val major::prems = 
paulson@1839
    74
goal thy "[| {|X,Y|} : parts H;       \
paulson@1839
    75
\            [| X : parts H; Y : parts H |] ==> P  \
paulson@1839
    76
\         |] ==> P";
paulson@1839
    77
by (cut_facts_tac [major] 1);
paulson@1839
    78
brs prems 1;
paulson@1839
    79
by (REPEAT (eresolve_tac [asm_rl, parts.Fst, parts.Snd] 1));
paulson@1839
    80
qed "MPair_parts";
paulson@1839
    81
paulson@1839
    82
AddIs  [parts.Inj];
paulson@1929
    83
paulson@1929
    84
val partsEs = [MPair_parts, make_elim parts.Body];
paulson@1929
    85
paulson@1929
    86
AddSEs partsEs;
paulson@1929
    87
(*NB These two rules are UNSAFE in the formal sense, as they discard the
paulson@1929
    88
     compound message.  They work well on THIS FILE, perhaps because its
paulson@1929
    89
     proofs concern only atomic messages.*)
paulson@1839
    90
paulson@1839
    91
goal thy "H <= parts(H)";
paulson@1839
    92
by (Fast_tac 1);
paulson@1839
    93
qed "parts_increasing";
paulson@1839
    94
paulson@1839
    95
(*Monotonicity*)
paulson@1839
    96
goalw thy parts.defs "!!G H. G<=H ==> parts(G) <= parts(H)";
paulson@1839
    97
by (rtac lfp_mono 1);
paulson@1839
    98
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
    99
qed "parts_mono";
paulson@1839
   100
paulson@1839
   101
goal thy "parts{} = {}";
paulson@1839
   102
by (Step_tac 1);
paulson@1839
   103
be parts.induct 1;
paulson@1839
   104
by (ALLGOALS Fast_tac);
paulson@1839
   105
qed "parts_empty";
paulson@1839
   106
Addsimps [parts_empty];
paulson@1839
   107
paulson@1839
   108
goal thy "!!X. X: parts{} ==> P";
paulson@1839
   109
by (Asm_full_simp_tac 1);
paulson@1839
   110
qed "parts_emptyE";
paulson@1839
   111
AddSEs [parts_emptyE];
paulson@1839
   112
paulson@1893
   113
(*WARNING: loops if H = {Y}, therefore must not be repeated!*)
paulson@1893
   114
goal thy "!!H. X: parts H ==> EX Y:H. X: parts {Y}";
paulson@1893
   115
be parts.induct 1;
paulson@1893
   116
by (ALLGOALS Fast_tac);
paulson@1893
   117
qed "parts_singleton";
paulson@1893
   118
paulson@1839
   119
paulson@1839
   120
(** Unions **)
paulson@1839
   121
paulson@1839
   122
goal thy "parts(G) Un parts(H) <= parts(G Un H)";
paulson@1839
   123
by (REPEAT (ares_tac [Un_least, parts_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   124
val parts_Un_subset1 = result();
paulson@1839
   125
paulson@1839
   126
goal thy "parts(G Un H) <= parts(G) Un parts(H)";
paulson@1839
   127
br subsetI 1;
paulson@1839
   128
be parts.induct 1;
paulson@1839
   129
by (ALLGOALS Fast_tac);
paulson@1839
   130
val parts_Un_subset2 = result();
paulson@1839
   131
paulson@1839
   132
goal thy "parts(G Un H) = parts(G) Un parts(H)";
paulson@1839
   133
by (REPEAT (ares_tac [equalityI, parts_Un_subset1, parts_Un_subset2] 1));
paulson@1839
   134
qed "parts_Un";
paulson@1839
   135
paulson@1852
   136
(*TWO inserts to avoid looping.  This rewrite is better than nothing...*)
paulson@1852
   137
goal thy "parts (insert X (insert Y H)) = parts {X} Un parts {Y} Un parts H";
paulson@1852
   138
by (stac (read_instantiate [("A","H")] insert_is_Un) 1);
paulson@1852
   139
by (stac (read_instantiate [("A","{Y} Un H")] insert_is_Un) 1);
paulson@1852
   140
by (simp_tac (HOL_ss addsimps [parts_Un, Un_assoc]) 1);
paulson@1852
   141
qed "parts_insert2";
paulson@1852
   142
paulson@1839
   143
goal thy "(UN x:A. parts(H x)) <= parts(UN x:A. H x)";
paulson@1839
   144
by (REPEAT (ares_tac [UN_least, parts_mono, UN_upper] 1));
paulson@1839
   145
val parts_UN_subset1 = result();
paulson@1839
   146
paulson@1839
   147
goal thy "parts(UN x:A. H x) <= (UN x:A. parts(H x))";
paulson@1839
   148
br subsetI 1;
paulson@1839
   149
be parts.induct 1;
paulson@1839
   150
by (ALLGOALS Fast_tac);
paulson@1839
   151
val parts_UN_subset2 = result();
paulson@1839
   152
paulson@1839
   153
goal thy "parts(UN x:A. H x) = (UN x:A. parts(H x))";
paulson@1839
   154
by (REPEAT (ares_tac [equalityI, parts_UN_subset1, parts_UN_subset2] 1));
paulson@1839
   155
qed "parts_UN";
paulson@1839
   156
paulson@1839
   157
goal thy "parts(UN x. H x) = (UN x. parts(H x))";
paulson@1839
   158
by (simp_tac (!simpset addsimps [UNION1_def, parts_UN]) 1);
paulson@1839
   159
qed "parts_UN1";
paulson@1839
   160
paulson@1913
   161
(*Added to simplify arguments to parts, analz and synth*)
paulson@1839
   162
Addsimps [parts_Un, parts_UN, parts_UN1];
paulson@1839
   163
paulson@1839
   164
goal thy "insert X (parts H) <= parts(insert X H)";
paulson@1852
   165
by (fast_tac (!claset addEs [impOfSubs parts_mono]) 1);
paulson@1839
   166
qed "parts_insert_subset";
paulson@1839
   167
paulson@1839
   168
(** Idempotence and transitivity **)
paulson@1839
   169
paulson@1839
   170
goal thy "!!H. X: parts (parts H) ==> X: parts H";
paulson@1839
   171
be parts.induct 1;
paulson@1839
   172
by (ALLGOALS Fast_tac);
paulson@1839
   173
qed "parts_partsE";
paulson@1839
   174
AddSEs [parts_partsE];
paulson@1839
   175
paulson@1839
   176
goal thy "parts (parts H) = parts H";
paulson@1839
   177
by (Fast_tac 1);
paulson@1839
   178
qed "parts_idem";
paulson@1839
   179
Addsimps [parts_idem];
paulson@1839
   180
paulson@1839
   181
goal thy "!!H. [| X: parts G;  G <= parts H |] ==> X: parts H";
paulson@1839
   182
by (dtac parts_mono 1);
paulson@1839
   183
by (Fast_tac 1);
paulson@1839
   184
qed "parts_trans";
paulson@1839
   185
paulson@1839
   186
(*Cut*)
paulson@1839
   187
goal thy "!!H. [| X: parts H;  Y: parts (insert X H) |] ==> Y: parts H";
paulson@1839
   188
be parts_trans 1;
paulson@1839
   189
by (Fast_tac 1);
paulson@1839
   190
qed "parts_cut";
paulson@1839
   191
paulson@1929
   192
goal thy "!!H. X: parts H ==> parts (insert X H) = parts H";
paulson@1929
   193
by (fast_tac (!claset addSEs [parts_cut]
paulson@1929
   194
                      addIs [impOfSubs (subset_insertI RS parts_mono)]) 1);
paulson@1929
   195
qed "parts_cut_eq";
paulson@1929
   196
paulson@1839
   197
paulson@1839
   198
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   199
paulson@1839
   200
goal thy "parts (insert (Agent agt) H) = insert (Agent agt) (parts H)";
paulson@1839
   201
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   202
br subsetI 1;
paulson@1839
   203
be parts.induct 1;
paulson@1839
   204
(*Simplification breaks up equalities between messages;
paulson@1839
   205
  how to make it work for fast_tac??*)
paulson@1839
   206
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   207
qed "parts_insert_Agent";
paulson@1839
   208
paulson@1839
   209
goal thy "parts (insert (Nonce N) H) = insert (Nonce N) (parts H)";
paulson@1839
   210
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   211
br subsetI 1;
paulson@1839
   212
be parts.induct 1;
paulson@1839
   213
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   214
qed "parts_insert_Nonce";
paulson@1839
   215
paulson@1839
   216
goal thy "parts (insert (Key K) H) = insert (Key K) (parts H)";
paulson@1839
   217
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   218
br subsetI 1;
paulson@1839
   219
be parts.induct 1;
paulson@1839
   220
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   221
qed "parts_insert_Key";
paulson@1839
   222
paulson@1839
   223
goal thy "parts (insert (Crypt X K) H) = \
paulson@1839
   224
\         insert (Crypt X K) (parts (insert X H))";
paulson@1839
   225
br equalityI 1;
paulson@1839
   226
br subsetI 1;
paulson@1839
   227
be parts.induct 1;
paulson@1839
   228
by (Auto_tac());
paulson@1839
   229
be parts.induct 1;
paulson@1839
   230
by (ALLGOALS (best_tac (!claset addIs [parts.Body])));
paulson@1839
   231
qed "parts_insert_Crypt";
paulson@1839
   232
paulson@1839
   233
goal thy "parts (insert {|X,Y|} H) = \
paulson@1839
   234
\         insert {|X,Y|} (parts (insert X (insert Y H)))";
paulson@1839
   235
br equalityI 1;
paulson@1839
   236
br subsetI 1;
paulson@1839
   237
be parts.induct 1;
paulson@1839
   238
by (Auto_tac());
paulson@1839
   239
be parts.induct 1;
paulson@1839
   240
by (ALLGOALS (best_tac (!claset addIs [parts.Fst, parts.Snd])));
paulson@1839
   241
qed "parts_insert_MPair";
paulson@1839
   242
paulson@1839
   243
Addsimps [parts_insert_Agent, parts_insert_Nonce, 
paulson@1839
   244
	  parts_insert_Key, parts_insert_Crypt, parts_insert_MPair];
paulson@1839
   245
paulson@1839
   246
paulson@1913
   247
(**** Inductive relation "analz" ****)
paulson@1839
   248
paulson@1839
   249
val major::prems = 
paulson@1913
   250
goal thy "[| {|X,Y|} : analz H;       \
paulson@1913
   251
\            [| X : analz H; Y : analz H |] ==> P  \
paulson@1839
   252
\         |] ==> P";
paulson@1839
   253
by (cut_facts_tac [major] 1);
paulson@1839
   254
brs prems 1;
paulson@1913
   255
by (REPEAT (eresolve_tac [asm_rl, analz.Fst, analz.Snd] 1));
paulson@1913
   256
qed "MPair_analz";
paulson@1839
   257
paulson@1913
   258
AddIs  [analz.Inj];
paulson@1913
   259
AddSEs [MPair_analz];
paulson@1913
   260
AddDs  [analz.Decrypt];
paulson@1839
   261
paulson@1913
   262
Addsimps [analz.Inj];
paulson@1885
   263
paulson@1913
   264
goal thy "H <= analz(H)";
paulson@1839
   265
by (Fast_tac 1);
paulson@1913
   266
qed "analz_increasing";
paulson@1839
   267
paulson@1913
   268
goal thy "analz H <= parts H";
paulson@1839
   269
by (rtac subsetI 1);
paulson@1913
   270
be analz.induct 1;
paulson@1839
   271
by (ALLGOALS Fast_tac);
paulson@1913
   272
qed "analz_subset_parts";
paulson@1839
   273
paulson@1913
   274
bind_thm ("not_parts_not_analz", analz_subset_parts RS contra_subsetD);
paulson@1839
   275
paulson@1839
   276
paulson@1913
   277
goal thy "parts (analz H) = parts H";
paulson@1839
   278
br equalityI 1;
paulson@1913
   279
br (analz_subset_parts RS parts_mono RS subset_trans) 1;
paulson@1839
   280
by (Simp_tac 1);
paulson@1913
   281
by (fast_tac (!claset addDs [analz_increasing RS parts_mono RS subsetD]) 1);
paulson@1913
   282
qed "parts_analz";
paulson@1913
   283
Addsimps [parts_analz];
paulson@1839
   284
paulson@1913
   285
goal thy "analz (parts H) = parts H";
paulson@1885
   286
by (Auto_tac());
paulson@1913
   287
be analz.induct 1;
paulson@1885
   288
by (Auto_tac());
paulson@1913
   289
qed "analz_parts";
paulson@1913
   290
Addsimps [analz_parts];
paulson@1885
   291
paulson@1839
   292
(*Monotonicity; Lemma 1 of Lowe*)
paulson@1913
   293
goalw thy analz.defs "!!G H. G<=H ==> analz(G) <= analz(H)";
paulson@1839
   294
by (rtac lfp_mono 1);
paulson@1839
   295
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   296
qed "analz_mono";
paulson@1839
   297
paulson@1839
   298
(** General equational properties **)
paulson@1839
   299
paulson@1913
   300
goal thy "analz{} = {}";
paulson@1839
   301
by (Step_tac 1);
paulson@1913
   302
be analz.induct 1;
paulson@1839
   303
by (ALLGOALS Fast_tac);
paulson@1913
   304
qed "analz_empty";
paulson@1913
   305
Addsimps [analz_empty];
paulson@1839
   306
paulson@1913
   307
(*Converse fails: we can analz more from the union than from the 
paulson@1839
   308
  separate parts, as a key in one might decrypt a message in the other*)
paulson@1913
   309
goal thy "analz(G) Un analz(H) <= analz(G Un H)";
paulson@1913
   310
by (REPEAT (ares_tac [Un_least, analz_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   311
qed "analz_Un";
paulson@1839
   312
paulson@1913
   313
goal thy "insert X (analz H) <= analz(insert X H)";
paulson@1913
   314
by (fast_tac (!claset addEs [impOfSubs analz_mono]) 1);
paulson@1913
   315
qed "analz_insert";
paulson@1839
   316
paulson@1839
   317
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   318
paulson@1913
   319
goal thy "analz (insert (Agent agt) H) = insert (Agent agt) (analz H)";
paulson@1913
   320
by (rtac (analz_insert RSN (2, equalityI)) 1);
paulson@1839
   321
br subsetI 1;
paulson@1913
   322
be analz.induct 1;
paulson@1839
   323
(*Simplification breaks up equalities between messages;
paulson@1839
   324
  how to make it work for fast_tac??*)
paulson@1839
   325
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1913
   326
qed "analz_insert_Agent";
paulson@1839
   327
paulson@1913
   328
goal thy "analz (insert (Nonce N) H) = insert (Nonce N) (analz H)";
paulson@1913
   329
by (rtac (analz_insert RSN (2, equalityI)) 1);
paulson@1839
   330
br subsetI 1;
paulson@1913
   331
be analz.induct 1;
paulson@1839
   332
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1913
   333
qed "analz_insert_Nonce";
paulson@1839
   334
paulson@1839
   335
(*Can only pull out Keys if they are not needed to decrypt the rest*)
paulson@1839
   336
goalw thy [keysFor_def]
paulson@1913
   337
    "!!K. K ~: keysFor (analz H) ==>  \
paulson@1913
   338
\         analz (insert (Key K) H) = insert (Key K) (analz H)";
paulson@1913
   339
by (rtac (analz_insert RSN (2, equalityI)) 1);
paulson@1839
   340
br subsetI 1;
paulson@1913
   341
be analz.induct 1;
paulson@1839
   342
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1913
   343
qed "analz_insert_Key";
paulson@1839
   344
paulson@1913
   345
goal thy "analz (insert {|X,Y|} H) = \
paulson@1913
   346
\         insert {|X,Y|} (analz (insert X (insert Y H)))";
paulson@1885
   347
br equalityI 1;
paulson@1885
   348
br subsetI 1;
paulson@1913
   349
be analz.induct 1;
paulson@1885
   350
by (Auto_tac());
paulson@1913
   351
be analz.induct 1;
paulson@1913
   352
by (ALLGOALS (deepen_tac (!claset addIs [analz.Fst, analz.Snd, analz.Decrypt]) 0));
paulson@1913
   353
qed "analz_insert_MPair";
paulson@1885
   354
paulson@1885
   355
(*Can pull out enCrypted message if the Key is not known*)
paulson@1913
   356
goal thy "!!H. Key (invKey K) ~: analz H ==>  \
paulson@1913
   357
\              analz (insert (Crypt X K) H) = \
paulson@1913
   358
\              insert (Crypt X K) (analz H)";
paulson@1913
   359
by (rtac (analz_insert RSN (2, equalityI)) 1);
paulson@1839
   360
br subsetI 1;
paulson@1913
   361
be analz.induct 1;
paulson@1839
   362
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1913
   363
qed "analz_insert_Crypt";
paulson@1839
   364
paulson@1913
   365
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@1913
   366
\              analz (insert (Crypt X K) H) <= \
paulson@1913
   367
\              insert (Crypt X K) (analz (insert X H))";
paulson@1839
   368
br subsetI 1;
paulson@1913
   369
by (eres_inst_tac [("za","x")] analz.induct 1);
paulson@1839
   370
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   371
val lemma1 = result();
paulson@1839
   372
paulson@1913
   373
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@1913
   374
\              insert (Crypt X K) (analz (insert X H)) <= \
paulson@1913
   375
\              analz (insert (Crypt X K) H)";
paulson@1839
   376
by (Auto_tac());
paulson@1913
   377
by (eres_inst_tac [("za","x")] analz.induct 1);
paulson@1839
   378
by (Auto_tac());
paulson@1913
   379
by (best_tac (!claset addIs [subset_insertI RS analz_mono RS subsetD,
paulson@1913
   380
			     analz.Decrypt]) 1);
paulson@1839
   381
val lemma2 = result();
paulson@1839
   382
paulson@1913
   383
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@1913
   384
\              analz (insert (Crypt X K) H) = \
paulson@1913
   385
\              insert (Crypt X K) (analz (insert X H))";
paulson@1839
   386
by (REPEAT (ares_tac [equalityI, lemma1, lemma2] 1));
paulson@1913
   387
qed "analz_insert_Decrypt";
paulson@1839
   388
paulson@1885
   389
(*Case analysis: either the message is secure, or it is not!
paulson@1946
   390
  Effective, but can cause subgoals to blow up!
paulson@1885
   391
  Use with expand_if;  apparently split_tac does not cope with patterns
paulson@1913
   392
  such as "analz (insert (Crypt X' K) H)" *)
paulson@1913
   393
goal thy "analz (insert (Crypt X' K) H) = \
paulson@1913
   394
\         (if (Key (invKey K)  : analz H) then    \
paulson@1913
   395
\               insert (Crypt X' K) (analz (insert X' H)) \
paulson@1913
   396
\          else insert (Crypt X' K) (analz H))";
paulson@1913
   397
by (excluded_middle_tac "Key (invKey K)  : analz H " 1);
paulson@1913
   398
by (ALLGOALS (asm_simp_tac (!simpset addsimps [analz_insert_Crypt, 
paulson@1913
   399
					       analz_insert_Decrypt])));
paulson@1913
   400
qed "analz_Crypt_if";
paulson@1885
   401
paulson@1913
   402
Addsimps [analz_insert_Agent, analz_insert_Nonce, 
paulson@1913
   403
	  analz_insert_Key, analz_insert_MPair, 
paulson@1913
   404
	  analz_Crypt_if];
paulson@1839
   405
paulson@1839
   406
(*This rule supposes "for the sake of argument" that we have the key.*)
paulson@1913
   407
goal thy  "analz (insert (Crypt X K) H) <=  \
paulson@1913
   408
\          insert (Crypt X K) (analz (insert X H))";
paulson@1839
   409
br subsetI 1;
paulson@1913
   410
be analz.induct 1;
paulson@1839
   411
by (Auto_tac());
paulson@1913
   412
qed "analz_insert_Crypt_subset";
paulson@1839
   413
paulson@1839
   414
paulson@1839
   415
(** Idempotence and transitivity **)
paulson@1839
   416
paulson@1913
   417
goal thy "!!H. X: analz (analz H) ==> X: analz H";
paulson@1913
   418
be analz.induct 1;
paulson@1839
   419
by (ALLGOALS Fast_tac);
paulson@1913
   420
qed "analz_analzE";
paulson@1913
   421
AddSEs [analz_analzE];
paulson@1839
   422
paulson@1913
   423
goal thy "analz (analz H) = analz H";
paulson@1839
   424
by (Fast_tac 1);
paulson@1913
   425
qed "analz_idem";
paulson@1913
   426
Addsimps [analz_idem];
paulson@1839
   427
paulson@1913
   428
goal thy "!!H. [| X: analz G;  G <= analz H |] ==> X: analz H";
paulson@1913
   429
by (dtac analz_mono 1);
paulson@1839
   430
by (Fast_tac 1);
paulson@1913
   431
qed "analz_trans";
paulson@1839
   432
paulson@1839
   433
(*Cut; Lemma 2 of Lowe*)
paulson@1913
   434
goal thy "!!H. [| X: analz H;  Y: analz (insert X H) |] ==> Y: analz H";
paulson@1913
   435
be analz_trans 1;
paulson@1839
   436
by (Fast_tac 1);
paulson@1913
   437
qed "analz_cut";
paulson@1839
   438
paulson@1839
   439
(*Cut can be proved easily by induction on
paulson@1913
   440
   "!!H. Y: analz (insert X H) ==> X: analz H --> Y: analz H"
paulson@1839
   441
*)
paulson@1839
   442
paulson@1885
   443
paulson@1913
   444
(** A congruence rule for "analz" **)
paulson@1885
   445
paulson@1913
   446
goal thy "!!H. [| analz G <= analz G'; analz H <= analz H' \
paulson@1913
   447
\              |] ==> analz (G Un H) <= analz (G' Un H')";
paulson@1885
   448
by (Step_tac 1);
paulson@1913
   449
be analz.induct 1;
paulson@1913
   450
by (ALLGOALS (best_tac (!claset addIs [analz_mono RS subsetD])));
paulson@1913
   451
qed "analz_subset_cong";
paulson@1885
   452
paulson@1913
   453
goal thy "!!H. [| analz G = analz G'; analz H = analz H' \
paulson@1913
   454
\              |] ==> analz (G Un H) = analz (G' Un H')";
paulson@1913
   455
by (REPEAT_FIRST (ares_tac [equalityI, analz_subset_cong]
paulson@1885
   456
	  ORELSE' etac equalityE));
paulson@1913
   457
qed "analz_cong";
paulson@1885
   458
paulson@1885
   459
paulson@1913
   460
goal thy "!!H. analz H = analz H' ==> analz(insert X H) = analz(insert X H')";
paulson@1885
   461
by (asm_simp_tac (!simpset addsimps [insert_def] 
paulson@1913
   462
		           setloop (rtac analz_cong)) 1);
paulson@1913
   463
qed "analz_insert_cong";
paulson@1885
   464
paulson@1913
   465
(*If there are no pairs or encryptions then analz does nothing*)
paulson@1839
   466
goal thy "!!H. [| ALL X Y. {|X,Y|} ~: H;  ALL X K. Crypt X K ~: H |] ==> \
paulson@1913
   467
\         analz H = H";
paulson@1839
   468
by (Step_tac 1);
paulson@1913
   469
be analz.induct 1;
paulson@1839
   470
by (ALLGOALS Fast_tac);
paulson@1913
   471
qed "analz_trivial";
paulson@1839
   472
paulson@1839
   473
(*Helps to prove Fake cases*)
paulson@1913
   474
goal thy "!!X. X: analz (UN i. analz (H i)) ==> X: analz (UN i. H i)";
paulson@1913
   475
be analz.induct 1;
paulson@1913
   476
by (ALLGOALS (fast_tac (!claset addEs [impOfSubs analz_mono])));
paulson@1839
   477
val lemma = result();
paulson@1839
   478
paulson@1913
   479
goal thy "analz (UN i. analz (H i)) = analz (UN i. H i)";
paulson@1839
   480
by (fast_tac (!claset addIs [lemma]
paulson@1913
   481
		      addEs [impOfSubs analz_mono]) 1);
paulson@1913
   482
qed "analz_UN_analz";
paulson@1913
   483
Addsimps [analz_UN_analz];
paulson@1839
   484
paulson@1839
   485
paulson@1913
   486
(**** Inductive relation "synth" ****)
paulson@1839
   487
paulson@1913
   488
AddIs  synth.intrs;
paulson@1839
   489
paulson@1913
   490
goal thy "H <= synth(H)";
paulson@1839
   491
by (Fast_tac 1);
paulson@1913
   492
qed "synth_increasing";
paulson@1839
   493
paulson@1839
   494
(*Monotonicity*)
paulson@1913
   495
goalw thy synth.defs "!!G H. G<=H ==> synth(G) <= synth(H)";
paulson@1839
   496
by (rtac lfp_mono 1);
paulson@1839
   497
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   498
qed "synth_mono";
paulson@1839
   499
paulson@1839
   500
(** Unions **)
paulson@1839
   501
paulson@1913
   502
(*Converse fails: we can synth more from the union than from the 
paulson@1839
   503
  separate parts, building a compound message using elements of each.*)
paulson@1913
   504
goal thy "synth(G) Un synth(H) <= synth(G Un H)";
paulson@1913
   505
by (REPEAT (ares_tac [Un_least, synth_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   506
qed "synth_Un";
paulson@1839
   507
paulson@1913
   508
goal thy "insert X (synth H) <= synth(insert X H)";
paulson@1913
   509
by (fast_tac (!claset addEs [impOfSubs synth_mono]) 1);
paulson@1913
   510
qed "synth_insert";
paulson@1885
   511
paulson@1839
   512
(** Idempotence and transitivity **)
paulson@1839
   513
paulson@1913
   514
goal thy "!!H. X: synth (synth H) ==> X: synth H";
paulson@1913
   515
be synth.induct 1;
paulson@1839
   516
by (ALLGOALS Fast_tac);
paulson@1913
   517
qed "synth_synthE";
paulson@1913
   518
AddSEs [synth_synthE];
paulson@1839
   519
paulson@1913
   520
goal thy "synth (synth H) = synth H";
paulson@1839
   521
by (Fast_tac 1);
paulson@1913
   522
qed "synth_idem";
paulson@1839
   523
paulson@1913
   524
goal thy "!!H. [| X: synth G;  G <= synth H |] ==> X: synth H";
paulson@1913
   525
by (dtac synth_mono 1);
paulson@1839
   526
by (Fast_tac 1);
paulson@1913
   527
qed "synth_trans";
paulson@1839
   528
paulson@1839
   529
(*Cut; Lemma 2 of Lowe*)
paulson@1913
   530
goal thy "!!H. [| X: synth H;  Y: synth (insert X H) |] ==> Y: synth H";
paulson@1913
   531
be synth_trans 1;
paulson@1839
   532
by (Fast_tac 1);
paulson@1913
   533
qed "synth_cut";
paulson@1839
   534
paulson@1839
   535
paulson@1839
   536
(*Can only produce a nonce or key if it is already known,
paulson@1913
   537
  but can synth a pair or encryption from its components...*)
paulson@1913
   538
val mk_cases = synth.mk_cases msg.simps;
paulson@1839
   539
paulson@1913
   540
(*NO Agent_synth, as any Agent name can be synthd*)
paulson@1913
   541
val Nonce_synth = mk_cases "Nonce n : synth H";
paulson@1913
   542
val Key_synth   = mk_cases "Key K : synth H";
paulson@1913
   543
val MPair_synth = mk_cases "{|X,Y|} : synth H";
paulson@1913
   544
val Crypt_synth = mk_cases "Crypt X K : synth H";
paulson@1839
   545
paulson@1913
   546
AddSEs [Nonce_synth, Key_synth, MPair_synth, Crypt_synth];
paulson@1839
   547
paulson@1946
   548
goal thy "Agent A : synth H";
paulson@1946
   549
by (Fast_tac 1);
paulson@1946
   550
qed "Agent_synth";
paulson@1946
   551
paulson@1913
   552
goal thy "(Nonce N : synth H) = (Nonce N : H)";
paulson@1839
   553
by (Fast_tac 1);
paulson@1913
   554
qed "Nonce_synth_eq";
paulson@1839
   555
paulson@1913
   556
goal thy "(Key K : synth H) = (Key K : H)";
paulson@1839
   557
by (Fast_tac 1);
paulson@1913
   558
qed "Key_synth_eq";
paulson@1839
   559
paulson@1946
   560
Addsimps [Agent_synth, Nonce_synth_eq, Key_synth_eq];
paulson@1839
   561
paulson@1839
   562
paulson@1839
   563
goalw thy [keysFor_def]
paulson@1913
   564
    "keysFor (synth H) = keysFor H Un invKey``{K. Key K : H}";
paulson@1839
   565
by (Fast_tac 1);
paulson@1913
   566
qed "keysFor_synth";
paulson@1913
   567
Addsimps [keysFor_synth];
paulson@1839
   568
paulson@1839
   569
paulson@1913
   570
(*** Combinations of parts, analz and synth ***)
paulson@1839
   571
paulson@1913
   572
goal thy "parts (synth H) = parts H Un synth H";
paulson@1839
   573
br equalityI 1;
paulson@1839
   574
br subsetI 1;
paulson@1839
   575
be parts.induct 1;
paulson@1839
   576
by (ALLGOALS
paulson@1913
   577
    (best_tac (!claset addIs ((synth_increasing RS parts_mono RS subsetD)
paulson@1839
   578
			     ::parts.intrs))));
paulson@1913
   579
qed "parts_synth";
paulson@1913
   580
Addsimps [parts_synth];
paulson@1839
   581
paulson@1913
   582
goal thy "analz (synth H) = analz H Un synth H";
paulson@1839
   583
br equalityI 1;
paulson@1839
   584
br subsetI 1;
paulson@1913
   585
be analz.induct 1;
paulson@1839
   586
by (best_tac
paulson@1913
   587
    (!claset addIs [synth_increasing RS analz_mono RS subsetD]) 5);
paulson@1839
   588
(*Strange that best_tac just can't hack this one...*)
paulson@1913
   589
by (ALLGOALS (deepen_tac (!claset addIs analz.intrs) 0));
paulson@1913
   590
qed "analz_synth";
paulson@1913
   591
Addsimps [analz_synth];
paulson@1839
   592
paulson@1839
   593
(*Hard to prove; still needed now that there's only one Enemy?*)
paulson@1913
   594
goal thy "analz (UN i. synth (H i)) = \
paulson@1913
   595
\         analz (UN i. H i) Un (UN i. synth (H i))";
paulson@1839
   596
br equalityI 1;
paulson@1839
   597
br subsetI 1;
paulson@1913
   598
be analz.induct 1;
paulson@1839
   599
by (best_tac
paulson@1913
   600
    (!claset addEs [impOfSubs synth_increasing,
paulson@1913
   601
		    impOfSubs analz_mono]) 5);
paulson@1839
   602
by (Best_tac 1);
paulson@1913
   603
by (deepen_tac (!claset addIs [analz.Fst]) 0 1);
paulson@1913
   604
by (deepen_tac (!claset addIs [analz.Snd]) 0 1);
paulson@1913
   605
by (deepen_tac (!claset addSEs [analz.Decrypt]
paulson@1913
   606
			addIs  [analz.Decrypt]) 0 1);
paulson@1913
   607
qed "analz_UN1_synth";
paulson@1913
   608
Addsimps [analz_UN1_synth];
paulson@1929
   609
paulson@1946
   610
paulson@1946
   611
(** For reasoning about the Fake rule in traces **)
paulson@1946
   612
paulson@1929
   613
goal thy "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H";
paulson@1929
   614
br ([parts_mono, parts_Un_subset2] MRS subset_trans) 1;
paulson@1929
   615
by (Fast_tac 1);
paulson@1929
   616
qed "parts_insert_subset_Un";
paulson@1929
   617
paulson@1946
   618
(*More specifically for Fake****OBSOLETE VERSION
paulson@1929
   619
goal thy "!!H. X: synth (analz H) ==> \
paulson@1929
   620
\              parts (insert X H) <= synth (analz H) Un parts H";
paulson@1929
   621
bd parts_insert_subset_Un 1;
paulson@1929
   622
by (Full_simp_tac 1);
paulson@1929
   623
by (Fast_tac 1);
paulson@1946
   624
qed "Fake_parts_insert";
paulson@1946
   625
*)
paulson@1946
   626
paulson@1946
   627
(*More specifically for Fake*)
paulson@1946
   628
goal thy "!!H. X: synth (analz G) ==> \
paulson@1946
   629
\              parts (insert X H) <= synth (analz G) Un parts G Un parts H";
paulson@1946
   630
bd parts_insert_subset_Un 1;
paulson@1946
   631
by (Full_simp_tac 1);
paulson@1946
   632
by (Deepen_tac 0 1);
paulson@1946
   633
qed "Fake_parts_insert";
paulson@1946
   634
paulson@1946
   635
goal thy "!!H. [| X: synth (analz G); G <= H |] ==> \
paulson@1946
   636
\              analz (insert X H) <= synth (analz H) Un analz H";
paulson@1946
   637
br subsetI 1;
paulson@1946
   638
by (subgoal_tac "x : analz (synth (analz H))" 1);
paulson@1946
   639
by (best_tac (!claset addIs [impOfSubs (analz_mono RS synth_mono)]
paulson@1946
   640
                      addSEs [impOfSubs analz_mono]) 2);
paulson@1946
   641
by (Full_simp_tac 1);
paulson@1946
   642
by (Fast_tac 1);
paulson@1946
   643
qed "Fake_analz_insert";
paulson@1929
   644
paulson@1929
   645
paulson@1929
   646
paulson@1929
   647
(*We do NOT want Crypt... messages broken up in protocols!!*)
paulson@1929
   648
Delrules partsEs;
paulson@1929
   649