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