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