src/HOL/Auth/Message.ML
author paulson
Mon Jul 29 18:31:39 1996 +0200 (1996-07-29)
changeset 1893 fa58f4a06f21
parent 1885 a18a6dc14f76
child 1913 2809adb15eb0
permissions -rw-r--r--
Works up to main theorem, then XXX...X
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@1839
     7
Inductive relations "parts", "analyze" and "synthesize"
paulson@1839
     8
*)
paulson@1839
     9
paulson@1839
    10
open Message;
paulson@1839
    11
paulson@1839
    12
paulson@1839
    13
(**************** INSTALL CENTRALLY SOMEWHERE? ****************)
paulson@1839
    14
paulson@1839
    15
(*Maybe swap the safe_tac and simp_tac lines?**)
paulson@1839
    16
fun auto_tac (cs,ss) = 
paulson@1839
    17
    TRY (safe_tac cs) THEN 
paulson@1839
    18
    ALLGOALS (asm_full_simp_tac ss) THEN
paulson@1839
    19
    REPEAT (FIRSTGOAL (best_tac (cs addss ss)));
paulson@1839
    20
paulson@1839
    21
fun Auto_tac() = auto_tac (!claset, !simpset);
paulson@1839
    22
paulson@1839
    23
fun auto() = by (Auto_tac());
paulson@1839
    24
paulson@1852
    25
fun impOfSubs th = th RSN (2, rev_subsetD);
paulson@1839
    26
paulson@1839
    27
(**************** INSTALL CENTRALLY SOMEWHERE? ****************)
paulson@1839
    28
paulson@1839
    29
paulson@1839
    30
paulson@1839
    31
(** Inverse of keys **)
paulson@1839
    32
paulson@1839
    33
goal thy "!!K K'. (invKey K = invKey K') = (K=K')";
paulson@1839
    34
by (Step_tac 1);
paulson@1839
    35
br box_equals 1;
paulson@1839
    36
by (REPEAT (rtac invKey 2));
paulson@1839
    37
by (Asm_simp_tac 1);
paulson@1839
    38
qed "invKey_eq";
paulson@1839
    39
paulson@1839
    40
Addsimps [invKey, invKey_eq];
paulson@1839
    41
paulson@1839
    42
paulson@1839
    43
(**** keysFor operator ****)
paulson@1839
    44
paulson@1839
    45
goalw thy [keysFor_def] "keysFor {} = {}";
paulson@1839
    46
by (Fast_tac 1);
paulson@1839
    47
qed "keysFor_empty";
paulson@1839
    48
paulson@1839
    49
goalw thy [keysFor_def] "keysFor (H Un H') = keysFor H Un keysFor H'";
paulson@1839
    50
by (Fast_tac 1);
paulson@1839
    51
qed "keysFor_Un";
paulson@1839
    52
paulson@1839
    53
goalw thy [keysFor_def] "keysFor (UN i. H i) = (UN i. keysFor (H i))";
paulson@1839
    54
by (Fast_tac 1);
paulson@1839
    55
qed "keysFor_UN";
paulson@1839
    56
paulson@1839
    57
(*Monotonicity*)
paulson@1839
    58
goalw thy [keysFor_def] "!!G H. G<=H ==> keysFor(G) <= keysFor(H)";
paulson@1839
    59
by (Fast_tac 1);
paulson@1839
    60
qed "keysFor_mono";
paulson@1839
    61
paulson@1839
    62
goalw thy [keysFor_def] "keysFor (insert (Agent A) H) = keysFor H";
paulson@1839
    63
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    64
qed "keysFor_insert_Agent";
paulson@1839
    65
paulson@1839
    66
goalw thy [keysFor_def] "keysFor (insert (Nonce N) H) = keysFor H";
paulson@1839
    67
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    68
qed "keysFor_insert_Nonce";
paulson@1839
    69
paulson@1839
    70
goalw thy [keysFor_def] "keysFor (insert (Key K) H) = keysFor H";
paulson@1839
    71
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    72
qed "keysFor_insert_Key";
paulson@1839
    73
paulson@1839
    74
goalw thy [keysFor_def] "keysFor (insert {|X,Y|} H) = keysFor H";
paulson@1839
    75
by (fast_tac (!claset addss (!simpset)) 1);
paulson@1839
    76
qed "keysFor_insert_MPair";
paulson@1839
    77
paulson@1839
    78
goalw thy [keysFor_def]
paulson@1839
    79
    "keysFor (insert (Crypt X K) H) = insert (invKey K) (keysFor H)";
paulson@1839
    80
by (Auto_tac());
paulson@1839
    81
by (fast_tac (!claset addIs [image_eqI]) 1);
paulson@1839
    82
qed "keysFor_insert_Crypt";
paulson@1839
    83
paulson@1839
    84
Addsimps [keysFor_empty, keysFor_Un, keysFor_UN, 
paulson@1839
    85
	  keysFor_insert_Agent, keysFor_insert_Nonce,
paulson@1839
    86
	  keysFor_insert_Key, keysFor_insert_MPair,
paulson@1839
    87
	  keysFor_insert_Crypt];
paulson@1839
    88
paulson@1839
    89
paulson@1839
    90
(**** Inductive relation "parts" ****)
paulson@1839
    91
paulson@1839
    92
val major::prems = 
paulson@1839
    93
goal thy "[| {|X,Y|} : parts H;       \
paulson@1839
    94
\            [| X : parts H; Y : parts H |] ==> P  \
paulson@1839
    95
\         |] ==> P";
paulson@1839
    96
by (cut_facts_tac [major] 1);
paulson@1839
    97
brs prems 1;
paulson@1839
    98
by (REPEAT (eresolve_tac [asm_rl, parts.Fst, parts.Snd] 1));
paulson@1839
    99
qed "MPair_parts";
paulson@1839
   100
paulson@1839
   101
AddIs  [parts.Inj];
paulson@1839
   102
AddSEs [MPair_parts];
paulson@1839
   103
AddDs  [parts.Body];
paulson@1839
   104
paulson@1839
   105
goal thy "H <= parts(H)";
paulson@1839
   106
by (Fast_tac 1);
paulson@1839
   107
qed "parts_increasing";
paulson@1839
   108
paulson@1839
   109
(*Monotonicity*)
paulson@1839
   110
goalw thy parts.defs "!!G H. G<=H ==> parts(G) <= parts(H)";
paulson@1839
   111
by (rtac lfp_mono 1);
paulson@1839
   112
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
   113
qed "parts_mono";
paulson@1839
   114
paulson@1839
   115
goal thy "parts{} = {}";
paulson@1839
   116
by (Step_tac 1);
paulson@1839
   117
be parts.induct 1;
paulson@1839
   118
by (ALLGOALS Fast_tac);
paulson@1839
   119
qed "parts_empty";
paulson@1839
   120
Addsimps [parts_empty];
paulson@1839
   121
paulson@1839
   122
goal thy "!!X. X: parts{} ==> P";
paulson@1839
   123
by (Asm_full_simp_tac 1);
paulson@1839
   124
qed "parts_emptyE";
paulson@1839
   125
AddSEs [parts_emptyE];
paulson@1839
   126
paulson@1893
   127
(*WARNING: loops if H = {Y}, therefore must not be repeated!*)
paulson@1893
   128
goal thy "!!H. X: parts H ==> EX Y:H. X: parts {Y}";
paulson@1893
   129
be parts.induct 1;
paulson@1893
   130
by (ALLGOALS Fast_tac);
paulson@1893
   131
qed "parts_singleton";
paulson@1893
   132
paulson@1839
   133
paulson@1839
   134
(** Unions **)
paulson@1839
   135
paulson@1839
   136
goal thy "parts(G) Un parts(H) <= parts(G Un H)";
paulson@1839
   137
by (REPEAT (ares_tac [Un_least, parts_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   138
val parts_Un_subset1 = result();
paulson@1839
   139
paulson@1839
   140
goal thy "parts(G Un H) <= parts(G) Un parts(H)";
paulson@1839
   141
br subsetI 1;
paulson@1839
   142
be parts.induct 1;
paulson@1839
   143
by (ALLGOALS Fast_tac);
paulson@1839
   144
val parts_Un_subset2 = result();
paulson@1839
   145
paulson@1839
   146
goal thy "parts(G Un H) = parts(G) Un parts(H)";
paulson@1839
   147
by (REPEAT (ares_tac [equalityI, parts_Un_subset1, parts_Un_subset2] 1));
paulson@1839
   148
qed "parts_Un";
paulson@1839
   149
paulson@1852
   150
(*TWO inserts to avoid looping.  This rewrite is better than nothing...*)
paulson@1852
   151
goal thy "parts (insert X (insert Y H)) = parts {X} Un parts {Y} Un parts H";
paulson@1852
   152
by (stac (read_instantiate [("A","H")] insert_is_Un) 1);
paulson@1852
   153
by (stac (read_instantiate [("A","{Y} Un H")] insert_is_Un) 1);
paulson@1852
   154
by (simp_tac (HOL_ss addsimps [parts_Un, Un_assoc]) 1);
paulson@1852
   155
qed "parts_insert2";
paulson@1852
   156
paulson@1839
   157
goal thy "(UN x:A. parts(H x)) <= parts(UN x:A. H x)";
paulson@1839
   158
by (REPEAT (ares_tac [UN_least, parts_mono, UN_upper] 1));
paulson@1839
   159
val parts_UN_subset1 = result();
paulson@1839
   160
paulson@1839
   161
goal thy "parts(UN x:A. H x) <= (UN x:A. parts(H x))";
paulson@1839
   162
br subsetI 1;
paulson@1839
   163
be parts.induct 1;
paulson@1839
   164
by (ALLGOALS Fast_tac);
paulson@1839
   165
val parts_UN_subset2 = result();
paulson@1839
   166
paulson@1839
   167
goal thy "parts(UN x:A. H x) = (UN x:A. parts(H x))";
paulson@1839
   168
by (REPEAT (ares_tac [equalityI, parts_UN_subset1, parts_UN_subset2] 1));
paulson@1839
   169
qed "parts_UN";
paulson@1839
   170
paulson@1839
   171
goal thy "parts(UN x. H x) = (UN x. parts(H x))";
paulson@1839
   172
by (simp_tac (!simpset addsimps [UNION1_def, parts_UN]) 1);
paulson@1839
   173
qed "parts_UN1";
paulson@1839
   174
paulson@1839
   175
(*Added to simplify arguments to parts, analyze and synthesize*)
paulson@1839
   176
Addsimps [parts_Un, parts_UN, parts_UN1];
paulson@1839
   177
paulson@1839
   178
goal thy "insert X (parts H) <= parts(insert X H)";
paulson@1852
   179
by (fast_tac (!claset addEs [impOfSubs parts_mono]) 1);
paulson@1839
   180
qed "parts_insert_subset";
paulson@1839
   181
paulson@1839
   182
(*Especially for reasoning about the Fake rule in traces*)
paulson@1839
   183
goal thy "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H";
paulson@1839
   184
br ([parts_mono, parts_Un_subset2] MRS subset_trans) 1;
paulson@1839
   185
by (Fast_tac 1);
paulson@1839
   186
qed "parts_insert_subset_Un";
paulson@1839
   187
paulson@1839
   188
(** Idempotence and transitivity **)
paulson@1839
   189
paulson@1839
   190
goal thy "!!H. X: parts (parts H) ==> X: parts H";
paulson@1839
   191
be parts.induct 1;
paulson@1839
   192
by (ALLGOALS Fast_tac);
paulson@1839
   193
qed "parts_partsE";
paulson@1839
   194
AddSEs [parts_partsE];
paulson@1839
   195
paulson@1839
   196
goal thy "parts (parts H) = parts H";
paulson@1839
   197
by (Fast_tac 1);
paulson@1839
   198
qed "parts_idem";
paulson@1839
   199
Addsimps [parts_idem];
paulson@1839
   200
paulson@1839
   201
goal thy "!!H. [| X: parts G;  G <= parts H |] ==> X: parts H";
paulson@1839
   202
by (dtac parts_mono 1);
paulson@1839
   203
by (Fast_tac 1);
paulson@1839
   204
qed "parts_trans";
paulson@1839
   205
paulson@1839
   206
(*Cut*)
paulson@1839
   207
goal thy "!!H. [| X: parts H;  Y: parts (insert X H) |] ==> Y: parts H";
paulson@1839
   208
be parts_trans 1;
paulson@1839
   209
by (Fast_tac 1);
paulson@1839
   210
qed "parts_cut";
paulson@1839
   211
paulson@1839
   212
paulson@1839
   213
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   214
paulson@1839
   215
goal thy "parts (insert (Agent agt) H) = insert (Agent agt) (parts H)";
paulson@1839
   216
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   217
br subsetI 1;
paulson@1839
   218
be parts.induct 1;
paulson@1839
   219
(*Simplification breaks up equalities between messages;
paulson@1839
   220
  how to make it work for fast_tac??*)
paulson@1839
   221
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   222
qed "parts_insert_Agent";
paulson@1839
   223
paulson@1839
   224
goal thy "parts (insert (Nonce N) H) = insert (Nonce N) (parts H)";
paulson@1839
   225
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   226
br subsetI 1;
paulson@1839
   227
be parts.induct 1;
paulson@1839
   228
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   229
qed "parts_insert_Nonce";
paulson@1839
   230
paulson@1839
   231
goal thy "parts (insert (Key K) H) = insert (Key K) (parts H)";
paulson@1839
   232
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   233
br subsetI 1;
paulson@1839
   234
be parts.induct 1;
paulson@1839
   235
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   236
qed "parts_insert_Key";
paulson@1839
   237
paulson@1839
   238
goal thy "parts (insert (Crypt X K) H) = \
paulson@1839
   239
\         insert (Crypt X K) (parts (insert X H))";
paulson@1839
   240
br equalityI 1;
paulson@1839
   241
br subsetI 1;
paulson@1839
   242
be parts.induct 1;
paulson@1839
   243
by (Auto_tac());
paulson@1839
   244
be parts.induct 1;
paulson@1839
   245
by (ALLGOALS (best_tac (!claset addIs [parts.Body])));
paulson@1839
   246
qed "parts_insert_Crypt";
paulson@1839
   247
paulson@1839
   248
goal thy "parts (insert {|X,Y|} H) = \
paulson@1839
   249
\         insert {|X,Y|} (parts (insert X (insert Y H)))";
paulson@1839
   250
br equalityI 1;
paulson@1839
   251
br subsetI 1;
paulson@1839
   252
be parts.induct 1;
paulson@1839
   253
by (Auto_tac());
paulson@1839
   254
be parts.induct 1;
paulson@1839
   255
by (ALLGOALS (best_tac (!claset addIs [parts.Fst, parts.Snd])));
paulson@1839
   256
qed "parts_insert_MPair";
paulson@1839
   257
paulson@1839
   258
Addsimps [parts_insert_Agent, parts_insert_Nonce, 
paulson@1839
   259
	  parts_insert_Key, parts_insert_Crypt, parts_insert_MPair];
paulson@1839
   260
paulson@1839
   261
paulson@1839
   262
(**** Inductive relation "analyze" ****)
paulson@1839
   263
paulson@1839
   264
val major::prems = 
paulson@1839
   265
goal thy "[| {|X,Y|} : analyze H;       \
paulson@1839
   266
\            [| X : analyze H; Y : analyze H |] ==> P  \
paulson@1839
   267
\         |] ==> P";
paulson@1839
   268
by (cut_facts_tac [major] 1);
paulson@1839
   269
brs prems 1;
paulson@1839
   270
by (REPEAT (eresolve_tac [asm_rl, analyze.Fst, analyze.Snd] 1));
paulson@1839
   271
qed "MPair_analyze";
paulson@1839
   272
paulson@1839
   273
AddIs  [analyze.Inj];
paulson@1839
   274
AddSEs [MPair_analyze];
paulson@1839
   275
AddDs  [analyze.Decrypt];
paulson@1839
   276
paulson@1885
   277
Addsimps [analyze.Inj];
paulson@1885
   278
paulson@1839
   279
goal thy "H <= analyze(H)";
paulson@1839
   280
by (Fast_tac 1);
paulson@1839
   281
qed "analyze_increasing";
paulson@1839
   282
paulson@1839
   283
goal thy "analyze H <= parts H";
paulson@1839
   284
by (rtac subsetI 1);
paulson@1839
   285
be analyze.induct 1;
paulson@1839
   286
by (ALLGOALS Fast_tac);
paulson@1839
   287
qed "analyze_subset_parts";
paulson@1839
   288
paulson@1839
   289
bind_thm ("not_parts_not_analyze", analyze_subset_parts RS contra_subsetD);
paulson@1839
   290
paulson@1839
   291
paulson@1839
   292
goal thy "parts (analyze H) = parts H";
paulson@1839
   293
br equalityI 1;
paulson@1839
   294
br (analyze_subset_parts RS parts_mono RS subset_trans) 1;
paulson@1839
   295
by (Simp_tac 1);
paulson@1839
   296
by (fast_tac (!claset addDs [analyze_increasing RS parts_mono RS subsetD]) 1);
paulson@1839
   297
qed "parts_analyze";
paulson@1839
   298
Addsimps [parts_analyze];
paulson@1839
   299
paulson@1885
   300
goal thy "analyze (parts H) = parts H";
paulson@1885
   301
by (Auto_tac());
paulson@1885
   302
be analyze.induct 1;
paulson@1885
   303
by (Auto_tac());
paulson@1885
   304
qed "analyze_parts";
paulson@1885
   305
Addsimps [analyze_parts];
paulson@1885
   306
paulson@1839
   307
(*Monotonicity; Lemma 1 of Lowe*)
paulson@1839
   308
goalw thy analyze.defs "!!G H. G<=H ==> analyze(G) <= analyze(H)";
paulson@1839
   309
by (rtac lfp_mono 1);
paulson@1839
   310
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
   311
qed "analyze_mono";
paulson@1839
   312
paulson@1839
   313
(** General equational properties **)
paulson@1839
   314
paulson@1839
   315
goal thy "analyze{} = {}";
paulson@1839
   316
by (Step_tac 1);
paulson@1839
   317
be analyze.induct 1;
paulson@1839
   318
by (ALLGOALS Fast_tac);
paulson@1839
   319
qed "analyze_empty";
paulson@1839
   320
Addsimps [analyze_empty];
paulson@1839
   321
paulson@1839
   322
(*Converse fails: we can analyze more from the union than from the 
paulson@1839
   323
  separate parts, as a key in one might decrypt a message in the other*)
paulson@1839
   324
goal thy "analyze(G) Un analyze(H) <= analyze(G Un H)";
paulson@1839
   325
by (REPEAT (ares_tac [Un_least, analyze_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   326
qed "analyze_Un";
paulson@1839
   327
paulson@1839
   328
goal thy "insert X (analyze H) <= analyze(insert X H)";
paulson@1852
   329
by (fast_tac (!claset addEs [impOfSubs analyze_mono]) 1);
paulson@1839
   330
qed "analyze_insert";
paulson@1839
   331
paulson@1839
   332
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   333
paulson@1839
   334
goal thy "analyze (insert (Agent agt) H) = insert (Agent agt) (analyze H)";
paulson@1839
   335
by (rtac (analyze_insert RSN (2, equalityI)) 1);
paulson@1839
   336
br subsetI 1;
paulson@1839
   337
be analyze.induct 1;
paulson@1839
   338
(*Simplification breaks up equalities between messages;
paulson@1839
   339
  how to make it work for fast_tac??*)
paulson@1839
   340
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   341
qed "analyze_insert_Agent";
paulson@1839
   342
paulson@1839
   343
goal thy "analyze (insert (Nonce N) H) = insert (Nonce N) (analyze H)";
paulson@1839
   344
by (rtac (analyze_insert RSN (2, equalityI)) 1);
paulson@1839
   345
br subsetI 1;
paulson@1839
   346
be analyze.induct 1;
paulson@1839
   347
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   348
qed "analyze_insert_Nonce";
paulson@1839
   349
paulson@1839
   350
(*Can only pull out Keys if they are not needed to decrypt the rest*)
paulson@1839
   351
goalw thy [keysFor_def]
paulson@1839
   352
    "!!K. K ~: keysFor (analyze H) ==>  \
paulson@1839
   353
\         analyze (insert (Key K) H) = insert (Key K) (analyze H)";
paulson@1839
   354
by (rtac (analyze_insert RSN (2, equalityI)) 1);
paulson@1839
   355
br subsetI 1;
paulson@1839
   356
be analyze.induct 1;
paulson@1839
   357
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   358
qed "analyze_insert_Key";
paulson@1839
   359
paulson@1885
   360
goal thy "analyze (insert {|X,Y|} H) = \
paulson@1885
   361
\         insert {|X,Y|} (analyze (insert X (insert Y H)))";
paulson@1885
   362
br equalityI 1;
paulson@1885
   363
br subsetI 1;
paulson@1885
   364
be analyze.induct 1;
paulson@1885
   365
by (Auto_tac());
paulson@1885
   366
be analyze.induct 1;
paulson@1885
   367
by (ALLGOALS (deepen_tac (!claset addIs [analyze.Fst, analyze.Snd, analyze.Decrypt]) 0));
paulson@1885
   368
qed "analyze_insert_MPair";
paulson@1885
   369
paulson@1885
   370
(*Can pull out enCrypted message if the Key is not known*)
paulson@1839
   371
goal thy "!!H. Key (invKey K) ~: analyze H ==>  \
paulson@1839
   372
\              analyze (insert (Crypt X K) H) = \
paulson@1839
   373
\              insert (Crypt X K) (analyze H)";
paulson@1839
   374
by (rtac (analyze_insert RSN (2, equalityI)) 1);
paulson@1839
   375
br subsetI 1;
paulson@1839
   376
be analyze.induct 1;
paulson@1839
   377
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   378
qed "analyze_insert_Crypt";
paulson@1839
   379
paulson@1839
   380
goal thy "!!H. Key (invKey K) : analyze H ==>  \
paulson@1839
   381
\              analyze (insert (Crypt X K) H) <= \
paulson@1839
   382
\              insert (Crypt X K) (analyze (insert X H))";
paulson@1839
   383
br subsetI 1;
paulson@1839
   384
by (eres_inst_tac [("za","x")] analyze.induct 1);
paulson@1839
   385
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   386
val lemma1 = result();
paulson@1839
   387
paulson@1839
   388
goal thy "!!H. Key (invKey K) : analyze H ==>  \
paulson@1839
   389
\              insert (Crypt X K) (analyze (insert X H)) <= \
paulson@1839
   390
\              analyze (insert (Crypt X K) H)";
paulson@1839
   391
by (Auto_tac());
paulson@1839
   392
by (eres_inst_tac [("za","x")] analyze.induct 1);
paulson@1839
   393
by (Auto_tac());
paulson@1839
   394
by (best_tac (!claset addIs [subset_insertI RS analyze_mono RS subsetD,
paulson@1839
   395
			     analyze.Decrypt]) 1);
paulson@1839
   396
val lemma2 = result();
paulson@1839
   397
paulson@1839
   398
goal thy "!!H. Key (invKey K) : analyze H ==>  \
paulson@1839
   399
\              analyze (insert (Crypt X K) H) = \
paulson@1839
   400
\              insert (Crypt X K) (analyze (insert X H))";
paulson@1839
   401
by (REPEAT (ares_tac [equalityI, lemma1, lemma2] 1));
paulson@1839
   402
qed "analyze_insert_Decrypt";
paulson@1839
   403
paulson@1885
   404
(*Case analysis: either the message is secure, or it is not!
paulson@1885
   405
  Use with expand_if;  apparently split_tac does not cope with patterns
paulson@1885
   406
  such as "analyze (insert (Crypt X' K) H)" *)
paulson@1885
   407
goal thy "analyze (insert (Crypt X' K) H) = \
paulson@1885
   408
\         (if (Key (invKey K)  : analyze H) then    \
paulson@1885
   409
\               insert (Crypt X' K) (analyze (insert X' H)) \
paulson@1885
   410
\          else insert (Crypt X' K) (analyze H))";
paulson@1885
   411
by (excluded_middle_tac "Key (invKey K)  : analyze H " 1);
paulson@1885
   412
by (ALLGOALS (asm_simp_tac (!simpset addsimps [analyze_insert_Crypt, 
paulson@1885
   413
					       analyze_insert_Decrypt])));
paulson@1885
   414
qed "analyze_Crypt_if";
paulson@1885
   415
paulson@1839
   416
Addsimps [analyze_insert_Agent, analyze_insert_Nonce, 
paulson@1885
   417
	  analyze_insert_Key, analyze_insert_MPair, 
paulson@1885
   418
	  analyze_Crypt_if];
paulson@1839
   419
paulson@1839
   420
(*This rule supposes "for the sake of argument" that we have the key.*)
paulson@1839
   421
goal thy  "analyze (insert (Crypt X K) H) <=  \
paulson@1885
   422
\          insert (Crypt X K) (analyze (insert X H))";
paulson@1839
   423
br subsetI 1;
paulson@1839
   424
be analyze.induct 1;
paulson@1839
   425
by (Auto_tac());
paulson@1839
   426
qed "analyze_insert_Crypt_subset";
paulson@1839
   427
paulson@1839
   428
paulson@1839
   429
(** Idempotence and transitivity **)
paulson@1839
   430
paulson@1839
   431
goal thy "!!H. X: analyze (analyze H) ==> X: analyze H";
paulson@1839
   432
be analyze.induct 1;
paulson@1839
   433
by (ALLGOALS Fast_tac);
paulson@1839
   434
qed "analyze_analyzeE";
paulson@1839
   435
AddSEs [analyze_analyzeE];
paulson@1839
   436
paulson@1839
   437
goal thy "analyze (analyze H) = analyze H";
paulson@1839
   438
by (Fast_tac 1);
paulson@1839
   439
qed "analyze_idem";
paulson@1839
   440
Addsimps [analyze_idem];
paulson@1839
   441
paulson@1839
   442
goal thy "!!H. [| X: analyze G;  G <= analyze H |] ==> X: analyze H";
paulson@1839
   443
by (dtac analyze_mono 1);
paulson@1839
   444
by (Fast_tac 1);
paulson@1839
   445
qed "analyze_trans";
paulson@1839
   446
paulson@1839
   447
(*Cut; Lemma 2 of Lowe*)
paulson@1839
   448
goal thy "!!H. [| X: analyze H;  Y: analyze (insert X H) |] ==> Y: analyze H";
paulson@1839
   449
be analyze_trans 1;
paulson@1839
   450
by (Fast_tac 1);
paulson@1839
   451
qed "analyze_cut";
paulson@1839
   452
paulson@1839
   453
(*Cut can be proved easily by induction on
paulson@1839
   454
   "!!H. Y: analyze (insert X H) ==> X: analyze H --> Y: analyze H"
paulson@1839
   455
*)
paulson@1839
   456
paulson@1885
   457
paulson@1885
   458
(** A congruence rule for "analyze" **)
paulson@1885
   459
paulson@1885
   460
goal thy "!!H. [| analyze G <= analyze G'; analyze H <= analyze H' \
paulson@1885
   461
\              |] ==> analyze (G Un H) <= analyze (G' Un H')";
paulson@1885
   462
by (Step_tac 1);
paulson@1885
   463
be analyze.induct 1;
paulson@1885
   464
by (ALLGOALS (best_tac (!claset addIs [analyze_mono RS subsetD])));
paulson@1885
   465
qed "analyze_subset_cong";
paulson@1885
   466
paulson@1885
   467
goal thy "!!H. [| analyze G = analyze G'; analyze H = analyze H' \
paulson@1885
   468
\              |] ==> analyze (G Un H) = analyze (G' Un H')";
paulson@1885
   469
by (REPEAT_FIRST (ares_tac [equalityI, analyze_subset_cong]
paulson@1885
   470
	  ORELSE' etac equalityE));
paulson@1885
   471
qed "analyze_cong";
paulson@1885
   472
paulson@1885
   473
paulson@1885
   474
goal thy "!!H. analyze H = analyze H'  ==>    \
paulson@1885
   475
\              analyze (insert X H) = analyze (insert X H')";
paulson@1885
   476
by (asm_simp_tac (!simpset addsimps [insert_def] 
paulson@1885
   477
		           setloop (rtac analyze_cong)) 1);
paulson@1885
   478
qed "analyze_insert_cong";
paulson@1885
   479
paulson@1839
   480
(*If there are no pairs or encryptions then analyze does nothing*)
paulson@1839
   481
goal thy "!!H. [| ALL X Y. {|X,Y|} ~: H;  ALL X K. Crypt X K ~: H |] ==> \
paulson@1839
   482
\         analyze H = H";
paulson@1839
   483
by (Step_tac 1);
paulson@1839
   484
be analyze.induct 1;
paulson@1839
   485
by (ALLGOALS Fast_tac);
paulson@1839
   486
qed "analyze_trivial";
paulson@1839
   487
paulson@1839
   488
(*Helps to prove Fake cases*)
paulson@1839
   489
goal thy "!!X. X: analyze (UN i. analyze (H i)) ==> X: analyze (UN i. H i)";
paulson@1839
   490
be analyze.induct 1;
paulson@1852
   491
by (ALLGOALS (fast_tac (!claset addEs [impOfSubs analyze_mono])));
paulson@1839
   492
val lemma = result();
paulson@1839
   493
paulson@1839
   494
goal thy "analyze (UN i. analyze (H i)) = analyze (UN i. H i)";
paulson@1839
   495
by (fast_tac (!claset addIs [lemma]
paulson@1852
   496
		      addEs [impOfSubs analyze_mono]) 1);
paulson@1839
   497
qed "analyze_UN_analyze";
paulson@1839
   498
Addsimps [analyze_UN_analyze];
paulson@1839
   499
paulson@1839
   500
paulson@1839
   501
(**** Inductive relation "synthesize" ****)
paulson@1839
   502
paulson@1839
   503
AddIs  synthesize.intrs;
paulson@1839
   504
paulson@1839
   505
goal thy "H <= synthesize(H)";
paulson@1839
   506
by (Fast_tac 1);
paulson@1839
   507
qed "synthesize_increasing";
paulson@1839
   508
paulson@1839
   509
(*Monotonicity*)
paulson@1839
   510
goalw thy synthesize.defs "!!G H. G<=H ==> synthesize(G) <= synthesize(H)";
paulson@1839
   511
by (rtac lfp_mono 1);
paulson@1839
   512
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
   513
qed "synthesize_mono";
paulson@1839
   514
paulson@1839
   515
(** Unions **)
paulson@1839
   516
paulson@1839
   517
(*Converse fails: we can synthesize more from the union than from the 
paulson@1839
   518
  separate parts, building a compound message using elements of each.*)
paulson@1839
   519
goal thy "synthesize(G) Un synthesize(H) <= synthesize(G Un H)";
paulson@1839
   520
by (REPEAT (ares_tac [Un_least, synthesize_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   521
qed "synthesize_Un";
paulson@1839
   522
paulson@1885
   523
goal thy "insert X (synthesize H) <= synthesize(insert X H)";
paulson@1885
   524
by (fast_tac (!claset addEs [impOfSubs synthesize_mono]) 1);
paulson@1885
   525
qed "synthesize_insert";
paulson@1885
   526
paulson@1839
   527
(** Idempotence and transitivity **)
paulson@1839
   528
paulson@1839
   529
goal thy "!!H. X: synthesize (synthesize H) ==> X: synthesize H";
paulson@1839
   530
be synthesize.induct 1;
paulson@1839
   531
by (ALLGOALS Fast_tac);
paulson@1839
   532
qed "synthesize_synthesizeE";
paulson@1839
   533
AddSEs [synthesize_synthesizeE];
paulson@1839
   534
paulson@1839
   535
goal thy "synthesize (synthesize H) = synthesize H";
paulson@1839
   536
by (Fast_tac 1);
paulson@1839
   537
qed "synthesize_idem";
paulson@1839
   538
paulson@1839
   539
goal thy "!!H. [| X: synthesize G;  G <= synthesize H |] ==> X: synthesize H";
paulson@1839
   540
by (dtac synthesize_mono 1);
paulson@1839
   541
by (Fast_tac 1);
paulson@1839
   542
qed "synthesize_trans";
paulson@1839
   543
paulson@1839
   544
(*Cut; Lemma 2 of Lowe*)
paulson@1839
   545
goal thy "!!H. [| X: synthesize H;  Y: synthesize (insert X H) \
paulson@1839
   546
\              |] ==> Y: synthesize H";
paulson@1839
   547
be synthesize_trans 1;
paulson@1839
   548
by (Fast_tac 1);
paulson@1839
   549
qed "synthesize_cut";
paulson@1839
   550
paulson@1839
   551
paulson@1839
   552
(*Can only produce a nonce or key if it is already known,
paulson@1839
   553
  but can synthesize a pair or encryption from its components...*)
paulson@1839
   554
val mk_cases = synthesize.mk_cases msg.simps;
paulson@1839
   555
paulson@1885
   556
(*NO Agent_synthesize, as any Agent name can be synthesized*)
paulson@1839
   557
val Nonce_synthesize = mk_cases "Nonce n : synthesize H";
paulson@1839
   558
val Key_synthesize   = mk_cases "Key K : synthesize H";
paulson@1839
   559
val MPair_synthesize = mk_cases "{|X,Y|} : synthesize H";
paulson@1839
   560
val Crypt_synthesize = mk_cases "Crypt X K : synthesize H";
paulson@1839
   561
paulson@1839
   562
AddSEs [Nonce_synthesize, Key_synthesize, MPair_synthesize, Crypt_synthesize];
paulson@1839
   563
paulson@1839
   564
goal thy "(Nonce N : synthesize H) = (Nonce N : H)";
paulson@1839
   565
by (Fast_tac 1);
paulson@1839
   566
qed "Nonce_synthesize_eq";
paulson@1839
   567
paulson@1839
   568
goal thy "(Key K : synthesize H) = (Key K : H)";
paulson@1839
   569
by (Fast_tac 1);
paulson@1839
   570
qed "Key_synthesize_eq";
paulson@1839
   571
paulson@1839
   572
Addsimps [Nonce_synthesize_eq, Key_synthesize_eq];
paulson@1839
   573
paulson@1839
   574
paulson@1839
   575
goalw thy [keysFor_def]
paulson@1839
   576
    "keysFor (synthesize H) = keysFor H Un invKey``{K. Key K : H}";
paulson@1839
   577
by (Fast_tac 1);
paulson@1839
   578
qed "keysFor_synthesize";
paulson@1839
   579
Addsimps [keysFor_synthesize];
paulson@1839
   580
paulson@1839
   581
paulson@1839
   582
(*** Combinations of parts, analyze and synthesize ***)
paulson@1839
   583
paulson@1839
   584
goal thy "parts (synthesize H) = parts H Un synthesize H";
paulson@1839
   585
br equalityI 1;
paulson@1839
   586
br subsetI 1;
paulson@1839
   587
be parts.induct 1;
paulson@1839
   588
by (ALLGOALS
paulson@1839
   589
    (best_tac (!claset addIs ((synthesize_increasing RS parts_mono RS subsetD)
paulson@1839
   590
			     ::parts.intrs))));
paulson@1839
   591
qed "parts_synthesize";
paulson@1839
   592
Addsimps [parts_synthesize];
paulson@1839
   593
paulson@1839
   594
goal thy "analyze (synthesize H) = analyze H Un synthesize H";
paulson@1839
   595
br equalityI 1;
paulson@1839
   596
br subsetI 1;
paulson@1839
   597
be analyze.induct 1;
paulson@1839
   598
by (best_tac
paulson@1839
   599
    (!claset addIs [synthesize_increasing RS analyze_mono RS subsetD]) 5);
paulson@1839
   600
(*Strange that best_tac just can't hack this one...*)
paulson@1839
   601
by (ALLGOALS (deepen_tac (!claset addIs analyze.intrs) 0));
paulson@1839
   602
qed "analyze_synthesize";
paulson@1839
   603
Addsimps [analyze_synthesize];
paulson@1839
   604
paulson@1839
   605
(*Hard to prove; still needed now that there's only one Enemy?*)
paulson@1839
   606
goal thy "analyze (UN i. synthesize (H i)) = \
paulson@1839
   607
\         analyze (UN i. H i) Un (UN i. synthesize (H i))";
paulson@1839
   608
br equalityI 1;
paulson@1839
   609
br subsetI 1;
paulson@1839
   610
be analyze.induct 1;
paulson@1839
   611
by (best_tac
paulson@1852
   612
    (!claset addEs [impOfSubs synthesize_increasing,
paulson@1852
   613
		    impOfSubs analyze_mono]) 5);
paulson@1839
   614
by (Best_tac 1);
paulson@1839
   615
by (deepen_tac (!claset addIs [analyze.Fst]) 0 1);
paulson@1839
   616
by (deepen_tac (!claset addIs [analyze.Snd]) 0 1);
paulson@1839
   617
by (deepen_tac (!claset addSEs [analyze.Decrypt]
paulson@1839
   618
			addIs  [analyze.Decrypt]) 0 1);
paulson@1839
   619
qed "analyze_UN1_synthesize";
paulson@1839
   620
Addsimps [analyze_UN1_synthesize];