src/HOL/Auth/Public.ML
author paulson
Wed Dec 24 10:02:30 1997 +0100 (1997-12-24)
changeset 4477 b3e5857d8d99
parent 4422 21238c9d363e
child 4686 74a12e86b20b
permissions -rw-r--r--
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson@2318
     1
(*  Title:      HOL/Auth/Public
paulson@2318
     2
    ID:         $Id$
paulson@2318
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@2318
     4
    Copyright   1996  University of Cambridge
paulson@2318
     5
paulson@2318
     6
Theory of Public Keys (common to all symmetric-key protocols)
paulson@2318
     7
paulson@2318
     8
Server keys; initial states of agents; new nonces and keys; function "sees" 
paulson@2318
     9
*)
paulson@2318
    10
paulson@2318
    11
paulson@2318
    12
open Public;
paulson@2318
    13
paulson@2497
    14
(*** Basic properties of pubK & priK ***)
paulson@2497
    15
paulson@2497
    16
AddIffs [inj_pubK RS inj_eq];
paulson@3477
    17
paulson@3477
    18
goal thy "!!A B. (priK A = priK B) = (A=B)";
paulson@3730
    19
by Safe_tac;
paulson@3477
    20
by (dres_inst_tac [("f","invKey")] arg_cong 1);
paulson@3477
    21
by (Full_simp_tac 1);
paulson@3477
    22
qed "priK_inj_eq";
paulson@3477
    23
paulson@3477
    24
AddIffs [priK_inj_eq];
paulson@3473
    25
AddIffs [priK_neq_pubK, priK_neq_pubK RS not_sym];
paulson@3473
    26
paulson@3473
    27
goalw thy [isSymKey_def] "~ isSymKey (pubK A)";
paulson@3473
    28
by (Simp_tac 1);
paulson@3473
    29
qed "not_isSymKey_pubK";
paulson@3473
    30
paulson@3473
    31
goalw thy [isSymKey_def] "~ isSymKey (priK A)";
paulson@3473
    32
by (Simp_tac 1);
paulson@3473
    33
qed "not_isSymKey_priK";
paulson@3473
    34
paulson@3473
    35
AddIffs [not_isSymKey_pubK, not_isSymKey_priK];
paulson@3473
    36
paulson@4422
    37
paulson@4422
    38
(** "Image" equations that hold for injective functions **)
paulson@4422
    39
paulson@4422
    40
goal thy "(invKey x : invKey``A) = (x:A)";
paulson@4477
    41
by Auto_tac;
paulson@4422
    42
qed "invKey_image_eq";
paulson@4422
    43
paulson@4422
    44
(*holds because invKey is injective*)
paulson@4422
    45
goal thy "(pubK x : pubK``A) = (x:A)";
paulson@4477
    46
by Auto_tac;
paulson@4422
    47
qed "pubK_image_eq";
paulson@4422
    48
paulson@4422
    49
goal thy "(priK x ~: pubK``A)";
paulson@4477
    50
by Auto_tac;
paulson@4422
    51
qed "priK_pubK_image_eq";
paulson@4422
    52
Addsimps [invKey_image_eq, pubK_image_eq, priK_pubK_image_eq];
paulson@4422
    53
paulson@4422
    54
paulson@3512
    55
(** Rewrites should not refer to  initState(Friend i) 
paulson@3512
    56
    -- not in normal form! **)
paulson@3512
    57
paulson@3519
    58
goalw thy [keysFor_def] "keysFor (parts (initState C)) = {}";
paulson@3667
    59
by (induct_tac "C" 1);
wenzelm@4091
    60
by (auto_tac (claset() addIs [range_eqI], simpset()));
paulson@3512
    61
qed "keysFor_parts_initState";
paulson@3512
    62
Addsimps [keysFor_parts_initState];
paulson@3512
    63
paulson@3512
    64
paulson@3683
    65
(*** Function "spies" ***)
paulson@2497
    66
paulson@2318
    67
(*Agents see their own private keys!*)
paulson@3683
    68
goal thy "Key (priK A) : initState A";
paulson@3667
    69
by (induct_tac "A" 1);
paulson@4477
    70
by Auto_tac;
paulson@3683
    71
qed "priK_in_initState";
paulson@3683
    72
AddIffs [priK_in_initState];
paulson@2318
    73
paulson@3683
    74
(*All public keys are visible*)
paulson@3683
    75
goal thy "Key (pubK A) : spies evs";
paulson@3667
    76
by (induct_tac "evs" 1);
paulson@3683
    77
by (ALLGOALS (asm_simp_tac
wenzelm@4091
    78
	      (simpset() addsimps [imageI, spies_Cons]
nipkow@3919
    79
	                addsplits [expand_event_case, expand_if])));
paulson@3683
    80
qed_spec_mp "spies_pubK";
paulson@2318
    81
paulson@3683
    82
(*Spy sees private keys of bad agents!*)
paulson@3683
    83
goal thy "!!A. A: bad ==> Key (priK A) : spies evs";
paulson@3667
    84
by (induct_tac "evs" 1);
paulson@3683
    85
by (ALLGOALS (asm_simp_tac
wenzelm@4091
    86
	      (simpset() addsimps [imageI, spies_Cons]
nipkow@3919
    87
	                addsplits [expand_event_case, expand_if])));
paulson@3683
    88
qed "Spy_spies_bad";
paulson@2318
    89
paulson@3683
    90
AddIffs [spies_pubK, spies_pubK RS analz.Inj];
paulson@3683
    91
AddSIs  [Spy_spies_bad];
paulson@2318
    92
paulson@2318
    93
paulson@3683
    94
(*For not_bad_tac*)
paulson@3683
    95
goal thy "!!A. [| Crypt (pubK A) X : analz (spies evs);  A: bad |] \
paulson@3683
    96
\              ==> X : analz (spies evs)";
wenzelm@4091
    97
by (blast_tac (claset() addSDs [analz.Decrypt]) 1);
paulson@3683
    98
qed "Crypt_Spy_analz_bad";
paulson@2318
    99
paulson@3442
   100
(*Prove that the agent is uncompromised by the confidentiality of 
paulson@3442
   101
  a component of a message she's said.*)
paulson@3683
   102
fun not_bad_tac s =
paulson@3683
   103
    case_tac ("(" ^ s ^ ") : bad") THEN'
paulson@3442
   104
    SELECT_GOAL 
paulson@3683
   105
      (REPEAT_DETERM (dtac (Says_imp_spies RS analz.Inj) 1) THEN
paulson@3442
   106
       REPEAT_DETERM (etac MPair_analz 1) THEN
paulson@3442
   107
       THEN_BEST_FIRST 
paulson@3683
   108
         (dres_inst_tac [("A", s)] Crypt_Spy_analz_bad 1 THEN assume_tac 1)
paulson@3442
   109
         (has_fewer_prems 1, size_of_thm)
paulson@3730
   110
         Safe_tac);
paulson@2318
   111
paulson@2318
   112
paulson@2497
   113
(*** Fresh nonces ***)
paulson@2497
   114
paulson@3519
   115
goal thy "Nonce N ~: parts (initState B)";
paulson@3667
   116
by (induct_tac "B" 1);
paulson@4477
   117
by Auto_tac;
paulson@2497
   118
qed "Nonce_notin_initState";
paulson@2497
   119
AddIffs [Nonce_notin_initState];
paulson@2497
   120
paulson@3512
   121
goal thy "Nonce N ~: used []";
wenzelm@4091
   122
by (simp_tac (simpset() addsimps [used_Nil]) 1);
paulson@3512
   123
qed "Nonce_notin_used_empty";
paulson@3512
   124
Addsimps [Nonce_notin_used_empty];
paulson@2497
   125
paulson@2497
   126
paulson@3512
   127
(*** Supply fresh nonces for possibility theorems. ***)
paulson@2516
   128
paulson@3683
   129
(*In any trace, there is an upper bound N on the greatest nonce in use.*)
paulson@3683
   130
goal thy "EX N. ALL n. N<=n --> Nonce n ~: used evs";
paulson@3667
   131
by (induct_tac "evs" 1);
paulson@2497
   132
by (res_inst_tac [("x","0")] exI 1);
paulson@3683
   133
by (ALLGOALS (asm_simp_tac
wenzelm@4091
   134
	      (simpset() addsimps [used_Cons]
nipkow@3919
   135
			addsplits [expand_event_case, expand_if])));
paulson@3730
   136
by Safe_tac;
paulson@3512
   137
by (ALLGOALS (rtac (msg_Nonce_supply RS exE)));
wenzelm@4091
   138
by (ALLGOALS (blast_tac (claset() addSEs [add_leE])));
paulson@2497
   139
val lemma = result();
paulson@2497
   140
paulson@3683
   141
goal thy "EX N. Nonce N ~: used evs";
paulson@3683
   142
by (rtac (lemma RS exE) 1);
paulson@3683
   143
by (Blast_tac 1);
paulson@3683
   144
qed "Nonce_supply1";
paulson@3683
   145
paulson@2497
   146
goal thy "Nonce (@ N. Nonce N ~: used evs) ~: used evs";
paulson@2516
   147
by (rtac (lemma RS exE) 1);
paulson@2516
   148
by (rtac selectI 1);
paulson@2497
   149
by (Fast_tac 1);
paulson@2497
   150
qed "Nonce_supply";
paulson@2497
   151
paulson@2516
   152
(*Tactic for possibility theorems*)
paulson@3544
   153
fun possibility_tac st = st |>
paulson@3673
   154
    REPEAT (*omit used_Says so that Nonces start from different traces!*)
wenzelm@4091
   155
    (ALLGOALS (simp_tac (simpset() delsimps [used_Says] setSolver safe_solver))
paulson@2516
   156
     THEN
paulson@2516
   157
     REPEAT_FIRST (eq_assume_tac ORELSE' 
paulson@2516
   158
                   resolve_tac [refl, conjI, Nonce_supply]));
paulson@2497
   159
paulson@3512
   160
paulson@3512
   161
(*** Specialized rewriting for the analz_image_... theorems ***)
paulson@2318
   162
paulson@3512
   163
goal thy "insert (Key K) H = Key `` {K} Un H";
paulson@3512
   164
by (Blast_tac 1);
paulson@3512
   165
qed "insert_Key_singleton";
paulson@3512
   166
paulson@3512
   167
goal thy "insert (Key K) (Key``KK Un C) = Key `` (insert K KK) Un C";
paulson@3512
   168
by (Blast_tac 1);
paulson@3512
   169
qed "insert_Key_image";
paulson@2318
   170
paulson@3512
   171
(*Reverse the normal simplification of "image" to build up (not break down)
paulson@3512
   172
  the set of keys.  Based on analz_image_freshK_ss, but simpler.*)
paulson@3512
   173
val analz_image_keys_ss = 
wenzelm@4091
   174
     simpset() addcongs [if_weak_cong]
paulson@3673
   175
	      delsimps [image_insert, image_Un]
paulson@3680
   176
              delsimps [imp_disjL]    (*reduces blow-up*)
paulson@3512
   177
              addsimps [image_insert RS sym, image_Un RS sym,
paulson@3512
   178
			rangeI, 
paulson@3512
   179
			insert_Key_singleton, 
paulson@3512
   180
			insert_Key_image, Un_assoc RS sym]
nipkow@3919
   181
              addsplits [expand_if];
paulson@2318
   182