src/HOL/Auth/Message.ML
author paulson
Mon Jun 09 10:21:05 1997 +0200 (1997-06-09)
changeset 3431 05b397185e1d
parent 3121 cbb6c0c1c58a
child 3449 6b17f82bbf01
permissions -rw-r--r--
Useful new lemma
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@2922
   408
by (blast_tac (!claset addIs [subset_insertI RS analz_mono RS subsetD,
paulson@2032
   409
                             analz.Decrypt]) 1);
paulson@1839
   410
val lemma2 = result();
paulson@1839
   411
paulson@1913
   412
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@2284
   413
\              analz (insert (Crypt K X) H) = \
paulson@2284
   414
\              insert (Crypt K X) (analz (insert X H))";
paulson@1839
   415
by (REPEAT (ares_tac [equalityI, lemma1, lemma2] 1));
paulson@1913
   416
qed "analz_insert_Decrypt";
paulson@1839
   417
paulson@1885
   418
(*Case analysis: either the message is secure, or it is not!
paulson@1946
   419
  Effective, but can cause subgoals to blow up!
paulson@1885
   420
  Use with expand_if;  apparently split_tac does not cope with patterns
paulson@2284
   421
  such as "analz (insert (Crypt K X) H)" *)
paulson@2284
   422
goal thy "analz (insert (Crypt K X) H) =                \
paulson@2154
   423
\         (if (Key (invKey K) : analz H)                \
paulson@2284
   424
\          then insert (Crypt K X) (analz (insert X H)) \
paulson@2284
   425
\          else insert (Crypt K X) (analz H))";
paulson@2102
   426
by (case_tac "Key (invKey K)  : analz H " 1);
paulson@1913
   427
by (ALLGOALS (asm_simp_tac (!simpset addsimps [analz_insert_Crypt, 
paulson@2032
   428
                                               analz_insert_Decrypt])));
paulson@1913
   429
qed "analz_Crypt_if";
paulson@1885
   430
paulson@2373
   431
Addsimps [analz_insert_Agent, analz_insert_Nonce, analz_insert_Key, 
paulson@2516
   432
          analz_insert_Hash, analz_insert_MPair, analz_Crypt_if];
paulson@1839
   433
paulson@1839
   434
(*This rule supposes "for the sake of argument" that we have the key.*)
paulson@2284
   435
goal thy  "analz (insert (Crypt K X) H) <=  \
paulson@2284
   436
\          insert (Crypt K X) (analz (insert X H))";
paulson@2032
   437
by (rtac subsetI 1);
paulson@2032
   438
by (etac analz.induct 1);
paulson@1839
   439
by (Auto_tac());
paulson@1913
   440
qed "analz_insert_Crypt_subset";
paulson@1839
   441
paulson@1839
   442
paulson@2026
   443
goal thy "analz (Key``N) = Key``N";
paulson@2026
   444
by (Auto_tac());
paulson@2032
   445
by (etac analz.induct 1);
paulson@2026
   446
by (Auto_tac());
paulson@2026
   447
qed "analz_image_Key";
paulson@2026
   448
paulson@2026
   449
Addsimps [analz_image_Key];
paulson@2026
   450
paulson@2026
   451
paulson@1839
   452
(** Idempotence and transitivity **)
paulson@1839
   453
paulson@1913
   454
goal thy "!!H. X: analz (analz H) ==> X: analz H";
paulson@2032
   455
by (etac analz.induct 1);
paulson@2891
   456
by (ALLGOALS Blast_tac);
paulson@2922
   457
qed "analz_analzD";
paulson@2922
   458
AddSDs [analz_analzD];
paulson@1839
   459
paulson@1913
   460
goal thy "analz (analz H) = analz H";
paulson@2891
   461
by (Blast_tac 1);
paulson@1913
   462
qed "analz_idem";
paulson@1913
   463
Addsimps [analz_idem];
paulson@1839
   464
paulson@1913
   465
goal thy "!!H. [| X: analz G;  G <= analz H |] ==> X: analz H";
paulson@1913
   466
by (dtac analz_mono 1);
paulson@2891
   467
by (Blast_tac 1);
paulson@1913
   468
qed "analz_trans";
paulson@1839
   469
paulson@1839
   470
(*Cut; Lemma 2 of Lowe*)
paulson@1998
   471
goal thy "!!H. [| Y: analz (insert X H);  X: analz H |] ==> Y: analz H";
paulson@2032
   472
by (etac analz_trans 1);
paulson@2891
   473
by (Blast_tac 1);
paulson@1913
   474
qed "analz_cut";
paulson@1839
   475
paulson@1839
   476
(*Cut can be proved easily by induction on
paulson@1913
   477
   "!!H. Y: analz (insert X H) ==> X: analz H --> Y: analz H"
paulson@1839
   478
*)
paulson@1839
   479
paulson@3431
   480
goal thy "!!H. X: analz H ==> analz (insert X H) = analz H";
paulson@3431
   481
by (blast_tac (!claset addIs [analz_cut, analz_insertI]) 1);
paulson@3431
   482
qed "analz_insert_eq";
paulson@3431
   483
paulson@1885
   484
paulson@1913
   485
(** A congruence rule for "analz" **)
paulson@1885
   486
paulson@1913
   487
goal thy "!!H. [| analz G <= analz G'; analz H <= analz H' \
paulson@1913
   488
\              |] ==> analz (G Un H) <= analz (G' Un H')";
paulson@1885
   489
by (Step_tac 1);
paulson@2032
   490
by (etac analz.induct 1);
paulson@1913
   491
by (ALLGOALS (best_tac (!claset addIs [analz_mono RS subsetD])));
paulson@1913
   492
qed "analz_subset_cong";
paulson@1885
   493
paulson@1913
   494
goal thy "!!H. [| analz G = analz G'; analz H = analz H' \
paulson@1913
   495
\              |] ==> analz (G Un H) = analz (G' Un H')";
paulson@1913
   496
by (REPEAT_FIRST (ares_tac [equalityI, analz_subset_cong]
paulson@2032
   497
          ORELSE' etac equalityE));
paulson@1913
   498
qed "analz_cong";
paulson@1885
   499
paulson@1885
   500
paulson@1913
   501
goal thy "!!H. analz H = analz H' ==> analz(insert X H) = analz(insert X H')";
paulson@1885
   502
by (asm_simp_tac (!simpset addsimps [insert_def] 
paulson@2032
   503
                           setloop (rtac analz_cong)) 1);
paulson@1913
   504
qed "analz_insert_cong";
paulson@1885
   505
paulson@1913
   506
(*If there are no pairs or encryptions then analz does nothing*)
paulson@2284
   507
goal thy "!!H. [| ALL X Y. {|X,Y|} ~: H;  ALL X K. Crypt K X ~: H |] ==> \
paulson@1913
   508
\         analz H = H";
paulson@1839
   509
by (Step_tac 1);
paulson@2032
   510
by (etac analz.induct 1);
paulson@2891
   511
by (ALLGOALS Blast_tac);
paulson@1913
   512
qed "analz_trivial";
paulson@1839
   513
paulson@1839
   514
(*Helps to prove Fake cases*)
paulson@1913
   515
goal thy "!!X. X: analz (UN i. analz (H i)) ==> X: analz (UN i. H i)";
paulson@2032
   516
by (etac analz.induct 1);
paulson@2922
   517
by (ALLGOALS (blast_tac (!claset addIs [impOfSubs analz_mono])));
paulson@1839
   518
val lemma = result();
paulson@1839
   519
paulson@1913
   520
goal thy "analz (UN i. analz (H i)) = analz (UN i. H i)";
paulson@2922
   521
by (blast_tac (!claset addIs [lemma, impOfSubs analz_mono]) 1);
paulson@1913
   522
qed "analz_UN_analz";
paulson@1913
   523
Addsimps [analz_UN_analz];
paulson@1839
   524
paulson@1839
   525
paulson@1913
   526
(**** Inductive relation "synth" ****)
paulson@1839
   527
paulson@1913
   528
AddIs  synth.intrs;
paulson@1839
   529
paulson@2011
   530
(*Can only produce a nonce or key if it is already known,
paulson@2011
   531
  but can synth a pair or encryption from its components...*)
paulson@2011
   532
val mk_cases = synth.mk_cases msg.simps;
paulson@2011
   533
paulson@2516
   534
(*NO Agent_synth, as any Agent name can be synthesized*)
paulson@2011
   535
val Nonce_synth = mk_cases "Nonce n : synth H";
paulson@2011
   536
val Key_synth   = mk_cases "Key K : synth H";
paulson@2373
   537
val Hash_synth  = mk_cases "Hash X : synth H";
paulson@2011
   538
val MPair_synth = mk_cases "{|X,Y|} : synth H";
paulson@2284
   539
val Crypt_synth = mk_cases "Crypt K X : synth H";
paulson@2011
   540
paulson@2373
   541
AddSEs [Nonce_synth, Key_synth, Hash_synth, MPair_synth, Crypt_synth];
paulson@2011
   542
paulson@1913
   543
goal thy "H <= synth(H)";
paulson@2891
   544
by (Blast_tac 1);
paulson@1913
   545
qed "synth_increasing";
paulson@1839
   546
paulson@1839
   547
(*Monotonicity*)
paulson@1913
   548
goalw thy synth.defs "!!G H. G<=H ==> synth(G) <= synth(H)";
paulson@1839
   549
by (rtac lfp_mono 1);
paulson@1839
   550
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   551
qed "synth_mono";
paulson@1839
   552
paulson@1839
   553
(** Unions **)
paulson@1839
   554
paulson@1913
   555
(*Converse fails: we can synth more from the union than from the 
paulson@1839
   556
  separate parts, building a compound message using elements of each.*)
paulson@1913
   557
goal thy "synth(G) Un synth(H) <= synth(G Un H)";
paulson@1913
   558
by (REPEAT (ares_tac [Un_least, synth_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   559
qed "synth_Un";
paulson@1839
   560
paulson@1913
   561
goal thy "insert X (synth H) <= synth(insert X H)";
paulson@2922
   562
by (blast_tac (!claset addIs [impOfSubs synth_mono]) 1);
paulson@1913
   563
qed "synth_insert";
paulson@1885
   564
paulson@1839
   565
(** Idempotence and transitivity **)
paulson@1839
   566
paulson@1913
   567
goal thy "!!H. X: synth (synth H) ==> X: synth H";
paulson@2032
   568
by (etac synth.induct 1);
paulson@2891
   569
by (ALLGOALS Blast_tac);
paulson@2922
   570
qed "synth_synthD";
paulson@2922
   571
AddSDs [synth_synthD];
paulson@1839
   572
paulson@1913
   573
goal thy "synth (synth H) = synth H";
paulson@2891
   574
by (Blast_tac 1);
paulson@1913
   575
qed "synth_idem";
paulson@1839
   576
paulson@1913
   577
goal thy "!!H. [| X: synth G;  G <= synth H |] ==> X: synth H";
paulson@1913
   578
by (dtac synth_mono 1);
paulson@2891
   579
by (Blast_tac 1);
paulson@1913
   580
qed "synth_trans";
paulson@1839
   581
paulson@1839
   582
(*Cut; Lemma 2 of Lowe*)
paulson@1998
   583
goal thy "!!H. [| Y: synth (insert X H);  X: synth H |] ==> Y: synth H";
paulson@2032
   584
by (etac synth_trans 1);
paulson@2891
   585
by (Blast_tac 1);
paulson@1913
   586
qed "synth_cut";
paulson@1839
   587
paulson@1946
   588
goal thy "Agent A : synth H";
paulson@2891
   589
by (Blast_tac 1);
paulson@1946
   590
qed "Agent_synth";
paulson@1946
   591
paulson@1913
   592
goal thy "(Nonce N : synth H) = (Nonce N : H)";
paulson@2891
   593
by (Blast_tac 1);
paulson@1913
   594
qed "Nonce_synth_eq";
paulson@1839
   595
paulson@1913
   596
goal thy "(Key K : synth H) = (Key K : H)";
paulson@2891
   597
by (Blast_tac 1);
paulson@1913
   598
qed "Key_synth_eq";
paulson@1839
   599
paulson@2373
   600
goal thy "!!K. Key K ~: H ==> (Crypt K X : synth H) = (Crypt K X : H)";
paulson@2891
   601
by (Blast_tac 1);
paulson@2011
   602
qed "Crypt_synth_eq";
paulson@2011
   603
paulson@2011
   604
Addsimps [Agent_synth, Nonce_synth_eq, Key_synth_eq, Crypt_synth_eq];
paulson@1839
   605
paulson@1839
   606
paulson@1839
   607
goalw thy [keysFor_def]
paulson@1913
   608
    "keysFor (synth H) = keysFor H Un invKey``{K. Key K : H}";
paulson@2891
   609
by (Blast_tac 1);
paulson@1913
   610
qed "keysFor_synth";
paulson@1913
   611
Addsimps [keysFor_synth];
paulson@1839
   612
paulson@1839
   613
paulson@1913
   614
(*** Combinations of parts, analz and synth ***)
paulson@1839
   615
paulson@1913
   616
goal thy "parts (synth H) = parts H Un synth H";
paulson@2032
   617
by (rtac equalityI 1);
paulson@2032
   618
by (rtac subsetI 1);
paulson@2032
   619
by (etac parts.induct 1);
paulson@1839
   620
by (ALLGOALS
paulson@2922
   621
    (blast_tac (!claset addIs ((synth_increasing RS parts_mono RS subsetD)
paulson@2032
   622
                             ::parts.intrs))));
paulson@1913
   623
qed "parts_synth";
paulson@1913
   624
Addsimps [parts_synth];
paulson@1839
   625
paulson@2373
   626
goal thy "analz (analz G Un H) = analz (G Un H)";
paulson@2373
   627
by (REPEAT_FIRST (resolve_tac [equalityI, analz_subset_cong]));
paulson@2373
   628
by (ALLGOALS Simp_tac);
paulson@2373
   629
qed "analz_analz_Un";
paulson@2373
   630
paulson@2373
   631
goal thy "analz (synth G Un H) = analz (G Un H) Un synth G";
paulson@2032
   632
by (rtac equalityI 1);
paulson@2032
   633
by (rtac subsetI 1);
paulson@2032
   634
by (etac analz.induct 1);
paulson@2922
   635
by (blast_tac (!claset addIs [impOfSubs analz_mono]) 5);
paulson@2922
   636
by (ALLGOALS (blast_tac (!claset addIs analz.intrs)));
paulson@2373
   637
qed "analz_synth_Un";
paulson@2373
   638
paulson@2373
   639
goal thy "analz (synth H) = analz H Un synth H";
paulson@2373
   640
by (cut_inst_tac [("H","{}")] analz_synth_Un 1);
paulson@2373
   641
by (Full_simp_tac 1);
paulson@1913
   642
qed "analz_synth";
paulson@2373
   643
Addsimps [analz_analz_Un, analz_synth_Un, analz_synth];
paulson@1839
   644
paulson@2032
   645
(*Hard to prove; still needed now that there's only one Spy?*)
paulson@1913
   646
goal thy "analz (UN i. synth (H i)) = \
paulson@1913
   647
\         analz (UN i. H i) Un (UN i. synth (H i))";
paulson@2032
   648
by (rtac equalityI 1);
paulson@2032
   649
by (rtac subsetI 1);
paulson@2032
   650
by (etac analz.induct 1);
paulson@2922
   651
by (blast_tac
paulson@2922
   652
    (!claset addIs [impOfSubs synth_increasing,
paulson@2032
   653
                    impOfSubs analz_mono]) 5);
paulson@2891
   654
by (Blast_tac 1);
paulson@2891
   655
by (blast_tac (!claset addIs [analz.Inj RS analz.Fst]) 1);
paulson@2891
   656
by (blast_tac (!claset addIs [analz.Inj RS analz.Snd]) 1);
paulson@2891
   657
by (blast_tac (!claset addIs [analz.Decrypt]) 1);
paulson@1913
   658
qed "analz_UN1_synth";
paulson@1913
   659
Addsimps [analz_UN1_synth];
paulson@1929
   660
paulson@1946
   661
paulson@1946
   662
(** For reasoning about the Fake rule in traces **)
paulson@1946
   663
paulson@1929
   664
goal thy "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H";
paulson@2032
   665
by (rtac ([parts_mono, parts_Un_subset2] MRS subset_trans) 1);
paulson@2891
   666
by (Blast_tac 1);
paulson@1929
   667
qed "parts_insert_subset_Un";
paulson@1929
   668
paulson@1946
   669
(*More specifically for Fake*)
paulson@1946
   670
goal thy "!!H. X: synth (analz G) ==> \
paulson@1946
   671
\              parts (insert X H) <= synth (analz G) Un parts G Un parts H";
paulson@2032
   672
by (dtac parts_insert_subset_Un 1);
paulson@1946
   673
by (Full_simp_tac 1);
paulson@2891
   674
by (Blast_tac 1);
paulson@1946
   675
qed "Fake_parts_insert";
paulson@1946
   676
paulson@2061
   677
goal thy
paulson@2284
   678
     "!!H. [| Crypt K Y : parts (insert X H);  X: synth (analz G);  \
paulson@2061
   679
\             Key K ~: analz G |]                                   \
paulson@2284
   680
\          ==> Crypt K Y : parts G Un parts H";
paulson@2061
   681
by (dtac (impOfSubs Fake_parts_insert) 1);
paulson@2170
   682
by (assume_tac 1);
paulson@3102
   683
by (blast_tac (!claset addDs [impOfSubs analz_subset_parts]) 1);
paulson@2061
   684
qed "Crypt_Fake_parts_insert";
paulson@2061
   685
paulson@2373
   686
goal thy "!!H. X: synth (analz G) ==> \
paulson@2373
   687
\              analz (insert X H) <= synth (analz G) Un analz (G Un H)";
paulson@2373
   688
by (rtac subsetI 1);
paulson@2373
   689
by (subgoal_tac "x : analz (synth (analz G) Un H)" 1);
paulson@2922
   690
by (blast_tac (!claset addIs [impOfSubs analz_mono,
paulson@2922
   691
			      impOfSubs (analz_mono RS synth_mono)]) 2);
paulson@2373
   692
by (Full_simp_tac 1);
paulson@2891
   693
by (Blast_tac 1);
paulson@2373
   694
qed "Fake_analz_insert";
paulson@2373
   695
paulson@2011
   696
goal thy "(X: analz H & X: parts H) = (X: analz H)";
paulson@2891
   697
by (blast_tac (!claset addIs [impOfSubs analz_subset_parts]) 1);
paulson@2011
   698
val analz_conj_parts = result();
paulson@2011
   699
paulson@2011
   700
goal thy "(X: analz H | X: parts H) = (X: parts H)";
paulson@2891
   701
by (blast_tac (!claset addIs [impOfSubs analz_subset_parts]) 1);
paulson@2011
   702
val analz_disj_parts = result();
paulson@2011
   703
paulson@2011
   704
AddIffs [analz_conj_parts, analz_disj_parts];
paulson@2011
   705
paulson@1998
   706
(*Without this equation, other rules for synth and analz would yield
paulson@1998
   707
  redundant cases*)
paulson@1998
   708
goal thy "({|X,Y|} : synth (analz H)) = \
paulson@1998
   709
\         (X : synth (analz H) & Y : synth (analz H))";
paulson@2891
   710
by (Blast_tac 1);
paulson@1998
   711
qed "MPair_synth_analz";
paulson@1998
   712
paulson@1998
   713
AddIffs [MPair_synth_analz];
paulson@1929
   714
paulson@2154
   715
goal thy "!!K. [| Key K : analz H;  Key (invKey K) : analz H |] \
paulson@2284
   716
\              ==> (Crypt K X : synth (analz H)) = (X : synth (analz H))";
paulson@2891
   717
by (Blast_tac 1);
paulson@2154
   718
qed "Crypt_synth_analz";
paulson@2154
   719
paulson@1929
   720
paulson@2516
   721
goal thy "!!K. X ~: synth (analz H) \
paulson@2516
   722
\   ==> (Hash{|X,Y|} : synth (analz H)) = (Hash{|X,Y|} : analz H)";
paulson@2891
   723
by (Blast_tac 1);
paulson@2373
   724
qed "Hash_synth_analz";
paulson@2373
   725
Addsimps [Hash_synth_analz];
paulson@2373
   726
paulson@2373
   727
paulson@2484
   728
(**** HPair: a combination of Hash and MPair ****)
paulson@2484
   729
paulson@2484
   730
(*** Freeness ***)
paulson@2484
   731
paulson@2516
   732
goalw thy [HPair_def] "Agent A ~= Hash[X] Y";
paulson@2484
   733
by (Simp_tac 1);
paulson@2484
   734
qed "Agent_neq_HPair";
paulson@2484
   735
paulson@2516
   736
goalw thy [HPair_def] "Nonce N ~= Hash[X] Y";
paulson@2484
   737
by (Simp_tac 1);
paulson@2484
   738
qed "Nonce_neq_HPair";
paulson@2484
   739
paulson@2516
   740
goalw thy [HPair_def] "Key K ~= Hash[X] Y";
paulson@2484
   741
by (Simp_tac 1);
paulson@2484
   742
qed "Key_neq_HPair";
paulson@2484
   743
paulson@2516
   744
goalw thy [HPair_def] "Hash Z ~= Hash[X] Y";
paulson@2484
   745
by (Simp_tac 1);
paulson@2484
   746
qed "Hash_neq_HPair";
paulson@2484
   747
paulson@2516
   748
goalw thy [HPair_def] "Crypt K X' ~= Hash[X] Y";
paulson@2484
   749
by (Simp_tac 1);
paulson@2484
   750
qed "Crypt_neq_HPair";
paulson@2484
   751
paulson@2484
   752
val HPair_neqs = [Agent_neq_HPair, Nonce_neq_HPair, 
paulson@2516
   753
                  Key_neq_HPair, Hash_neq_HPair, Crypt_neq_HPair];
paulson@2484
   754
paulson@2484
   755
AddIffs HPair_neqs;
paulson@2484
   756
AddIffs (HPair_neqs RL [not_sym]);
paulson@2484
   757
paulson@2516
   758
goalw thy [HPair_def] "(Hash[X'] Y' = Hash[X] Y) = (X' = X & Y'=Y)";
paulson@2484
   759
by (Simp_tac 1);
paulson@2484
   760
qed "HPair_eq";
paulson@2484
   761
paulson@2516
   762
goalw thy [HPair_def] "({|X',Y'|} = Hash[X] Y) = (X' = Hash{|X,Y|} & Y'=Y)";
paulson@2484
   763
by (Simp_tac 1);
paulson@2484
   764
qed "MPair_eq_HPair";
paulson@2484
   765
paulson@2516
   766
goalw thy [HPair_def] "(Hash[X] Y = {|X',Y'|}) = (X' = Hash{|X,Y|} & Y'=Y)";
paulson@2484
   767
by (Auto_tac());
paulson@2484
   768
qed "HPair_eq_MPair";
paulson@2484
   769
paulson@2484
   770
AddIffs [HPair_eq, MPair_eq_HPair, HPair_eq_MPair];
paulson@2484
   771
paulson@2484
   772
paulson@2484
   773
(*** Specialized laws, proved in terms of those for Hash and MPair ***)
paulson@2484
   774
paulson@2516
   775
goalw thy [HPair_def] "keysFor (insert (Hash[X] Y) H) = keysFor H";
paulson@2484
   776
by (Simp_tac 1);
paulson@2484
   777
qed "keysFor_insert_HPair";
paulson@2484
   778
paulson@2484
   779
goalw thy [HPair_def]
paulson@2516
   780
    "parts (insert (Hash[X] Y) H) = \
paulson@2516
   781
\    insert (Hash[X] Y) (insert (Hash{|X,Y|}) (parts (insert Y H)))";
paulson@2484
   782
by (Simp_tac 1);
paulson@2484
   783
qed "parts_insert_HPair";
paulson@2484
   784
paulson@2484
   785
goalw thy [HPair_def]
paulson@2516
   786
    "analz (insert (Hash[X] Y) H) = \
paulson@2516
   787
\    insert (Hash[X] Y) (insert (Hash{|X,Y|}) (analz (insert Y H)))";
paulson@2484
   788
by (Simp_tac 1);
paulson@2484
   789
qed "analz_insert_HPair";
paulson@2484
   790
paulson@2484
   791
goalw thy [HPair_def] "!!H. X ~: synth (analz H) \
paulson@2516
   792
\   ==> (Hash[X] Y : synth (analz H)) = \
paulson@2484
   793
\       (Hash {|X, Y|} : analz H & Y : synth (analz H))";
paulson@2484
   794
by (Simp_tac 1);
paulson@2891
   795
by (Blast_tac 1);
paulson@2484
   796
qed "HPair_synth_analz";
paulson@2484
   797
paulson@2484
   798
Addsimps [keysFor_insert_HPair, parts_insert_HPair, analz_insert_HPair, 
paulson@2516
   799
          HPair_synth_analz, HPair_synth_analz];
paulson@2484
   800
paulson@2484
   801
paulson@1929
   802
(*We do NOT want Crypt... messages broken up in protocols!!*)
paulson@1929
   803
Delrules partsEs;
paulson@1929
   804
paulson@2327
   805
paulson@2327
   806
(** Rewrites to push in Key and Crypt messages, so that other messages can
paulson@2327
   807
    be pulled out using the analz_insert rules **)
paulson@2327
   808
paulson@2327
   809
fun insComm thy x y = read_instantiate_sg (sign_of thy) [("x",x), ("y",y)] 
paulson@2327
   810
                          insert_commute;
paulson@2327
   811
paulson@2327
   812
val pushKeys = map (insComm thy "Key ?K") 
paulson@2373
   813
                   ["Agent ?C", "Nonce ?N", "Hash ?X", 
paulson@2516
   814
                    "MPair ?X ?Y", "Crypt ?X ?K'"];
paulson@2327
   815
paulson@2327
   816
val pushCrypts = map (insComm thy "Crypt ?X ?K") 
paulson@2373
   817
                     ["Agent ?C", "Nonce ?N", "Hash ?X'", "MPair ?X' ?Y"];
paulson@2327
   818
paulson@2327
   819
(*Cannot be added with Addsimps -- we don't always want to re-order messages*)
paulson@2327
   820
val pushes = pushKeys@pushCrypts;
paulson@2327
   821
paulson@3121
   822
paulson@3121
   823
(*** Tactics useful for many protocol proofs ***)
paulson@3121
   824
paulson@3121
   825
(*Prove base case (subgoal i) and simplify others*)
paulson@3121
   826
fun prove_simple_subgoals_tac i = 
paulson@3121
   827
    fast_tac (!claset addss (!simpset)) i THEN
paulson@3121
   828
    ALLGOALS Asm_simp_tac;
paulson@3121
   829
paulson@3121
   830
fun Fake_parts_insert_tac i = 
paulson@3121
   831
    blast_tac (!claset addDs [impOfSubs analz_subset_parts,
paulson@3121
   832
			      impOfSubs Fake_parts_insert]) i;
paulson@3121
   833
paulson@3121
   834
(*Apply rules to break down assumptions of the form
paulson@3121
   835
  Y : parts(insert X H)  and  Y : analz(insert X H)
paulson@3121
   836
*)
paulson@2373
   837
val Fake_insert_tac = 
paulson@2373
   838
    dresolve_tac [impOfSubs Fake_analz_insert,
paulson@2516
   839
                  impOfSubs Fake_parts_insert] THEN'
paulson@2373
   840
    eresolve_tac [asm_rl, synth.Inj];
paulson@2373
   841
paulson@2373
   842
(*Analysis of Fake cases and of messages that forward unknown parts.
paulson@2327
   843
  Abstraction over i is ESSENTIAL: it delays the dereferencing of claset
paulson@2327
   844
  DEPENDS UPON "X" REFERRING TO THE FRADULENT MESSAGE *)
paulson@2327
   845
fun spy_analz_tac i =
paulson@2373
   846
  DETERM
paulson@2373
   847
   (SELECT_GOAL
paulson@2373
   848
     (EVERY 
paulson@2373
   849
      [  (*push in occurrences of X...*)
paulson@2373
   850
       (REPEAT o CHANGED)
paulson@2373
   851
           (res_inst_tac [("x1","X")] (insert_commute RS ssubst) 1),
paulson@2373
   852
       (*...allowing further simplifications*)
paulson@2373
   853
       simp_tac (!simpset setloop split_tac [expand_if]) 1,
paulson@2373
   854
       REPEAT (FIRSTGOAL (resolve_tac [allI,impI,notI,conjI])),
paulson@2373
   855
       DEPTH_SOLVE 
paulson@2373
   856
         (REPEAT (Fake_insert_tac 1) THEN Asm_full_simp_tac 1
paulson@2516
   857
          THEN
paulson@3102
   858
          IF_UNSOLVED (Blast.depth_tac
paulson@3102
   859
		       (!claset addIs [impOfSubs analz_mono,
paulson@3102
   860
				       impOfSubs analz_subset_parts]) 2 1))
paulson@2373
   861
       ]) i);
paulson@2327
   862
paulson@2415
   863
(** Useful in many uniqueness proofs **)
paulson@2327
   864
fun ex_strip_tac i = REPEAT (swap_res_tac [exI, conjI] i) THEN 
paulson@2327
   865
                     assume_tac (i+1);
paulson@2327
   866
paulson@2415
   867
(*Apply the EX-ALL quantifification to prove uniqueness theorems in 
paulson@2415
   868
  their standard form*)
paulson@2415
   869
fun prove_unique_tac lemma = 
paulson@2415
   870
  EVERY' [dtac lemma,
paulson@2516
   871
          REPEAT o (mp_tac ORELSE' eresolve_tac [asm_rl,exE]),
paulson@2516
   872
          (*Duplicate the assumption*)
paulson@2516
   873
          forw_inst_tac [("psi", "ALL C.?P(C)")] asm_rl,
paulson@3102
   874
          Blast.depth_tac (!claset addSDs [spec]) 0];
paulson@2415
   875
paulson@2373
   876
paulson@2373
   877
(*Needed occasionally with spy_analz_tac, e.g. in analz_insert_Key_newK*)
paulson@2373
   878
goal Set.thy "A Un (B Un A) = B Un A";
paulson@2891
   879
by (Blast_tac 1);
paulson@2373
   880
val Un_absorb3 = result();
paulson@2373
   881
Addsimps [Un_absorb3];