src/HOL/Auth/Message.ML
author paulson
Thu Jun 19 11:24:37 1997 +0200 (1997-06-19)
changeset 3449 6b17f82bbf01
parent 3431 05b397185e1d
child 3470 8160cc3f6d40
permissions -rw-r--r--
New comments; a tidied proof
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@2373
    12
AddIffs (msg.inject);
paulson@1839
    13
paulson@1839
    14
(** Inverse of keys **)
paulson@1839
    15
paulson@1839
    16
goal thy "!!K K'. (invKey K = invKey K') = (K=K')";
paulson@1839
    17
by (Step_tac 1);
paulson@2032
    18
by (rtac box_equals 1);
paulson@1839
    19
by (REPEAT (rtac invKey 2));
paulson@1839
    20
by (Asm_simp_tac 1);
paulson@1839
    21
qed "invKey_eq";
paulson@1839
    22
paulson@1839
    23
Addsimps [invKey, invKey_eq];
paulson@1839
    24
paulson@1839
    25
paulson@1839
    26
(**** keysFor operator ****)
paulson@1839
    27
paulson@1839
    28
goalw thy [keysFor_def] "keysFor {} = {}";
paulson@2891
    29
by (Blast_tac 1);
paulson@1839
    30
qed "keysFor_empty";
paulson@1839
    31
paulson@1839
    32
goalw thy [keysFor_def] "keysFor (H Un H') = keysFor H Un keysFor H'";
paulson@2891
    33
by (Blast_tac 1);
paulson@1839
    34
qed "keysFor_Un";
paulson@1839
    35
paulson@1839
    36
goalw thy [keysFor_def] "keysFor (UN i. H i) = (UN i. keysFor (H i))";
paulson@2891
    37
by (Blast_tac 1);
paulson@3121
    38
qed "keysFor_UN1";
paulson@1839
    39
paulson@1839
    40
(*Monotonicity*)
paulson@1839
    41
goalw thy [keysFor_def] "!!G H. G<=H ==> keysFor(G) <= keysFor(H)";
paulson@2891
    42
by (Blast_tac 1);
paulson@1839
    43
qed "keysFor_mono";
paulson@1839
    44
paulson@1839
    45
goalw thy [keysFor_def] "keysFor (insert (Agent A) H) = keysFor H";
paulson@3102
    46
by (Blast_tac 1);
paulson@1839
    47
qed "keysFor_insert_Agent";
paulson@1839
    48
paulson@1839
    49
goalw thy [keysFor_def] "keysFor (insert (Nonce N) H) = keysFor H";
paulson@3102
    50
by (Blast_tac 1);
paulson@1839
    51
qed "keysFor_insert_Nonce";
paulson@1839
    52
paulson@1839
    53
goalw thy [keysFor_def] "keysFor (insert (Key K) H) = keysFor H";
paulson@3102
    54
by (Blast_tac 1);
paulson@1839
    55
qed "keysFor_insert_Key";
paulson@1839
    56
paulson@2373
    57
goalw thy [keysFor_def] "keysFor (insert (Hash X) H) = keysFor H";
paulson@3102
    58
by (Blast_tac 1);
paulson@2373
    59
qed "keysFor_insert_Hash";
paulson@2373
    60
paulson@1839
    61
goalw thy [keysFor_def] "keysFor (insert {|X,Y|} H) = keysFor H";
paulson@3102
    62
by (Blast_tac 1);
paulson@1839
    63
qed "keysFor_insert_MPair";
paulson@1839
    64
paulson@1839
    65
goalw thy [keysFor_def]
paulson@2284
    66
    "keysFor (insert (Crypt K X) H) = insert (invKey K) (keysFor H)";
paulson@1839
    67
by (Auto_tac());
paulson@1839
    68
qed "keysFor_insert_Crypt";
paulson@1839
    69
paulson@3121
    70
Addsimps [keysFor_empty, keysFor_Un, keysFor_UN1, 
paulson@2373
    71
          keysFor_insert_Agent, keysFor_insert_Nonce, keysFor_insert_Key, 
paulson@2516
    72
          keysFor_insert_Hash, keysFor_insert_MPair, keysFor_insert_Crypt];
paulson@3121
    73
AddSEs [keysFor_Un RS equalityD1 RS subsetD RS UnE,
paulson@3121
    74
	keysFor_UN1 RS equalityD1 RS subsetD RS UN1_E];
paulson@1839
    75
paulson@2284
    76
goalw thy [keysFor_def] "!!H. Crypt K X : H ==> invKey K : keysFor H";
paulson@2891
    77
by (Blast_tac 1);
paulson@2068
    78
qed "Crypt_imp_invKey_keysFor";
paulson@2068
    79
paulson@1839
    80
paulson@1839
    81
(**** Inductive relation "parts" ****)
paulson@1839
    82
paulson@1839
    83
val major::prems = 
paulson@1839
    84
goal thy "[| {|X,Y|} : parts H;       \
paulson@1839
    85
\            [| X : parts H; Y : parts H |] ==> P  \
paulson@1839
    86
\         |] ==> P";
paulson@1839
    87
by (cut_facts_tac [major] 1);
paulson@2032
    88
by (resolve_tac prems 1);
paulson@1839
    89
by (REPEAT (eresolve_tac [asm_rl, parts.Fst, parts.Snd] 1));
paulson@1839
    90
qed "MPair_parts";
paulson@1839
    91
paulson@1839
    92
AddIs  [parts.Inj];
paulson@1929
    93
paulson@1929
    94
val partsEs = [MPair_parts, make_elim parts.Body];
paulson@1929
    95
paulson@1929
    96
AddSEs partsEs;
paulson@1929
    97
(*NB These two rules are UNSAFE in the formal sense, as they discard the
paulson@1929
    98
     compound message.  They work well on THIS FILE, perhaps because its
paulson@1929
    99
     proofs concern only atomic messages.*)
paulson@1839
   100
paulson@1839
   101
goal thy "H <= parts(H)";
paulson@2891
   102
by (Blast_tac 1);
paulson@1839
   103
qed "parts_increasing";
paulson@1839
   104
paulson@1839
   105
(*Monotonicity*)
paulson@1839
   106
goalw thy parts.defs "!!G H. G<=H ==> parts(G) <= parts(H)";
paulson@1839
   107
by (rtac lfp_mono 1);
paulson@1839
   108
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
   109
qed "parts_mono";
paulson@1839
   110
paulson@2373
   111
val parts_insertI = impOfSubs (subset_insertI RS parts_mono);
paulson@2373
   112
paulson@1839
   113
goal thy "parts{} = {}";
paulson@1839
   114
by (Step_tac 1);
paulson@2032
   115
by (etac parts.induct 1);
paulson@2891
   116
by (ALLGOALS Blast_tac);
paulson@1839
   117
qed "parts_empty";
paulson@1839
   118
Addsimps [parts_empty];
paulson@1839
   119
paulson@1839
   120
goal thy "!!X. X: parts{} ==> P";
paulson@1839
   121
by (Asm_full_simp_tac 1);
paulson@1839
   122
qed "parts_emptyE";
paulson@1839
   123
AddSEs [parts_emptyE];
paulson@1839
   124
paulson@1893
   125
(*WARNING: loops if H = {Y}, therefore must not be repeated!*)
paulson@1893
   126
goal thy "!!H. X: parts H ==> EX Y:H. X: parts {Y}";
paulson@2032
   127
by (etac parts.induct 1);
paulson@2891
   128
by (ALLGOALS Blast_tac);
paulson@1893
   129
qed "parts_singleton";
paulson@1893
   130
paulson@1839
   131
paulson@1839
   132
(** Unions **)
paulson@1839
   133
paulson@1839
   134
goal thy "parts(G) Un parts(H) <= parts(G Un H)";
paulson@1839
   135
by (REPEAT (ares_tac [Un_least, parts_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   136
val parts_Un_subset1 = result();
paulson@1839
   137
paulson@1839
   138
goal thy "parts(G Un H) <= parts(G) Un parts(H)";
paulson@2032
   139
by (rtac subsetI 1);
paulson@2032
   140
by (etac parts.induct 1);
paulson@2891
   141
by (ALLGOALS Blast_tac);
paulson@1839
   142
val parts_Un_subset2 = result();
paulson@1839
   143
paulson@1839
   144
goal thy "parts(G Un H) = parts(G) Un parts(H)";
paulson@1839
   145
by (REPEAT (ares_tac [equalityI, parts_Un_subset1, parts_Un_subset2] 1));
paulson@1839
   146
qed "parts_Un";
paulson@1839
   147
paulson@2011
   148
goal thy "parts (insert X H) = parts {X} Un parts H";
paulson@1852
   149
by (stac (read_instantiate [("A","H")] insert_is_Un) 1);
paulson@2011
   150
by (simp_tac (HOL_ss addsimps [parts_Un]) 1);
paulson@2011
   151
qed "parts_insert";
paulson@2011
   152
paulson@2011
   153
(*TWO inserts to avoid looping.  This rewrite is better than nothing.
paulson@2011
   154
  Not suitable for Addsimps: its behaviour can be strange.*)
paulson@2011
   155
goal thy "parts (insert X (insert Y H)) = parts {X} Un parts {Y} Un parts H";
paulson@2011
   156
by (simp_tac (!simpset addsimps [Un_assoc]) 1);
paulson@2011
   157
by (simp_tac (!simpset addsimps [parts_insert RS sym]) 1);
paulson@1852
   158
qed "parts_insert2";
paulson@1852
   159
paulson@1839
   160
goal thy "(UN x:A. parts(H x)) <= parts(UN x:A. H x)";
paulson@1839
   161
by (REPEAT (ares_tac [UN_least, parts_mono, UN_upper] 1));
paulson@1839
   162
val parts_UN_subset1 = result();
paulson@1839
   163
paulson@1839
   164
goal thy "parts(UN x:A. H x) <= (UN x:A. parts(H x))";
paulson@2032
   165
by (rtac subsetI 1);
paulson@2032
   166
by (etac parts.induct 1);
paulson@2891
   167
by (ALLGOALS Blast_tac);
paulson@1839
   168
val parts_UN_subset2 = result();
paulson@1839
   169
paulson@1839
   170
goal thy "parts(UN x:A. H x) = (UN x:A. parts(H x))";
paulson@1839
   171
by (REPEAT (ares_tac [equalityI, parts_UN_subset1, parts_UN_subset2] 1));
paulson@1839
   172
qed "parts_UN";
paulson@1839
   173
paulson@1839
   174
goal thy "parts(UN x. H x) = (UN x. parts(H x))";
paulson@1839
   175
by (simp_tac (!simpset addsimps [UNION1_def, parts_UN]) 1);
paulson@1839
   176
qed "parts_UN1";
paulson@1839
   177
paulson@3121
   178
(*Added to simplify arguments to parts, analz and synth.
paulson@3121
   179
  NOTE: the UN versions are no longer used!*)
paulson@1839
   180
Addsimps [parts_Un, parts_UN, parts_UN1];
paulson@3121
   181
AddSEs [parts_Un RS equalityD1 RS subsetD RS UnE,
paulson@3121
   182
	parts_UN RS equalityD1 RS subsetD RS UN_E,
paulson@3121
   183
	parts_UN1 RS equalityD1 RS subsetD RS UN1_E];
paulson@1839
   184
paulson@1839
   185
goal thy "insert X (parts H) <= parts(insert X H)";
paulson@2922
   186
by (blast_tac (!claset addIs [impOfSubs parts_mono]) 1);
paulson@1839
   187
qed "parts_insert_subset";
paulson@1839
   188
paulson@1839
   189
(** Idempotence and transitivity **)
paulson@1839
   190
paulson@1839
   191
goal thy "!!H. X: parts (parts H) ==> X: parts H";
paulson@2032
   192
by (etac parts.induct 1);
paulson@2891
   193
by (ALLGOALS Blast_tac);
paulson@2922
   194
qed "parts_partsD";
paulson@2922
   195
AddSDs [parts_partsD];
paulson@1839
   196
paulson@1839
   197
goal thy "parts (parts H) = parts H";
paulson@2891
   198
by (Blast_tac 1);
paulson@1839
   199
qed "parts_idem";
paulson@1839
   200
Addsimps [parts_idem];
paulson@1839
   201
paulson@1839
   202
goal thy "!!H. [| X: parts G;  G <= parts H |] ==> X: parts H";
paulson@1839
   203
by (dtac parts_mono 1);
paulson@2891
   204
by (Blast_tac 1);
paulson@1839
   205
qed "parts_trans";
paulson@1839
   206
paulson@1839
   207
(*Cut*)
paulson@2373
   208
goal thy "!!H. [| Y: parts (insert X G);  X: parts H |] \
paulson@2373
   209
\              ==> Y: parts (G Un H)";
paulson@2032
   210
by (etac parts_trans 1);
paulson@2373
   211
by (Auto_tac());
paulson@1839
   212
qed "parts_cut";
paulson@1839
   213
paulson@1929
   214
goal thy "!!H. X: parts H ==> parts (insert X H) = parts H";
paulson@2373
   215
by (fast_tac (!claset addSDs [parts_cut]
paulson@2373
   216
                      addIs  [parts_insertI] 
paulson@2373
   217
                      addss (!simpset)) 1);
paulson@1929
   218
qed "parts_cut_eq";
paulson@1929
   219
paulson@2028
   220
Addsimps [parts_cut_eq];
paulson@2028
   221
paulson@1839
   222
paulson@1839
   223
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   224
paulson@2373
   225
fun parts_tac i =
paulson@2373
   226
  EVERY [rtac ([subsetI, parts_insert_subset] MRS equalityI) i,
paulson@2516
   227
         etac parts.induct i,
paulson@3102
   228
         REPEAT (Blast_tac i)];
paulson@2373
   229
paulson@1839
   230
goal thy "parts (insert (Agent agt) H) = insert (Agent agt) (parts H)";
paulson@2373
   231
by (parts_tac 1);
paulson@1839
   232
qed "parts_insert_Agent";
paulson@1839
   233
paulson@1839
   234
goal thy "parts (insert (Nonce N) H) = insert (Nonce N) (parts H)";
paulson@2373
   235
by (parts_tac 1);
paulson@1839
   236
qed "parts_insert_Nonce";
paulson@1839
   237
paulson@1839
   238
goal thy "parts (insert (Key K) H) = insert (Key K) (parts H)";
paulson@2373
   239
by (parts_tac 1);
paulson@1839
   240
qed "parts_insert_Key";
paulson@1839
   241
paulson@2373
   242
goal thy "parts (insert (Hash X) H) = insert (Hash X) (parts H)";
paulson@2373
   243
by (parts_tac 1);
paulson@2373
   244
qed "parts_insert_Hash";
paulson@2373
   245
paulson@2284
   246
goal thy "parts (insert (Crypt K X) H) = \
paulson@2284
   247
\         insert (Crypt K X) (parts (insert X H))";
paulson@2032
   248
by (rtac equalityI 1);
paulson@2032
   249
by (rtac subsetI 1);
paulson@2032
   250
by (etac parts.induct 1);
paulson@1839
   251
by (Auto_tac());
paulson@2032
   252
by (etac parts.induct 1);
paulson@2922
   253
by (ALLGOALS (blast_tac (!claset addIs [parts.Body])));
paulson@1839
   254
qed "parts_insert_Crypt";
paulson@1839
   255
paulson@1839
   256
goal thy "parts (insert {|X,Y|} H) = \
paulson@1839
   257
\         insert {|X,Y|} (parts (insert X (insert Y H)))";
paulson@2032
   258
by (rtac equalityI 1);
paulson@2032
   259
by (rtac subsetI 1);
paulson@2032
   260
by (etac parts.induct 1);
paulson@1839
   261
by (Auto_tac());
paulson@2032
   262
by (etac parts.induct 1);
paulson@2922
   263
by (ALLGOALS (blast_tac (!claset addIs [parts.Fst, parts.Snd])));
paulson@1839
   264
qed "parts_insert_MPair";
paulson@1839
   265
paulson@2373
   266
Addsimps [parts_insert_Agent, parts_insert_Nonce, parts_insert_Key, 
paulson@2373
   267
          parts_insert_Hash, parts_insert_Crypt, parts_insert_MPair];
paulson@1839
   268
paulson@1839
   269
paulson@2026
   270
goal thy "parts (Key``N) = Key``N";
paulson@2026
   271
by (Auto_tac());
paulson@2032
   272
by (etac parts.induct 1);
paulson@2026
   273
by (Auto_tac());
paulson@2026
   274
qed "parts_image_Key";
paulson@2026
   275
paulson@2026
   276
Addsimps [parts_image_Key];
paulson@2026
   277
paulson@2026
   278
paulson@1913
   279
(**** Inductive relation "analz" ****)
paulson@1839
   280
paulson@1839
   281
val major::prems = 
paulson@1913
   282
goal thy "[| {|X,Y|} : analz H;       \
paulson@1913
   283
\            [| X : analz H; Y : analz H |] ==> P  \
paulson@1839
   284
\         |] ==> P";
paulson@1839
   285
by (cut_facts_tac [major] 1);
paulson@2032
   286
by (resolve_tac prems 1);
paulson@1913
   287
by (REPEAT (eresolve_tac [asm_rl, analz.Fst, analz.Snd] 1));
paulson@1913
   288
qed "MPair_analz";
paulson@1839
   289
paulson@1913
   290
AddIs  [analz.Inj];
paulson@2011
   291
AddSEs [MPair_analz];      (*Perhaps it should NOT be deemed safe!*)
paulson@1913
   292
AddDs  [analz.Decrypt];
paulson@1839
   293
paulson@1913
   294
Addsimps [analz.Inj];
paulson@1885
   295
paulson@1913
   296
goal thy "H <= analz(H)";
paulson@2891
   297
by (Blast_tac 1);
paulson@1913
   298
qed "analz_increasing";
paulson@1839
   299
paulson@1913
   300
goal thy "analz H <= parts H";
paulson@1839
   301
by (rtac subsetI 1);
paulson@2032
   302
by (etac analz.induct 1);
paulson@2891
   303
by (ALLGOALS Blast_tac);
paulson@1913
   304
qed "analz_subset_parts";
paulson@1839
   305
paulson@1913
   306
bind_thm ("not_parts_not_analz", analz_subset_parts RS contra_subsetD);
paulson@1839
   307
paulson@1839
   308
paulson@1913
   309
goal thy "parts (analz H) = parts H";
paulson@2032
   310
by (rtac equalityI 1);
paulson@2032
   311
by (rtac (analz_subset_parts RS parts_mono RS subset_trans) 1);
paulson@1839
   312
by (Simp_tac 1);
paulson@2891
   313
by (blast_tac (!claset addIs [analz_increasing RS parts_mono RS subsetD]) 1);
paulson@1913
   314
qed "parts_analz";
paulson@1913
   315
Addsimps [parts_analz];
paulson@1839
   316
paulson@1913
   317
goal thy "analz (parts H) = parts H";
paulson@1885
   318
by (Auto_tac());
paulson@2032
   319
by (etac analz.induct 1);
paulson@1885
   320
by (Auto_tac());
paulson@1913
   321
qed "analz_parts";
paulson@1913
   322
Addsimps [analz_parts];
paulson@1885
   323
paulson@1839
   324
(*Monotonicity; Lemma 1 of Lowe*)
paulson@1913
   325
goalw thy analz.defs "!!G H. G<=H ==> analz(G) <= analz(H)";
paulson@1839
   326
by (rtac lfp_mono 1);
paulson@1839
   327
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   328
qed "analz_mono";
paulson@1839
   329
paulson@2373
   330
val analz_insertI = impOfSubs (subset_insertI RS analz_mono);
paulson@2373
   331
paulson@1839
   332
(** General equational properties **)
paulson@1839
   333
paulson@1913
   334
goal thy "analz{} = {}";
paulson@1839
   335
by (Step_tac 1);
paulson@2032
   336
by (etac analz.induct 1);
paulson@2891
   337
by (ALLGOALS Blast_tac);
paulson@1913
   338
qed "analz_empty";
paulson@1913
   339
Addsimps [analz_empty];
paulson@1839
   340
paulson@1913
   341
(*Converse fails: we can analz more from the union than from the 
paulson@1839
   342
  separate parts, as a key in one might decrypt a message in the other*)
paulson@1913
   343
goal thy "analz(G) Un analz(H) <= analz(G Un H)";
paulson@1913
   344
by (REPEAT (ares_tac [Un_least, analz_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   345
qed "analz_Un";
paulson@1839
   346
paulson@1913
   347
goal thy "insert X (analz H) <= analz(insert X H)";
paulson@2922
   348
by (blast_tac (!claset addIs [impOfSubs analz_mono]) 1);
paulson@1913
   349
qed "analz_insert";
paulson@1839
   350
paulson@1839
   351
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   352
paulson@2373
   353
fun analz_tac i =
paulson@2373
   354
  EVERY [rtac ([subsetI, analz_insert] MRS equalityI) i,
paulson@2516
   355
         etac analz.induct i,
paulson@3102
   356
         REPEAT (Blast_tac i)];
paulson@2373
   357
paulson@1913
   358
goal thy "analz (insert (Agent agt) H) = insert (Agent agt) (analz H)";
paulson@2373
   359
by (analz_tac 1);
paulson@1913
   360
qed "analz_insert_Agent";
paulson@1839
   361
paulson@1913
   362
goal thy "analz (insert (Nonce N) H) = insert (Nonce N) (analz H)";
paulson@2373
   363
by (analz_tac 1);
paulson@1913
   364
qed "analz_insert_Nonce";
paulson@1839
   365
paulson@2373
   366
goal thy "analz (insert (Hash X) H) = insert (Hash X) (analz H)";
paulson@2373
   367
by (analz_tac 1);
paulson@2373
   368
qed "analz_insert_Hash";
paulson@2373
   369
paulson@1839
   370
(*Can only pull out Keys if they are not needed to decrypt the rest*)
paulson@1839
   371
goalw thy [keysFor_def]
paulson@1913
   372
    "!!K. K ~: keysFor (analz H) ==>  \
paulson@1913
   373
\         analz (insert (Key K) H) = insert (Key K) (analz H)";
paulson@2373
   374
by (analz_tac 1);
paulson@1913
   375
qed "analz_insert_Key";
paulson@1839
   376
paulson@1913
   377
goal thy "analz (insert {|X,Y|} H) = \
paulson@1913
   378
\         insert {|X,Y|} (analz (insert X (insert Y H)))";
paulson@2032
   379
by (rtac equalityI 1);
paulson@2032
   380
by (rtac subsetI 1);
paulson@2032
   381
by (etac analz.induct 1);
paulson@1885
   382
by (Auto_tac());
paulson@2032
   383
by (etac analz.induct 1);
paulson@2922
   384
by (ALLGOALS (blast_tac (!claset addIs [analz.Fst, analz.Snd])));
paulson@1913
   385
qed "analz_insert_MPair";
paulson@1885
   386
paulson@1885
   387
(*Can pull out enCrypted message if the Key is not known*)
paulson@1913
   388
goal thy "!!H. Key (invKey K) ~: analz H ==>  \
paulson@2284
   389
\              analz (insert (Crypt K X) H) = \
paulson@2284
   390
\              insert (Crypt K X) (analz H)";
paulson@2373
   391
by (analz_tac 1);
paulson@1913
   392
qed "analz_insert_Crypt";
paulson@1839
   393
paulson@1913
   394
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@2284
   395
\              analz (insert (Crypt K X) H) <= \
paulson@2284
   396
\              insert (Crypt K X) (analz (insert X H))";
paulson@2032
   397
by (rtac subsetI 1);
paulson@1913
   398
by (eres_inst_tac [("za","x")] analz.induct 1);
paulson@3102
   399
by (ALLGOALS (Blast_tac));
paulson@1839
   400
val lemma1 = result();
paulson@1839
   401
paulson@1913
   402
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@2284
   403
\              insert (Crypt K X) (analz (insert X H)) <= \
paulson@2284
   404
\              analz (insert (Crypt K X) H)";
paulson@1839
   405
by (Auto_tac());
paulson@1913
   406
by (eres_inst_tac [("za","x")] analz.induct 1);
paulson@1839
   407
by (Auto_tac());
paulson@3449
   408
by (blast_tac (!claset addIs [analz_insertI, analz.Decrypt]) 1);
paulson@1839
   409
val lemma2 = result();
paulson@1839
   410
paulson@1913
   411
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@2284
   412
\              analz (insert (Crypt K X) H) = \
paulson@2284
   413
\              insert (Crypt K X) (analz (insert X H))";
paulson@1839
   414
by (REPEAT (ares_tac [equalityI, lemma1, lemma2] 1));
paulson@1913
   415
qed "analz_insert_Decrypt";
paulson@1839
   416
paulson@1885
   417
(*Case analysis: either the message is secure, or it is not!
paulson@1946
   418
  Effective, but can cause subgoals to blow up!
paulson@1885
   419
  Use with expand_if;  apparently split_tac does not cope with patterns
paulson@2284
   420
  such as "analz (insert (Crypt K X) H)" *)
paulson@2284
   421
goal thy "analz (insert (Crypt K X) H) =                \
paulson@2154
   422
\         (if (Key (invKey K) : analz H)                \
paulson@2284
   423
\          then insert (Crypt K X) (analz (insert X H)) \
paulson@2284
   424
\          else insert (Crypt K X) (analz H))";
paulson@2102
   425
by (case_tac "Key (invKey K)  : analz H " 1);
paulson@1913
   426
by (ALLGOALS (asm_simp_tac (!simpset addsimps [analz_insert_Crypt, 
paulson@2032
   427
                                               analz_insert_Decrypt])));
paulson@1913
   428
qed "analz_Crypt_if";
paulson@1885
   429
paulson@2373
   430
Addsimps [analz_insert_Agent, analz_insert_Nonce, analz_insert_Key, 
paulson@2516
   431
          analz_insert_Hash, analz_insert_MPair, analz_Crypt_if];
paulson@1839
   432
paulson@1839
   433
(*This rule supposes "for the sake of argument" that we have the key.*)
paulson@2284
   434
goal thy  "analz (insert (Crypt K X) H) <=  \
paulson@2284
   435
\          insert (Crypt K X) (analz (insert X H))";
paulson@2032
   436
by (rtac subsetI 1);
paulson@2032
   437
by (etac analz.induct 1);
paulson@1839
   438
by (Auto_tac());
paulson@1913
   439
qed "analz_insert_Crypt_subset";
paulson@1839
   440
paulson@1839
   441
paulson@2026
   442
goal thy "analz (Key``N) = Key``N";
paulson@2026
   443
by (Auto_tac());
paulson@2032
   444
by (etac analz.induct 1);
paulson@2026
   445
by (Auto_tac());
paulson@2026
   446
qed "analz_image_Key";
paulson@2026
   447
paulson@2026
   448
Addsimps [analz_image_Key];
paulson@2026
   449
paulson@2026
   450
paulson@1839
   451
(** Idempotence and transitivity **)
paulson@1839
   452
paulson@1913
   453
goal thy "!!H. X: analz (analz H) ==> X: analz H";
paulson@2032
   454
by (etac analz.induct 1);
paulson@2891
   455
by (ALLGOALS Blast_tac);
paulson@2922
   456
qed "analz_analzD";
paulson@2922
   457
AddSDs [analz_analzD];
paulson@1839
   458
paulson@1913
   459
goal thy "analz (analz H) = analz H";
paulson@2891
   460
by (Blast_tac 1);
paulson@1913
   461
qed "analz_idem";
paulson@1913
   462
Addsimps [analz_idem];
paulson@1839
   463
paulson@1913
   464
goal thy "!!H. [| X: analz G;  G <= analz H |] ==> X: analz H";
paulson@1913
   465
by (dtac analz_mono 1);
paulson@2891
   466
by (Blast_tac 1);
paulson@1913
   467
qed "analz_trans";
paulson@1839
   468
paulson@1839
   469
(*Cut; Lemma 2 of Lowe*)
paulson@1998
   470
goal thy "!!H. [| Y: analz (insert X H);  X: analz H |] ==> Y: analz H";
paulson@2032
   471
by (etac analz_trans 1);
paulson@2891
   472
by (Blast_tac 1);
paulson@1913
   473
qed "analz_cut";
paulson@1839
   474
paulson@1839
   475
(*Cut can be proved easily by induction on
paulson@1913
   476
   "!!H. Y: analz (insert X H) ==> X: analz H --> Y: analz H"
paulson@1839
   477
*)
paulson@1839
   478
paulson@3449
   479
(*This rewrite rule helps in the simplification of messages that involve
paulson@3449
   480
  the forwarding of unknown components (X).  Without it, removing occurrences
paulson@3449
   481
  of X can be very complicated. *)
paulson@3431
   482
goal thy "!!H. X: analz H ==> analz (insert X H) = analz H";
paulson@3431
   483
by (blast_tac (!claset addIs [analz_cut, analz_insertI]) 1);
paulson@3431
   484
qed "analz_insert_eq";
paulson@3431
   485
paulson@1885
   486
paulson@1913
   487
(** A congruence rule for "analz" **)
paulson@1885
   488
paulson@1913
   489
goal thy "!!H. [| analz G <= analz G'; analz H <= analz H' \
paulson@1913
   490
\              |] ==> analz (G Un H) <= analz (G' Un H')";
paulson@1885
   491
by (Step_tac 1);
paulson@2032
   492
by (etac analz.induct 1);
paulson@1913
   493
by (ALLGOALS (best_tac (!claset addIs [analz_mono RS subsetD])));
paulson@1913
   494
qed "analz_subset_cong";
paulson@1885
   495
paulson@1913
   496
goal thy "!!H. [| analz G = analz G'; analz H = analz H' \
paulson@1913
   497
\              |] ==> analz (G Un H) = analz (G' Un H')";
paulson@1913
   498
by (REPEAT_FIRST (ares_tac [equalityI, analz_subset_cong]
paulson@2032
   499
          ORELSE' etac equalityE));
paulson@1913
   500
qed "analz_cong";
paulson@1885
   501
paulson@1885
   502
paulson@1913
   503
goal thy "!!H. analz H = analz H' ==> analz(insert X H) = analz(insert X H')";
paulson@1885
   504
by (asm_simp_tac (!simpset addsimps [insert_def] 
paulson@2032
   505
                           setloop (rtac analz_cong)) 1);
paulson@1913
   506
qed "analz_insert_cong";
paulson@1885
   507
paulson@1913
   508
(*If there are no pairs or encryptions then analz does nothing*)
paulson@2284
   509
goal thy "!!H. [| ALL X Y. {|X,Y|} ~: H;  ALL X K. Crypt K X ~: H |] ==> \
paulson@1913
   510
\         analz H = H";
paulson@1839
   511
by (Step_tac 1);
paulson@2032
   512
by (etac analz.induct 1);
paulson@2891
   513
by (ALLGOALS Blast_tac);
paulson@1913
   514
qed "analz_trivial";
paulson@1839
   515
paulson@1839
   516
(*Helps to prove Fake cases*)
paulson@1913
   517
goal thy "!!X. X: analz (UN i. analz (H i)) ==> X: analz (UN i. H i)";
paulson@2032
   518
by (etac analz.induct 1);
paulson@2922
   519
by (ALLGOALS (blast_tac (!claset addIs [impOfSubs analz_mono])));
paulson@1839
   520
val lemma = result();
paulson@1839
   521
paulson@1913
   522
goal thy "analz (UN i. analz (H i)) = analz (UN i. H i)";
paulson@2922
   523
by (blast_tac (!claset addIs [lemma, 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@2922
   564
by (blast_tac (!claset addIs [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@2922
   572
qed "synth_synthD";
paulson@2922
   573
AddSDs [synth_synthD];
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@2922
   623
    (blast_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@2922
   637
by (blast_tac (!claset addIs [impOfSubs analz_mono]) 5);
paulson@2922
   638
by (ALLGOALS (blast_tac (!claset addIs analz.intrs)));
paulson@2373
   639
qed "analz_synth_Un";
paulson@2373
   640
paulson@2373
   641
goal thy "analz (synth H) = analz H Un synth H";
paulson@2373
   642
by (cut_inst_tac [("H","{}")] analz_synth_Un 1);
paulson@2373
   643
by (Full_simp_tac 1);
paulson@1913
   644
qed "analz_synth";
paulson@2373
   645
Addsimps [analz_analz_Un, analz_synth_Un, analz_synth];
paulson@1839
   646
paulson@2032
   647
(*Hard to prove; still needed now that there's only one Spy?*)
paulson@1913
   648
goal thy "analz (UN i. synth (H i)) = \
paulson@1913
   649
\         analz (UN i. H i) Un (UN i. synth (H i))";
paulson@2032
   650
by (rtac equalityI 1);
paulson@2032
   651
by (rtac subsetI 1);
paulson@2032
   652
by (etac analz.induct 1);
paulson@2922
   653
by (blast_tac
paulson@2922
   654
    (!claset addIs [impOfSubs synth_increasing,
paulson@2032
   655
                    impOfSubs analz_mono]) 5);
paulson@2891
   656
by (Blast_tac 1);
paulson@2891
   657
by (blast_tac (!claset addIs [analz.Inj RS analz.Fst]) 1);
paulson@2891
   658
by (blast_tac (!claset addIs [analz.Inj RS analz.Snd]) 1);
paulson@2891
   659
by (blast_tac (!claset addIs [analz.Decrypt]) 1);
paulson@1913
   660
qed "analz_UN1_synth";
paulson@1913
   661
Addsimps [analz_UN1_synth];
paulson@1929
   662
paulson@1946
   663
paulson@1946
   664
(** For reasoning about the Fake rule in traces **)
paulson@1946
   665
paulson@1929
   666
goal thy "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H";
paulson@2032
   667
by (rtac ([parts_mono, parts_Un_subset2] MRS subset_trans) 1);
paulson@2891
   668
by (Blast_tac 1);
paulson@1929
   669
qed "parts_insert_subset_Un";
paulson@1929
   670
paulson@1946
   671
(*More specifically for Fake*)
paulson@1946
   672
goal thy "!!H. X: synth (analz G) ==> \
paulson@1946
   673
\              parts (insert X H) <= synth (analz G) Un parts G Un parts H";
paulson@2032
   674
by (dtac parts_insert_subset_Un 1);
paulson@1946
   675
by (Full_simp_tac 1);
paulson@2891
   676
by (Blast_tac 1);
paulson@1946
   677
qed "Fake_parts_insert";
paulson@1946
   678
paulson@2061
   679
goal thy
paulson@2284
   680
     "!!H. [| Crypt K Y : parts (insert X H);  X: synth (analz G);  \
paulson@2061
   681
\             Key K ~: analz G |]                                   \
paulson@2284
   682
\          ==> Crypt K Y : parts G Un parts H";
paulson@2061
   683
by (dtac (impOfSubs Fake_parts_insert) 1);
paulson@2170
   684
by (assume_tac 1);
paulson@3102
   685
by (blast_tac (!claset addDs [impOfSubs analz_subset_parts]) 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@3121
   824
paulson@3121
   825
(*** Tactics useful for many protocol proofs ***)
paulson@3121
   826
paulson@3121
   827
(*Prove base case (subgoal i) and simplify others*)
paulson@3121
   828
fun prove_simple_subgoals_tac i = 
paulson@3121
   829
    fast_tac (!claset addss (!simpset)) i THEN
paulson@3121
   830
    ALLGOALS Asm_simp_tac;
paulson@3121
   831
paulson@3121
   832
fun Fake_parts_insert_tac i = 
paulson@3121
   833
    blast_tac (!claset addDs [impOfSubs analz_subset_parts,
paulson@3121
   834
			      impOfSubs Fake_parts_insert]) i;
paulson@3121
   835
paulson@3121
   836
(*Apply rules to break down assumptions of the form
paulson@3121
   837
  Y : parts(insert X H)  and  Y : analz(insert X H)
paulson@3121
   838
*)
paulson@2373
   839
val Fake_insert_tac = 
paulson@2373
   840
    dresolve_tac [impOfSubs Fake_analz_insert,
paulson@2516
   841
                  impOfSubs Fake_parts_insert] THEN'
paulson@2373
   842
    eresolve_tac [asm_rl, synth.Inj];
paulson@2373
   843
paulson@3449
   844
(*Analysis of Fake cases.  Also works for messages that forward unknown parts,
paulson@3449
   845
  but this application is no longer necessary if analz_insert_eq is used.
paulson@2327
   846
  Abstraction over i is ESSENTIAL: it delays the dereferencing of claset
paulson@2327
   847
  DEPENDS UPON "X" REFERRING TO THE FRADULENT MESSAGE *)
paulson@2327
   848
fun spy_analz_tac i =
paulson@2373
   849
  DETERM
paulson@2373
   850
   (SELECT_GOAL
paulson@2373
   851
     (EVERY 
paulson@2373
   852
      [  (*push in occurrences of X...*)
paulson@2373
   853
       (REPEAT o CHANGED)
paulson@2373
   854
           (res_inst_tac [("x1","X")] (insert_commute RS ssubst) 1),
paulson@2373
   855
       (*...allowing further simplifications*)
paulson@2373
   856
       simp_tac (!simpset setloop split_tac [expand_if]) 1,
paulson@2373
   857
       REPEAT (FIRSTGOAL (resolve_tac [allI,impI,notI,conjI])),
paulson@2373
   858
       DEPTH_SOLVE 
paulson@2373
   859
         (REPEAT (Fake_insert_tac 1) THEN Asm_full_simp_tac 1
paulson@2516
   860
          THEN
paulson@3102
   861
          IF_UNSOLVED (Blast.depth_tac
paulson@3102
   862
		       (!claset addIs [impOfSubs analz_mono,
paulson@3102
   863
				       impOfSubs analz_subset_parts]) 2 1))
paulson@2373
   864
       ]) i);
paulson@2327
   865
paulson@2415
   866
(** Useful in many uniqueness proofs **)
paulson@2327
   867
fun ex_strip_tac i = REPEAT (swap_res_tac [exI, conjI] i) THEN 
paulson@2327
   868
                     assume_tac (i+1);
paulson@2327
   869
paulson@2415
   870
(*Apply the EX-ALL quantifification to prove uniqueness theorems in 
paulson@2415
   871
  their standard form*)
paulson@2415
   872
fun prove_unique_tac lemma = 
paulson@2415
   873
  EVERY' [dtac lemma,
paulson@2516
   874
          REPEAT o (mp_tac ORELSE' eresolve_tac [asm_rl,exE]),
paulson@2516
   875
          (*Duplicate the assumption*)
paulson@2516
   876
          forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl,
paulson@3102
   877
          Blast.depth_tac (!claset addSDs [spec]) 0];
paulson@2415
   878
paulson@2373
   879
paulson@2373
   880
(*Needed occasionally with spy_analz_tac, e.g. in analz_insert_Key_newK*)
paulson@2373
   881
goal Set.thy "A Un (B Un A) = B Un A";
paulson@2891
   882
by (Blast_tac 1);
paulson@2373
   883
val Un_absorb3 = result();
paulson@2373
   884
Addsimps [Un_absorb3];