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