src/HOL/Auth/Message.ML
author paulson
Fri Apr 04 11:18:52 1997 +0200 (1997-04-04)
changeset 2891 d8f254ad1ab9
parent 2637 e9b203f854ae
child 2922 580647a879cf
permissions -rw-r--r--
Calls 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@1852
   191
by (fast_tac (!claset addEs [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@1839
   199
qed "parts_partsE";
paulson@2891
   200
AddSDs [parts_partsE];
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@1839
   258
by (ALLGOALS (best_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@1839
   268
by (ALLGOALS (best_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@1913
   353
by (fast_tac (!claset addEs [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@2891
   389
by (ALLGOALS (deepen_tac (!claset addIs [analz.Fst, analz.Snd]) 0));
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@1913
   413
by (best_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@1913
   462
qed "analz_analzE";
paulson@2891
   463
AddSDs [analz_analzE];
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@1913
   518
by (ALLGOALS (fast_tac (!claset addEs [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@1839
   522
by (fast_tac (!claset addIs [lemma]
paulson@2032
   523
                      addEs [impOfSubs analz_mono]) 1);
paulson@1913
   524
qed "analz_UN_analz";
paulson@1913
   525
Addsimps [analz_UN_analz];
paulson@1839
   526
paulson@1839
   527
paulson@1913
   528
(**** Inductive relation "synth" ****)
paulson@1839
   529
paulson@1913
   530
AddIs  synth.intrs;
paulson@1839
   531
paulson@2011
   532
(*Can only produce a nonce or key if it is already known,
paulson@2011
   533
  but can synth a pair or encryption from its components...*)
paulson@2011
   534
val mk_cases = synth.mk_cases msg.simps;
paulson@2011
   535
paulson@2516
   536
(*NO Agent_synth, as any Agent name can be synthesized*)
paulson@2011
   537
val Nonce_synth = mk_cases "Nonce n : synth H";
paulson@2011
   538
val Key_synth   = mk_cases "Key K : synth H";
paulson@2373
   539
val Hash_synth  = mk_cases "Hash X : synth H";
paulson@2011
   540
val MPair_synth = mk_cases "{|X,Y|} : synth H";
paulson@2284
   541
val Crypt_synth = mk_cases "Crypt K X : synth H";
paulson@2011
   542
paulson@2373
   543
AddSEs [Nonce_synth, Key_synth, Hash_synth, MPair_synth, Crypt_synth];
paulson@2011
   544
paulson@1913
   545
goal thy "H <= synth(H)";
paulson@2891
   546
by (Blast_tac 1);
paulson@1913
   547
qed "synth_increasing";
paulson@1839
   548
paulson@1839
   549
(*Monotonicity*)
paulson@1913
   550
goalw thy synth.defs "!!G H. G<=H ==> synth(G) <= synth(H)";
paulson@1839
   551
by (rtac lfp_mono 1);
paulson@1839
   552
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   553
qed "synth_mono";
paulson@1839
   554
paulson@1839
   555
(** Unions **)
paulson@1839
   556
paulson@1913
   557
(*Converse fails: we can synth more from the union than from the 
paulson@1839
   558
  separate parts, building a compound message using elements of each.*)
paulson@1913
   559
goal thy "synth(G) Un synth(H) <= synth(G Un H)";
paulson@1913
   560
by (REPEAT (ares_tac [Un_least, synth_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   561
qed "synth_Un";
paulson@1839
   562
paulson@1913
   563
goal thy "insert X (synth H) <= synth(insert X H)";
paulson@1913
   564
by (fast_tac (!claset addEs [impOfSubs synth_mono]) 1);
paulson@1913
   565
qed "synth_insert";
paulson@1885
   566
paulson@1839
   567
(** Idempotence and transitivity **)
paulson@1839
   568
paulson@1913
   569
goal thy "!!H. X: synth (synth H) ==> X: synth H";
paulson@2032
   570
by (etac synth.induct 1);
paulson@2891
   571
by (ALLGOALS Blast_tac);
paulson@1913
   572
qed "synth_synthE";
paulson@2891
   573
AddSDs [synth_synthE];
paulson@1839
   574
paulson@1913
   575
goal thy "synth (synth H) = synth H";
paulson@2891
   576
by (Blast_tac 1);
paulson@1913
   577
qed "synth_idem";
paulson@1839
   578
paulson@1913
   579
goal thy "!!H. [| X: synth G;  G <= synth H |] ==> X: synth H";
paulson@1913
   580
by (dtac synth_mono 1);
paulson@2891
   581
by (Blast_tac 1);
paulson@1913
   582
qed "synth_trans";
paulson@1839
   583
paulson@1839
   584
(*Cut; Lemma 2 of Lowe*)
paulson@1998
   585
goal thy "!!H. [| Y: synth (insert X H);  X: synth H |] ==> Y: synth H";
paulson@2032
   586
by (etac synth_trans 1);
paulson@2891
   587
by (Blast_tac 1);
paulson@1913
   588
qed "synth_cut";
paulson@1839
   589
paulson@1946
   590
goal thy "Agent A : synth H";
paulson@2891
   591
by (Blast_tac 1);
paulson@1946
   592
qed "Agent_synth";
paulson@1946
   593
paulson@1913
   594
goal thy "(Nonce N : synth H) = (Nonce N : H)";
paulson@2891
   595
by (Blast_tac 1);
paulson@1913
   596
qed "Nonce_synth_eq";
paulson@1839
   597
paulson@1913
   598
goal thy "(Key K : synth H) = (Key K : H)";
paulson@2891
   599
by (Blast_tac 1);
paulson@1913
   600
qed "Key_synth_eq";
paulson@1839
   601
paulson@2373
   602
goal thy "!!K. Key K ~: H ==> (Crypt K X : synth H) = (Crypt K X : H)";
paulson@2891
   603
by (Blast_tac 1);
paulson@2011
   604
qed "Crypt_synth_eq";
paulson@2011
   605
paulson@2011
   606
Addsimps [Agent_synth, Nonce_synth_eq, Key_synth_eq, Crypt_synth_eq];
paulson@1839
   607
paulson@1839
   608
paulson@1839
   609
goalw thy [keysFor_def]
paulson@1913
   610
    "keysFor (synth H) = keysFor H Un invKey``{K. Key K : H}";
paulson@2891
   611
by (Blast_tac 1);
paulson@1913
   612
qed "keysFor_synth";
paulson@1913
   613
Addsimps [keysFor_synth];
paulson@1839
   614
paulson@1839
   615
paulson@1913
   616
(*** Combinations of parts, analz and synth ***)
paulson@1839
   617
paulson@1913
   618
goal thy "parts (synth H) = parts H Un synth H";
paulson@2032
   619
by (rtac equalityI 1);
paulson@2032
   620
by (rtac subsetI 1);
paulson@2032
   621
by (etac parts.induct 1);
paulson@1839
   622
by (ALLGOALS
paulson@1913
   623
    (best_tac (!claset addIs ((synth_increasing RS parts_mono RS subsetD)
paulson@2032
   624
                             ::parts.intrs))));
paulson@1913
   625
qed "parts_synth";
paulson@1913
   626
Addsimps [parts_synth];
paulson@1839
   627
paulson@2373
   628
goal thy "analz (analz G Un H) = analz (G Un H)";
paulson@2373
   629
by (REPEAT_FIRST (resolve_tac [equalityI, analz_subset_cong]));
paulson@2373
   630
by (ALLGOALS Simp_tac);
paulson@2373
   631
qed "analz_analz_Un";
paulson@2373
   632
paulson@2373
   633
goal thy "analz (synth G Un H) = analz (G Un H) Un synth G";
paulson@2032
   634
by (rtac equalityI 1);
paulson@2032
   635
by (rtac subsetI 1);
paulson@2032
   636
by (etac analz.induct 1);
paulson@2373
   637
by (deepen_tac (!claset addIs [impOfSubs analz_mono]) 0 5);
paulson@1839
   638
(*Strange that best_tac just can't hack this one...*)
paulson@1913
   639
by (ALLGOALS (deepen_tac (!claset addIs analz.intrs) 0));
paulson@2373
   640
qed "analz_synth_Un";
paulson@2373
   641
paulson@2373
   642
goal thy "analz (synth H) = analz H Un synth H";
paulson@2373
   643
by (cut_inst_tac [("H","{}")] analz_synth_Un 1);
paulson@2373
   644
by (Full_simp_tac 1);
paulson@1913
   645
qed "analz_synth";
paulson@2373
   646
Addsimps [analz_analz_Un, analz_synth_Un, analz_synth];
paulson@1839
   647
paulson@2032
   648
(*Hard to prove; still needed now that there's only one Spy?*)
paulson@1913
   649
goal thy "analz (UN i. synth (H i)) = \
paulson@1913
   650
\         analz (UN i. H i) Un (UN i. synth (H i))";
paulson@2032
   651
by (rtac equalityI 1);
paulson@2032
   652
by (rtac subsetI 1);
paulson@2032
   653
by (etac analz.induct 1);
paulson@1839
   654
by (best_tac
paulson@1913
   655
    (!claset addEs [impOfSubs synth_increasing,
paulson@2032
   656
                    impOfSubs analz_mono]) 5);
paulson@2891
   657
by (Blast_tac 1);
paulson@2891
   658
by (blast_tac (!claset addIs [analz.Inj RS analz.Fst]) 1);
paulson@2891
   659
by (blast_tac (!claset addIs [analz.Inj RS analz.Snd]) 1);
paulson@2891
   660
by (blast_tac (!claset addIs [analz.Decrypt]) 1);
paulson@1913
   661
qed "analz_UN1_synth";
paulson@1913
   662
Addsimps [analz_UN1_synth];
paulson@1929
   663
paulson@1946
   664
paulson@1946
   665
(** For reasoning about the Fake rule in traces **)
paulson@1946
   666
paulson@1929
   667
goal thy "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H";
paulson@2032
   668
by (rtac ([parts_mono, parts_Un_subset2] MRS subset_trans) 1);
paulson@2891
   669
by (Blast_tac 1);
paulson@1929
   670
qed "parts_insert_subset_Un";
paulson@1929
   671
paulson@1946
   672
(*More specifically for Fake*)
paulson@1946
   673
goal thy "!!H. X: synth (analz G) ==> \
paulson@1946
   674
\              parts (insert X H) <= synth (analz G) Un parts G Un parts H";
paulson@2032
   675
by (dtac parts_insert_subset_Un 1);
paulson@1946
   676
by (Full_simp_tac 1);
paulson@2891
   677
by (Blast_tac 1);
paulson@1946
   678
qed "Fake_parts_insert";
paulson@1946
   679
paulson@2061
   680
goal thy
paulson@2284
   681
     "!!H. [| Crypt K Y : parts (insert X H);  X: synth (analz G);  \
paulson@2061
   682
\             Key K ~: analz G |]                                   \
paulson@2284
   683
\          ==> Crypt K Y : parts G Un parts H";
paulson@2061
   684
by (dtac (impOfSubs Fake_parts_insert) 1);
paulson@2170
   685
by (assume_tac 1);
paulson@2061
   686
by (fast_tac (!claset addDs [impOfSubs analz_subset_parts]
paulson@2061
   687
                      addss (!simpset)) 1);
paulson@2061
   688
qed "Crypt_Fake_parts_insert";
paulson@2061
   689
paulson@2373
   690
goal thy "!!H. X: synth (analz G) ==> \
paulson@2373
   691
\              analz (insert X H) <= synth (analz G) Un analz (G Un H)";
paulson@2373
   692
by (rtac subsetI 1);
paulson@2373
   693
by (subgoal_tac "x : analz (synth (analz G) Un H)" 1);
paulson@2373
   694
by (best_tac (!claset addIs [impOfSubs (analz_mono RS synth_mono)]
paulson@2373
   695
                      addSEs [impOfSubs analz_mono]) 2);
paulson@2373
   696
by (Full_simp_tac 1);
paulson@2891
   697
by (Blast_tac 1);
paulson@2373
   698
qed "Fake_analz_insert";
paulson@2373
   699
paulson@2011
   700
goal thy "(X: analz H & X: parts H) = (X: analz H)";
paulson@2891
   701
by (blast_tac (!claset addIs [impOfSubs analz_subset_parts]) 1);
paulson@2011
   702
val analz_conj_parts = result();
paulson@2011
   703
paulson@2011
   704
goal thy "(X: analz H | X: parts H) = (X: parts H)";
paulson@2891
   705
by (blast_tac (!claset addIs [impOfSubs analz_subset_parts]) 1);
paulson@2011
   706
val analz_disj_parts = result();
paulson@2011
   707
paulson@2011
   708
AddIffs [analz_conj_parts, analz_disj_parts];
paulson@2011
   709
paulson@1998
   710
(*Without this equation, other rules for synth and analz would yield
paulson@1998
   711
  redundant cases*)
paulson@1998
   712
goal thy "({|X,Y|} : synth (analz H)) = \
paulson@1998
   713
\         (X : synth (analz H) & Y : synth (analz H))";
paulson@2891
   714
by (Blast_tac 1);
paulson@1998
   715
qed "MPair_synth_analz";
paulson@1998
   716
paulson@1998
   717
AddIffs [MPair_synth_analz];
paulson@1929
   718
paulson@2154
   719
goal thy "!!K. [| Key K : analz H;  Key (invKey K) : analz H |] \
paulson@2284
   720
\              ==> (Crypt K X : synth (analz H)) = (X : synth (analz H))";
paulson@2891
   721
by (Blast_tac 1);
paulson@2154
   722
qed "Crypt_synth_analz";
paulson@2154
   723
paulson@1929
   724
paulson@2516
   725
goal thy "!!K. X ~: synth (analz H) \
paulson@2516
   726
\   ==> (Hash{|X,Y|} : synth (analz H)) = (Hash{|X,Y|} : analz H)";
paulson@2891
   727
by (Blast_tac 1);
paulson@2373
   728
qed "Hash_synth_analz";
paulson@2373
   729
Addsimps [Hash_synth_analz];
paulson@2373
   730
paulson@2373
   731
paulson@2484
   732
(**** HPair: a combination of Hash and MPair ****)
paulson@2484
   733
paulson@2484
   734
(*** Freeness ***)
paulson@2484
   735
paulson@2516
   736
goalw thy [HPair_def] "Agent A ~= Hash[X] Y";
paulson@2484
   737
by (Simp_tac 1);
paulson@2484
   738
qed "Agent_neq_HPair";
paulson@2484
   739
paulson@2516
   740
goalw thy [HPair_def] "Nonce N ~= Hash[X] Y";
paulson@2484
   741
by (Simp_tac 1);
paulson@2484
   742
qed "Nonce_neq_HPair";
paulson@2484
   743
paulson@2516
   744
goalw thy [HPair_def] "Key K ~= Hash[X] Y";
paulson@2484
   745
by (Simp_tac 1);
paulson@2484
   746
qed "Key_neq_HPair";
paulson@2484
   747
paulson@2516
   748
goalw thy [HPair_def] "Hash Z ~= Hash[X] Y";
paulson@2484
   749
by (Simp_tac 1);
paulson@2484
   750
qed "Hash_neq_HPair";
paulson@2484
   751
paulson@2516
   752
goalw thy [HPair_def] "Crypt K X' ~= Hash[X] Y";
paulson@2484
   753
by (Simp_tac 1);
paulson@2484
   754
qed "Crypt_neq_HPair";
paulson@2484
   755
paulson@2484
   756
val HPair_neqs = [Agent_neq_HPair, Nonce_neq_HPair, 
paulson@2516
   757
                  Key_neq_HPair, Hash_neq_HPair, Crypt_neq_HPair];
paulson@2484
   758
paulson@2484
   759
AddIffs HPair_neqs;
paulson@2484
   760
AddIffs (HPair_neqs RL [not_sym]);
paulson@2484
   761
paulson@2516
   762
goalw thy [HPair_def] "(Hash[X'] Y' = Hash[X] Y) = (X' = X & Y'=Y)";
paulson@2484
   763
by (Simp_tac 1);
paulson@2484
   764
qed "HPair_eq";
paulson@2484
   765
paulson@2516
   766
goalw thy [HPair_def] "({|X',Y'|} = Hash[X] Y) = (X' = Hash{|X,Y|} & Y'=Y)";
paulson@2484
   767
by (Simp_tac 1);
paulson@2484
   768
qed "MPair_eq_HPair";
paulson@2484
   769
paulson@2516
   770
goalw thy [HPair_def] "(Hash[X] Y = {|X',Y'|}) = (X' = Hash{|X,Y|} & Y'=Y)";
paulson@2484
   771
by (Auto_tac());
paulson@2484
   772
qed "HPair_eq_MPair";
paulson@2484
   773
paulson@2484
   774
AddIffs [HPair_eq, MPair_eq_HPair, HPair_eq_MPair];
paulson@2484
   775
paulson@2484
   776
paulson@2484
   777
(*** Specialized laws, proved in terms of those for Hash and MPair ***)
paulson@2484
   778
paulson@2516
   779
goalw thy [HPair_def] "keysFor (insert (Hash[X] Y) H) = keysFor H";
paulson@2484
   780
by (Simp_tac 1);
paulson@2484
   781
qed "keysFor_insert_HPair";
paulson@2484
   782
paulson@2484
   783
goalw thy [HPair_def]
paulson@2516
   784
    "parts (insert (Hash[X] Y) H) = \
paulson@2516
   785
\    insert (Hash[X] Y) (insert (Hash{|X,Y|}) (parts (insert Y H)))";
paulson@2484
   786
by (Simp_tac 1);
paulson@2484
   787
qed "parts_insert_HPair";
paulson@2484
   788
paulson@2484
   789
goalw thy [HPair_def]
paulson@2516
   790
    "analz (insert (Hash[X] Y) H) = \
paulson@2516
   791
\    insert (Hash[X] Y) (insert (Hash{|X,Y|}) (analz (insert Y H)))";
paulson@2484
   792
by (Simp_tac 1);
paulson@2484
   793
qed "analz_insert_HPair";
paulson@2484
   794
paulson@2484
   795
goalw thy [HPair_def] "!!H. X ~: synth (analz H) \
paulson@2516
   796
\   ==> (Hash[X] Y : synth (analz H)) = \
paulson@2484
   797
\       (Hash {|X, Y|} : analz H & Y : synth (analz H))";
paulson@2484
   798
by (Simp_tac 1);
paulson@2891
   799
by (Blast_tac 1);
paulson@2484
   800
qed "HPair_synth_analz";
paulson@2484
   801
paulson@2484
   802
Addsimps [keysFor_insert_HPair, parts_insert_HPair, analz_insert_HPair, 
paulson@2516
   803
          HPair_synth_analz, HPair_synth_analz];
paulson@2484
   804
paulson@2484
   805
paulson@1929
   806
(*We do NOT want Crypt... messages broken up in protocols!!*)
paulson@1929
   807
Delrules partsEs;
paulson@1929
   808
paulson@2327
   809
paulson@2327
   810
(** Rewrites to push in Key and Crypt messages, so that other messages can
paulson@2327
   811
    be pulled out using the analz_insert rules **)
paulson@2327
   812
paulson@2327
   813
fun insComm thy x y = read_instantiate_sg (sign_of thy) [("x",x), ("y",y)] 
paulson@2327
   814
                          insert_commute;
paulson@2327
   815
paulson@2327
   816
val pushKeys = map (insComm thy "Key ?K") 
paulson@2373
   817
                   ["Agent ?C", "Nonce ?N", "Hash ?X", 
paulson@2516
   818
                    "MPair ?X ?Y", "Crypt ?X ?K'"];
paulson@2327
   819
paulson@2327
   820
val pushCrypts = map (insComm thy "Crypt ?X ?K") 
paulson@2373
   821
                     ["Agent ?C", "Nonce ?N", "Hash ?X'", "MPair ?X' ?Y"];
paulson@2327
   822
paulson@2327
   823
(*Cannot be added with Addsimps -- we don't always want to re-order messages*)
paulson@2327
   824
val pushes = pushKeys@pushCrypts;
paulson@2327
   825
paulson@2373
   826
val Fake_insert_tac = 
paulson@2373
   827
    dresolve_tac [impOfSubs Fake_analz_insert,
paulson@2516
   828
                  impOfSubs Fake_parts_insert] THEN'
paulson@2373
   829
    eresolve_tac [asm_rl, synth.Inj];
paulson@2373
   830
paulson@2373
   831
(*Analysis of Fake cases and of messages that forward unknown parts.
paulson@2327
   832
  Abstraction over i is ESSENTIAL: it delays the dereferencing of claset
paulson@2327
   833
  DEPENDS UPON "X" REFERRING TO THE FRADULENT MESSAGE *)
paulson@2327
   834
fun spy_analz_tac i =
paulson@2373
   835
  DETERM
paulson@2373
   836
   (SELECT_GOAL
paulson@2373
   837
     (EVERY 
paulson@2373
   838
      [  (*push in occurrences of X...*)
paulson@2373
   839
       (REPEAT o CHANGED)
paulson@2373
   840
           (res_inst_tac [("x1","X")] (insert_commute RS ssubst) 1),
paulson@2373
   841
       (*...allowing further simplifications*)
paulson@2373
   842
       simp_tac (!simpset setloop split_tac [expand_if]) 1,
paulson@2373
   843
       REPEAT (FIRSTGOAL (resolve_tac [allI,impI,notI,conjI])),
paulson@2373
   844
       DEPTH_SOLVE 
paulson@2373
   845
         (REPEAT (Fake_insert_tac 1) THEN Asm_full_simp_tac 1
paulson@2516
   846
          THEN
paulson@2516
   847
          IF_UNSOLVED (depth_tac (!claset addIs [impOfSubs analz_mono,
paulson@2516
   848
                                                 impOfSubs analz_subset_parts]) 2 1))
paulson@2373
   849
       ]) i);
paulson@2327
   850
paulson@2415
   851
(** Useful in many uniqueness proofs **)
paulson@2327
   852
fun ex_strip_tac i = REPEAT (swap_res_tac [exI, conjI] i) THEN 
paulson@2327
   853
                     assume_tac (i+1);
paulson@2327
   854
paulson@2415
   855
(*Apply the EX-ALL quantifification to prove uniqueness theorems in 
paulson@2415
   856
  their standard form*)
paulson@2415
   857
fun prove_unique_tac lemma = 
paulson@2415
   858
  EVERY' [dtac lemma,
paulson@2516
   859
          REPEAT o (mp_tac ORELSE' eresolve_tac [asm_rl,exE]),
paulson@2516
   860
          (*Duplicate the assumption*)
paulson@2516
   861
          forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl,
paulson@2559
   862
          depth_tac (!claset addSDs [spec]) 0];
paulson@2415
   863
paulson@2373
   864
paulson@2373
   865
(*Needed occasionally with spy_analz_tac, e.g. in analz_insert_Key_newK*)
paulson@2373
   866
goal Set.thy "A Un (B Un A) = B Un A";
paulson@2891
   867
by (Blast_tac 1);
paulson@2373
   868
val Un_absorb3 = result();
paulson@2373
   869
Addsimps [Un_absorb3];