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