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