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