src/HOL/Auth/Guard/GuardK.thy
changeset 67613 ce654b0e6d69
parent 62390 842917225d56
child 69597 ff784d5a5bfb
equal deleted inserted replaced
67610:4939494ed791 67613:ce654b0e6d69
    21 
    21 
    22 inductive_set
    22 inductive_set
    23   guardK :: "nat => key set => msg set"
    23   guardK :: "nat => key set => msg set"
    24   for n :: nat and Ks :: "key set"
    24   for n :: nat and Ks :: "key set"
    25 where
    25 where
    26   No_Key [intro]: "Key n ~:parts {X} ==> X:guardK n Ks"
    26   No_Key [intro]: "Key n \<notin> parts {X} \<Longrightarrow> X \<in> guardK n Ks"
    27 | Guard_Key [intro]: "invKey K:Ks ==> Crypt K X:guardK n Ks"
    27 | Guard_Key [intro]: "invKey K \<in> Ks ==> Crypt K X \<in> guardK n Ks"
    28 | Crypt [intro]: "X:guardK n Ks ==> Crypt K X:guardK n Ks"
    28 | Crypt [intro]: "X \<in> guardK n Ks \<Longrightarrow> Crypt K X \<in> guardK n Ks"
    29 | Pair [intro]: "[| X:guardK n Ks; Y:guardK n Ks |] ==> \<lbrace>X,Y\<rbrace>:guardK n Ks"
    29 | Pair [intro]: "[| X \<in> guardK n Ks; Y \<in> guardK n Ks |] ==> \<lbrace>X,Y\<rbrace> \<in> guardK n Ks"
    30 
    30 
    31 subsection\<open>basic facts about @{term guardK}\<close>
    31 subsection\<open>basic facts about @{term guardK}\<close>
    32 
    32 
    33 lemma Nonce_is_guardK [iff]: "Nonce p:guardK n Ks"
    33 lemma Nonce_is_guardK [iff]: "Nonce p \<in> guardK n Ks"
    34 by auto
    34 by auto
    35 
    35 
    36 lemma Agent_is_guardK [iff]: "Agent A:guardK n Ks"
    36 lemma Agent_is_guardK [iff]: "Agent A \<in> guardK n Ks"
    37 by auto
    37 by auto
    38 
    38 
    39 lemma Number_is_guardK [iff]: "Number r:guardK n Ks"
    39 lemma Number_is_guardK [iff]: "Number r \<in> guardK n Ks"
    40 by auto
    40 by auto
    41 
    41 
    42 lemma Key_notin_guardK: "X:guardK n Ks ==> X ~= Key n"
    42 lemma Key_notin_guardK: "X \<in> guardK n Ks \<Longrightarrow> X \<noteq> Key n"
    43 by (erule guardK.induct, auto)
    43 by (erule guardK.induct, auto)
    44 
    44 
    45 lemma Key_notin_guardK_iff [iff]: "Key n ~:guardK n Ks"
    45 lemma Key_notin_guardK_iff [iff]: "Key n \<notin> guardK n Ks"
    46 by (auto dest: Key_notin_guardK)
    46 by (auto dest: Key_notin_guardK)
    47 
    47 
    48 lemma guardK_has_Crypt [rule_format]: "X:guardK n Ks ==> Key n:parts {X}
    48 lemma guardK_has_Crypt [rule_format]: "X \<in> guardK n Ks \<Longrightarrow> Key n \<in> parts {X}
    49 --> (EX K Y. Crypt K Y:kparts {X} & Key n:parts {Y})"
    49 \<longrightarrow> (\<exists>K Y. Crypt K Y \<in> kparts {X} \<and> Key n \<in> parts {Y})"
    50 by (erule guardK.induct, auto)
    50 by (erule guardK.induct, auto)
    51 
    51 
    52 lemma Key_notin_kparts_msg: "X:guardK n Ks ==> Key n ~:kparts {X}"
    52 lemma Key_notin_kparts_msg: "X \<in> guardK n Ks \<Longrightarrow> Key n \<notin> kparts {X}"
    53 by (erule guardK.induct, auto dest: kparts_parts)
    53 by (erule guardK.induct, auto dest: kparts_parts)
    54 
    54 
    55 lemma Key_in_kparts_imp_no_guardK: "Key n:kparts H
    55 lemma Key_in_kparts_imp_no_guardK: "Key n \<in> kparts H
    56 ==> EX X. X:H & X ~:guardK n Ks"
    56 \<Longrightarrow> \<exists>X. X \<in> H \<and> X \<notin> guardK n Ks"
    57 apply (drule in_kparts, clarify)
    57 apply (drule in_kparts, clarify)
    58 apply (rule_tac x=X in exI, clarify)
    58 apply (rule_tac x=X in exI, clarify)
    59 by (auto dest: Key_notin_kparts_msg)
    59 by (auto dest: Key_notin_kparts_msg)
    60 
    60 
    61 lemma guardK_kparts [rule_format]: "X:guardK n Ks ==>
    61 lemma guardK_kparts [rule_format]: "X \<in> guardK n Ks \<Longrightarrow>
    62 Y:kparts {X} --> Y:guardK n Ks"
    62 Y \<in> kparts {X} \<longrightarrow> Y \<in> guardK n Ks"
    63 by (erule guardK.induct, auto dest: kparts_parts parts_sub)
    63 by (erule guardK.induct, auto dest: kparts_parts parts_sub)
    64 
    64 
    65 lemma guardK_Crypt: "[| Crypt K Y:guardK n Ks; K ~:invKey`Ks |] ==> Y:guardK n Ks"
    65 lemma guardK_Crypt: "[| Crypt K Y \<in> guardK n Ks; K \<notin> invKey`Ks |] ==> Y \<in> guardK n Ks"
    66   by (ind_cases "Crypt K Y:guardK n Ks") (auto intro!: image_eqI)
    66   by (ind_cases "Crypt K Y \<in> guardK n Ks") (auto intro!: image_eqI)
    67 
    67 
    68 lemma guardK_MPair [iff]: "(\<lbrace>X,Y\<rbrace>:guardK n Ks)
    68 lemma guardK_MPair [iff]: "(\<lbrace>X,Y\<rbrace> \<in> guardK n Ks)
    69 = (X:guardK n Ks & Y:guardK n Ks)"
    69 = (X \<in> guardK n Ks \<and> Y \<in> guardK n Ks)"
    70 by (auto, (ind_cases "\<lbrace>X,Y\<rbrace>:guardK n Ks", auto)+)
    70 by (auto, (ind_cases "\<lbrace>X,Y\<rbrace> \<in> guardK n Ks", auto)+)
    71 
    71 
    72 lemma guardK_not_guardK [rule_format]: "X:guardK n Ks ==>
    72 lemma guardK_not_guardK [rule_format]: "X \<in>guardK n Ks \<Longrightarrow>
    73 Crypt K Y:kparts {X} --> Key n:kparts {Y} --> Y ~:guardK n Ks"
    73 Crypt K Y \<in> kparts {X} \<longrightarrow> Key n \<in> kparts {Y} \<longrightarrow> Y \<notin> guardK n Ks"
    74 by (erule guardK.induct, auto dest: guardK_kparts)
    74 by (erule guardK.induct, auto dest: guardK_kparts)
    75 
    75 
    76 lemma guardK_extand: "[| X:guardK n Ks; Ks <= Ks';
    76 lemma guardK_extand: "[| X \<in> guardK n Ks; Ks \<subseteq> Ks';
    77 [| K:Ks'; K ~:Ks |] ==> Key K ~:parts {X} |] ==> X:guardK n Ks'"
    77 [| K \<in> Ks'; K \<notin> Ks |] ==> Key K \<notin> parts {X} |] ==> X \<in> guardK n Ks'"
    78 by (erule guardK.induct, auto)
    78 by (erule guardK.induct, auto)
    79 
    79 
    80 subsection\<open>guarded sets\<close>
    80 subsection\<open>guarded sets\<close>
    81 
    81 
    82 definition GuardK :: "nat => key set => msg set => bool" where
    82 definition GuardK :: "nat \<Rightarrow> key set \<Rightarrow> msg set \<Rightarrow> bool" where
    83 "GuardK n Ks H == ALL X. X:H --> X:guardK n Ks"
    83 "GuardK n Ks H \<equiv> \<forall>X. X \<in> H \<longrightarrow> X \<in> guardK n Ks"
    84 
    84 
    85 subsection\<open>basic facts about @{term GuardK}\<close>
    85 subsection\<open>basic facts about @{term GuardK}\<close>
    86 
    86 
    87 lemma GuardK_empty [iff]: "GuardK n Ks {}"
    87 lemma GuardK_empty [iff]: "GuardK n Ks {}"
    88 by (simp add: GuardK_def)
    88 by (simp add: GuardK_def)
    89 
    89 
    90 lemma Key_notin_kparts [simplified]: "GuardK n Ks H ==> Key n ~:kparts H"
    90 lemma Key_notin_kparts [simplified]: "GuardK n Ks H \<Longrightarrow> Key n \<notin> kparts H"
    91 by (auto simp: GuardK_def dest: in_kparts Key_notin_kparts_msg)
    91 by (auto simp: GuardK_def dest: in_kparts Key_notin_kparts_msg)
    92 
    92 
    93 lemma GuardK_must_decrypt: "[| GuardK n Ks H; Key n:analz H |] ==>
    93 lemma GuardK_must_decrypt: "[| GuardK n Ks H; Key n \<in> analz H |] ==>
    94 EX K Y. Crypt K Y:kparts H & Key (invKey K):kparts H"
    94 \<exists>K Y. Crypt K Y \<in> kparts H \<and> Key (invKey K) \<in> kparts H"
    95 apply (drule_tac P="%G. Key n:G" in analz_pparts_kparts_substD, simp)
    95 apply (drule_tac P="\<lambda>G. Key n \<in> G" in analz_pparts_kparts_substD, simp)
    96 by (drule must_decrypt, auto dest: Key_notin_kparts)
    96 by (drule must_decrypt, auto dest: Key_notin_kparts)
    97 
    97 
    98 lemma GuardK_kparts [intro]: "GuardK n Ks H ==> GuardK n Ks (kparts H)"
    98 lemma GuardK_kparts [intro]: "GuardK n Ks H \<Longrightarrow> GuardK n Ks (kparts H)"
    99 by (auto simp: GuardK_def dest: in_kparts guardK_kparts)
    99 by (auto simp: GuardK_def dest: in_kparts guardK_kparts)
   100 
   100 
   101 lemma GuardK_mono: "[| GuardK n Ks H; G <= H |] ==> GuardK n Ks G"
   101 lemma GuardK_mono: "[| GuardK n Ks H; G \<subseteq> H |] ==> GuardK n Ks G"
   102 by (auto simp: GuardK_def)
   102 by (auto simp: GuardK_def)
   103 
   103 
   104 lemma GuardK_insert [iff]: "GuardK n Ks (insert X H)
   104 lemma GuardK_insert [iff]: "GuardK n Ks (insert X H)
   105 = (GuardK n Ks H & X:guardK n Ks)"
   105 = (GuardK n Ks H \<and> X \<in> guardK n Ks)"
   106 by (auto simp: GuardK_def)
   106 by (auto simp: GuardK_def)
   107 
   107 
   108 lemma GuardK_Un [iff]: "GuardK n Ks (G Un H) = (GuardK n Ks G & GuardK n Ks H)"
   108 lemma GuardK_Un [iff]: "GuardK n Ks (G Un H) = (GuardK n Ks G & GuardK n Ks H)"
   109 by (auto simp: GuardK_def)
   109 by (auto simp: GuardK_def)
   110 
   110 
   111 lemma GuardK_synth [intro]: "GuardK n Ks G ==> GuardK n Ks (synth G)"
   111 lemma GuardK_synth [intro]: "GuardK n Ks G \<Longrightarrow> GuardK n Ks (synth G)"
   112 by (auto simp: GuardK_def, erule synth.induct, auto)
   112 by (auto simp: GuardK_def, erule synth.induct, auto)
   113 
   113 
   114 lemma GuardK_analz [intro]: "[| GuardK n Ks G; ALL K. K:Ks --> Key K ~:analz G |]
   114 lemma GuardK_analz [intro]: "[| GuardK n Ks G; \<forall>K. K \<in> Ks \<longrightarrow> Key K \<notin> analz G |]
   115 ==> GuardK n Ks (analz G)"
   115 ==> GuardK n Ks (analz G)"
   116 apply (auto simp: GuardK_def)
   116 apply (auto simp: GuardK_def)
   117 apply (erule analz.induct, auto)
   117 apply (erule analz.induct, auto)
   118 by (ind_cases "Crypt K Xa:guardK n Ks" for K Xa, auto)
   118 by (ind_cases "Crypt K Xa \<in> guardK n Ks" for K Xa, auto)
   119 
   119 
   120 lemma in_GuardK [dest]: "[| X:G; GuardK n Ks G |] ==> X:guardK n Ks"
   120 lemma in_GuardK [dest]: "[| X \<in> G; GuardK n Ks G |] ==> X \<in> guardK n Ks"
   121 by (auto simp: GuardK_def)
   121 by (auto simp: GuardK_def)
   122 
   122 
   123 lemma in_synth_GuardK: "[| X:synth G; GuardK n Ks G |] ==> X:guardK n Ks"
   123 lemma in_synth_GuardK: "[| X \<in> synth G; GuardK n Ks G |] ==> X \<in> guardK n Ks"
   124 by (drule GuardK_synth, auto)
   124 by (drule GuardK_synth, auto)
   125 
   125 
   126 lemma in_analz_GuardK: "[| X:analz G; GuardK n Ks G;
   126 lemma in_analz_GuardK: "[| X \<in> analz G; GuardK n Ks G;
   127 ALL K. K:Ks --> Key K ~:analz G |] ==> X:guardK n Ks"
   127 \<forall>K. K \<in> Ks \<longrightarrow> Key K \<notin> analz G |] ==> X \<in> guardK n Ks"
   128 by (drule GuardK_analz, auto)
   128 by (drule GuardK_analz, auto)
   129 
   129 
   130 lemma GuardK_keyset [simp]: "[| keyset G; Key n ~:G |] ==> GuardK n Ks G"
   130 lemma GuardK_keyset [simp]: "[| keyset G; Key n \<notin> G |] ==> GuardK n Ks G"
   131 by (simp only: GuardK_def, clarify, drule keyset_in, auto)
   131 by (simp only: GuardK_def, clarify, drule keyset_in, auto)
   132 
   132 
   133 lemma GuardK_Un_keyset: "[| GuardK n Ks G; keyset H; Key n ~:H |]
   133 lemma GuardK_Un_keyset: "[| GuardK n Ks G; keyset H; Key n \<notin> H |]
   134 ==> GuardK n Ks (G Un H)"
   134 ==> GuardK n Ks (G Un H)"
   135 by auto
   135 by auto
   136 
   136 
   137 lemma in_GuardK_kparts: "[| X:G; GuardK n Ks G; Y:kparts {X} |] ==> Y:guardK n Ks"
   137 lemma in_GuardK_kparts: "[| X \<in> G; GuardK n Ks G; Y \<in> kparts {X} |] ==> Y \<in> guardK n Ks"
   138 by blast
   138 by blast
   139 
   139 
   140 lemma in_GuardK_kparts_neq: "[| X:G; GuardK n Ks G; Key n':kparts {X} |]
   140 lemma in_GuardK_kparts_neq: "[| X \<in> G; GuardK n Ks G; Key n' \<in> kparts {X} |]
   141 ==> n ~= n'"
   141 ==> n \<noteq> n'"
   142 by (blast dest: in_GuardK_kparts)
   142 by (blast dest: in_GuardK_kparts)
   143 
   143 
   144 lemma in_GuardK_kparts_Crypt: "[| X:G; GuardK n Ks G; is_MPair X;
   144 lemma in_GuardK_kparts_Crypt: "[| X \<in> G; GuardK n Ks G; is_MPair X;
   145 Crypt K Y:kparts {X}; Key n:kparts {Y} |] ==> invKey K:Ks"
   145 Crypt K Y \<in> kparts {X}; Key n \<in> kparts {Y} |] ==> invKey K \<in> Ks"
   146 apply (drule in_GuardK, simp)
   146 apply (drule in_GuardK, simp)
   147 apply (frule guardK_not_guardK, simp+)
   147 apply (frule guardK_not_guardK, simp+)
   148 apply (drule guardK_kparts, simp)
   148 apply (drule guardK_kparts, simp)
   149 by (ind_cases "Crypt K Y:guardK n Ks", auto)
   149 by (ind_cases "Crypt K Y \<in> guardK n Ks", auto)
   150 
   150 
   151 lemma GuardK_extand: "[| GuardK n Ks G; Ks <= Ks';
   151 lemma GuardK_extand: "[| GuardK n Ks G; Ks \<subseteq> Ks';
   152 [| K:Ks'; K ~:Ks |] ==> Key K ~:parts G |] ==> GuardK n Ks' G"
   152 [| K \<in> Ks'; K \<notin> Ks |] ==> Key K \<notin> parts G |] ==> GuardK n Ks' G"
   153 by (auto simp: GuardK_def dest: guardK_extand parts_sub)
   153 by (auto simp: GuardK_def dest: guardK_extand parts_sub)
   154 
   154 
   155 subsection\<open>set obtained by decrypting a message\<close>
   155 subsection\<open>set obtained by decrypting a message\<close>
   156 
   156 
   157 abbreviation (input)
   157 abbreviation (input)
   158   decrypt :: "msg set => key => msg => msg set" where
   158   decrypt :: "msg set \<Rightarrow> key \<Rightarrow> msg \<Rightarrow> msg set" where
   159   "decrypt H K Y == insert Y (H - {Crypt K Y})"
   159   "decrypt H K Y \<equiv> insert Y (H - {Crypt K Y})"
   160 
   160 
   161 lemma analz_decrypt: "[| Crypt K Y:H; Key (invKey K):H; Key n:analz H |]
   161 lemma analz_decrypt: "[| Crypt K Y \<in> H; Key (invKey K) \<in> H; Key n \<in> analz H |]
   162 ==> Key n:analz (decrypt H K Y)"
   162 ==> Key n \<in> analz (decrypt H K Y)"
   163 apply (drule_tac P="%H. Key n:analz H" in ssubst [OF insert_Diff])
   163 apply (drule_tac P="\<lambda>H. Key n \<in> analz H" in ssubst [OF insert_Diff])
   164 apply assumption 
   164 apply assumption 
   165 apply (simp only: analz_Crypt_if, simp)
   165 apply (simp only: analz_Crypt_if, simp)
   166 done
   166 done
   167 
   167 
   168 lemma parts_decrypt: "[| Crypt K Y:H; X:parts (decrypt H K Y) |] ==> X:parts H"
   168 lemma parts_decrypt: "[| Crypt K Y \<in> H; X \<in> parts (decrypt H K Y) |] ==> X \<in> parts H"
   169 by (erule parts.induct, auto intro: parts.Fst parts.Snd parts.Body)
   169 by (erule parts.induct, auto intro: parts.Fst parts.Snd parts.Body)
   170 
   170 
   171 subsection\<open>number of Crypt's in a message\<close>
   171 subsection\<open>number of Crypt's in a message\<close>
   172 
   172 
   173 fun crypt_nb :: "msg => nat" where
   173 fun crypt_nb :: "msg => nat" where
   175 "crypt_nb \<lbrace>X,Y\<rbrace> = crypt_nb X + crypt_nb Y" |
   175 "crypt_nb \<lbrace>X,Y\<rbrace> = crypt_nb X + crypt_nb Y" |
   176 "crypt_nb X = 0" (* otherwise *)
   176 "crypt_nb X = 0" (* otherwise *)
   177 
   177 
   178 subsection\<open>basic facts about @{term crypt_nb}\<close>
   178 subsection\<open>basic facts about @{term crypt_nb}\<close>
   179 
   179 
   180 lemma non_empty_crypt_msg: "Crypt K Y:parts {X} ==> crypt_nb X \<noteq> 0"
   180 lemma non_empty_crypt_msg: "Crypt K Y \<in> parts {X} \<Longrightarrow> crypt_nb X \<noteq> 0"
   181 by (induct X, simp_all, safe, simp_all)
   181 by (induct X, simp_all, safe, simp_all)
   182 
   182 
   183 subsection\<open>number of Crypt's in a message list\<close>
   183 subsection\<open>number of Crypt's in a message list\<close>
   184 
   184 
   185 primrec cnb :: "msg list => nat" where
   185 primrec cnb :: "msg list => nat" where
   198 
   198 
   199 lemma cnb_minus [simp]: "x \<in> set l ==> cnb (remove l x) = cnb l - crypt_nb x"
   199 lemma cnb_minus [simp]: "x \<in> set l ==> cnb (remove l x) = cnb l - crypt_nb x"
   200 apply (induct l, auto)
   200 apply (induct l, auto)
   201 by (erule_tac l=l and x=x in mem_cnb_minus_substI, simp)
   201 by (erule_tac l=l and x=x in mem_cnb_minus_substI, simp)
   202 
   202 
   203 lemma parts_cnb: "Z:parts (set l) ==>
   203 lemma parts_cnb: "Z \<in> parts (set l) \<Longrightarrow>
   204 cnb l = (cnb l - crypt_nb Z) + crypt_nb Z"
   204 cnb l = (cnb l - crypt_nb Z) + crypt_nb Z"
   205 by (erule parts.induct, auto simp: in_set_conv_decomp)
   205 by (erule parts.induct, auto simp: in_set_conv_decomp)
   206 
   206 
   207 lemma non_empty_crypt: "Crypt K Y:parts (set l) ==> cnb l \<noteq> 0"
   207 lemma non_empty_crypt: "Crypt K Y \<in> parts (set l) \<Longrightarrow> cnb l \<noteq> 0"
   208 by (induct l, auto dest: non_empty_crypt_msg parts_insert_substD)
   208 by (induct l, auto dest: non_empty_crypt_msg parts_insert_substD)
   209 
   209 
   210 subsection\<open>list of kparts\<close>
   210 subsection\<open>list of kparts\<close>
   211 
   211 
   212 lemma kparts_msg_set: "EX l. kparts {X} = set l & cnb l = crypt_nb X"
   212 lemma kparts_msg_set: "\<exists>l. kparts {X} = set l \<and> cnb l = crypt_nb X"
   213 apply (induct X, simp_all)
   213 apply (induct X, simp_all)
   214 apply (rename_tac agent, rule_tac x="[Agent agent]" in exI, simp)
   214 apply (rename_tac agent, rule_tac x="[Agent agent]" in exI, simp)
   215 apply (rename_tac nat, rule_tac x="[Number nat]" in exI, simp)
   215 apply (rename_tac nat, rule_tac x="[Number nat]" in exI, simp)
   216 apply (rename_tac nat, rule_tac x="[Nonce nat]" in exI, simp)
   216 apply (rename_tac nat, rule_tac x="[Nonce nat]" in exI, simp)
   217 apply (rename_tac nat, rule_tac x="[Key nat]" in exI, simp)
   217 apply (rename_tac nat, rule_tac x="[Key nat]" in exI, simp)
   218 apply (rule_tac x="[Hash X]" in exI, simp)
   218 apply (rule_tac x="[Hash X]" in exI, simp)
   219 apply (clarify, rule_tac x="l@la" in exI, simp)
   219 apply (clarify, rule_tac x="l@la" in exI, simp)
   220 by (clarify, rename_tac nat X y, rule_tac x="[Crypt nat X]" in exI, simp)
   220 by (clarify, rename_tac nat X y, rule_tac x="[Crypt nat X]" in exI, simp)
   221 
   221 
   222 lemma kparts_set: "EX l'. kparts (set l) = set l' & cnb l' = cnb l"
   222 lemma kparts_set: "\<exists>l'. kparts (set l) = set l' & cnb l' = cnb l"
   223 apply (induct l)
   223 apply (induct l)
   224 apply (rule_tac x="[]" in exI, simp, clarsimp)
   224 apply (rule_tac x="[]" in exI, simp, clarsimp)
   225 apply (rename_tac a b l')
   225 apply (rename_tac a b l')
   226 apply (subgoal_tac "EX l''.  kparts {a} = set l'' & cnb l'' = crypt_nb a", clarify)
   226 apply (subgoal_tac "\<exists>l''.  kparts {a} = set l'' & cnb l'' = crypt_nb a", clarify)
   227 apply (rule_tac x="l''@l'" in exI, simp)
   227 apply (rule_tac x="l''@l'" in exI, simp)
   228 apply (rule kparts_insert_substI, simp)
   228 apply (rule kparts_insert_substI, simp)
   229 by (rule kparts_msg_set)
   229 by (rule kparts_msg_set)
   230 
   230 
   231 subsection\<open>list corresponding to "decrypt"\<close>
   231 subsection\<open>list corresponding to "decrypt"\<close>
   241 by (induct l, auto)
   241 by (induct l, auto)
   242 
   242 
   243 text\<open>if the analysis of a finite guarded set gives n then it must also give
   243 text\<open>if the analysis of a finite guarded set gives n then it must also give
   244 one of the keys of Ks\<close>
   244 one of the keys of Ks\<close>
   245 
   245 
   246 lemma GuardK_invKey_by_list [rule_format]: "ALL l. cnb l = p
   246 lemma GuardK_invKey_by_list [rule_format]: "\<forall>l. cnb l = p
   247 --> GuardK n Ks (set l) --> Key n:analz (set l)
   247 \<longrightarrow> GuardK n Ks (set l) \<longrightarrow> Key n \<in> analz (set l)
   248 --> (EX K. K:Ks & Key K:analz (set l))"
   248 \<longrightarrow> (\<exists>K. K \<in> Ks \<and> Key K \<in> analz (set l))"
   249 apply (induct p)
   249 apply (induct p)
   250 (* case p=0 *)
   250 (* case p=0 *)
   251 apply (clarify, drule GuardK_must_decrypt, simp, clarify)
   251 apply (clarify, drule GuardK_must_decrypt, simp, clarify)
   252 apply (drule kparts_parts, drule non_empty_crypt, simp)
   252 apply (drule kparts_parts, drule non_empty_crypt, simp)
   253 (* case p>0 *)
   253 (* case p>0 *)
   254 apply (clarify, frule GuardK_must_decrypt, simp, clarify)
   254 apply (clarify, frule GuardK_must_decrypt, simp, clarify)
   255 apply (drule_tac P="%G. Key n:G" in analz_pparts_kparts_substD, simp)
   255 apply (drule_tac P="\<lambda>G. Key n \<in> G" in analz_pparts_kparts_substD, simp)
   256 apply (frule analz_decrypt, simp_all)
   256 apply (frule analz_decrypt, simp_all)
   257 apply (subgoal_tac "EX l'. kparts (set l) = set l' & cnb l' = cnb l", clarsimp)
   257 apply (subgoal_tac "\<exists>l'. kparts (set l) = set l' \<and> cnb l' = cnb l", clarsimp)
   258 apply (drule_tac G="insert Y (set l' - {Crypt K Y})"
   258 apply (drule_tac G="insert Y (set l' - {Crypt K Y})"
   259 and H="set (decrypt' l' K Y)" in analz_sub, rule decrypt_minus)
   259 and H="set (decrypt' l' K Y)" in analz_sub, rule decrypt_minus)
   260 apply (rule_tac analz_pparts_kparts_substI, simp)
   260 apply (rule_tac analz_pparts_kparts_substI, simp)
   261 apply (case_tac "K:invKey`Ks")
   261 apply (case_tac "K \<in> invKey`Ks")
   262 (* K:invKey`Ks *)
   262 (* K:invKey`Ks *)
   263 apply (clarsimp, blast)
   263 apply (clarsimp, blast)
   264 (* K ~:invKey`Ks *)
   264 (* K ~:invKey`Ks *)
   265 apply (subgoal_tac "GuardK n Ks (set (decrypt' l' K Y))")
   265 apply (subgoal_tac "GuardK n Ks (set (decrypt' l' K Y))")
   266 apply (drule_tac x="decrypt' l' K Y" in spec, simp)
   266 apply (drule_tac x="decrypt' l' K Y" in spec, simp)
   267 apply (subgoal_tac "Crypt K Y:parts (set l)")
   267 apply (subgoal_tac "Crypt K Y \<in> parts (set l)")
   268 apply (drule parts_cnb, rotate_tac -1, simp)
   268 apply (drule parts_cnb, rotate_tac -1, simp)
   269 apply (clarify, drule_tac X="Key Ka" and H="insert Y (set l')" in analz_sub)
   269 apply (clarify, drule_tac X="Key Ka" and H="insert Y (set l')" in analz_sub)
   270 apply (rule insert_mono, rule set_remove)
   270 apply (rule insert_mono, rule set_remove)
   271 apply (simp add: analz_insertD, blast)
   271 apply (simp add: analz_insertD, blast)
   272 (* Crypt K Y:parts (set l) *)
   272 (* Crypt K Y:parts (set l) *)
   278 apply (drule_tac t="set l'" in sym, simp)
   278 apply (drule_tac t="set l'" in sym, simp)
   279 apply (rule GuardK_kparts, simp, simp)
   279 apply (rule GuardK_kparts, simp, simp)
   280 apply (rule_tac B="set l'" in subset_trans, rule set_remove, blast)
   280 apply (rule_tac B="set l'" in subset_trans, rule set_remove, blast)
   281 by (rule kparts_set)
   281 by (rule kparts_set)
   282 
   282 
   283 lemma GuardK_invKey_finite: "[| Key n:analz G; GuardK n Ks G; finite G |]
   283 lemma GuardK_invKey_finite: "[| Key n \<in> analz G; GuardK n Ks G; finite G |]
   284 ==> EX K. K:Ks & Key K:analz G"
   284 ==> \<exists>K. K \<in> Ks \<and> Key K \<in> analz G"
   285 apply (drule finite_list, clarify)
   285 apply (drule finite_list, clarify)
   286 by (rule GuardK_invKey_by_list, auto)
   286 by (rule GuardK_invKey_by_list, auto)
   287 
   287 
   288 lemma GuardK_invKey: "[| Key n:analz G; GuardK n Ks G |]
   288 lemma GuardK_invKey: "[| Key n \<in> analz G; GuardK n Ks G |]
   289 ==> EX K. K:Ks & Key K:analz G"
   289 ==> \<exists>K. K \<in> Ks \<and> Key K \<in> analz G"
   290 by (auto dest: analz_needs_only_finite GuardK_invKey_finite)
   290 by (auto dest: analz_needs_only_finite GuardK_invKey_finite)
   291 
   291 
   292 text\<open>if the analyse of a finite guarded set and a (possibly infinite) set of
   292 text\<open>if the analyse of a finite guarded set and a (possibly infinite) set of
   293 keys gives n then it must also gives Ks\<close>
   293 keys gives n then it must also gives Ks\<close>
   294 
   294 
   295 lemma GuardK_invKey_keyset: "[| Key n:analz (G Un H); GuardK n Ks G; finite G;
   295 lemma GuardK_invKey_keyset: "[| Key n \<in> analz (G \<union> H); GuardK n Ks G; finite G;
   296 keyset H; Key n ~:H |] ==> EX K. K:Ks & Key K:analz (G Un H)"
   296 keyset H; Key n \<notin> H |] ==> \<exists>K. K \<in> Ks \<and> Key K \<in> analz (G \<union> H)"
   297 apply (frule_tac P="%G. Key n:G" and G=G in analz_keyset_substD, simp_all)
   297 apply (frule_tac P="\<lambda>G. Key n \<in> G" and G=G in analz_keyset_substD, simp_all)
   298 apply (drule_tac G="G Un (H Int keysfor G)" in GuardK_invKey_finite)
   298 apply (drule_tac G="G Un (H Int keysfor G)" in GuardK_invKey_finite)
   299 apply (auto simp: GuardK_def intro: analz_sub)
   299 apply (auto simp: GuardK_def intro: analz_sub)
   300 by (drule keyset_in, auto)
   300 by (drule keyset_in, auto)
   301 
   301 
   302 end
   302 end