src/HOL/Auth/Message.ML
author paulson
Tue Oct 08 10:19:31 1996 +0200 (1996-10-08)
changeset 2068 0d05468dc80c
parent 2061 b14a08bf61bf
child 2102 41a667d2c3fa
permissions -rw-r--r--
New theorem Crypt_imp_invKey_keysFor
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@1839
    12
paulson@1839
    13
(** Inverse of keys **)
paulson@1839
    14
paulson@1839
    15
goal thy "!!K K'. (invKey K = invKey K') = (K=K')";
paulson@1839
    16
by (Step_tac 1);
paulson@2032
    17
by (rtac box_equals 1);
paulson@1839
    18
by (REPEAT (rtac invKey 2));
paulson@1839
    19
by (Asm_simp_tac 1);
paulson@1839
    20
qed "invKey_eq";
paulson@1839
    21
paulson@1839
    22
Addsimps [invKey, invKey_eq];
paulson@1839
    23
paulson@1839
    24
paulson@1839
    25
(**** keysFor operator ****)
paulson@1839
    26
paulson@1839
    27
goalw thy [keysFor_def] "keysFor {} = {}";
paulson@1839
    28
by (Fast_tac 1);
paulson@1839
    29
qed "keysFor_empty";
paulson@1839
    30
paulson@1839
    31
goalw thy [keysFor_def] "keysFor (H Un H') = keysFor H Un keysFor H'";
paulson@1839
    32
by (Fast_tac 1);
paulson@1839
    33
qed "keysFor_Un";
paulson@1839
    34
paulson@1839
    35
goalw thy [keysFor_def] "keysFor (UN i. H i) = (UN i. keysFor (H i))";
paulson@1839
    36
by (Fast_tac 1);
paulson@1839
    37
qed "keysFor_UN";
paulson@1839
    38
paulson@1839
    39
(*Monotonicity*)
paulson@1839
    40
goalw thy [keysFor_def] "!!G H. G<=H ==> keysFor(G) <= keysFor(H)";
paulson@1839
    41
by (Fast_tac 1);
paulson@1839
    42
qed "keysFor_mono";
paulson@1839
    43
paulson@1839
    44
goalw thy [keysFor_def] "keysFor (insert (Agent A) H) = keysFor H";
paulson@1839
    45
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    46
qed "keysFor_insert_Agent";
paulson@1839
    47
paulson@1839
    48
goalw thy [keysFor_def] "keysFor (insert (Nonce N) H) = keysFor H";
paulson@1839
    49
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    50
qed "keysFor_insert_Nonce";
paulson@1839
    51
paulson@1839
    52
goalw thy [keysFor_def] "keysFor (insert (Key K) H) = keysFor H";
paulson@1839
    53
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    54
qed "keysFor_insert_Key";
paulson@1839
    55
paulson@1839
    56
goalw thy [keysFor_def] "keysFor (insert {|X,Y|} H) = keysFor H";
paulson@1839
    57
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    58
qed "keysFor_insert_MPair";
paulson@1839
    59
paulson@1839
    60
goalw thy [keysFor_def]
paulson@1839
    61
    "keysFor (insert (Crypt X K) H) = insert (invKey K) (keysFor H)";
paulson@1839
    62
by (Auto_tac());
paulson@1964
    63
by (Fast_tac 1);
paulson@1839
    64
qed "keysFor_insert_Crypt";
paulson@1839
    65
paulson@1839
    66
Addsimps [keysFor_empty, keysFor_Un, keysFor_UN, 
paulson@2032
    67
          keysFor_insert_Agent, keysFor_insert_Nonce,
paulson@2032
    68
          keysFor_insert_Key, keysFor_insert_MPair,
paulson@2032
    69
          keysFor_insert_Crypt];
paulson@1839
    70
paulson@2068
    71
goalw thy [keysFor_def] "!!H. Crypt X K : H ==> invKey K : keysFor H";
paulson@2068
    72
by (Fast_tac 1);
paulson@2068
    73
qed "Crypt_imp_invKey_keysFor";
paulson@2068
    74
paulson@1839
    75
paulson@1839
    76
(**** Inductive relation "parts" ****)
paulson@1839
    77
paulson@1839
    78
val major::prems = 
paulson@1839
    79
goal thy "[| {|X,Y|} : parts H;       \
paulson@1839
    80
\            [| X : parts H; Y : parts H |] ==> P  \
paulson@1839
    81
\         |] ==> P";
paulson@1839
    82
by (cut_facts_tac [major] 1);
paulson@2032
    83
by (resolve_tac prems 1);
paulson@1839
    84
by (REPEAT (eresolve_tac [asm_rl, parts.Fst, parts.Snd] 1));
paulson@1839
    85
qed "MPair_parts";
paulson@1839
    86
paulson@1839
    87
AddIs  [parts.Inj];
paulson@1929
    88
paulson@1929
    89
val partsEs = [MPair_parts, make_elim parts.Body];
paulson@1929
    90
paulson@1929
    91
AddSEs partsEs;
paulson@1929
    92
(*NB These two rules are UNSAFE in the formal sense, as they discard the
paulson@1929
    93
     compound message.  They work well on THIS FILE, perhaps because its
paulson@1929
    94
     proofs concern only atomic messages.*)
paulson@1839
    95
paulson@1839
    96
goal thy "H <= parts(H)";
paulson@1839
    97
by (Fast_tac 1);
paulson@1839
    98
qed "parts_increasing";
paulson@1839
    99
paulson@1839
   100
(*Monotonicity*)
paulson@1839
   101
goalw thy parts.defs "!!G H. G<=H ==> parts(G) <= parts(H)";
paulson@1839
   102
by (rtac lfp_mono 1);
paulson@1839
   103
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
   104
qed "parts_mono";
paulson@1839
   105
paulson@1839
   106
goal thy "parts{} = {}";
paulson@1839
   107
by (Step_tac 1);
paulson@2032
   108
by (etac parts.induct 1);
paulson@1839
   109
by (ALLGOALS Fast_tac);
paulson@1839
   110
qed "parts_empty";
paulson@1839
   111
Addsimps [parts_empty];
paulson@1839
   112
paulson@1839
   113
goal thy "!!X. X: parts{} ==> P";
paulson@1839
   114
by (Asm_full_simp_tac 1);
paulson@1839
   115
qed "parts_emptyE";
paulson@1839
   116
AddSEs [parts_emptyE];
paulson@1839
   117
paulson@1893
   118
(*WARNING: loops if H = {Y}, therefore must not be repeated!*)
paulson@1893
   119
goal thy "!!H. X: parts H ==> EX Y:H. X: parts {Y}";
paulson@2032
   120
by (etac parts.induct 1);
paulson@1893
   121
by (ALLGOALS Fast_tac);
paulson@1893
   122
qed "parts_singleton";
paulson@1893
   123
paulson@1839
   124
paulson@1839
   125
(** Unions **)
paulson@1839
   126
paulson@1839
   127
goal thy "parts(G) Un parts(H) <= parts(G Un H)";
paulson@1839
   128
by (REPEAT (ares_tac [Un_least, parts_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   129
val parts_Un_subset1 = result();
paulson@1839
   130
paulson@1839
   131
goal thy "parts(G Un H) <= parts(G) Un parts(H)";
paulson@2032
   132
by (rtac subsetI 1);
paulson@2032
   133
by (etac parts.induct 1);
paulson@1839
   134
by (ALLGOALS Fast_tac);
paulson@1839
   135
val parts_Un_subset2 = result();
paulson@1839
   136
paulson@1839
   137
goal thy "parts(G Un H) = parts(G) Un parts(H)";
paulson@1839
   138
by (REPEAT (ares_tac [equalityI, parts_Un_subset1, parts_Un_subset2] 1));
paulson@1839
   139
qed "parts_Un";
paulson@1839
   140
paulson@2011
   141
goal thy "parts (insert X H) = parts {X} Un parts H";
paulson@1852
   142
by (stac (read_instantiate [("A","H")] insert_is_Un) 1);
paulson@2011
   143
by (simp_tac (HOL_ss addsimps [parts_Un]) 1);
paulson@2011
   144
qed "parts_insert";
paulson@2011
   145
paulson@2011
   146
(*TWO inserts to avoid looping.  This rewrite is better than nothing.
paulson@2011
   147
  Not suitable for Addsimps: its behaviour can be strange.*)
paulson@2011
   148
goal thy "parts (insert X (insert Y H)) = parts {X} Un parts {Y} Un parts H";
paulson@2011
   149
by (simp_tac (!simpset addsimps [Un_assoc]) 1);
paulson@2011
   150
by (simp_tac (!simpset addsimps [parts_insert RS sym]) 1);
paulson@1852
   151
qed "parts_insert2";
paulson@1852
   152
paulson@1839
   153
goal thy "(UN x:A. parts(H x)) <= parts(UN x:A. H x)";
paulson@1839
   154
by (REPEAT (ares_tac [UN_least, parts_mono, UN_upper] 1));
paulson@1839
   155
val parts_UN_subset1 = result();
paulson@1839
   156
paulson@1839
   157
goal thy "parts(UN x:A. H x) <= (UN x:A. parts(H x))";
paulson@2032
   158
by (rtac subsetI 1);
paulson@2032
   159
by (etac parts.induct 1);
paulson@1839
   160
by (ALLGOALS Fast_tac);
paulson@1839
   161
val parts_UN_subset2 = result();
paulson@1839
   162
paulson@1839
   163
goal thy "parts(UN x:A. H x) = (UN x:A. parts(H x))";
paulson@1839
   164
by (REPEAT (ares_tac [equalityI, parts_UN_subset1, parts_UN_subset2] 1));
paulson@1839
   165
qed "parts_UN";
paulson@1839
   166
paulson@1839
   167
goal thy "parts(UN x. H x) = (UN x. parts(H x))";
paulson@1839
   168
by (simp_tac (!simpset addsimps [UNION1_def, parts_UN]) 1);
paulson@1839
   169
qed "parts_UN1";
paulson@1839
   170
paulson@1913
   171
(*Added to simplify arguments to parts, analz and synth*)
paulson@1839
   172
Addsimps [parts_Un, parts_UN, parts_UN1];
paulson@1839
   173
paulson@1839
   174
goal thy "insert X (parts H) <= parts(insert X H)";
paulson@1852
   175
by (fast_tac (!claset addEs [impOfSubs parts_mono]) 1);
paulson@1839
   176
qed "parts_insert_subset";
paulson@1839
   177
paulson@1839
   178
(** Idempotence and transitivity **)
paulson@1839
   179
paulson@1839
   180
goal thy "!!H. X: parts (parts H) ==> X: parts H";
paulson@2032
   181
by (etac parts.induct 1);
paulson@1839
   182
by (ALLGOALS Fast_tac);
paulson@1839
   183
qed "parts_partsE";
paulson@1839
   184
AddSEs [parts_partsE];
paulson@1839
   185
paulson@1839
   186
goal thy "parts (parts H) = parts H";
paulson@1839
   187
by (Fast_tac 1);
paulson@1839
   188
qed "parts_idem";
paulson@1839
   189
Addsimps [parts_idem];
paulson@1839
   190
paulson@1839
   191
goal thy "!!H. [| X: parts G;  G <= parts H |] ==> X: parts H";
paulson@1839
   192
by (dtac parts_mono 1);
paulson@1839
   193
by (Fast_tac 1);
paulson@1839
   194
qed "parts_trans";
paulson@1839
   195
paulson@1839
   196
(*Cut*)
paulson@1998
   197
goal thy "!!H. [| Y: parts (insert X H);  X: parts H |] ==> Y: parts H";
paulson@2032
   198
by (etac parts_trans 1);
paulson@1839
   199
by (Fast_tac 1);
paulson@1839
   200
qed "parts_cut";
paulson@1839
   201
paulson@2011
   202
val parts_insertI = impOfSubs (subset_insertI RS parts_mono);
paulson@2011
   203
paulson@1929
   204
goal thy "!!H. X: parts H ==> parts (insert X H) = parts H";
paulson@1929
   205
by (fast_tac (!claset addSEs [parts_cut]
paulson@2011
   206
                      addIs  [parts_insertI]) 1);
paulson@1929
   207
qed "parts_cut_eq";
paulson@1929
   208
paulson@2028
   209
Addsimps [parts_cut_eq];
paulson@2028
   210
paulson@1839
   211
paulson@1839
   212
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   213
paulson@1839
   214
goal thy "parts (insert (Agent agt) H) = insert (Agent agt) (parts H)";
paulson@1839
   215
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@2032
   216
by (rtac subsetI 1);
paulson@2032
   217
by (etac parts.induct 1);
paulson@1839
   218
(*Simplification breaks up equalities between messages;
paulson@1839
   219
  how to make it work for fast_tac??*)
paulson@1839
   220
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   221
qed "parts_insert_Agent";
paulson@1839
   222
paulson@1839
   223
goal thy "parts (insert (Nonce N) H) = insert (Nonce N) (parts H)";
paulson@1839
   224
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@2032
   225
by (rtac subsetI 1);
paulson@2032
   226
by (etac parts.induct 1);
paulson@1839
   227
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   228
qed "parts_insert_Nonce";
paulson@1839
   229
paulson@1839
   230
goal thy "parts (insert (Key K) H) = insert (Key K) (parts H)";
paulson@1839
   231
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@2032
   232
by (rtac subsetI 1);
paulson@2032
   233
by (etac parts.induct 1);
paulson@1839
   234
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   235
qed "parts_insert_Key";
paulson@1839
   236
paulson@1839
   237
goal thy "parts (insert (Crypt X K) H) = \
paulson@1839
   238
\         insert (Crypt X K) (parts (insert X H))";
paulson@2032
   239
by (rtac equalityI 1);
paulson@2032
   240
by (rtac subsetI 1);
paulson@2032
   241
by (etac parts.induct 1);
paulson@1839
   242
by (Auto_tac());
paulson@2032
   243
by (etac parts.induct 1);
paulson@1839
   244
by (ALLGOALS (best_tac (!claset addIs [parts.Body])));
paulson@1839
   245
qed "parts_insert_Crypt";
paulson@1839
   246
paulson@1839
   247
goal thy "parts (insert {|X,Y|} H) = \
paulson@1839
   248
\         insert {|X,Y|} (parts (insert X (insert Y H)))";
paulson@2032
   249
by (rtac equalityI 1);
paulson@2032
   250
by (rtac subsetI 1);
paulson@2032
   251
by (etac parts.induct 1);
paulson@1839
   252
by (Auto_tac());
paulson@2032
   253
by (etac parts.induct 1);
paulson@1839
   254
by (ALLGOALS (best_tac (!claset addIs [parts.Fst, parts.Snd])));
paulson@1839
   255
qed "parts_insert_MPair";
paulson@1839
   256
paulson@1839
   257
Addsimps [parts_insert_Agent, parts_insert_Nonce, 
paulson@2032
   258
          parts_insert_Key, parts_insert_Crypt, parts_insert_MPair];
paulson@1839
   259
paulson@1839
   260
paulson@2026
   261
goal thy "parts (Key``N) = Key``N";
paulson@2026
   262
by (Auto_tac());
paulson@2032
   263
by (etac parts.induct 1);
paulson@2026
   264
by (Auto_tac());
paulson@2026
   265
qed "parts_image_Key";
paulson@2026
   266
paulson@2026
   267
Addsimps [parts_image_Key];
paulson@2026
   268
paulson@2026
   269
paulson@1913
   270
(**** Inductive relation "analz" ****)
paulson@1839
   271
paulson@1839
   272
val major::prems = 
paulson@1913
   273
goal thy "[| {|X,Y|} : analz H;       \
paulson@1913
   274
\            [| X : analz H; Y : analz H |] ==> P  \
paulson@1839
   275
\         |] ==> P";
paulson@1839
   276
by (cut_facts_tac [major] 1);
paulson@2032
   277
by (resolve_tac prems 1);
paulson@1913
   278
by (REPEAT (eresolve_tac [asm_rl, analz.Fst, analz.Snd] 1));
paulson@1913
   279
qed "MPair_analz";
paulson@1839
   280
paulson@1913
   281
AddIs  [analz.Inj];
paulson@2011
   282
AddSEs [MPair_analz];      (*Perhaps it should NOT be deemed safe!*)
paulson@1913
   283
AddDs  [analz.Decrypt];
paulson@1839
   284
paulson@1913
   285
Addsimps [analz.Inj];
paulson@1885
   286
paulson@1913
   287
goal thy "H <= analz(H)";
paulson@1839
   288
by (Fast_tac 1);
paulson@1913
   289
qed "analz_increasing";
paulson@1839
   290
paulson@1913
   291
goal thy "analz H <= parts H";
paulson@1839
   292
by (rtac subsetI 1);
paulson@2032
   293
by (etac analz.induct 1);
paulson@1839
   294
by (ALLGOALS Fast_tac);
paulson@1913
   295
qed "analz_subset_parts";
paulson@1839
   296
paulson@1913
   297
bind_thm ("not_parts_not_analz", analz_subset_parts RS contra_subsetD);
paulson@1839
   298
paulson@1839
   299
paulson@1913
   300
goal thy "parts (analz H) = parts H";
paulson@2032
   301
by (rtac equalityI 1);
paulson@2032
   302
by (rtac (analz_subset_parts RS parts_mono RS subset_trans) 1);
paulson@1839
   303
by (Simp_tac 1);
paulson@1913
   304
by (fast_tac (!claset addDs [analz_increasing RS parts_mono RS subsetD]) 1);
paulson@1913
   305
qed "parts_analz";
paulson@1913
   306
Addsimps [parts_analz];
paulson@1839
   307
paulson@1913
   308
goal thy "analz (parts H) = parts H";
paulson@1885
   309
by (Auto_tac());
paulson@2032
   310
by (etac analz.induct 1);
paulson@1885
   311
by (Auto_tac());
paulson@1913
   312
qed "analz_parts";
paulson@1913
   313
Addsimps [analz_parts];
paulson@1885
   314
paulson@1839
   315
(*Monotonicity; Lemma 1 of Lowe*)
paulson@1913
   316
goalw thy analz.defs "!!G H. G<=H ==> analz(G) <= analz(H)";
paulson@1839
   317
by (rtac lfp_mono 1);
paulson@1839
   318
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   319
qed "analz_mono";
paulson@1839
   320
paulson@1839
   321
(** General equational properties **)
paulson@1839
   322
paulson@1913
   323
goal thy "analz{} = {}";
paulson@1839
   324
by (Step_tac 1);
paulson@2032
   325
by (etac analz.induct 1);
paulson@1839
   326
by (ALLGOALS Fast_tac);
paulson@1913
   327
qed "analz_empty";
paulson@1913
   328
Addsimps [analz_empty];
paulson@1839
   329
paulson@1913
   330
(*Converse fails: we can analz more from the union than from the 
paulson@1839
   331
  separate parts, as a key in one might decrypt a message in the other*)
paulson@1913
   332
goal thy "analz(G) Un analz(H) <= analz(G Un H)";
paulson@1913
   333
by (REPEAT (ares_tac [Un_least, analz_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   334
qed "analz_Un";
paulson@1839
   335
paulson@1913
   336
goal thy "insert X (analz H) <= analz(insert X H)";
paulson@1913
   337
by (fast_tac (!claset addEs [impOfSubs analz_mono]) 1);
paulson@1913
   338
qed "analz_insert";
paulson@1839
   339
paulson@1839
   340
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   341
paulson@1913
   342
goal thy "analz (insert (Agent agt) H) = insert (Agent agt) (analz H)";
paulson@1913
   343
by (rtac (analz_insert RSN (2, equalityI)) 1);
paulson@2032
   344
by (rtac subsetI 1);
paulson@2032
   345
by (etac analz.induct 1);
paulson@1839
   346
(*Simplification breaks up equalities between messages;
paulson@1839
   347
  how to make it work for fast_tac??*)
paulson@1839
   348
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1913
   349
qed "analz_insert_Agent";
paulson@1839
   350
paulson@1913
   351
goal thy "analz (insert (Nonce N) H) = insert (Nonce N) (analz H)";
paulson@1913
   352
by (rtac (analz_insert RSN (2, equalityI)) 1);
paulson@2032
   353
by (rtac subsetI 1);
paulson@2032
   354
by (etac analz.induct 1);
paulson@1839
   355
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1913
   356
qed "analz_insert_Nonce";
paulson@1839
   357
paulson@1839
   358
(*Can only pull out Keys if they are not needed to decrypt the rest*)
paulson@1839
   359
goalw thy [keysFor_def]
paulson@1913
   360
    "!!K. K ~: keysFor (analz H) ==>  \
paulson@1913
   361
\         analz (insert (Key K) H) = insert (Key K) (analz H)";
paulson@1913
   362
by (rtac (analz_insert RSN (2, equalityI)) 1);
paulson@2032
   363
by (rtac subsetI 1);
paulson@2032
   364
by (etac analz.induct 1);
paulson@1839
   365
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1913
   366
qed "analz_insert_Key";
paulson@1839
   367
paulson@1913
   368
goal thy "analz (insert {|X,Y|} H) = \
paulson@1913
   369
\         insert {|X,Y|} (analz (insert X (insert Y H)))";
paulson@2032
   370
by (rtac equalityI 1);
paulson@2032
   371
by (rtac subsetI 1);
paulson@2032
   372
by (etac analz.induct 1);
paulson@1885
   373
by (Auto_tac());
paulson@2032
   374
by (etac analz.induct 1);
paulson@1913
   375
by (ALLGOALS (deepen_tac (!claset addIs [analz.Fst, analz.Snd, analz.Decrypt]) 0));
paulson@1913
   376
qed "analz_insert_MPair";
paulson@1885
   377
paulson@1885
   378
(*Can pull out enCrypted message if the Key is not known*)
paulson@1913
   379
goal thy "!!H. Key (invKey K) ~: analz H ==>  \
paulson@1913
   380
\              analz (insert (Crypt X K) H) = \
paulson@1913
   381
\              insert (Crypt X K) (analz H)";
paulson@1913
   382
by (rtac (analz_insert RSN (2, equalityI)) 1);
paulson@2032
   383
by (rtac subsetI 1);
paulson@2032
   384
by (etac analz.induct 1);
paulson@1839
   385
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1913
   386
qed "analz_insert_Crypt";
paulson@1839
   387
paulson@1913
   388
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@1913
   389
\              analz (insert (Crypt X K) H) <= \
paulson@1913
   390
\              insert (Crypt X K) (analz (insert X H))";
paulson@2032
   391
by (rtac subsetI 1);
paulson@1913
   392
by (eres_inst_tac [("za","x")] analz.induct 1);
paulson@1839
   393
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   394
val lemma1 = result();
paulson@1839
   395
paulson@1913
   396
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@1913
   397
\              insert (Crypt X K) (analz (insert X H)) <= \
paulson@1913
   398
\              analz (insert (Crypt X K) H)";
paulson@1839
   399
by (Auto_tac());
paulson@1913
   400
by (eres_inst_tac [("za","x")] analz.induct 1);
paulson@1839
   401
by (Auto_tac());
paulson@1913
   402
by (best_tac (!claset addIs [subset_insertI RS analz_mono RS subsetD,
paulson@2032
   403
                             analz.Decrypt]) 1);
paulson@1839
   404
val lemma2 = result();
paulson@1839
   405
paulson@1913
   406
goal thy "!!H. Key (invKey K) : analz H ==>  \
paulson@1913
   407
\              analz (insert (Crypt X K) H) = \
paulson@1913
   408
\              insert (Crypt X K) (analz (insert X H))";
paulson@1839
   409
by (REPEAT (ares_tac [equalityI, lemma1, lemma2] 1));
paulson@1913
   410
qed "analz_insert_Decrypt";
paulson@1839
   411
paulson@1885
   412
(*Case analysis: either the message is secure, or it is not!
paulson@1946
   413
  Effective, but can cause subgoals to blow up!
paulson@1885
   414
  Use with expand_if;  apparently split_tac does not cope with patterns
paulson@1913
   415
  such as "analz (insert (Crypt X' K) H)" *)
paulson@1913
   416
goal thy "analz (insert (Crypt X' K) H) = \
paulson@1913
   417
\         (if (Key (invKey K)  : analz H) then    \
paulson@1913
   418
\               insert (Crypt X' K) (analz (insert X' H)) \
paulson@1913
   419
\          else insert (Crypt X' K) (analz H))";
paulson@1913
   420
by (excluded_middle_tac "Key (invKey K)  : analz H " 1);
paulson@1913
   421
by (ALLGOALS (asm_simp_tac (!simpset addsimps [analz_insert_Crypt, 
paulson@2032
   422
                                               analz_insert_Decrypt])));
paulson@1913
   423
qed "analz_Crypt_if";
paulson@1885
   424
paulson@1913
   425
Addsimps [analz_insert_Agent, analz_insert_Nonce, 
paulson@2032
   426
          analz_insert_Key, analz_insert_MPair, 
paulson@2032
   427
          analz_Crypt_if];
paulson@1839
   428
paulson@1839
   429
(*This rule supposes "for the sake of argument" that we have the key.*)
paulson@1913
   430
goal thy  "analz (insert (Crypt X K) H) <=  \
paulson@1913
   431
\          insert (Crypt X K) (analz (insert X H))";
paulson@2032
   432
by (rtac subsetI 1);
paulson@2032
   433
by (etac analz.induct 1);
paulson@1839
   434
by (Auto_tac());
paulson@1913
   435
qed "analz_insert_Crypt_subset";
paulson@1839
   436
paulson@1839
   437
paulson@2026
   438
goal thy "analz (Key``N) = Key``N";
paulson@2026
   439
by (Auto_tac());
paulson@2032
   440
by (etac analz.induct 1);
paulson@2026
   441
by (Auto_tac());
paulson@2026
   442
qed "analz_image_Key";
paulson@2026
   443
paulson@2026
   444
Addsimps [analz_image_Key];
paulson@2026
   445
paulson@2026
   446
paulson@1839
   447
(** Idempotence and transitivity **)
paulson@1839
   448
paulson@1913
   449
goal thy "!!H. X: analz (analz H) ==> X: analz H";
paulson@2032
   450
by (etac analz.induct 1);
paulson@1839
   451
by (ALLGOALS Fast_tac);
paulson@1913
   452
qed "analz_analzE";
paulson@1913
   453
AddSEs [analz_analzE];
paulson@1839
   454
paulson@1913
   455
goal thy "analz (analz H) = analz H";
paulson@1839
   456
by (Fast_tac 1);
paulson@1913
   457
qed "analz_idem";
paulson@1913
   458
Addsimps [analz_idem];
paulson@1839
   459
paulson@1913
   460
goal thy "!!H. [| X: analz G;  G <= analz H |] ==> X: analz H";
paulson@1913
   461
by (dtac analz_mono 1);
paulson@1839
   462
by (Fast_tac 1);
paulson@1913
   463
qed "analz_trans";
paulson@1839
   464
paulson@1839
   465
(*Cut; Lemma 2 of Lowe*)
paulson@1998
   466
goal thy "!!H. [| Y: analz (insert X H);  X: analz H |] ==> Y: analz H";
paulson@2032
   467
by (etac analz_trans 1);
paulson@1839
   468
by (Fast_tac 1);
paulson@1913
   469
qed "analz_cut";
paulson@1839
   470
paulson@1839
   471
(*Cut can be proved easily by induction on
paulson@1913
   472
   "!!H. Y: analz (insert X H) ==> X: analz H --> Y: analz H"
paulson@1839
   473
*)
paulson@1839
   474
paulson@1885
   475
paulson@1913
   476
(** A congruence rule for "analz" **)
paulson@1885
   477
paulson@1913
   478
goal thy "!!H. [| analz G <= analz G'; analz H <= analz H' \
paulson@1913
   479
\              |] ==> analz (G Un H) <= analz (G' Un H')";
paulson@1885
   480
by (Step_tac 1);
paulson@2032
   481
by (etac analz.induct 1);
paulson@1913
   482
by (ALLGOALS (best_tac (!claset addIs [analz_mono RS subsetD])));
paulson@1913
   483
qed "analz_subset_cong";
paulson@1885
   484
paulson@1913
   485
goal thy "!!H. [| analz G = analz G'; analz H = analz H' \
paulson@1913
   486
\              |] ==> analz (G Un H) = analz (G' Un H')";
paulson@1913
   487
by (REPEAT_FIRST (ares_tac [equalityI, analz_subset_cong]
paulson@2032
   488
          ORELSE' etac equalityE));
paulson@1913
   489
qed "analz_cong";
paulson@1885
   490
paulson@1885
   491
paulson@1913
   492
goal thy "!!H. analz H = analz H' ==> analz(insert X H) = analz(insert X H')";
paulson@1885
   493
by (asm_simp_tac (!simpset addsimps [insert_def] 
paulson@2032
   494
                           setloop (rtac analz_cong)) 1);
paulson@1913
   495
qed "analz_insert_cong";
paulson@1885
   496
paulson@1913
   497
(*If there are no pairs or encryptions then analz does nothing*)
paulson@1839
   498
goal thy "!!H. [| ALL X Y. {|X,Y|} ~: H;  ALL X K. Crypt X K ~: H |] ==> \
paulson@1913
   499
\         analz H = H";
paulson@1839
   500
by (Step_tac 1);
paulson@2032
   501
by (etac analz.induct 1);
paulson@1839
   502
by (ALLGOALS Fast_tac);
paulson@1913
   503
qed "analz_trivial";
paulson@1839
   504
paulson@1839
   505
(*Helps to prove Fake cases*)
paulson@1913
   506
goal thy "!!X. X: analz (UN i. analz (H i)) ==> X: analz (UN i. H i)";
paulson@2032
   507
by (etac analz.induct 1);
paulson@1913
   508
by (ALLGOALS (fast_tac (!claset addEs [impOfSubs analz_mono])));
paulson@1839
   509
val lemma = result();
paulson@1839
   510
paulson@1913
   511
goal thy "analz (UN i. analz (H i)) = analz (UN i. H i)";
paulson@1839
   512
by (fast_tac (!claset addIs [lemma]
paulson@2032
   513
                      addEs [impOfSubs analz_mono]) 1);
paulson@1913
   514
qed "analz_UN_analz";
paulson@1913
   515
Addsimps [analz_UN_analz];
paulson@1839
   516
paulson@1839
   517
paulson@1913
   518
(**** Inductive relation "synth" ****)
paulson@1839
   519
paulson@1913
   520
AddIs  synth.intrs;
paulson@1839
   521
paulson@2011
   522
(*Can only produce a nonce or key if it is already known,
paulson@2011
   523
  but can synth a pair or encryption from its components...*)
paulson@2011
   524
val mk_cases = synth.mk_cases msg.simps;
paulson@2011
   525
paulson@2011
   526
(*NO Agent_synth, as any Agent name can be synthd*)
paulson@2011
   527
val Nonce_synth = mk_cases "Nonce n : synth H";
paulson@2011
   528
val Key_synth   = mk_cases "Key K : synth H";
paulson@2011
   529
val MPair_synth = mk_cases "{|X,Y|} : synth H";
paulson@2011
   530
val Crypt_synth = mk_cases "Crypt X K : synth H";
paulson@2011
   531
paulson@2011
   532
AddSEs [Nonce_synth, Key_synth, MPair_synth, Crypt_synth];
paulson@2011
   533
paulson@1913
   534
goal thy "H <= synth(H)";
paulson@1839
   535
by (Fast_tac 1);
paulson@1913
   536
qed "synth_increasing";
paulson@1839
   537
paulson@1839
   538
(*Monotonicity*)
paulson@1913
   539
goalw thy synth.defs "!!G H. G<=H ==> synth(G) <= synth(H)";
paulson@1839
   540
by (rtac lfp_mono 1);
paulson@1839
   541
by (REPEAT (ares_tac basic_monos 1));
paulson@1913
   542
qed "synth_mono";
paulson@1839
   543
paulson@1839
   544
(** Unions **)
paulson@1839
   545
paulson@1913
   546
(*Converse fails: we can synth more from the union than from the 
paulson@1839
   547
  separate parts, building a compound message using elements of each.*)
paulson@1913
   548
goal thy "synth(G) Un synth(H) <= synth(G Un H)";
paulson@1913
   549
by (REPEAT (ares_tac [Un_least, synth_mono, Un_upper1, Un_upper2] 1));
paulson@1913
   550
qed "synth_Un";
paulson@1839
   551
paulson@1913
   552
goal thy "insert X (synth H) <= synth(insert X H)";
paulson@1913
   553
by (fast_tac (!claset addEs [impOfSubs synth_mono]) 1);
paulson@1913
   554
qed "synth_insert";
paulson@1885
   555
paulson@1839
   556
(** Idempotence and transitivity **)
paulson@1839
   557
paulson@1913
   558
goal thy "!!H. X: synth (synth H) ==> X: synth H";
paulson@2032
   559
by (etac synth.induct 1);
paulson@1839
   560
by (ALLGOALS Fast_tac);
paulson@1913
   561
qed "synth_synthE";
paulson@1913
   562
AddSEs [synth_synthE];
paulson@1839
   563
paulson@1913
   564
goal thy "synth (synth H) = synth H";
paulson@1839
   565
by (Fast_tac 1);
paulson@1913
   566
qed "synth_idem";
paulson@1839
   567
paulson@1913
   568
goal thy "!!H. [| X: synth G;  G <= synth H |] ==> X: synth H";
paulson@1913
   569
by (dtac synth_mono 1);
paulson@1839
   570
by (Fast_tac 1);
paulson@1913
   571
qed "synth_trans";
paulson@1839
   572
paulson@1839
   573
(*Cut; Lemma 2 of Lowe*)
paulson@1998
   574
goal thy "!!H. [| Y: synth (insert X H);  X: synth H |] ==> Y: synth H";
paulson@2032
   575
by (etac synth_trans 1);
paulson@1839
   576
by (Fast_tac 1);
paulson@1913
   577
qed "synth_cut";
paulson@1839
   578
paulson@1946
   579
goal thy "Agent A : synth H";
paulson@1946
   580
by (Fast_tac 1);
paulson@1946
   581
qed "Agent_synth";
paulson@1946
   582
paulson@1913
   583
goal thy "(Nonce N : synth H) = (Nonce N : H)";
paulson@1839
   584
by (Fast_tac 1);
paulson@1913
   585
qed "Nonce_synth_eq";
paulson@1839
   586
paulson@1913
   587
goal thy "(Key K : synth H) = (Key K : H)";
paulson@1839
   588
by (Fast_tac 1);
paulson@1913
   589
qed "Key_synth_eq";
paulson@1839
   590
paulson@2011
   591
goal thy "!!K. Key K ~: H ==> (Crypt X K : synth H) = (Crypt X K: H)";
paulson@2011
   592
by (Fast_tac 1);
paulson@2011
   593
qed "Crypt_synth_eq";
paulson@2011
   594
paulson@2011
   595
Addsimps [Agent_synth, Nonce_synth_eq, Key_synth_eq, Crypt_synth_eq];
paulson@1839
   596
paulson@1839
   597
paulson@1839
   598
goalw thy [keysFor_def]
paulson@1913
   599
    "keysFor (synth H) = keysFor H Un invKey``{K. Key K : H}";
paulson@1839
   600
by (Fast_tac 1);
paulson@1913
   601
qed "keysFor_synth";
paulson@1913
   602
Addsimps [keysFor_synth];
paulson@1839
   603
paulson@1839
   604
paulson@1913
   605
(*** Combinations of parts, analz and synth ***)
paulson@1839
   606
paulson@1913
   607
goal thy "parts (synth H) = parts H Un synth H";
paulson@2032
   608
by (rtac equalityI 1);
paulson@2032
   609
by (rtac subsetI 1);
paulson@2032
   610
by (etac parts.induct 1);
paulson@1839
   611
by (ALLGOALS
paulson@1913
   612
    (best_tac (!claset addIs ((synth_increasing RS parts_mono RS subsetD)
paulson@2032
   613
                             ::parts.intrs))));
paulson@1913
   614
qed "parts_synth";
paulson@1913
   615
Addsimps [parts_synth];
paulson@1839
   616
paulson@1913
   617
goal thy "analz (synth H) = analz H Un synth H";
paulson@2032
   618
by (rtac equalityI 1);
paulson@2032
   619
by (rtac subsetI 1);
paulson@2032
   620
by (etac analz.induct 1);
paulson@1839
   621
by (best_tac
paulson@1913
   622
    (!claset addIs [synth_increasing RS analz_mono RS subsetD]) 5);
paulson@1839
   623
(*Strange that best_tac just can't hack this one...*)
paulson@1913
   624
by (ALLGOALS (deepen_tac (!claset addIs analz.intrs) 0));
paulson@1913
   625
qed "analz_synth";
paulson@1913
   626
Addsimps [analz_synth];
paulson@1839
   627
paulson@2032
   628
(*Hard to prove; still needed now that there's only one Spy?*)
paulson@1913
   629
goal thy "analz (UN i. synth (H i)) = \
paulson@1913
   630
\         analz (UN i. H i) Un (UN i. synth (H i))";
paulson@2032
   631
by (rtac equalityI 1);
paulson@2032
   632
by (rtac subsetI 1);
paulson@2032
   633
by (etac analz.induct 1);
paulson@1839
   634
by (best_tac
paulson@1913
   635
    (!claset addEs [impOfSubs synth_increasing,
paulson@2032
   636
                    impOfSubs analz_mono]) 5);
paulson@1839
   637
by (Best_tac 1);
paulson@1913
   638
by (deepen_tac (!claset addIs [analz.Fst]) 0 1);
paulson@1913
   639
by (deepen_tac (!claset addIs [analz.Snd]) 0 1);
paulson@1913
   640
by (deepen_tac (!claset addSEs [analz.Decrypt]
paulson@2032
   641
                        addIs  [analz.Decrypt]) 0 1);
paulson@1913
   642
qed "analz_UN1_synth";
paulson@1913
   643
Addsimps [analz_UN1_synth];
paulson@1929
   644
paulson@1946
   645
paulson@1946
   646
(** For reasoning about the Fake rule in traces **)
paulson@1946
   647
paulson@1929
   648
goal thy "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H";
paulson@2032
   649
by (rtac ([parts_mono, parts_Un_subset2] MRS subset_trans) 1);
paulson@1929
   650
by (Fast_tac 1);
paulson@1929
   651
qed "parts_insert_subset_Un";
paulson@1929
   652
paulson@1946
   653
(*More specifically for Fake*)
paulson@1946
   654
goal thy "!!H. X: synth (analz G) ==> \
paulson@1946
   655
\              parts (insert X H) <= synth (analz G) Un parts G Un parts H";
paulson@2032
   656
by (dtac parts_insert_subset_Un 1);
paulson@1946
   657
by (Full_simp_tac 1);
paulson@1946
   658
by (Deepen_tac 0 1);
paulson@1946
   659
qed "Fake_parts_insert";
paulson@1946
   660
paulson@2061
   661
goal thy
paulson@2061
   662
     "!!H. [| Crypt Y K : parts (insert X H);  X: synth (analz G);  \
paulson@2061
   663
\             Key K ~: analz G |]                                   \
paulson@2061
   664
\          ==> Crypt Y K : parts G Un parts H";
paulson@2061
   665
by (dtac (impOfSubs Fake_parts_insert) 1);
paulson@2061
   666
ba 1;
paulson@2061
   667
by (fast_tac (!claset addDs [impOfSubs analz_subset_parts]
paulson@2061
   668
                      addss (!simpset)) 1);
paulson@2061
   669
qed "Crypt_Fake_parts_insert";
paulson@2061
   670
paulson@1946
   671
goal thy "!!H. [| X: synth (analz G); G <= H |] ==> \
paulson@1946
   672
\              analz (insert X H) <= synth (analz H) Un analz H";
paulson@2032
   673
by (rtac subsetI 1);
paulson@1946
   674
by (subgoal_tac "x : analz (synth (analz H))" 1);
paulson@1946
   675
by (best_tac (!claset addIs [impOfSubs (analz_mono RS synth_mono)]
paulson@1946
   676
                      addSEs [impOfSubs analz_mono]) 2);
paulson@1946
   677
by (Full_simp_tac 1);
paulson@1946
   678
by (Fast_tac 1);
paulson@1946
   679
qed "Fake_analz_insert";
paulson@1929
   680
paulson@2011
   681
goal thy "(X: analz H & X: parts H) = (X: analz H)";
paulson@2011
   682
by (fast_tac (!claset addDs [impOfSubs analz_subset_parts]) 1);
paulson@2011
   683
val analz_conj_parts = result();
paulson@2011
   684
paulson@2011
   685
goal thy "(X: analz H | X: parts H) = (X: parts H)";
paulson@2011
   686
by (fast_tac (!claset addDs [impOfSubs analz_subset_parts]) 1);
paulson@2011
   687
val analz_disj_parts = result();
paulson@2011
   688
paulson@2011
   689
AddIffs [analz_conj_parts, analz_disj_parts];
paulson@2011
   690
paulson@1998
   691
(*Without this equation, other rules for synth and analz would yield
paulson@1998
   692
  redundant cases*)
paulson@1998
   693
goal thy "({|X,Y|} : synth (analz H)) = \
paulson@1998
   694
\         (X : synth (analz H) & Y : synth (analz H))";
paulson@1998
   695
by (Fast_tac 1);
paulson@1998
   696
qed "MPair_synth_analz";
paulson@1998
   697
paulson@1998
   698
AddIffs [MPair_synth_analz];
paulson@1929
   699
paulson@1929
   700
paulson@1929
   701
(*We do NOT want Crypt... messages broken up in protocols!!*)
paulson@1929
   702
Delrules partsEs;
paulson@1929
   703