1 (* Title: HOL/Auth/Public
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory
4 Copyright 1996 University of Cambridge
6 Theory of Public Keys (common to all public-key protocols)
8 Private and public keys; initial states of agents
10 theory Public imports Event
16 @{text pubK} maps agents to their public keys. The function
17 @{text priK} maps agents to their private keys. It is merely
18 an abbreviation (cf.\ \S\ref{sec:abbreviations}) defined in terms of
19 @{text invKey} and @{text pubK}.
22 consts pubK :: "agent \<Rightarrow> key"
23 abbreviation priK :: "agent \<Rightarrow> key"
24 where "priK x \<equiv> invKey(pubK x)"
27 (*Agents know their private key and all public keys*)
28 initState_Server: "initState Server =
29 insert (Key (priK Server)) (Key ` range pubK)"
30 initState_Friend: "initState (Friend i) =
31 insert (Key (priK (Friend i))) (Key ` range pubK)"
32 initState_Spy: "initState Spy =
33 (Key`invKey`pubK`bad) Un (Key ` range pubK)"
38 The set @{text bad} consists of those agents whose private keys are known to
41 Two axioms are asserted about the public-key cryptosystem.
42 No two agents have the same public key, and no private key equals
48 priK_neq_pubK: "priK A \<noteq> pubK B"
50 lemmas [iff] = inj_pubK [THEN inj_eq]
52 lemma priK_inj_eq[iff]: "(priK A = priK B) = (A=B)"
54 apply (drule_tac f=invKey in arg_cong)
58 lemmas [iff] = priK_neq_pubK priK_neq_pubK [THEN not_sym]
60 lemma not_symKeys_pubK[iff]: "pubK A \<notin> symKeys"
61 by (simp add: symKeys_def)
63 lemma not_symKeys_priK[iff]: "priK A \<notin> symKeys"
64 by (simp add: symKeys_def)
66 lemma symKeys_neq_imp_neq: "(K \<in> symKeys) \<noteq> (K' \<in> symKeys) \<Longrightarrow> K \<noteq> K'"
69 lemma analz_symKeys_Decrypt: "[| Crypt K X \<in> analz H; K \<in> symKeys; Key K \<in> analz H |]
71 by (auto simp add: symKeys_def)
74 (** "Image" equations that hold for injective functions **)
76 lemma invKey_image_eq[simp]: "(invKey x : invKey`A) = (x:A)"
79 (*holds because invKey is injective*)
80 lemma pubK_image_eq[simp]: "(pubK x : pubK`A) = (x:A)"
83 lemma priK_pubK_image_eq[simp]: "(priK x ~: pubK`A)"
87 (** Rewrites should not refer to initState(Friend i)
88 -- not in normal form! **)
90 lemma keysFor_parts_initState[simp]: "keysFor (parts (initState C)) = {}"
91 apply (unfold keysFor_def)
93 apply (auto intro: range_eqI)
97 (*** Function "spies" ***)
99 (*Agents see their own private keys!*)
100 lemma priK_in_initState[iff]: "Key (priK A) : initState A"
103 (*All public keys are visible*)
104 lemma spies_pubK[iff]: "Key (pubK A) : spies evs"
105 by (induct evs) (simp_all add: imageI knows_Cons split: event.split)
107 (*Spy sees private keys of bad agents!*)
108 lemma Spy_spies_bad[intro!]: "A: bad ==> Key (priK A) : spies evs"
109 by (induct evs) (simp_all add: imageI knows_Cons split: event.split)
111 lemmas [iff] = spies_pubK [THEN analz.Inj]
114 (*** Fresh nonces ***)
116 lemma Nonce_notin_initState[iff]: "Nonce N ~: parts (initState B)"
119 lemma Nonce_notin_used_empty[simp]: "Nonce N ~: used []"
120 by (simp add: used_Nil)
123 (*** Supply fresh nonces for possibility theorems. ***)
125 (*In any trace, there is an upper bound N on the greatest nonce in use.*)
126 lemma Nonce_supply_lemma: "EX N. ALL n. N<=n --> Nonce n \<notin> used evs"
127 apply (induct_tac "evs")
128 apply (rule_tac x = 0 in exI)
129 apply (simp_all (no_asm_simp) add: used_Cons split add: event.split)
131 apply (rule msg_Nonce_supply [THEN exE], blast elim!: add_leE)+
134 lemma Nonce_supply1: "EX N. Nonce N \<notin> used evs"
135 by (rule Nonce_supply_lemma [THEN exE], blast)
137 lemma Nonce_supply: "Nonce (@ N. Nonce N \<notin> used evs) \<notin> used evs"
138 apply (rule Nonce_supply_lemma [THEN exE])
139 apply (rule someI, fast)
143 (*** Specialized rewriting for the analz_image_... theorems ***)
145 lemma insert_Key_singleton: "insert (Key K) H = Key ` {K} Un H"
148 lemma insert_Key_image: "insert (Key K) (Key`KK Un C) = Key ` (insert K KK) Un C"
152 (*Specialized methods*)
154 (*Tactic for possibility theorems*)
156 fun possibility_tac st = st |>
157 REPEAT (*omit used_Says so that Nonces start from different traces!*)
158 (ALLGOALS (simp_tac (@{simpset} delsimps [used_Says]))
160 REPEAT_FIRST (eq_assume_tac ORELSE'
161 resolve_tac [refl, conjI, @{thm Nonce_supply}]));
164 method_setup possibility = {* Method.no_args (SIMPLE_METHOD possibility_tac) *}
165 "for proving possibility theorems"