src/HOL/Auth/Message.ML
author paulson
Wed Apr 09 12:32:04 1997 +0200 (1997-04-09)
changeset 2922 580647a879cf
parent 2891 d8f254ad1ab9
child 2948 f18035b1d531
permissions -rw-r--r--
Using Blast_tac
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@2327
    10
val prems = goal HOL.thy "[| P ==> Q(True); ~P ==> Q(False) |] ==> Q(P)";
paulson@2327
    11
by (case_tac "P" 1);
paulson@2327
    12
by (ALLGOALS (asm_simp_tac (!simpset addsimps prems)));
paulson@2327
    13
val expand_case = result();
paulson@2327
    14
paulson@2327
    15
fun expand_case_tac P i =
paulson@2327
    16
    res_inst_tac [("P",P)] expand_case i THEN
paulson@2327
    17
    Simp_tac (i+1) THEN 
paulson@2327
    18
    Simp_tac i;
paulson@2327
    19
paulson@2327
    20
paulson@1839
    21
open Message;
paulson@1839
    22
paulson@2373
    23
AddIffs (msg.inject);
paulson@1839
    24
paulson@1839
    25
(** Inverse of keys **)
paulson@1839
    26
paulson@1839
    27
goal thy "!!K K'. (invKey K = invKey K') = (K=K')";
paulson@1839
    28
by (Step_tac 1);
paulson@2032
    29
by (rtac box_equals 1);
paulson@1839
    30
by (REPEAT (rtac invKey 2));
paulson@1839
    31
by (Asm_simp_tac 1);
paulson@1839
    32
qed "invKey_eq";
paulson@1839
    33
paulson@1839
    34
Addsimps [invKey, invKey_eq];
paulson@1839
    35
paulson@1839
    36
paulson@1839
    37
(**** keysFor operator ****)
paulson@1839
    38
paulson@1839
    39
goalw thy [keysFor_def] "keysFor {} = {}";
paulson@2891
    40
by (Blast_tac 1);
paulson@1839
    41
qed "keysFor_empty";
paulson@1839
    42
paulson@1839
    43
goalw thy [keysFor_def] "keysFor (H Un H') = keysFor H Un keysFor H'";
paulson@2891
    44
by (Blast_tac 1);
paulson@1839
    45
qed "keysFor_Un";
paulson@1839
    46
paulson@1839
    47
goalw thy [keysFor_def] "keysFor (UN i. H i) = (UN i. keysFor (H i))";
paulson@2891
    48
by (Blast_tac 1);
paulson@1839
    49
qed "keysFor_UN";
paulson@1839
    50
paulson@1839
    51
(*Monotonicity*)
paulson@1839
    52
goalw thy [keysFor_def] "!!G H. G<=H ==> keysFor(G) <= keysFor(H)";
paulson@2891
    53
by (Blast_tac 1);
paulson@1839
    54
qed "keysFor_mono";
paulson@1839
    55
paulson@1839
    56
goalw thy [keysFor_def] "keysFor (insert (Agent A) H) = keysFor H";
paulson@1839
    57
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    58
qed "keysFor_insert_Agent";
paulson@1839
    59
paulson@1839
    60
goalw thy [keysFor_def] "keysFor (insert (Nonce N) H) = keysFor H";
paulson@1839
    61
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    62
qed "keysFor_insert_Nonce";
paulson@1839
    63
paulson@1839
    64
goalw thy [keysFor_def] "keysFor (insert (Key K) H) = keysFor H";
paulson@1839
    65
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    66
qed "keysFor_insert_Key";
paulson@1839
    67
paulson@2373
    68
goalw thy [keysFor_def] "keysFor (insert (Hash X) H) = keysFor H";
paulson@2373
    69
by (fast_tac (!claset addss (!simpset)) 1);
paulson@2373
    70
qed "keysFor_insert_Hash";
paulson@2373
    71
paulson@1839
    72
goalw thy [keysFor_def] "keysFor (insert {|X,Y|} H) = keysFor H";
paulson@1839
    73
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    74
qed "keysFor_insert_MPair";
paulson@1839
    75
paulson@1839
    76
goalw thy [keysFor_def]
paulson@2284
    77
    "keysFor (insert (Crypt K X) H) = insert (invKey K) (keysFor H)";
paulson@1839
    78
by (Auto_tac());
paulson@1839
    79
qed "keysFor_insert_Crypt";
paulson@1839
    80
paulson@1839
    81
Addsimps [keysFor_empty, keysFor_Un, keysFor_UN, 
paulson@2373
    82
          keysFor_insert_Agent, keysFor_insert_Nonce, keysFor_insert_Key, 
paulson@2516
    83
          keysFor_insert_Hash, keysFor_insert_MPair, keysFor_insert_Crypt];
paulson@1839
    84
paulson@2284
    85
goalw thy [keysFor_def] "!!H. Crypt K X : H ==> invKey K : keysFor H";
paulson@2891
    86
by (Blast_tac 1);
paulson@2068
    87
qed "Crypt_imp_invKey_keysFor";
paulson@2068
    88
paulson@1839
    89
paulson@1839
    90
(**** Inductive relation "parts" ****)
paulson@1839
    91
paulson@1839
    92
val major::prems = 
paulson@1839
    93
goal thy "[| {|X,Y|} : parts H;       \
paulson@1839
    94
\            [| X : parts H; Y : parts H |] ==> P  \
paulson@1839
    95
\         |] ==> P";
paulson@1839
    96
by (cut_facts_tac [major] 1);
paulson@2032
    97
by (resolve_tac prems 1);
paulson@1839
    98
by (REPEAT (eresolve_tac [asm_rl, parts.Fst, parts.Snd] 1));
paulson@1839
    99
qed "MPair_parts";
paulson@1839
   100
paulson@1839
   101
AddIs  [parts.Inj];
paulson@1929
   102
paulson@1929
   103
val partsEs = [MPair_parts, make_elim parts.Body];
paulson@1929
   104
paulson@1929
   105
AddSEs partsEs;
paulson@1929
   106
(*NB These two rules are UNSAFE in the formal sense, as they discard the
paulson@1929
   107
     compound message.  They work well on THIS FILE, perhaps because its
paulson@1929
   108
     proofs concern only atomic messages.*)
paulson@1839
   109
paulson@1839
   110
goal thy "H <= parts(H)";
paulson@2891
   111
by (Blast_tac 1);
paulson@1839
   112
qed "parts_increasing";
paulson@1839
   113
paulson@1839
   114
(*Monotonicity*)
paulson@1839
   115
goalw thy parts.defs "!!G H. G<=H ==> parts(G) <= parts(H)";
paulson@1839
   116
by (rtac lfp_mono 1);
paulson@1839
   117
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
   118
qed "parts_mono";
paulson@1839
   119
paulson@2373
   120
val parts_insertI = impOfSubs (subset_insertI RS parts_mono);
paulson@2373
   121
paulson@1839
   122
goal thy "parts{} = {}";
paulson@1839
   123
by (Step_tac 1);
paulson@2032
   124
by (etac parts.induct 1);
paulson@2891
   125
by (ALLGOALS Blast_tac);
paulson@1839
   126
qed "parts_empty";
paulson@1839
   127
Addsimps [parts_empty];
paulson@1839
   128
paulson@1839
   129
goal thy "!!X. X: parts{} ==> P";
paulson@1839
   130
by (Asm_full_simp_tac 1);
paulson@1839
   131
qed "parts_emptyE";
paulson@1839
   132
AddSEs [parts_emptyE];
paulson@1839
   133
paulson@1893
   134
(*WARNING: loops if H = {Y}, therefore must not be repeated!*)
paulson@1893
   135
goal thy "!!H. X: parts H ==> EX Y:H. X: parts {Y}";
paulson@2032
   136
by (etac parts.induct 1);
paulson@2891
   137
by (ALLGOALS Blast_tac);
paulson@1893
   138
qed "parts_singleton";
paulson@1893
   139
paulson@1839
   140
paulson@1839
   141
(** Unions **)
paulson@1839
   142
paulson@1839
   143
goal thy "parts(G) Un parts(H) <= parts(G Un H)";
paulson@1839
   144
by (REPEAT (ares_tac [Un_least, parts_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   145
val parts_Un_subset1 = result();
paulson@1839
   146
paulson@1839
   147
goal thy "parts(G Un H) <= parts(G) Un parts(H)";
paulson@2032
   148
by (rtac subsetI 1);
paulson@2032
   149
by (etac parts.induct 1);
paulson@2891
   150
by (ALLGOALS Blast_tac);
paulson@1839
   151
val parts_Un_subset2 = result();
paulson@1839
   152
paulson@1839
   153
goal thy "parts(G Un H) = parts(G) Un parts(H)";
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@2011
   157
goal thy "parts (insert X H) = parts {X} Un parts H";
paulson@1852
   158
by (stac (read_instantiate [("A","H")] insert_is_Un) 1);
paulson@2011
   159
by (simp_tac (HOL_ss addsimps [parts_Un]) 1);
paulson@2011
   160
qed "parts_insert";
paulson@2011
   161
paulson@2011
   162
(*TWO inserts to avoid looping.  This rewrite is better than nothing.
paulson@2011
   163
  Not suitable for Addsimps: its behaviour can be strange.*)
paulson@2011
   164
goal thy "parts (insert X (insert Y H)) = parts {X} Un parts {Y} Un parts H";
paulson@2011
   165
by (simp_tac (!simpset addsimps [Un_assoc]) 1);
paulson@2011
   166
by (simp_tac (!simpset addsimps [parts_insert RS sym]) 1);
paulson@1852
   167
qed "parts_insert2";
paulson@1852
   168
paulson@1839
   169
goal thy "(UN x:A. parts(H x)) <= parts(UN x:A. H x)";
paulson@1839
   170
by (REPEAT (ares_tac [UN_least, parts_mono, UN_upper] 1));
paulson@1839
   171
val parts_UN_subset1 = result();
paulson@1839
   172
paulson@1839
   173
goal thy "parts(UN x:A. H x) <= (UN x:A. parts(H x))";
paulson@2032
   174
by (rtac subsetI 1);
paulson@2032
   175
by (etac parts.induct 1);
paulson@2891
   176
by (ALLGOALS Blast_tac);
paulson@1839
   177
val parts_UN_subset2 = result();
paulson@1839
   178
paulson@1839
   179
goal thy "parts(UN x:A. H x) = (UN x:A. parts(H x))";
paulson@1839
   180
by (REPEAT (ares_tac [equalityI, parts_UN_subset1, parts_UN_subset2] 1));
paulson@1839
   181
qed "parts_UN";
paulson@1839
   182
paulson@1839
   183
goal thy "parts(UN x. H x) = (UN x. parts(H x))";
paulson@1839
   184
by (simp_tac (!simpset addsimps [UNION1_def, parts_UN]) 1);
paulson@1839
   185
qed "parts_UN1";
paulson@1839
   186
paulson@1913
   187
(*Added to simplify arguments to parts, analz and synth*)
paulson@1839
   188
Addsimps [parts_Un, parts_UN, parts_UN1];
paulson@1839
   189
paulson@1839
   190
goal thy "insert X (parts H) <= parts(insert X H)";
paulson@2922
   191
by (blast_tac (!claset addIs [impOfSubs parts_mono]) 1);
paulson@1839
   192
qed "parts_insert_subset";
paulson@1839
   193
paulson@1839
   194
(** Idempotence and transitivity **)
paulson@1839
   195
paulson@1839
   196
goal thy "!!H. X: parts (parts H) ==> X: parts H";
paulson@2032
   197
by (etac parts.induct 1);
paulson@2891
   198
by (ALLGOALS Blast_tac);
paulson@2922
   199
qed "parts_partsD";
paulson@2922
   200
AddSDs [parts_partsD];
paulson@1839
   201
paulson@1839
   202
goal thy "parts (parts H) = parts H";
paulson@2891
   203
by (Blast_tac 1);
paulson@1839
   204
qed "parts_idem";
paulson@1839
   205
Addsimps [parts_idem];
paulson@1839
   206
paulson@1839
   207
goal thy "!!H. [| X: parts G;  G <= parts H |] ==> X: parts H";
paulson@1839
   208
by (dtac parts_mono 1);
paulson@2891
   209
by (Blast_tac 1);
paulson@1839
   210
qed "parts_trans";
paulson@1839
   211
paulson@1839
   212
(*Cut*)
paulson@2373
   213
goal thy "!!H. [| Y: parts (insert X G);  X: parts H |] \
paulson@2373
   214
\              ==> Y: parts (G Un H)";
paulson@2032
   215
by (etac parts_trans 1);
paulson@2373
   216
by (Auto_tac());
paulson@1839
   217
qed "parts_cut";
paulson@1839
   218
paulson@1929
   219
goal thy "!!H. X: parts H ==> parts (insert X H) = parts H";
paulson@2373
   220
by (fast_tac (!claset addSDs [parts_cut]
paulson@2373
   221
                      addIs  [parts_insertI] 
paulson@2373
   222
                      addss (!simpset)) 1);
paulson@1929
   223
qed "parts_cut_eq";
paulson@1929
   224
paulson@2028
   225
Addsimps [parts_cut_eq];
paulson@2028
   226
paulson@1839
   227
paulson@1839
   228
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   229
paulson@2373
   230
fun parts_tac i =
paulson@2373
   231
  EVERY [rtac ([subsetI, parts_insert_subset] MRS equalityI) i,
paulson@2516
   232
         etac parts.induct i,
paulson@2516
   233
         REPEAT (fast_tac (!claset addss (!simpset)) i)];
paulson@2373
   234
paulson@1839
   235
goal thy "parts (insert (Agent agt) H) = insert (Agent agt) (parts H)";
paulson@2373
   236
by (parts_tac 1);
paulson@1839
   237
qed "parts_insert_Agent";
paulson@1839
   238
paulson@1839
   239
goal thy "parts (insert (Nonce N) H) = insert (Nonce N) (parts H)";
paulson@2373
   240
by (parts_tac 1);
paulson@1839
   241
qed "parts_insert_Nonce";
paulson@1839
   242
paulson@1839
   243
goal thy "parts (insert (Key K) H) = insert (Key K) (parts H)";
paulson@2373
   244
by (parts_tac 1);
paulson@1839
   245
qed "parts_insert_Key";
paulson@1839
   246
paulson@2373
   247
goal thy "parts (insert (Hash X) H) = insert (Hash X) (parts H)";
paulson@2373
   248
by (parts_tac 1);
paulson@2373
   249
qed "parts_insert_Hash";
paulson@2373
   250
paulson@2284
   251
goal thy "parts (insert (Crypt K X) H) = \
paulson@2284
   252
\         insert (Crypt K X) (parts (insert X H))";
paulson@2032
   253
by (rtac equalityI 1);
paulson@2032
   254
by (rtac subsetI 1);
paulson@2032
   255
by (etac parts.induct 1);
paulson@1839
   256
by (Auto_tac());
paulson@2032
   257
by (etac parts.induct 1);
paulson@2922
   258
by (ALLGOALS (blast_tac (!claset addIs [parts.Body])));
paulson@1839
   259
qed "parts_insert_Crypt";
paulson@1839
   260
paulson@1839
   261
goal thy "parts (insert {|X,Y|} H) = \
paulson@1839
   262
\         insert {|X,Y|} (parts (insert X (insert Y H)))";
paulson@2032
   263
by (rtac equalityI 1);
paulson@2032
   264
by (rtac subsetI 1);
paulson@2032
   265
by (etac parts.induct 1);
paulson@1839
   266
by (Auto_tac());
paulson@2032
   267
by (etac parts.induct 1);
paulson@2922
   268
by (ALLGOALS (blast_tac (!claset addIs [parts.Fst, parts.Snd])));
paulson@1839
   269
qed "parts_insert_MPair";
paulson@1839
   270
paulson@2373
   271
Addsimps [parts_insert_Agent, parts_insert_Nonce, parts_insert_Key, 
paulson@2373
   272
          parts_insert_Hash, parts_insert_Crypt, parts_insert_MPair];
paulson@1839
   273
paulson@1839
   274
paulson@2026
   275
goal thy "parts (Key``N) = Key``N";
paulson@2026
   276
by (Auto_tac());
paulson@2032
   277
by (etac parts.induct 1);
paulson@2026
   278
by (Auto_tac());
paulson@2026
   279
qed "parts_image_Key";
paulson@2026
   280
paulson@2026
   281
Addsimps [parts_image_Key];
paulson@2026
   282
paulson@2026
   283
paulson@1913
   284
(**** Inductive relation "analz" ****)
paulson@1839
   285
paulson@1839
   286
val major::prems = 
paulson@1913
   287
goal thy "[| {|X,Y|} : analz H;       \
paulson@1913
   288
\            [| X : analz H; Y : analz H |] ==> P  \
paulson@1839
   289
\         |] ==> P";
paulson@1839
   290
by (cut_facts_tac [major] 1);
paulson@2032
   291
by (resolve_tac prems 1);
paulson@1913
   292
by (REPEAT (eresolve_tac [asm_rl, analz.Fst, analz.Snd] 1));
paulson@1913
   293
qed "MPair_analz";
paulson@1839
   294
paulson@1913
   295
AddIs  [analz.Inj];
paulson@2011
   296
AddSEs [MPair_analz];      (*Perhaps it should NOT be deemed safe!*)
paulson@1913
   297
AddDs  [analz.Decrypt];
paulson@1839
   298
paulson@1913
   299
Addsimps [analz.Inj];
paulson@1885
   300
paulson@1913
   301
goal thy "H <= analz(H)";
paulson@2891
   302
by (Blast_tac 1);
paulson@1913
   303
qed "analz_increasing";
paulson@1839
   304
paulson@1913
   305
goal thy "analz H <= parts H";
paulson@1839
   306
by (rtac subsetI 1);
paulson@2032
   307
by (etac analz.induct 1);
paulson@2891
   308
by (ALLGOALS Blast_tac);
paulson@1913
   309
qed "analz_subset_parts";
paulson@1839
   310
paulson@1913
   311
bind_thm ("not_parts_not_analz", analz_subset_parts RS contra_subsetD);
paulson@1839
   312
paulson@1839
   313
paulson@1913
   314
goal thy "parts (analz H) = parts H";
paulson@2032
   315
by (rtac equalityI 1);
paulson@2032
   316
by (rtac (analz_subset_parts RS parts_mono RS subset_trans) 1);
paulson@1839
   317
by (Simp_tac 1);
paulson@2891
   318
by (blast_tac (!claset addIs [analz_increasing RS parts_mono RS subsetD]) 1);
paulson@1913
   319
qed "parts_analz";
paulson@1913
   320
Addsimps [parts_analz];
paulson@1839
   321
paulson@1913
   322
goal thy "analz (parts H) = parts H";
paulson@1885
   323
by (Auto_tac());
paulson@2032
   324
by (etac analz.induct 1);
paulson@1885
   325
by (Auto_tac());
paulson@1913
   326
qed "analz_parts";
paulson@1913
   327
Addsimps [analz_parts];
paulson@1885
   328
paulson@1839
   329
(*Monotonicity; Lemma 1 of Lowe*)
paulson@1913
   330
goalw thy analz.defs "!!G H. G<=H ==> analz(G) <= analz(H)";
paulson@1839
   331
by (rtac lfp_mono 1);
paulson@1839
   332
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   333
qed "analz_mono";
paulson@1839
   334
paulson@2373
   335
val analz_insertI = impOfSubs (subset_insertI RS analz_mono);
paulson@2373
   336
paulson@1839
   337
(** General equational properties **)
paulson@1839
   338
paulson@1913
   339
goal thy "analz{} = {}";
paulson@1839
   340
by (Step_tac 1);
paulson@2032
   341
by (etac analz.induct 1);
paulson@2891
   342
by (ALLGOALS Blast_tac);
paulson@1913
   343
qed "analz_empty";
paulson@1913
   344
Addsimps [analz_empty];
paulson@1839
   345
paulson@1913
   346
(*Converse fails: we can analz more from the union than from the 
paulson@1839
   347
  separate parts, as a key in one might decrypt a message in the other*)
paulson@1913
   348
goal thy "analz(G) Un analz(H) <= analz(G Un H)";
paulson@1913
   349
by (REPEAT (ares_tac [Un_least, analz_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   350
qed "analz_Un";
paulson@1839
   351
paulson@1913
   352
goal thy "insert X (analz H) <= analz(insert X H)";
paulson@2922
   353
by (blast_tac (!claset addIs [impOfSubs analz_mono]) 1);
paulson@1913
   354
qed "analz_insert";
paulson@1839
   355
paulson@1839
   356
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   357
paulson@2373
   358
fun analz_tac i =
paulson@2373
   359
  EVERY [rtac ([subsetI, analz_insert] MRS equalityI) i,
paulson@2516
   360
         etac analz.induct i,
paulson@2516
   361
         REPEAT (fast_tac (!claset addss (!simpset)) i)];
paulson@2373
   362
paulson@1913
   363
goal thy "analz (insert (Agent agt) H) = insert (Agent agt) (analz H)";
paulson@2373
   364
by (analz_tac 1);
paulson@1913
   365
qed "analz_insert_Agent";
paulson@1839
   366
paulson@1913
   367
goal thy "analz (insert (Nonce N) H) = insert (Nonce N) (analz H)";
paulson@2373
   368
by (analz_tac 1);
paulson@1913
   369
qed "analz_insert_Nonce";
paulson@1839
   370
paulson@2373
   371
goal thy "analz (insert (Hash X) H) = insert (Hash X) (analz H)";
paulson@2373
   372
by (analz_tac 1);
paulson@2373
   373
qed "analz_insert_Hash";
paulson@2373
   374
paulson@1839
   375
(*Can only pull out Keys if they are not needed to decrypt the rest*)
paulson@1839
   376
goalw thy [keysFor_def]
paulson@1913
   377
    "!!K. K ~: keysFor (analz H) ==>  \
paulson@1913
   378
\         analz (insert (Key K) H) = insert (Key K) (analz H)";
paulson@2373
   379
by (analz_tac 1);
paulson@1913
   380
qed "analz_insert_Key";
paulson@1839
   381
paulson@1913
   382
goal thy "analz (insert {|X,Y|} H) = \
paulson@1913
   383
\         insert {|X,Y|} (analz (insert X (insert Y H)))";
paulson@2032
   384
by (rtac equalityI 1);
paulson@2032
   385
by (rtac subsetI 1);
paulson@2032
   386
by (etac analz.induct 1);
paulson@1885
   387
by (Auto_tac());
paulson@2032
   388
by (etac analz.induct 1);
paulson@2922
   389
by (ALLGOALS (blast_tac (!claset addIs [analz.Fst, analz.Snd])));
paulson@1913
   390
qed "analz_insert_MPair";
paulson@1885
   391
paulson@1885
   392
(*Can pull out enCrypted message if the Key is not known*)
paulson@1913
   393
goal thy "!!H. Key (invKey K) ~: analz H ==>  \
paulson@2284
   394
\              analz (insert (Crypt K X) H) = \
paulson@2284
   395
\              insert (Crypt K X) (analz H)";
paulson@2373
   396
by (analz_tac 1);
paulson@1913
   397
qed "analz_insert_Crypt";
paulson@1839
   398
paulson@1913
   399
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@2284
   400
\              analz (insert (Crypt K X) H) <= \
paulson@2284
   401
\              insert (Crypt K X) (analz (insert X H))";
paulson@2032
   402
by (rtac subsetI 1);
paulson@1913
   403
by (eres_inst_tac [("za","x")] analz.induct 1);
paulson@1839
   404
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   405
val lemma1 = result();
paulson@1839
   406
paulson@1913
   407
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@2284
   408
\              insert (Crypt K X) (analz (insert X H)) <= \
paulson@2284
   409
\              analz (insert (Crypt K X) H)";
paulson@1839
   410
by (Auto_tac());
paulson@1913
   411
by (eres_inst_tac [("za","x")] analz.induct 1);
paulson@1839
   412
by (Auto_tac());
paulson@2922
   413
by (blast_tac (!claset addIs [subset_insertI RS analz_mono RS subsetD,
paulson@2032
   414
                             analz.Decrypt]) 1);
paulson@1839
   415
val lemma2 = result();
paulson@1839
   416
paulson@1913
   417
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@2284
   418
\              analz (insert (Crypt K X) H) = \
paulson@2284
   419
\              insert (Crypt K X) (analz (insert X H))";
paulson@1839
   420
by (REPEAT (ares_tac [equalityI, lemma1, lemma2] 1));
paulson@1913
   421
qed "analz_insert_Decrypt";
paulson@1839
   422
paulson@1885
   423
(*Case analysis: either the message is secure, or it is not!
paulson@1946
   424
  Effective, but can cause subgoals to blow up!
paulson@1885
   425
  Use with expand_if;  apparently split_tac does not cope with patterns
paulson@2284
   426
  such as "analz (insert (Crypt K X) H)" *)
paulson@2284
   427
goal thy "analz (insert (Crypt K X) H) =                \
paulson@2154
   428
\         (if (Key (invKey K) : analz H)                \
paulson@2284
   429
\          then insert (Crypt K X) (analz (insert X H)) \
paulson@2284
   430
\          else insert (Crypt K X) (analz H))";
paulson@2102
   431
by (case_tac "Key (invKey K)  : analz H " 1);
paulson@1913
   432
by (ALLGOALS (asm_simp_tac (!simpset addsimps [analz_insert_Crypt, 
paulson@2032
   433
                                               analz_insert_Decrypt])));
paulson@1913
   434
qed "analz_Crypt_if";
paulson@1885
   435
paulson@2373
   436
Addsimps [analz_insert_Agent, analz_insert_Nonce, analz_insert_Key, 
paulson@2516
   437
          analz_insert_Hash, analz_insert_MPair, analz_Crypt_if];
paulson@1839
   438
paulson@1839
   439
(*This rule supposes "for the sake of argument" that we have the key.*)
paulson@2284
   440
goal thy  "analz (insert (Crypt K X) H) <=  \
paulson@2284
   441
\          insert (Crypt K X) (analz (insert X H))";
paulson@2032
   442
by (rtac subsetI 1);
paulson@2032
   443
by (etac analz.induct 1);
paulson@1839
   444
by (Auto_tac());
paulson@1913
   445
qed "analz_insert_Crypt_subset";
paulson@1839
   446
paulson@1839
   447
paulson@2026
   448
goal thy "analz (Key``N) = Key``N";
paulson@2026
   449
by (Auto_tac());
paulson@2032
   450
by (etac analz.induct 1);
paulson@2026
   451
by (Auto_tac());
paulson@2026
   452
qed "analz_image_Key";
paulson@2026
   453
paulson@2026
   454
Addsimps [analz_image_Key];
paulson@2026
   455
paulson@2026
   456
paulson@1839
   457
(** Idempotence and transitivity **)
paulson@1839
   458
paulson@1913
   459
goal thy "!!H. X: analz (analz H) ==> X: analz H";
paulson@2032
   460
by (etac analz.induct 1);
paulson@2891
   461
by (ALLGOALS Blast_tac);
paulson@2922
   462
qed "analz_analzD";
paulson@2922
   463
AddSDs [analz_analzD];
paulson@1839
   464
paulson@1913
   465
goal thy "analz (analz H) = analz H";
paulson@2891
   466
by (Blast_tac 1);
paulson@1913
   467
qed "analz_idem";
paulson@1913
   468
Addsimps [analz_idem];
paulson@1839
   469
paulson@1913
   470
goal thy "!!H. [| X: analz G;  G <= analz H |] ==> X: analz H";
paulson@1913
   471
by (dtac analz_mono 1);
paulson@2891
   472
by (Blast_tac 1);
paulson@1913
   473
qed "analz_trans";
paulson@1839
   474
paulson@1839
   475
(*Cut; Lemma 2 of Lowe*)
paulson@1998
   476
goal thy "!!H. [| Y: analz (insert X H);  X: analz H |] ==> Y: analz H";
paulson@2032
   477
by (etac analz_trans 1);
paulson@2891
   478
by (Blast_tac 1);
paulson@1913
   479
qed "analz_cut";
paulson@1839
   480
paulson@1839
   481
(*Cut can be proved easily by induction on
paulson@1913
   482
   "!!H. Y: analz (insert X H) ==> X: analz H --> Y: analz H"
paulson@1839
   483
*)
paulson@1839
   484
paulson@1885
   485
paulson@1913
   486
(** A congruence rule for "analz" **)
paulson@1885
   487
paulson@1913
   488
goal thy "!!H. [| analz G <= analz G'; analz H <= analz H' \
paulson@1913
   489
\              |] ==> analz (G Un H) <= analz (G' Un H')";
paulson@1885
   490
by (Step_tac 1);
paulson@2032
   491
by (etac analz.induct 1);
paulson@1913
   492
by (ALLGOALS (best_tac (!claset addIs [analz_mono RS subsetD])));
paulson@1913
   493
qed "analz_subset_cong";
paulson@1885
   494
paulson@1913
   495
goal thy "!!H. [| analz G = analz G'; analz H = analz H' \
paulson@1913
   496
\              |] ==> analz (G Un H) = analz (G' Un H')";
paulson@1913
   497
by (REPEAT_FIRST (ares_tac [equalityI, analz_subset_cong]
paulson@2032
   498
          ORELSE' etac equalityE));
paulson@1913
   499
qed "analz_cong";
paulson@1885
   500
paulson@1885
   501
paulson@1913
   502
goal thy "!!H. analz H = analz H' ==> analz(insert X H) = analz(insert X H')";
paulson@1885
   503
by (asm_simp_tac (!simpset addsimps [insert_def] 
paulson@2032
   504
                           setloop (rtac analz_cong)) 1);
paulson@1913
   505
qed "analz_insert_cong";
paulson@1885
   506
paulson@1913
   507
(*If there are no pairs or encryptions then analz does nothing*)
paulson@2284
   508
goal thy "!!H. [| ALL X Y. {|X,Y|} ~: H;  ALL X K. Crypt K X ~: H |] ==> \
paulson@1913
   509
\         analz H = H";
paulson@1839
   510
by (Step_tac 1);
paulson@2032
   511
by (etac analz.induct 1);
paulson@2891
   512
by (ALLGOALS Blast_tac);
paulson@1913
   513
qed "analz_trivial";
paulson@1839
   514
paulson@1839
   515
(*Helps to prove Fake cases*)
paulson@1913
   516
goal thy "!!X. X: analz (UN i. analz (H i)) ==> X: analz (UN i. H i)";
paulson@2032
   517
by (etac analz.induct 1);
paulson@2922
   518
by (ALLGOALS (blast_tac (!claset addIs [impOfSubs analz_mono])));
paulson@1839
   519
val lemma = result();
paulson@1839
   520
paulson@1913
   521
goal thy "analz (UN i. analz (H i)) = analz (UN i. H i)";
paulson@2922
   522
by (blast_tac (!claset addIs [lemma, impOfSubs analz_mono]) 1);
paulson@1913
   523
qed "analz_UN_analz";
paulson@1913
   524
Addsimps [analz_UN_analz];
paulson@1839
   525
paulson@1839
   526
paulson@1913
   527
(**** Inductive relation "synth" ****)
paulson@1839
   528
paulson@1913
   529
AddIs  synth.intrs;
paulson@1839
   530
paulson@2011
   531
(*Can only produce a nonce or key if it is already known,
paulson@2011
   532
  but can synth a pair or encryption from its components...*)
paulson@2011
   533
val mk_cases = synth.mk_cases msg.simps;
paulson@2011
   534
paulson@2516
   535
(*NO Agent_synth, as any Agent name can be synthesized*)
paulson@2011
   536
val Nonce_synth = mk_cases "Nonce n : synth H";
paulson@2011
   537
val Key_synth   = mk_cases "Key K : synth H";
paulson@2373
   538
val Hash_synth  = mk_cases "Hash X : synth H";
paulson@2011
   539
val MPair_synth = mk_cases "{|X,Y|} : synth H";
paulson@2284
   540
val Crypt_synth = mk_cases "Crypt K X : synth H";
paulson@2011
   541
paulson@2373
   542
AddSEs [Nonce_synth, Key_synth, Hash_synth, MPair_synth, Crypt_synth];
paulson@2011
   543
paulson@1913
   544
goal thy "H <= synth(H)";
paulson@2891
   545
by (Blast_tac 1);
paulson@1913
   546
qed "synth_increasing";
paulson@1839
   547
paulson@1839
   548
(*Monotonicity*)
paulson@1913
   549
goalw thy synth.defs "!!G H. G<=H ==> synth(G) <= synth(H)";
paulson@1839
   550
by (rtac lfp_mono 1);
paulson@1839
   551
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   552
qed "synth_mono";
paulson@1839
   553
paulson@1839
   554
(** Unions **)
paulson@1839
   555
paulson@1913
   556
(*Converse fails: we can synth more from the union than from the 
paulson@1839
   557
  separate parts, building a compound message using elements of each.*)
paulson@1913
   558
goal thy "synth(G) Un synth(H) <= synth(G Un H)";
paulson@1913
   559
by (REPEAT (ares_tac [Un_least, synth_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   560
qed "synth_Un";
paulson@1839
   561
paulson@1913
   562
goal thy "insert X (synth H) <= synth(insert X H)";
paulson@2922
   563
by (blast_tac (!claset addIs [impOfSubs synth_mono]) 1);
paulson@1913
   564
qed "synth_insert";
paulson@1885
   565
paulson@1839
   566
(** Idempotence and transitivity **)
paulson@1839
   567
paulson@1913
   568
goal thy "!!H. X: synth (synth H) ==> X: synth H";
paulson@2032
   569
by (etac synth.induct 1);
paulson@2891
   570
by (ALLGOALS Blast_tac);
paulson@2922
   571
qed "synth_synthD";
paulson@2922
   572
AddSDs [synth_synthD];
paulson@1839
   573
paulson@1913
   574
goal thy "synth (synth H) = synth H";
paulson@2891
   575
by (Blast_tac 1);
paulson@1913
   576
qed "synth_idem";
paulson@1839
   577
paulson@1913
   578
goal thy "!!H. [| X: synth G;  G <= synth H |] ==> X: synth H";
paulson@1913
   579
by (dtac synth_mono 1);
paulson@2891
   580
by (Blast_tac 1);
paulson@1913
   581
qed "synth_trans";
paulson@1839
   582
paulson@1839
   583
(*Cut; Lemma 2 of Lowe*)
paulson@1998
   584
goal thy "!!H. [| Y: synth (insert X H);  X: synth H |] ==> Y: synth H";
paulson@2032
   585
by (etac synth_trans 1);
paulson@2891
   586
by (Blast_tac 1);
paulson@1913
   587
qed "synth_cut";
paulson@1839
   588
paulson@1946
   589
goal thy "Agent A : synth H";
paulson@2891
   590
by (Blast_tac 1);
paulson@1946
   591
qed "Agent_synth";
paulson@1946
   592
paulson@1913
   593
goal thy "(Nonce N : synth H) = (Nonce N : H)";
paulson@2891
   594
by (Blast_tac 1);
paulson@1913
   595
qed "Nonce_synth_eq";
paulson@1839
   596
paulson@1913
   597
goal thy "(Key K : synth H) = (Key K : H)";
paulson@2891
   598
by (Blast_tac 1);
paulson@1913
   599
qed "Key_synth_eq";
paulson@1839
   600
paulson@2373
   601
goal thy "!!K. Key K ~: H ==> (Crypt K X : synth H) = (Crypt K X : H)";
paulson@2891
   602
by (Blast_tac 1);
paulson@2011
   603
qed "Crypt_synth_eq";
paulson@2011
   604
paulson@2011
   605
Addsimps [Agent_synth, Nonce_synth_eq, Key_synth_eq, Crypt_synth_eq];
paulson@1839
   606
paulson@1839
   607
paulson@1839
   608
goalw thy [keysFor_def]
paulson@1913
   609
    "keysFor (synth H) = keysFor H Un invKey``{K. Key K : H}";
paulson@2891
   610
by (Blast_tac 1);
paulson@1913
   611
qed "keysFor_synth";
paulson@1913
   612
Addsimps [keysFor_synth];
paulson@1839
   613
paulson@1839
   614
paulson@1913
   615
(*** Combinations of parts, analz and synth ***)
paulson@1839
   616
paulson@1913
   617
goal thy "parts (synth H) = parts H Un synth H";
paulson@2032
   618
by (rtac equalityI 1);
paulson@2032
   619
by (rtac subsetI 1);
paulson@2032
   620
by (etac parts.induct 1);
paulson@1839
   621
by (ALLGOALS
paulson@2922
   622
    (blast_tac (!claset addIs ((synth_increasing RS parts_mono RS subsetD)
paulson@2032
   623
                             ::parts.intrs))));
paulson@1913
   624
qed "parts_synth";
paulson@1913
   625
Addsimps [parts_synth];
paulson@1839
   626
paulson@2373
   627
goal thy "analz (analz G Un H) = analz (G Un H)";
paulson@2373
   628
by (REPEAT_FIRST (resolve_tac [equalityI, analz_subset_cong]));
paulson@2373
   629
by (ALLGOALS Simp_tac);
paulson@2373
   630
qed "analz_analz_Un";
paulson@2373
   631
paulson@2373
   632
goal thy "analz (synth G Un H) = analz (G Un H) Un synth G";
paulson@2032
   633
by (rtac equalityI 1);
paulson@2032
   634
by (rtac subsetI 1);
paulson@2032
   635
by (etac analz.induct 1);
paulson@2922
   636
by (blast_tac (!claset addIs [impOfSubs analz_mono]) 5);
paulson@2922
   637
by (ALLGOALS (blast_tac (!claset addIs analz.intrs)));
paulson@2373
   638
qed "analz_synth_Un";
paulson@2373
   639
paulson@2373
   640
goal thy "analz (synth H) = analz H Un synth H";
paulson@2373
   641
by (cut_inst_tac [("H","{}")] analz_synth_Un 1);
paulson@2373
   642
by (Full_simp_tac 1);
paulson@1913
   643
qed "analz_synth";
paulson@2373
   644
Addsimps [analz_analz_Un, analz_synth_Un, analz_synth];
paulson@1839
   645
paulson@2032
   646
(*Hard to prove; still needed now that there's only one Spy?*)
paulson@1913
   647
goal thy "analz (UN i. synth (H i)) = \
paulson@1913
   648
\         analz (UN i. H i) Un (UN i. synth (H i))";
paulson@2032
   649
by (rtac equalityI 1);
paulson@2032
   650
by (rtac subsetI 1);
paulson@2032
   651
by (etac analz.induct 1);
paulson@2922
   652
by (blast_tac
paulson@2922
   653
    (!claset addIs [impOfSubs synth_increasing,
paulson@2032
   654
                    impOfSubs analz_mono]) 5);
paulson@2891
   655
by (Blast_tac 1);
paulson@2891
   656
by (blast_tac (!claset addIs [analz.Inj RS analz.Fst]) 1);
paulson@2891
   657
by (blast_tac (!claset addIs [analz.Inj RS analz.Snd]) 1);
paulson@2891
   658
by (blast_tac (!claset addIs [analz.Decrypt]) 1);
paulson@1913
   659
qed "analz_UN1_synth";
paulson@1913
   660
Addsimps [analz_UN1_synth];
paulson@1929
   661
paulson@1946
   662
paulson@1946
   663
(** For reasoning about the Fake rule in traces **)
paulson@1946
   664
paulson@1929
   665
goal thy "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H";
paulson@2032
   666
by (rtac ([parts_mono, parts_Un_subset2] MRS subset_trans) 1);
paulson@2891
   667
by (Blast_tac 1);
paulson@1929
   668
qed "parts_insert_subset_Un";
paulson@1929
   669
paulson@1946
   670
(*More specifically for Fake*)
paulson@1946
   671
goal thy "!!H. X: synth (analz G) ==> \
paulson@1946
   672
\              parts (insert X H) <= synth (analz G) Un parts G Un parts H";
paulson@2032
   673
by (dtac parts_insert_subset_Un 1);
paulson@1946
   674
by (Full_simp_tac 1);
paulson@2891
   675
by (Blast_tac 1);
paulson@1946
   676
qed "Fake_parts_insert";
paulson@1946
   677
paulson@2061
   678
goal thy
paulson@2284
   679
     "!!H. [| Crypt K Y : parts (insert X H);  X: synth (analz G);  \
paulson@2061
   680
\             Key K ~: analz G |]                                   \
paulson@2284
   681
\          ==> Crypt K Y : parts G Un parts H";
paulson@2061
   682
by (dtac (impOfSubs Fake_parts_insert) 1);
paulson@2170
   683
by (assume_tac 1);
paulson@2061
   684
by (fast_tac (!claset addDs [impOfSubs analz_subset_parts]
paulson@2061
   685
                      addss (!simpset)) 1);
paulson@2061
   686
qed "Crypt_Fake_parts_insert";
paulson@2061
   687
paulson@2373
   688
goal thy "!!H. X: synth (analz G) ==> \
paulson@2373
   689
\              analz (insert X H) <= synth (analz G) Un analz (G Un H)";
paulson@2373
   690
by (rtac subsetI 1);
paulson@2373
   691
by (subgoal_tac "x : analz (synth (analz G) Un H)" 1);
paulson@2922
   692
by (blast_tac (!claset addIs [impOfSubs analz_mono,
paulson@2922
   693
			      impOfSubs (analz_mono RS synth_mono)]) 2);
paulson@2373
   694
by (Full_simp_tac 1);
paulson@2891
   695
by (Blast_tac 1);
paulson@2373
   696
qed "Fake_analz_insert";
paulson@2373
   697
paulson@2011
   698
goal thy "(X: analz H & X: parts H) = (X: analz H)";
paulson@2891
   699
by (blast_tac (!claset addIs [impOfSubs analz_subset_parts]) 1);
paulson@2011
   700
val analz_conj_parts = result();
paulson@2011
   701
paulson@2011
   702
goal thy "(X: analz H | X: parts H) = (X: parts H)";
paulson@2891
   703
by (blast_tac (!claset addIs [impOfSubs analz_subset_parts]) 1);
paulson@2011
   704
val analz_disj_parts = result();
paulson@2011
   705
paulson@2011
   706
AddIffs [analz_conj_parts, analz_disj_parts];
paulson@2011
   707
paulson@1998
   708
(*Without this equation, other rules for synth and analz would yield
paulson@1998
   709
  redundant cases*)
paulson@1998
   710
goal thy "({|X,Y|} : synth (analz H)) = \
paulson@1998
   711
\         (X : synth (analz H) & Y : synth (analz H))";
paulson@2891
   712
by (Blast_tac 1);
paulson@1998
   713
qed "MPair_synth_analz";
paulson@1998
   714
paulson@1998
   715
AddIffs [MPair_synth_analz];
paulson@1929
   716
paulson@2154
   717
goal thy "!!K. [| Key K : analz H;  Key (invKey K) : analz H |] \
paulson@2284
   718
\              ==> (Crypt K X : synth (analz H)) = (X : synth (analz H))";
paulson@2891
   719
by (Blast_tac 1);
paulson@2154
   720
qed "Crypt_synth_analz";
paulson@2154
   721
paulson@1929
   722
paulson@2516
   723
goal thy "!!K. X ~: synth (analz H) \
paulson@2516
   724
\   ==> (Hash{|X,Y|} : synth (analz H)) = (Hash{|X,Y|} : analz H)";
paulson@2891
   725
by (Blast_tac 1);
paulson@2373
   726
qed "Hash_synth_analz";
paulson@2373
   727
Addsimps [Hash_synth_analz];
paulson@2373
   728
paulson@2373
   729
paulson@2484
   730
(**** HPair: a combination of Hash and MPair ****)
paulson@2484
   731
paulson@2484
   732
(*** Freeness ***)
paulson@2484
   733
paulson@2516
   734
goalw thy [HPair_def] "Agent A ~= Hash[X] Y";
paulson@2484
   735
by (Simp_tac 1);
paulson@2484
   736
qed "Agent_neq_HPair";
paulson@2484
   737
paulson@2516
   738
goalw thy [HPair_def] "Nonce N ~= Hash[X] Y";
paulson@2484
   739
by (Simp_tac 1);
paulson@2484
   740
qed "Nonce_neq_HPair";
paulson@2484
   741
paulson@2516
   742
goalw thy [HPair_def] "Key K ~= Hash[X] Y";
paulson@2484
   743
by (Simp_tac 1);
paulson@2484
   744
qed "Key_neq_HPair";
paulson@2484
   745
paulson@2516
   746
goalw thy [HPair_def] "Hash Z ~= Hash[X] Y";
paulson@2484
   747
by (Simp_tac 1);
paulson@2484
   748
qed "Hash_neq_HPair";
paulson@2484
   749
paulson@2516
   750
goalw thy [HPair_def] "Crypt K X' ~= Hash[X] Y";
paulson@2484
   751
by (Simp_tac 1);
paulson@2484
   752
qed "Crypt_neq_HPair";
paulson@2484
   753
paulson@2484
   754
val HPair_neqs = [Agent_neq_HPair, Nonce_neq_HPair, 
paulson@2516
   755
                  Key_neq_HPair, Hash_neq_HPair, Crypt_neq_HPair];
paulson@2484
   756
paulson@2484
   757
AddIffs HPair_neqs;
paulson@2484
   758
AddIffs (HPair_neqs RL [not_sym]);
paulson@2484
   759
paulson@2516
   760
goalw thy [HPair_def] "(Hash[X'] Y' = Hash[X] Y) = (X' = X & Y'=Y)";
paulson@2484
   761
by (Simp_tac 1);
paulson@2484
   762
qed "HPair_eq";
paulson@2484
   763
paulson@2516
   764
goalw thy [HPair_def] "({|X',Y'|} = Hash[X] Y) = (X' = Hash{|X,Y|} & Y'=Y)";
paulson@2484
   765
by (Simp_tac 1);
paulson@2484
   766
qed "MPair_eq_HPair";
paulson@2484
   767
paulson@2516
   768
goalw thy [HPair_def] "(Hash[X] Y = {|X',Y'|}) = (X' = Hash{|X,Y|} & Y'=Y)";
paulson@2484
   769
by (Auto_tac());
paulson@2484
   770
qed "HPair_eq_MPair";
paulson@2484
   771
paulson@2484
   772
AddIffs [HPair_eq, MPair_eq_HPair, HPair_eq_MPair];
paulson@2484
   773
paulson@2484
   774
paulson@2484
   775
(*** Specialized laws, proved in terms of those for Hash and MPair ***)
paulson@2484
   776
paulson@2516
   777
goalw thy [HPair_def] "keysFor (insert (Hash[X] Y) H) = keysFor H";
paulson@2484
   778
by (Simp_tac 1);
paulson@2484
   779
qed "keysFor_insert_HPair";
paulson@2484
   780
paulson@2484
   781
goalw thy [HPair_def]
paulson@2516
   782
    "parts (insert (Hash[X] Y) H) = \
paulson@2516
   783
\    insert (Hash[X] Y) (insert (Hash{|X,Y|}) (parts (insert Y H)))";
paulson@2484
   784
by (Simp_tac 1);
paulson@2484
   785
qed "parts_insert_HPair";
paulson@2484
   786
paulson@2484
   787
goalw thy [HPair_def]
paulson@2516
   788
    "analz (insert (Hash[X] Y) H) = \
paulson@2516
   789
\    insert (Hash[X] Y) (insert (Hash{|X,Y|}) (analz (insert Y H)))";
paulson@2484
   790
by (Simp_tac 1);
paulson@2484
   791
qed "analz_insert_HPair";
paulson@2484
   792
paulson@2484
   793
goalw thy [HPair_def] "!!H. X ~: synth (analz H) \
paulson@2516
   794
\   ==> (Hash[X] Y : synth (analz H)) = \
paulson@2484
   795
\       (Hash {|X, Y|} : analz H & Y : synth (analz H))";
paulson@2484
   796
by (Simp_tac 1);
paulson@2891
   797
by (Blast_tac 1);
paulson@2484
   798
qed "HPair_synth_analz";
paulson@2484
   799
paulson@2484
   800
Addsimps [keysFor_insert_HPair, parts_insert_HPair, analz_insert_HPair, 
paulson@2516
   801
          HPair_synth_analz, HPair_synth_analz];
paulson@2484
   802
paulson@2484
   803
paulson@1929
   804
(*We do NOT want Crypt... messages broken up in protocols!!*)
paulson@1929
   805
Delrules partsEs;
paulson@1929
   806
paulson@2327
   807
paulson@2327
   808
(** Rewrites to push in Key and Crypt messages, so that other messages can
paulson@2327
   809
    be pulled out using the analz_insert rules **)
paulson@2327
   810
paulson@2327
   811
fun insComm thy x y = read_instantiate_sg (sign_of thy) [("x",x), ("y",y)] 
paulson@2327
   812
                          insert_commute;
paulson@2327
   813
paulson@2327
   814
val pushKeys = map (insComm thy "Key ?K") 
paulson@2373
   815
                   ["Agent ?C", "Nonce ?N", "Hash ?X", 
paulson@2516
   816
                    "MPair ?X ?Y", "Crypt ?X ?K'"];
paulson@2327
   817
paulson@2327
   818
val pushCrypts = map (insComm thy "Crypt ?X ?K") 
paulson@2373
   819
                     ["Agent ?C", "Nonce ?N", "Hash ?X'", "MPair ?X' ?Y"];
paulson@2327
   820
paulson@2327
   821
(*Cannot be added with Addsimps -- we don't always want to re-order messages*)
paulson@2327
   822
val pushes = pushKeys@pushCrypts;
paulson@2327
   823
paulson@2373
   824
val Fake_insert_tac = 
paulson@2373
   825
    dresolve_tac [impOfSubs Fake_analz_insert,
paulson@2516
   826
                  impOfSubs Fake_parts_insert] THEN'
paulson@2373
   827
    eresolve_tac [asm_rl, synth.Inj];
paulson@2373
   828
paulson@2373
   829
(*Analysis of Fake cases and of messages that forward unknown parts.
paulson@2327
   830
  Abstraction over i is ESSENTIAL: it delays the dereferencing of claset
paulson@2327
   831
  DEPENDS UPON "X" REFERRING TO THE FRADULENT MESSAGE *)
paulson@2327
   832
fun spy_analz_tac i =
paulson@2373
   833
  DETERM
paulson@2373
   834
   (SELECT_GOAL
paulson@2373
   835
     (EVERY 
paulson@2373
   836
      [  (*push in occurrences of X...*)
paulson@2373
   837
       (REPEAT o CHANGED)
paulson@2373
   838
           (res_inst_tac [("x1","X")] (insert_commute RS ssubst) 1),
paulson@2373
   839
       (*...allowing further simplifications*)
paulson@2373
   840
       simp_tac (!simpset setloop split_tac [expand_if]) 1,
paulson@2373
   841
       REPEAT (FIRSTGOAL (resolve_tac [allI,impI,notI,conjI])),
paulson@2373
   842
       DEPTH_SOLVE 
paulson@2373
   843
         (REPEAT (Fake_insert_tac 1) THEN Asm_full_simp_tac 1
paulson@2516
   844
          THEN
paulson@2516
   845
          IF_UNSOLVED (depth_tac (!claset addIs [impOfSubs analz_mono,
paulson@2516
   846
                                                 impOfSubs analz_subset_parts]) 2 1))
paulson@2373
   847
       ]) i);
paulson@2327
   848
paulson@2415
   849
(** Useful in many uniqueness proofs **)
paulson@2327
   850
fun ex_strip_tac i = REPEAT (swap_res_tac [exI, conjI] i) THEN 
paulson@2327
   851
                     assume_tac (i+1);
paulson@2327
   852
paulson@2415
   853
(*Apply the EX-ALL quantifification to prove uniqueness theorems in 
paulson@2415
   854
  their standard form*)
paulson@2415
   855
fun prove_unique_tac lemma = 
paulson@2415
   856
  EVERY' [dtac lemma,
paulson@2516
   857
          REPEAT o (mp_tac ORELSE' eresolve_tac [asm_rl,exE]),
paulson@2516
   858
          (*Duplicate the assumption*)
paulson@2516
   859
          forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl,
paulson@2559
   860
          depth_tac (!claset addSDs [spec]) 0];
paulson@2415
   861
paulson@2373
   862
paulson@2373
   863
(*Needed occasionally with spy_analz_tac, e.g. in analz_insert_Key_newK*)
paulson@2373
   864
goal Set.thy "A Un (B Un A) = B Un A";
paulson@2891
   865
by (Blast_tac 1);
paulson@2373
   866
val Un_absorb3 = result();
paulson@2373
   867
Addsimps [Un_absorb3];