src/HOL/Auth/Message.ML
author paulson
Fri Jun 28 15:26:39 1996 +0200 (1996-06-28)
changeset 1839 199243afac2b
child 1852 289ce6cb5c84
permissions -rw-r--r--
Proving safety properties of authentication protocols
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@1839
    25
fun imp_of_subset 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@1839
   127
paulson@1839
   128
(** Unions **)
paulson@1839
   129
paulson@1839
   130
goal thy "parts(G) Un parts(H) <= parts(G Un H)";
paulson@1839
   131
by (REPEAT (ares_tac [Un_least, parts_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   132
val parts_Un_subset1 = result();
paulson@1839
   133
paulson@1839
   134
goal thy "parts(G Un H) <= parts(G) Un parts(H)";
paulson@1839
   135
br subsetI 1;
paulson@1839
   136
be parts.induct 1;
paulson@1839
   137
by (ALLGOALS Fast_tac);
paulson@1839
   138
val parts_Un_subset2 = result();
paulson@1839
   139
paulson@1839
   140
goal thy "parts(G Un H) = parts(G) Un parts(H)";
paulson@1839
   141
by (REPEAT (ares_tac [equalityI, parts_Un_subset1, parts_Un_subset2] 1));
paulson@1839
   142
qed "parts_Un";
paulson@1839
   143
paulson@1839
   144
goal thy "(UN x:A. parts(H x)) <= parts(UN x:A. H x)";
paulson@1839
   145
by (REPEAT (ares_tac [UN_least, parts_mono, UN_upper] 1));
paulson@1839
   146
val parts_UN_subset1 = result();
paulson@1839
   147
paulson@1839
   148
goal thy "parts(UN x:A. H x) <= (UN x:A. parts(H x))";
paulson@1839
   149
br subsetI 1;
paulson@1839
   150
be parts.induct 1;
paulson@1839
   151
by (ALLGOALS Fast_tac);
paulson@1839
   152
val parts_UN_subset2 = result();
paulson@1839
   153
paulson@1839
   154
goal thy "parts(UN x:A. H x) = (UN x:A. parts(H x))";
paulson@1839
   155
by (REPEAT (ares_tac [equalityI, parts_UN_subset1, parts_UN_subset2] 1));
paulson@1839
   156
qed "parts_UN";
paulson@1839
   157
paulson@1839
   158
goal thy "parts(UN x. H x) = (UN x. parts(H x))";
paulson@1839
   159
by (simp_tac (!simpset addsimps [UNION1_def, parts_UN]) 1);
paulson@1839
   160
qed "parts_UN1";
paulson@1839
   161
paulson@1839
   162
(*Added to simplify arguments to parts, analyze and synthesize*)
paulson@1839
   163
Addsimps [parts_Un, parts_UN, parts_UN1];
paulson@1839
   164
paulson@1839
   165
goal thy "insert X (parts H) <= parts(insert X H)";
paulson@1839
   166
by (fast_tac (!claset addEs [imp_of_subset parts_mono]) 1);
paulson@1839
   167
qed "parts_insert_subset";
paulson@1839
   168
paulson@1839
   169
(*Especially for reasoning about the Fake rule in traces*)
paulson@1839
   170
goal thy "!!Y. X: G ==> parts(insert X H) <= parts G Un parts H";
paulson@1839
   171
br ([parts_mono, parts_Un_subset2] MRS subset_trans) 1;
paulson@1839
   172
by (Fast_tac 1);
paulson@1839
   173
qed "parts_insert_subset_Un";
paulson@1839
   174
paulson@1839
   175
(** Idempotence and transitivity **)
paulson@1839
   176
paulson@1839
   177
goal thy "!!H. X: parts (parts H) ==> X: parts H";
paulson@1839
   178
be parts.induct 1;
paulson@1839
   179
by (ALLGOALS Fast_tac);
paulson@1839
   180
qed "parts_partsE";
paulson@1839
   181
AddSEs [parts_partsE];
paulson@1839
   182
paulson@1839
   183
goal thy "parts (parts H) = parts H";
paulson@1839
   184
by (Fast_tac 1);
paulson@1839
   185
qed "parts_idem";
paulson@1839
   186
Addsimps [parts_idem];
paulson@1839
   187
paulson@1839
   188
goal thy "!!H. [| X: parts G;  G <= parts H |] ==> X: parts H";
paulson@1839
   189
by (dtac parts_mono 1);
paulson@1839
   190
by (Fast_tac 1);
paulson@1839
   191
qed "parts_trans";
paulson@1839
   192
paulson@1839
   193
(*Cut*)
paulson@1839
   194
goal thy "!!H. [| X: parts H;  Y: parts (insert X H) |] ==> Y: parts H";
paulson@1839
   195
be parts_trans 1;
paulson@1839
   196
by (Fast_tac 1);
paulson@1839
   197
qed "parts_cut";
paulson@1839
   198
paulson@1839
   199
paulson@1839
   200
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   201
paulson@1839
   202
goal thy "parts (insert (Agent agt) H) = insert (Agent agt) (parts H)";
paulson@1839
   203
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   204
br subsetI 1;
paulson@1839
   205
be parts.induct 1;
paulson@1839
   206
(*Simplification breaks up equalities between messages;
paulson@1839
   207
  how to make it work for fast_tac??*)
paulson@1839
   208
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   209
qed "parts_insert_Agent";
paulson@1839
   210
paulson@1839
   211
goal thy "parts (insert (Nonce N) H) = insert (Nonce N) (parts H)";
paulson@1839
   212
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   213
br subsetI 1;
paulson@1839
   214
be parts.induct 1;
paulson@1839
   215
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   216
qed "parts_insert_Nonce";
paulson@1839
   217
paulson@1839
   218
goal thy "parts (insert (Key K) H) = insert (Key K) (parts H)";
paulson@1839
   219
by (rtac (parts_insert_subset RSN (2, equalityI)) 1);
paulson@1839
   220
br subsetI 1;
paulson@1839
   221
be parts.induct 1;
paulson@1839
   222
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   223
qed "parts_insert_Key";
paulson@1839
   224
paulson@1839
   225
goal thy "parts (insert (Crypt X K) H) = \
paulson@1839
   226
\         insert (Crypt X K) (parts (insert X H))";
paulson@1839
   227
br equalityI 1;
paulson@1839
   228
br subsetI 1;
paulson@1839
   229
be parts.induct 1;
paulson@1839
   230
by (Auto_tac());
paulson@1839
   231
be parts.induct 1;
paulson@1839
   232
by (ALLGOALS (best_tac (!claset addIs [parts.Body])));
paulson@1839
   233
qed "parts_insert_Crypt";
paulson@1839
   234
paulson@1839
   235
goal thy "parts (insert {|X,Y|} H) = \
paulson@1839
   236
\         insert {|X,Y|} (parts (insert X (insert Y H)))";
paulson@1839
   237
br equalityI 1;
paulson@1839
   238
br subsetI 1;
paulson@1839
   239
be parts.induct 1;
paulson@1839
   240
by (Auto_tac());
paulson@1839
   241
be parts.induct 1;
paulson@1839
   242
by (ALLGOALS (best_tac (!claset addIs [parts.Fst, parts.Snd])));
paulson@1839
   243
qed "parts_insert_MPair";
paulson@1839
   244
paulson@1839
   245
Addsimps [parts_insert_Agent, parts_insert_Nonce, 
paulson@1839
   246
	  parts_insert_Key, parts_insert_Crypt, parts_insert_MPair];
paulson@1839
   247
paulson@1839
   248
paulson@1839
   249
(**** Inductive relation "analyze" ****)
paulson@1839
   250
paulson@1839
   251
val major::prems = 
paulson@1839
   252
goal thy "[| {|X,Y|} : analyze H;       \
paulson@1839
   253
\            [| X : analyze H; Y : analyze H |] ==> P  \
paulson@1839
   254
\         |] ==> P";
paulson@1839
   255
by (cut_facts_tac [major] 1);
paulson@1839
   256
brs prems 1;
paulson@1839
   257
by (REPEAT (eresolve_tac [asm_rl, analyze.Fst, analyze.Snd] 1));
paulson@1839
   258
qed "MPair_analyze";
paulson@1839
   259
paulson@1839
   260
AddIs  [analyze.Inj];
paulson@1839
   261
AddSEs [MPair_analyze];
paulson@1839
   262
AddDs  [analyze.Decrypt];
paulson@1839
   263
paulson@1839
   264
goal thy "H <= analyze(H)";
paulson@1839
   265
by (Fast_tac 1);
paulson@1839
   266
qed "analyze_increasing";
paulson@1839
   267
paulson@1839
   268
goal thy "analyze H <= parts H";
paulson@1839
   269
by (rtac subsetI 1);
paulson@1839
   270
be analyze.induct 1;
paulson@1839
   271
by (ALLGOALS Fast_tac);
paulson@1839
   272
qed "analyze_subset_parts";
paulson@1839
   273
paulson@1839
   274
bind_thm ("not_parts_not_analyze", analyze_subset_parts RS contra_subsetD);
paulson@1839
   275
paulson@1839
   276
paulson@1839
   277
goal thy "parts (analyze H) = parts H";
paulson@1839
   278
br equalityI 1;
paulson@1839
   279
br (analyze_subset_parts RS parts_mono RS subset_trans) 1;
paulson@1839
   280
by (Simp_tac 1);
paulson@1839
   281
by (fast_tac (!claset addDs [analyze_increasing RS parts_mono RS subsetD]) 1);
paulson@1839
   282
qed "parts_analyze";
paulson@1839
   283
Addsimps [parts_analyze];
paulson@1839
   284
paulson@1839
   285
(*Monotonicity; Lemma 1 of Lowe*)
paulson@1839
   286
goalw thy analyze.defs "!!G H. G<=H ==> analyze(G) <= analyze(H)";
paulson@1839
   287
by (rtac lfp_mono 1);
paulson@1839
   288
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
   289
qed "analyze_mono";
paulson@1839
   290
paulson@1839
   291
(** General equational properties **)
paulson@1839
   292
paulson@1839
   293
goal thy "analyze{} = {}";
paulson@1839
   294
by (Step_tac 1);
paulson@1839
   295
be analyze.induct 1;
paulson@1839
   296
by (ALLGOALS Fast_tac);
paulson@1839
   297
qed "analyze_empty";
paulson@1839
   298
Addsimps [analyze_empty];
paulson@1839
   299
paulson@1839
   300
(*Converse fails: we can analyze more from the union than from the 
paulson@1839
   301
  separate parts, as a key in one might decrypt a message in the other*)
paulson@1839
   302
goal thy "analyze(G) Un analyze(H) <= analyze(G Un H)";
paulson@1839
   303
by (REPEAT (ares_tac [Un_least, analyze_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   304
qed "analyze_Un";
paulson@1839
   305
paulson@1839
   306
goal thy "insert X (analyze H) <= analyze(insert X H)";
paulson@1839
   307
by (fast_tac (!claset addEs [imp_of_subset analyze_mono]) 1);
paulson@1839
   308
qed "analyze_insert";
paulson@1839
   309
paulson@1839
   310
(** Rewrite rules for pulling out atomic messages **)
paulson@1839
   311
paulson@1839
   312
goal thy "analyze (insert (Agent agt) H) = insert (Agent agt) (analyze H)";
paulson@1839
   313
by (rtac (analyze_insert RSN (2, equalityI)) 1);
paulson@1839
   314
br subsetI 1;
paulson@1839
   315
be analyze.induct 1;
paulson@1839
   316
(*Simplification breaks up equalities between messages;
paulson@1839
   317
  how to make it work for fast_tac??*)
paulson@1839
   318
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   319
qed "analyze_insert_Agent";
paulson@1839
   320
paulson@1839
   321
goal thy "analyze (insert (Nonce N) H) = insert (Nonce N) (analyze H)";
paulson@1839
   322
by (rtac (analyze_insert RSN (2, equalityI)) 1);
paulson@1839
   323
br subsetI 1;
paulson@1839
   324
be analyze.induct 1;
paulson@1839
   325
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   326
qed "analyze_insert_Nonce";
paulson@1839
   327
paulson@1839
   328
(*Can only pull out Keys if they are not needed to decrypt the rest*)
paulson@1839
   329
goalw thy [keysFor_def]
paulson@1839
   330
    "!!K. K ~: keysFor (analyze H) ==>  \
paulson@1839
   331
\         analyze (insert (Key K) H) = insert (Key K) (analyze H)";
paulson@1839
   332
by (rtac (analyze_insert RSN (2, equalityI)) 1);
paulson@1839
   333
br subsetI 1;
paulson@1839
   334
be analyze.induct 1;
paulson@1839
   335
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   336
qed "analyze_insert_Key";
paulson@1839
   337
paulson@1839
   338
goal thy "!!H. Key (invKey K) ~: analyze H ==>  \
paulson@1839
   339
\              analyze (insert (Crypt X K) H) = \
paulson@1839
   340
\              insert (Crypt X K) (analyze H)";
paulson@1839
   341
by (rtac (analyze_insert RSN (2, equalityI)) 1);
paulson@1839
   342
br subsetI 1;
paulson@1839
   343
be analyze.induct 1;
paulson@1839
   344
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   345
qed "analyze_insert_Crypt";
paulson@1839
   346
paulson@1839
   347
goal thy "!!H. Key (invKey K) : analyze H ==>  \
paulson@1839
   348
\              analyze (insert (Crypt X K) H) <= \
paulson@1839
   349
\              insert (Crypt X K) (analyze (insert X H))";
paulson@1839
   350
br subsetI 1;
paulson@1839
   351
by (eres_inst_tac [("za","x")] analyze.induct 1);
paulson@1839
   352
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   353
val lemma1 = result();
paulson@1839
   354
paulson@1839
   355
goal thy "!!H. Key (invKey K) : analyze H ==>  \
paulson@1839
   356
\              insert (Crypt X K) (analyze (insert X H)) <= \
paulson@1839
   357
\              analyze (insert (Crypt X K) H)";
paulson@1839
   358
by (Auto_tac());
paulson@1839
   359
by (eres_inst_tac [("za","x")] analyze.induct 1);
paulson@1839
   360
by (Auto_tac());
paulson@1839
   361
by (best_tac (!claset addIs [subset_insertI RS analyze_mono RS subsetD,
paulson@1839
   362
			     analyze.Decrypt]) 1);
paulson@1839
   363
val lemma2 = result();
paulson@1839
   364
paulson@1839
   365
goal thy "!!H. Key (invKey K) : analyze H ==>  \
paulson@1839
   366
\              analyze (insert (Crypt X K) H) = \
paulson@1839
   367
\              insert (Crypt X K) (analyze (insert X H))";
paulson@1839
   368
by (REPEAT (ares_tac [equalityI, lemma1, lemma2] 1));
paulson@1839
   369
qed "analyze_insert_Decrypt";
paulson@1839
   370
paulson@1839
   371
Addsimps [analyze_insert_Agent, analyze_insert_Nonce, 
paulson@1839
   372
	  analyze_insert_Key, analyze_insert_Crypt,
paulson@1839
   373
	  analyze_insert_Decrypt];
paulson@1839
   374
paulson@1839
   375
paulson@1839
   376
(*This rule supposes "for the sake of argument" that we have the key.*)
paulson@1839
   377
goal thy  "analyze (insert (Crypt X K) H) <=  \
paulson@1839
   378
\         insert (Crypt X K) (analyze (insert X H))";
paulson@1839
   379
br subsetI 1;
paulson@1839
   380
be analyze.induct 1;
paulson@1839
   381
by (Auto_tac());
paulson@1839
   382
qed "analyze_insert_Crypt_subset";
paulson@1839
   383
paulson@1839
   384
paulson@1839
   385
(** Rewrite rules for pulling out atomic parts of messages **)
paulson@1839
   386
paulson@1839
   387
goal thy "analyze (insert X H) <= analyze (insert {|X,Y|} H)";
paulson@1839
   388
br subsetI 1;
paulson@1839
   389
be analyze.induct 1;
paulson@1839
   390
by (ALLGOALS (best_tac (!claset addIs [analyze.Fst]))); 
paulson@1839
   391
qed "analyze_insert_subset_MPair1";
paulson@1839
   392
paulson@1839
   393
goal thy "analyze (insert Y H) <= analyze (insert {|X,Y|} H)";
paulson@1839
   394
br subsetI 1;
paulson@1839
   395
be analyze.induct 1;
paulson@1839
   396
by (ALLGOALS (best_tac (!claset addIs [analyze.Snd]))); 
paulson@1839
   397
qed "analyze_insert_subset_MPair2";
paulson@1839
   398
paulson@1839
   399
goal thy "analyze (insert {|Agent agt,Y|} H) = \
paulson@1839
   400
\         insert {|Agent agt,Y|} (insert (Agent agt) (analyze (insert Y H)))";
paulson@1839
   401
by (rtac equalityI 1);
paulson@1839
   402
by (best_tac (!claset addIs [analyze.Fst,
paulson@1839
   403
			     imp_of_subset analyze_insert_subset_MPair2]) 2); 
paulson@1839
   404
br subsetI 1;
paulson@1839
   405
be analyze.induct 1;
paulson@1839
   406
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   407
qed "analyze_insert_Agent_MPair";
paulson@1839
   408
paulson@1839
   409
goal thy "analyze (insert {|Nonce N,Y|} H) = \
paulson@1839
   410
\         insert {|Nonce N,Y|} (insert (Nonce N) (analyze (insert Y H)))";
paulson@1839
   411
by (rtac equalityI 1);
paulson@1839
   412
by (best_tac (!claset addIs [analyze.Fst,
paulson@1839
   413
			     imp_of_subset analyze_insert_subset_MPair2]) 2); 
paulson@1839
   414
br subsetI 1;
paulson@1839
   415
be analyze.induct 1;
paulson@1839
   416
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   417
qed "analyze_insert_Nonce_MPair";
paulson@1839
   418
paulson@1839
   419
(*Can only pull out Keys if they are not needed to decrypt the rest*)
paulson@1839
   420
goalw thy [keysFor_def]
paulson@1839
   421
    "!!K. K ~: keysFor (analyze (insert Y H)) ==>  \
paulson@1839
   422
\         analyze (insert {|Key K, Y|} H) = \
paulson@1839
   423
\         insert {|Key K, Y|} (insert (Key K) (analyze (insert Y H)))";
paulson@1839
   424
by (rtac equalityI 1);
paulson@1839
   425
by (best_tac (!claset addIs [analyze.Fst,
paulson@1839
   426
			     imp_of_subset analyze_insert_subset_MPair2]) 2); 
paulson@1839
   427
br subsetI 1;
paulson@1839
   428
be analyze.induct 1;
paulson@1839
   429
by (ALLGOALS (fast_tac (!claset addss (!simpset))));
paulson@1839
   430
qed "analyze_insert_Key_MPair";
paulson@1839
   431
paulson@1839
   432
Addsimps [analyze_insert_Agent_MPair, analyze_insert_Nonce_MPair,
paulson@1839
   433
	  analyze_insert_Key_MPair];
paulson@1839
   434
paulson@1839
   435
(** Idempotence and transitivity **)
paulson@1839
   436
paulson@1839
   437
goal thy "!!H. X: analyze (analyze H) ==> X: analyze H";
paulson@1839
   438
be analyze.induct 1;
paulson@1839
   439
by (ALLGOALS Fast_tac);
paulson@1839
   440
qed "analyze_analyzeE";
paulson@1839
   441
AddSEs [analyze_analyzeE];
paulson@1839
   442
paulson@1839
   443
goal thy "analyze (analyze H) = analyze H";
paulson@1839
   444
by (Fast_tac 1);
paulson@1839
   445
qed "analyze_idem";
paulson@1839
   446
Addsimps [analyze_idem];
paulson@1839
   447
paulson@1839
   448
goal thy "!!H. [| X: analyze G;  G <= analyze H |] ==> X: analyze H";
paulson@1839
   449
by (dtac analyze_mono 1);
paulson@1839
   450
by (Fast_tac 1);
paulson@1839
   451
qed "analyze_trans";
paulson@1839
   452
paulson@1839
   453
(*Cut; Lemma 2 of Lowe*)
paulson@1839
   454
goal thy "!!H. [| X: analyze H;  Y: analyze (insert X H) |] ==> Y: analyze H";
paulson@1839
   455
be analyze_trans 1;
paulson@1839
   456
by (Fast_tac 1);
paulson@1839
   457
qed "analyze_cut";
paulson@1839
   458
paulson@1839
   459
(*Cut can be proved easily by induction on
paulson@1839
   460
   "!!H. Y: analyze (insert X H) ==> X: analyze H --> Y: analyze H"
paulson@1839
   461
*)
paulson@1839
   462
paulson@1839
   463
(*If there are no pairs or encryptions then analyze does nothing*)
paulson@1839
   464
goal thy "!!H. [| ALL X Y. {|X,Y|} ~: H;  ALL X K. Crypt X K ~: H |] ==> \
paulson@1839
   465
\         analyze H = H";
paulson@1839
   466
by (Step_tac 1);
paulson@1839
   467
be analyze.induct 1;
paulson@1839
   468
by (ALLGOALS Fast_tac);
paulson@1839
   469
qed "analyze_trivial";
paulson@1839
   470
paulson@1839
   471
(*Helps to prove Fake cases*)
paulson@1839
   472
goal thy "!!X. X: analyze (UN i. analyze (H i)) ==> X: analyze (UN i. H i)";
paulson@1839
   473
be analyze.induct 1;
paulson@1839
   474
by (ALLGOALS (fast_tac (!claset addEs [imp_of_subset analyze_mono])));
paulson@1839
   475
val lemma = result();
paulson@1839
   476
paulson@1839
   477
goal thy "analyze (UN i. analyze (H i)) = analyze (UN i. H i)";
paulson@1839
   478
by (fast_tac (!claset addIs [lemma]
paulson@1839
   479
		      addEs [imp_of_subset analyze_mono]) 1);
paulson@1839
   480
qed "analyze_UN_analyze";
paulson@1839
   481
Addsimps [analyze_UN_analyze];
paulson@1839
   482
paulson@1839
   483
paulson@1839
   484
(**** Inductive relation "synthesize" ****)
paulson@1839
   485
paulson@1839
   486
AddIs  synthesize.intrs;
paulson@1839
   487
paulson@1839
   488
goal thy "H <= synthesize(H)";
paulson@1839
   489
by (Fast_tac 1);
paulson@1839
   490
qed "synthesize_increasing";
paulson@1839
   491
paulson@1839
   492
(*Monotonicity*)
paulson@1839
   493
goalw thy synthesize.defs "!!G H. G<=H ==> synthesize(G) <= synthesize(H)";
paulson@1839
   494
by (rtac lfp_mono 1);
paulson@1839
   495
by (REPEAT (ares_tac basic_monos 1));
paulson@1839
   496
qed "synthesize_mono";
paulson@1839
   497
paulson@1839
   498
(** Unions **)
paulson@1839
   499
paulson@1839
   500
(*Converse fails: we can synthesize more from the union than from the 
paulson@1839
   501
  separate parts, building a compound message using elements of each.*)
paulson@1839
   502
goal thy "synthesize(G) Un synthesize(H) <= synthesize(G Un H)";
paulson@1839
   503
by (REPEAT (ares_tac [Un_least, synthesize_mono, Un_upper1, Un_upper2] 1));
paulson@1839
   504
qed "synthesize_Un";
paulson@1839
   505
paulson@1839
   506
(** Idempotence and transitivity **)
paulson@1839
   507
paulson@1839
   508
goal thy "!!H. X: synthesize (synthesize H) ==> X: synthesize H";
paulson@1839
   509
be synthesize.induct 1;
paulson@1839
   510
by (ALLGOALS Fast_tac);
paulson@1839
   511
qed "synthesize_synthesizeE";
paulson@1839
   512
AddSEs [synthesize_synthesizeE];
paulson@1839
   513
paulson@1839
   514
goal thy "synthesize (synthesize H) = synthesize H";
paulson@1839
   515
by (Fast_tac 1);
paulson@1839
   516
qed "synthesize_idem";
paulson@1839
   517
paulson@1839
   518
goal thy "!!H. [| X: synthesize G;  G <= synthesize H |] ==> X: synthesize H";
paulson@1839
   519
by (dtac synthesize_mono 1);
paulson@1839
   520
by (Fast_tac 1);
paulson@1839
   521
qed "synthesize_trans";
paulson@1839
   522
paulson@1839
   523
(*Cut; Lemma 2 of Lowe*)
paulson@1839
   524
goal thy "!!H. [| X: synthesize H;  Y: synthesize (insert X H) \
paulson@1839
   525
\              |] ==> Y: synthesize H";
paulson@1839
   526
be synthesize_trans 1;
paulson@1839
   527
by (Fast_tac 1);
paulson@1839
   528
qed "synthesize_cut";
paulson@1839
   529
paulson@1839
   530
paulson@1839
   531
(*Can only produce a nonce or key if it is already known,
paulson@1839
   532
  but can synthesize a pair or encryption from its components...*)
paulson@1839
   533
val mk_cases = synthesize.mk_cases msg.simps;
paulson@1839
   534
paulson@1839
   535
val Nonce_synthesize = mk_cases "Nonce n : synthesize H";
paulson@1839
   536
val Key_synthesize   = mk_cases "Key K : synthesize H";
paulson@1839
   537
val MPair_synthesize = mk_cases "{|X,Y|} : synthesize H";
paulson@1839
   538
val Crypt_synthesize = mk_cases "Crypt X K : synthesize H";
paulson@1839
   539
paulson@1839
   540
AddSEs [Nonce_synthesize, Key_synthesize, MPair_synthesize, Crypt_synthesize];
paulson@1839
   541
paulson@1839
   542
goal thy "(Nonce N : synthesize H) = (Nonce N : H)";
paulson@1839
   543
by (Fast_tac 1);
paulson@1839
   544
qed "Nonce_synthesize_eq";
paulson@1839
   545
paulson@1839
   546
goal thy "(Key K : synthesize H) = (Key K : H)";
paulson@1839
   547
by (Fast_tac 1);
paulson@1839
   548
qed "Key_synthesize_eq";
paulson@1839
   549
paulson@1839
   550
Addsimps [Nonce_synthesize_eq, Key_synthesize_eq];
paulson@1839
   551
paulson@1839
   552
paulson@1839
   553
goalw thy [keysFor_def]
paulson@1839
   554
    "keysFor (synthesize H) = keysFor H Un invKey``{K. Key K : H}";
paulson@1839
   555
by (Fast_tac 1);
paulson@1839
   556
qed "keysFor_synthesize";
paulson@1839
   557
Addsimps [keysFor_synthesize];
paulson@1839
   558
paulson@1839
   559
paulson@1839
   560
(*** Combinations of parts, analyze and synthesize ***)
paulson@1839
   561
paulson@1839
   562
(*Not that useful, in view of the following one...*)
paulson@1839
   563
goal thy "parts (synthesize H) <= synthesize (parts H)";
paulson@1839
   564
by (Step_tac 1);
paulson@1839
   565
be parts.induct 1;
paulson@1839
   566
be (parts_increasing RS synthesize_mono RS subsetD) 1;
paulson@1839
   567
by (ALLGOALS Fast_tac);
paulson@1839
   568
qed "parts_synthesize_subset";
paulson@1839
   569
paulson@1839
   570
goal thy "parts (synthesize H) = parts H Un synthesize H";
paulson@1839
   571
br equalityI 1;
paulson@1839
   572
br subsetI 1;
paulson@1839
   573
be parts.induct 1;
paulson@1839
   574
by (ALLGOALS
paulson@1839
   575
    (best_tac (!claset addIs ((synthesize_increasing RS parts_mono RS subsetD)
paulson@1839
   576
			     ::parts.intrs))));
paulson@1839
   577
qed "parts_synthesize";
paulson@1839
   578
Addsimps [parts_synthesize];
paulson@1839
   579
paulson@1839
   580
goal thy "analyze (synthesize H) = analyze H Un synthesize H";
paulson@1839
   581
br equalityI 1;
paulson@1839
   582
br subsetI 1;
paulson@1839
   583
be analyze.induct 1;
paulson@1839
   584
by (best_tac
paulson@1839
   585
    (!claset addIs [synthesize_increasing RS analyze_mono RS subsetD]) 5);
paulson@1839
   586
(*Strange that best_tac just can't hack this one...*)
paulson@1839
   587
by (ALLGOALS (deepen_tac (!claset addIs analyze.intrs) 0));
paulson@1839
   588
qed "analyze_synthesize";
paulson@1839
   589
Addsimps [analyze_synthesize];
paulson@1839
   590
paulson@1839
   591
(*Hard to prove; still needed now that there's only one Enemy?*)
paulson@1839
   592
goal thy "analyze (UN i. synthesize (H i)) = \
paulson@1839
   593
\         analyze (UN i. H i) Un (UN i. synthesize (H i))";
paulson@1839
   594
br equalityI 1;
paulson@1839
   595
br subsetI 1;
paulson@1839
   596
be analyze.induct 1;
paulson@1839
   597
by (best_tac
paulson@1839
   598
    (!claset addEs [imp_of_subset synthesize_increasing,
paulson@1839
   599
		    imp_of_subset analyze_mono]) 5);
paulson@1839
   600
by (Best_tac 1);
paulson@1839
   601
by (deepen_tac (!claset addIs [analyze.Fst]) 0 1);
paulson@1839
   602
by (deepen_tac (!claset addIs [analyze.Snd]) 0 1);
paulson@1839
   603
by (deepen_tac (!claset addSEs [analyze.Decrypt]
paulson@1839
   604
			addIs  [analyze.Decrypt]) 0 1);
paulson@1839
   605
qed "analyze_UN1_synthesize";
paulson@1839
   606
Addsimps [analyze_UN1_synthesize];