src/HOL/Auth/Message.thy
author wenzelm
Mon Jan 11 21:21:02 2016 +0100 (2016-01-11)
changeset 62145 5b946c81dfbf
parent 61956 38b73f7940af
child 62343 24106dc44def
permissions -rw-r--r--
eliminated old defs;
wenzelm@37936
     1
(*  Title:      HOL/Auth/Message.thy
paulson@1839
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@1839
     3
    Copyright   1996  University of Cambridge
paulson@1839
     4
paulson@1839
     5
Datatypes of agents and messages;
paulson@1913
     6
Inductive relations "parts", "analz" and "synth"
paulson@1839
     7
*)
paulson@1839
     8
wenzelm@61830
     9
section\<open>Theory of Agents and Messages for Security Protocols\<close>
paulson@13956
    10
haftmann@27105
    11
theory Message
haftmann@27105
    12
imports Main
haftmann@27105
    13
begin
paulson@11189
    14
paulson@11189
    15
(*Needed occasionally with spy_analz_tac, e.g. in analz_insert_Key_newK*)
paulson@13926
    16
lemma [simp] : "A \<union> (B \<union> A) = B \<union> A"
paulson@11189
    17
by blast
paulson@1839
    18
wenzelm@41774
    19
type_synonym
paulson@1839
    20
  key = nat
paulson@1839
    21
paulson@1839
    22
consts
wenzelm@61830
    23
  all_symmetric :: bool        \<comment>\<open>true if all keys are symmetric\<close>
wenzelm@61830
    24
  invKey        :: "key=>key"  \<comment>\<open>inverse of a symmetric key\<close>
paulson@14126
    25
paulson@14126
    26
specification (invKey)
paulson@14181
    27
  invKey [simp]: "invKey (invKey K) = K"
paulson@14181
    28
  invKey_symmetric: "all_symmetric --> invKey = id"
paulson@14126
    29
    by (rule exI [of _ id], auto)
paulson@1839
    30
paulson@14126
    31
wenzelm@61830
    32
text\<open>The inverse of a symmetric key is itself; that of a public key
wenzelm@61830
    33
      is the private key and vice versa\<close>
paulson@1839
    34
haftmann@35416
    35
definition symKeys :: "key set" where
paulson@11230
    36
  "symKeys == {K. invKey K = K}"
paulson@1839
    37
wenzelm@61830
    38
datatype  \<comment>\<open>We allow any number of friendly agents\<close>
paulson@2032
    39
  agent = Server | Friend nat | Spy
paulson@1839
    40
blanchet@58310
    41
datatype
wenzelm@61830
    42
     msg = Agent  agent     \<comment>\<open>Agent names\<close>
wenzelm@61830
    43
         | Number nat       \<comment>\<open>Ordinary integers, timestamps, ...\<close>
wenzelm@61830
    44
         | Nonce  nat       \<comment>\<open>Unguessable nonces\<close>
wenzelm@61830
    45
         | Key    key       \<comment>\<open>Crypto keys\<close>
wenzelm@61830
    46
         | Hash   msg       \<comment>\<open>Hashing\<close>
wenzelm@61830
    47
         | MPair  msg msg   \<comment>\<open>Compound messages\<close>
wenzelm@61830
    48
         | Crypt  key msg   \<comment>\<open>Encryption, public- or shared-key\<close>
paulson@1839
    49
paulson@5234
    50
wenzelm@61956
    51
text\<open>Concrete syntax: messages appear as \<open>\<lbrace>A,B,NA\<rbrace>\<close>, etc...\<close>
paulson@5234
    52
syntax
wenzelm@61956
    53
  "_MTuple" :: "['a, args] \<Rightarrow> 'a * 'b"  ("(2\<lbrace>_,/ _\<rbrace>)")
paulson@1839
    54
translations
wenzelm@61956
    55
  "\<lbrace>x, y, z\<rbrace>" \<rightleftharpoons> "\<lbrace>x, \<lbrace>y, z\<rbrace>\<rbrace>"
wenzelm@61956
    56
  "\<lbrace>x, y\<rbrace>" \<rightleftharpoons> "CONST MPair x y"
paulson@1839
    57
paulson@1839
    58
haftmann@35416
    59
definition HPair :: "[msg,msg] => msg" ("(4Hash[_] /_)" [0, 1000]) where
wenzelm@61830
    60
    \<comment>\<open>Message Y paired with a MAC computed with the help of X\<close>
wenzelm@61956
    61
    "Hash[X] Y == \<lbrace>Hash\<lbrace>X,Y\<rbrace>, Y\<rbrace>"
paulson@2484
    62
haftmann@35416
    63
definition keysFor :: "msg set => key set" where
wenzelm@61830
    64
    \<comment>\<open>Keys useful to decrypt elements of a message set\<close>
paulson@11192
    65
  "keysFor H == invKey ` {K. \<exists>X. Crypt K X \<in> H}"
paulson@1839
    66
paulson@16818
    67
wenzelm@61830
    68
subsubsection\<open>Inductive Definition of All Parts" of a Message\<close>
paulson@1839
    69
berghofe@23746
    70
inductive_set
berghofe@23746
    71
  parts :: "msg set => msg set"
berghofe@23746
    72
  for H :: "msg set"
berghofe@23746
    73
  where
wenzelm@61956
    74
    Inj [intro]: "X \<in> H ==> X \<in> parts H"
wenzelm@61956
    75
  | Fst:         "\<lbrace>X,Y\<rbrace> \<in> parts H ==> X \<in> parts H"
wenzelm@61956
    76
  | Snd:         "\<lbrace>X,Y\<rbrace> \<in> parts H ==> Y \<in> parts H"
berghofe@23746
    77
  | Body:        "Crypt K X \<in> parts H ==> X \<in> parts H"
paulson@11189
    78
paulson@11189
    79
wenzelm@61830
    80
text\<open>Monotonicity\<close>
paulson@16818
    81
lemma parts_mono: "G \<subseteq> H ==> parts(G) \<subseteq> parts(H)"
paulson@11189
    82
apply auto
paulson@11189
    83
apply (erule parts.induct) 
paulson@16818
    84
apply (blast dest: parts.Fst parts.Snd parts.Body)+
paulson@11189
    85
done
paulson@1839
    86
paulson@1839
    87
wenzelm@61830
    88
text\<open>Equations hold because constructors are injective.\<close>
paulson@13926
    89
lemma Friend_image_eq [simp]: "(Friend x \<in> Friend`A) = (x:A)"
paulson@13926
    90
by auto
paulson@13926
    91
paulson@13926
    92
lemma Key_image_eq [simp]: "(Key x \<in> Key`A) = (x\<in>A)"
paulson@13926
    93
by auto
paulson@13926
    94
paulson@13926
    95
lemma Nonce_Key_image_eq [simp]: "(Nonce x \<notin> Key`A)"
paulson@13926
    96
by auto
paulson@13926
    97
paulson@13926
    98
wenzelm@61830
    99
subsubsection\<open>Inverse of keys\<close>
paulson@13926
   100
paulson@13926
   101
lemma invKey_eq [simp]: "(invKey K = invKey K') = (K=K')"
paulson@28698
   102
by (metis invKey)
paulson@13926
   103
paulson@13926
   104
wenzelm@61830
   105
subsection\<open>keysFor operator\<close>
paulson@13926
   106
paulson@13926
   107
lemma keysFor_empty [simp]: "keysFor {} = {}"
paulson@13926
   108
by (unfold keysFor_def, blast)
paulson@13926
   109
paulson@13926
   110
lemma keysFor_Un [simp]: "keysFor (H \<union> H') = keysFor H \<union> keysFor H'"
paulson@13926
   111
by (unfold keysFor_def, blast)
paulson@13926
   112
paulson@13926
   113
lemma keysFor_UN [simp]: "keysFor (\<Union>i\<in>A. H i) = (\<Union>i\<in>A. keysFor (H i))"
paulson@13926
   114
by (unfold keysFor_def, blast)
paulson@13926
   115
wenzelm@61830
   116
text\<open>Monotonicity\<close>
paulson@16818
   117
lemma keysFor_mono: "G \<subseteq> H ==> keysFor(G) \<subseteq> keysFor(H)"
paulson@13926
   118
by (unfold keysFor_def, blast)
paulson@13926
   119
paulson@13926
   120
lemma keysFor_insert_Agent [simp]: "keysFor (insert (Agent A) H) = keysFor H"
paulson@13926
   121
by (unfold keysFor_def, auto)
paulson@13926
   122
paulson@13926
   123
lemma keysFor_insert_Nonce [simp]: "keysFor (insert (Nonce N) H) = keysFor H"
paulson@13926
   124
by (unfold keysFor_def, auto)
paulson@13926
   125
paulson@13926
   126
lemma keysFor_insert_Number [simp]: "keysFor (insert (Number N) H) = keysFor H"
paulson@13926
   127
by (unfold keysFor_def, auto)
paulson@13926
   128
paulson@13926
   129
lemma keysFor_insert_Key [simp]: "keysFor (insert (Key K) H) = keysFor H"
paulson@13926
   130
by (unfold keysFor_def, auto)
paulson@13926
   131
paulson@13926
   132
lemma keysFor_insert_Hash [simp]: "keysFor (insert (Hash X) H) = keysFor H"
paulson@13926
   133
by (unfold keysFor_def, auto)
paulson@13926
   134
wenzelm@61956
   135
lemma keysFor_insert_MPair [simp]: "keysFor (insert \<lbrace>X,Y\<rbrace> H) = keysFor H"
paulson@13926
   136
by (unfold keysFor_def, auto)
paulson@13926
   137
paulson@13926
   138
lemma keysFor_insert_Crypt [simp]: 
paulson@13926
   139
    "keysFor (insert (Crypt K X) H) = insert (invKey K) (keysFor H)"
paulson@14200
   140
by (unfold keysFor_def, auto)
paulson@13926
   141
paulson@13926
   142
lemma keysFor_image_Key [simp]: "keysFor (Key`E) = {}"
paulson@13926
   143
by (unfold keysFor_def, auto)
paulson@13926
   144
paulson@13926
   145
lemma Crypt_imp_invKey_keysFor: "Crypt K X \<in> H ==> invKey K \<in> keysFor H"
paulson@13926
   146
by (unfold keysFor_def, blast)
paulson@13926
   147
paulson@13926
   148
wenzelm@61830
   149
subsection\<open>Inductive relation "parts"\<close>
paulson@13926
   150
paulson@13926
   151
lemma MPair_parts:
wenzelm@61956
   152
     "[| \<lbrace>X,Y\<rbrace> \<in> parts H;        
paulson@13926
   153
         [| X \<in> parts H; Y \<in> parts H |] ==> P |] ==> P"
paulson@13926
   154
by (blast dest: parts.Fst parts.Snd) 
paulson@13926
   155
paulson@13926
   156
declare MPair_parts [elim!]  parts.Body [dest!]
wenzelm@61830
   157
text\<open>NB These two rules are UNSAFE in the formal sense, as they discard the
paulson@13926
   158
     compound message.  They work well on THIS FILE.  
wenzelm@61830
   159
  \<open>MPair_parts\<close> is left as SAFE because it speeds up proofs.
wenzelm@61830
   160
  The Crypt rule is normally kept UNSAFE to avoid breaking up certificates.\<close>
paulson@13926
   161
paulson@13926
   162
lemma parts_increasing: "H \<subseteq> parts(H)"
paulson@13926
   163
by blast
paulson@13926
   164
wenzelm@45605
   165
lemmas parts_insertI = subset_insertI [THEN parts_mono, THEN subsetD]
paulson@13926
   166
paulson@13926
   167
lemma parts_empty [simp]: "parts{} = {}"
paulson@13926
   168
apply safe
paulson@13926
   169
apply (erule parts.induct, blast+)
paulson@13926
   170
done
paulson@13926
   171
paulson@13926
   172
lemma parts_emptyE [elim!]: "X\<in> parts{} ==> P"
paulson@13926
   173
by simp
paulson@13926
   174
wenzelm@61830
   175
text\<open>WARNING: loops if H = {Y}, therefore must not be repeated!\<close>
paulson@13926
   176
lemma parts_singleton: "X\<in> parts H ==> \<exists>Y\<in>H. X\<in> parts {Y}"
berghofe@26807
   177
by (erule parts.induct, fast+)
paulson@13926
   178
paulson@13926
   179
wenzelm@61830
   180
subsubsection\<open>Unions\<close>
paulson@13926
   181
paulson@13926
   182
lemma parts_Un_subset1: "parts(G) \<union> parts(H) \<subseteq> parts(G \<union> H)"
paulson@13926
   183
by (intro Un_least parts_mono Un_upper1 Un_upper2)
paulson@13926
   184
paulson@13926
   185
lemma parts_Un_subset2: "parts(G \<union> H) \<subseteq> parts(G) \<union> parts(H)"
paulson@13926
   186
apply (rule subsetI)
paulson@13926
   187
apply (erule parts.induct, blast+)
paulson@13926
   188
done
paulson@13926
   189
paulson@13926
   190
lemma parts_Un [simp]: "parts(G \<union> H) = parts(G) \<union> parts(H)"
paulson@13926
   191
by (intro equalityI parts_Un_subset1 parts_Un_subset2)
paulson@13926
   192
paulson@13926
   193
lemma parts_insert: "parts (insert X H) = parts {X} \<union> parts H"
paulson@34185
   194
by (metis insert_is_Un parts_Un)
paulson@13926
   195
wenzelm@61830
   196
text\<open>TWO inserts to avoid looping.  This rewrite is better than nothing.
wenzelm@61830
   197
  But its behaviour can be strange.\<close>
paulson@14200
   198
lemma parts_insert2:
paulson@14200
   199
     "parts (insert X (insert Y H)) = parts {X} \<union> parts {Y} \<union> parts H"
paulson@34185
   200
by (metis Un_commute Un_empty_right Un_insert_right insert_is_Un parts_Un)
paulson@13926
   201
paulson@13926
   202
lemma parts_UN_subset1: "(\<Union>x\<in>A. parts(H x)) \<subseteq> parts(\<Union>x\<in>A. H x)"
paulson@13926
   203
by (intro UN_least parts_mono UN_upper)
paulson@13926
   204
paulson@13926
   205
lemma parts_UN_subset2: "parts(\<Union>x\<in>A. H x) \<subseteq> (\<Union>x\<in>A. parts(H x))"
paulson@13926
   206
apply (rule subsetI)
paulson@13926
   207
apply (erule parts.induct, blast+)
paulson@13926
   208
done
paulson@13926
   209
paulson@13926
   210
lemma parts_UN [simp]: "parts(\<Union>x\<in>A. H x) = (\<Union>x\<in>A. parts(H x))"
paulson@13926
   211
by (intro equalityI parts_UN_subset1 parts_UN_subset2)
paulson@13926
   212
wenzelm@61830
   213
text\<open>Added to simplify arguments to parts, analz and synth.
wenzelm@61830
   214
  NOTE: the UN versions are no longer used!\<close>
paulson@13926
   215
paulson@13926
   216
wenzelm@61830
   217
text\<open>This allows \<open>blast\<close> to simplify occurrences of 
wenzelm@61830
   218
  @{term "parts(G\<union>H)"} in the assumption.\<close>
paulson@17729
   219
lemmas in_parts_UnE = parts_Un [THEN equalityD1, THEN subsetD, THEN UnE] 
paulson@17729
   220
declare in_parts_UnE [elim!]
paulson@13926
   221
paulson@13926
   222
paulson@13926
   223
lemma parts_insert_subset: "insert X (parts H) \<subseteq> parts(insert X H)"
paulson@13926
   224
by (blast intro: parts_mono [THEN [2] rev_subsetD])
paulson@13926
   225
wenzelm@61830
   226
subsubsection\<open>Idempotence and transitivity\<close>
paulson@13926
   227
paulson@13926
   228
lemma parts_partsD [dest!]: "X\<in> parts (parts H) ==> X\<in> parts H"
paulson@13926
   229
by (erule parts.induct, blast+)
paulson@13926
   230
paulson@13926
   231
lemma parts_idem [simp]: "parts (parts H) = parts H"
paulson@13926
   232
by blast
paulson@13926
   233
paulson@17689
   234
lemma parts_subset_iff [simp]: "(parts G \<subseteq> parts H) = (G \<subseteq> parts H)"
paulson@35566
   235
by (metis parts_idem parts_increasing parts_mono subset_trans)
paulson@17689
   236
paulson@13926
   237
lemma parts_trans: "[| X\<in> parts G;  G \<subseteq> parts H |] ==> X\<in> parts H"
paulson@41693
   238
by (metis parts_subset_iff set_mp)
paulson@13926
   239
wenzelm@61830
   240
text\<open>Cut\<close>
paulson@14200
   241
lemma parts_cut:
paulson@18492
   242
     "[| Y\<in> parts (insert X G);  X\<in> parts H |] ==> Y\<in> parts (G \<union> H)" 
paulson@18492
   243
by (blast intro: parts_trans) 
paulson@18492
   244
paulson@13926
   245
lemma parts_cut_eq [simp]: "X\<in> parts H ==> parts (insert X H) = parts H"
paulson@41693
   246
by (metis insert_absorb parts_idem parts_insert)
paulson@13926
   247
paulson@13926
   248
wenzelm@61830
   249
subsubsection\<open>Rewrite rules for pulling out atomic messages\<close>
paulson@13926
   250
paulson@13926
   251
lemmas parts_insert_eq_I = equalityI [OF subsetI parts_insert_subset]
paulson@13926
   252
paulson@13926
   253
paulson@14200
   254
lemma parts_insert_Agent [simp]:
paulson@14200
   255
     "parts (insert (Agent agt) H) = insert (Agent agt) (parts H)"
paulson@13926
   256
apply (rule parts_insert_eq_I) 
paulson@13926
   257
apply (erule parts.induct, auto) 
paulson@13926
   258
done
paulson@13926
   259
paulson@14200
   260
lemma parts_insert_Nonce [simp]:
paulson@14200
   261
     "parts (insert (Nonce N) H) = insert (Nonce N) (parts H)"
paulson@13926
   262
apply (rule parts_insert_eq_I) 
paulson@13926
   263
apply (erule parts.induct, auto) 
paulson@13926
   264
done
paulson@13926
   265
paulson@14200
   266
lemma parts_insert_Number [simp]:
paulson@14200
   267
     "parts (insert (Number N) H) = insert (Number N) (parts H)"
paulson@13926
   268
apply (rule parts_insert_eq_I) 
paulson@13926
   269
apply (erule parts.induct, auto) 
paulson@13926
   270
done
paulson@13926
   271
paulson@14200
   272
lemma parts_insert_Key [simp]:
paulson@14200
   273
     "parts (insert (Key K) H) = insert (Key K) (parts H)"
paulson@13926
   274
apply (rule parts_insert_eq_I) 
paulson@13926
   275
apply (erule parts.induct, auto) 
paulson@13926
   276
done
paulson@13926
   277
paulson@14200
   278
lemma parts_insert_Hash [simp]:
paulson@14200
   279
     "parts (insert (Hash X) H) = insert (Hash X) (parts H)"
paulson@13926
   280
apply (rule parts_insert_eq_I) 
paulson@13926
   281
apply (erule parts.induct, auto) 
paulson@13926
   282
done
paulson@13926
   283
paulson@14200
   284
lemma parts_insert_Crypt [simp]:
paulson@17689
   285
     "parts (insert (Crypt K X) H) = insert (Crypt K X) (parts (insert X H))"
paulson@13926
   286
apply (rule equalityI)
paulson@13926
   287
apply (rule subsetI)
paulson@13926
   288
apply (erule parts.induct, auto)
paulson@17689
   289
apply (blast intro: parts.Body)
paulson@13926
   290
done
paulson@13926
   291
paulson@14200
   292
lemma parts_insert_MPair [simp]:
wenzelm@61956
   293
     "parts (insert \<lbrace>X,Y\<rbrace> H) =  
wenzelm@61956
   294
          insert \<lbrace>X,Y\<rbrace> (parts (insert X (insert Y H)))"
paulson@13926
   295
apply (rule equalityI)
paulson@13926
   296
apply (rule subsetI)
paulson@13926
   297
apply (erule parts.induct, auto)
paulson@13926
   298
apply (blast intro: parts.Fst parts.Snd)+
paulson@13926
   299
done
paulson@13926
   300
paulson@13926
   301
lemma parts_image_Key [simp]: "parts (Key`N) = Key`N"
paulson@13926
   302
apply auto
paulson@13926
   303
apply (erule parts.induct, auto)
paulson@13926
   304
done
paulson@13926
   305
paulson@13926
   306
wenzelm@61830
   307
text\<open>In any message, there is an upper bound N on its greatest nonce.\<close>
paulson@13926
   308
lemma msg_Nonce_supply: "\<exists>N. \<forall>n. N\<le>n --> Nonce n \<notin> parts {msg}"
lp15@57394
   309
proof (induct msg)
lp15@57394
   310
  case (Nonce n)
lp15@57394
   311
    show ?case
lp15@57394
   312
      by simp (metis Suc_n_not_le_n)
lp15@57394
   313
next
lp15@57394
   314
  case (MPair X Y)
wenzelm@61830
   315
    then show ?case \<comment>\<open>metis works out the necessary sum itself!\<close>
lp15@57394
   316
      by (simp add: parts_insert2) (metis le_trans nat_le_linear)
lp15@57394
   317
qed auto
paulson@13926
   318
wenzelm@61830
   319
subsection\<open>Inductive relation "analz"\<close>
paulson@13926
   320
wenzelm@61830
   321
text\<open>Inductive definition of "analz" -- what can be broken down from a set of
paulson@1839
   322
    messages, including keys.  A form of downward closure.  Pairs can
wenzelm@61830
   323
    be taken apart; messages decrypted with known keys.\<close>
paulson@1839
   324
berghofe@23746
   325
inductive_set
berghofe@23746
   326
  analz :: "msg set => msg set"
berghofe@23746
   327
  for H :: "msg set"
berghofe@23746
   328
  where
wenzelm@61956
   329
    Inj [intro,simp]: "X \<in> H ==> X \<in> analz H"
wenzelm@61956
   330
  | Fst:     "\<lbrace>X,Y\<rbrace> \<in> analz H ==> X \<in> analz H"
wenzelm@61956
   331
  | Snd:     "\<lbrace>X,Y\<rbrace> \<in> analz H ==> Y \<in> analz H"
berghofe@23746
   332
  | Decrypt [dest]: 
paulson@11192
   333
             "[|Crypt K X \<in> analz H; Key(invKey K): analz H|] ==> X \<in> analz H"
paulson@1839
   334
paulson@1839
   335
wenzelm@61830
   336
text\<open>Monotonicity; Lemma 1 of Lowe's paper\<close>
paulson@14200
   337
lemma analz_mono: "G\<subseteq>H ==> analz(G) \<subseteq> analz(H)"
paulson@11189
   338
apply auto
paulson@11189
   339
apply (erule analz.induct) 
paulson@16818
   340
apply (auto dest: analz.Fst analz.Snd) 
paulson@11189
   341
done
paulson@11189
   342
wenzelm@61830
   343
text\<open>Making it safe speeds up proofs\<close>
paulson@13926
   344
lemma MPair_analz [elim!]:
wenzelm@61956
   345
     "[| \<lbrace>X,Y\<rbrace> \<in> analz H;        
paulson@13926
   346
             [| X \<in> analz H; Y \<in> analz H |] ==> P   
paulson@13926
   347
          |] ==> P"
paulson@13926
   348
by (blast dest: analz.Fst analz.Snd)
paulson@13926
   349
paulson@13926
   350
lemma analz_increasing: "H \<subseteq> analz(H)"
paulson@13926
   351
by blast
paulson@13926
   352
paulson@13926
   353
lemma analz_subset_parts: "analz H \<subseteq> parts H"
paulson@13926
   354
apply (rule subsetI)
paulson@13926
   355
apply (erule analz.induct, blast+)
paulson@13926
   356
done
paulson@13926
   357
wenzelm@45605
   358
lemmas analz_into_parts = analz_subset_parts [THEN subsetD]
paulson@14200
   359
wenzelm@45605
   360
lemmas not_parts_not_analz = analz_subset_parts [THEN contra_subsetD]
paulson@13926
   361
paulson@13926
   362
paulson@13926
   363
lemma parts_analz [simp]: "parts (analz H) = parts H"
paulson@34185
   364
by (metis analz_increasing analz_subset_parts equalityI parts_mono parts_subset_iff)
paulson@13926
   365
paulson@13926
   366
lemma analz_parts [simp]: "analz (parts H) = parts H"
paulson@13926
   367
apply auto
paulson@13926
   368
apply (erule analz.induct, auto)
paulson@13926
   369
done
paulson@13926
   370
wenzelm@45605
   371
lemmas analz_insertI = subset_insertI [THEN analz_mono, THEN [2] rev_subsetD]
paulson@13926
   372
wenzelm@61830
   373
subsubsection\<open>General equational properties\<close>
paulson@13926
   374
paulson@13926
   375
lemma analz_empty [simp]: "analz{} = {}"
paulson@13926
   376
apply safe
paulson@13926
   377
apply (erule analz.induct, blast+)
paulson@13926
   378
done
paulson@13926
   379
wenzelm@61830
   380
text\<open>Converse fails: we can analz more from the union than from the 
wenzelm@61830
   381
  separate parts, as a key in one might decrypt a message in the other\<close>
paulson@13926
   382
lemma analz_Un: "analz(G) \<union> analz(H) \<subseteq> analz(G \<union> H)"
paulson@13926
   383
by (intro Un_least analz_mono Un_upper1 Un_upper2)
paulson@13926
   384
paulson@13926
   385
lemma analz_insert: "insert X (analz H) \<subseteq> analz(insert X H)"
paulson@13926
   386
by (blast intro: analz_mono [THEN [2] rev_subsetD])
paulson@13926
   387
wenzelm@61830
   388
subsubsection\<open>Rewrite rules for pulling out atomic messages\<close>
paulson@13926
   389
paulson@13926
   390
lemmas analz_insert_eq_I = equalityI [OF subsetI analz_insert]
paulson@13926
   391
paulson@14200
   392
lemma analz_insert_Agent [simp]:
paulson@14200
   393
     "analz (insert (Agent agt) H) = insert (Agent agt) (analz H)"
paulson@13926
   394
apply (rule analz_insert_eq_I) 
paulson@13926
   395
apply (erule analz.induct, auto) 
paulson@13926
   396
done
paulson@13926
   397
paulson@14200
   398
lemma analz_insert_Nonce [simp]:
paulson@14200
   399
     "analz (insert (Nonce N) H) = insert (Nonce N) (analz H)"
paulson@13926
   400
apply (rule analz_insert_eq_I) 
paulson@13926
   401
apply (erule analz.induct, auto) 
paulson@13926
   402
done
paulson@13926
   403
paulson@14200
   404
lemma analz_insert_Number [simp]:
paulson@14200
   405
     "analz (insert (Number N) H) = insert (Number N) (analz H)"
paulson@13926
   406
apply (rule analz_insert_eq_I) 
paulson@13926
   407
apply (erule analz.induct, auto) 
paulson@13926
   408
done
paulson@13926
   409
paulson@14200
   410
lemma analz_insert_Hash [simp]:
paulson@14200
   411
     "analz (insert (Hash X) H) = insert (Hash X) (analz H)"
paulson@13926
   412
apply (rule analz_insert_eq_I) 
paulson@13926
   413
apply (erule analz.induct, auto) 
paulson@13926
   414
done
paulson@13926
   415
wenzelm@61830
   416
text\<open>Can only pull out Keys if they are not needed to decrypt the rest\<close>
paulson@13926
   417
lemma analz_insert_Key [simp]: 
paulson@13926
   418
    "K \<notin> keysFor (analz H) ==>   
paulson@13926
   419
          analz (insert (Key K) H) = insert (Key K) (analz H)"
paulson@13926
   420
apply (unfold keysFor_def)
paulson@13926
   421
apply (rule analz_insert_eq_I) 
paulson@13926
   422
apply (erule analz.induct, auto) 
paulson@13926
   423
done
paulson@13926
   424
paulson@14200
   425
lemma analz_insert_MPair [simp]:
wenzelm@61956
   426
     "analz (insert \<lbrace>X,Y\<rbrace> H) =  
wenzelm@61956
   427
          insert \<lbrace>X,Y\<rbrace> (analz (insert X (insert Y H)))"
paulson@13926
   428
apply (rule equalityI)
paulson@13926
   429
apply (rule subsetI)
paulson@13926
   430
apply (erule analz.induct, auto)
paulson@13926
   431
apply (erule analz.induct)
paulson@13926
   432
apply (blast intro: analz.Fst analz.Snd)+
paulson@13926
   433
done
paulson@13926
   434
wenzelm@61830
   435
text\<open>Can pull out enCrypted message if the Key is not known\<close>
paulson@13926
   436
lemma analz_insert_Crypt:
paulson@13926
   437
     "Key (invKey K) \<notin> analz H 
paulson@13926
   438
      ==> analz (insert (Crypt K X) H) = insert (Crypt K X) (analz H)"
paulson@13926
   439
apply (rule analz_insert_eq_I) 
paulson@13926
   440
apply (erule analz.induct, auto) 
paulson@13926
   441
paulson@13926
   442
done
paulson@13926
   443
paulson@13926
   444
lemma lemma1: "Key (invKey K) \<in> analz H ==>   
paulson@13926
   445
               analz (insert (Crypt K X) H) \<subseteq>  
paulson@13926
   446
               insert (Crypt K X) (analz (insert X H))"
paulson@13926
   447
apply (rule subsetI)
berghofe@23746
   448
apply (erule_tac x = x in analz.induct, auto)
paulson@13926
   449
done
paulson@13926
   450
paulson@13926
   451
lemma lemma2: "Key (invKey K) \<in> analz H ==>   
paulson@13926
   452
               insert (Crypt K X) (analz (insert X H)) \<subseteq>  
paulson@13926
   453
               analz (insert (Crypt K X) H)"
paulson@13926
   454
apply auto
berghofe@23746
   455
apply (erule_tac x = x in analz.induct, auto)
paulson@13926
   456
apply (blast intro: analz_insertI analz.Decrypt)
paulson@13926
   457
done
paulson@13926
   458
paulson@14200
   459
lemma analz_insert_Decrypt:
paulson@14200
   460
     "Key (invKey K) \<in> analz H ==>   
paulson@13926
   461
               analz (insert (Crypt K X) H) =  
paulson@13926
   462
               insert (Crypt K X) (analz (insert X H))"
paulson@13926
   463
by (intro equalityI lemma1 lemma2)
paulson@13926
   464
wenzelm@61830
   465
text\<open>Case analysis: either the message is secure, or it is not! Effective,
wenzelm@61830
   466
but can cause subgoals to blow up! Use with \<open>split_if\<close>; apparently
wenzelm@61830
   467
\<open>split_tac\<close> does not cope with patterns such as @{term"analz (insert
wenzelm@61830
   468
(Crypt K X) H)"}\<close> 
paulson@13926
   469
lemma analz_Crypt_if [simp]:
paulson@13926
   470
     "analz (insert (Crypt K X) H) =                 
paulson@13926
   471
          (if (Key (invKey K) \<in> analz H)                 
paulson@13926
   472
           then insert (Crypt K X) (analz (insert X H))  
paulson@13926
   473
           else insert (Crypt K X) (analz H))"
paulson@13926
   474
by (simp add: analz_insert_Crypt analz_insert_Decrypt)
paulson@13926
   475
paulson@13926
   476
wenzelm@61830
   477
text\<open>This rule supposes "for the sake of argument" that we have the key.\<close>
paulson@14200
   478
lemma analz_insert_Crypt_subset:
paulson@14200
   479
     "analz (insert (Crypt K X) H) \<subseteq>   
paulson@13926
   480
           insert (Crypt K X) (analz (insert X H))"
paulson@13926
   481
apply (rule subsetI)
paulson@13926
   482
apply (erule analz.induct, auto)
paulson@13926
   483
done
paulson@13926
   484
paulson@13926
   485
paulson@13926
   486
lemma analz_image_Key [simp]: "analz (Key`N) = Key`N"
paulson@13926
   487
apply auto
paulson@13926
   488
apply (erule analz.induct, auto)
paulson@13926
   489
done
paulson@13926
   490
paulson@13926
   491
wenzelm@61830
   492
subsubsection\<open>Idempotence and transitivity\<close>
paulson@13926
   493
paulson@13926
   494
lemma analz_analzD [dest!]: "X\<in> analz (analz H) ==> X\<in> analz H"
paulson@13926
   495
by (erule analz.induct, blast+)
paulson@13926
   496
paulson@13926
   497
lemma analz_idem [simp]: "analz (analz H) = analz H"
paulson@13926
   498
by blast
paulson@13926
   499
paulson@17689
   500
lemma analz_subset_iff [simp]: "(analz G \<subseteq> analz H) = (G \<subseteq> analz H)"
paulson@34185
   501
by (metis analz_idem analz_increasing analz_mono subset_trans)
paulson@17689
   502
paulson@13926
   503
lemma analz_trans: "[| X\<in> analz G;  G \<subseteq> analz H |] ==> X\<in> analz H"
paulson@13926
   504
by (drule analz_mono, blast)
paulson@13926
   505
wenzelm@61830
   506
text\<open>Cut; Lemma 2 of Lowe\<close>
paulson@13926
   507
lemma analz_cut: "[| Y\<in> analz (insert X H);  X\<in> analz H |] ==> Y\<in> analz H"
paulson@13926
   508
by (erule analz_trans, blast)
paulson@13926
   509
paulson@13926
   510
(*Cut can be proved easily by induction on
paulson@13926
   511
   "Y: analz (insert X H) ==> X: analz H --> Y: analz H"
paulson@13926
   512
*)
paulson@13926
   513
wenzelm@61830
   514
text\<open>This rewrite rule helps in the simplification of messages that involve
paulson@13926
   515
  the forwarding of unknown components (X).  Without it, removing occurrences
wenzelm@61830
   516
  of X can be very complicated.\<close>
paulson@13926
   517
lemma analz_insert_eq: "X\<in> analz H ==> analz (insert X H) = analz H"
paulson@41693
   518
by (metis analz_cut analz_insert_eq_I insert_absorb)
paulson@13926
   519
paulson@13926
   520
wenzelm@61830
   521
text\<open>A congruence rule for "analz"\<close>
paulson@13926
   522
paulson@14200
   523
lemma analz_subset_cong:
paulson@17689
   524
     "[| analz G \<subseteq> analz G'; analz H \<subseteq> analz H' |] 
paulson@17689
   525
      ==> analz (G \<union> H) \<subseteq> analz (G' \<union> H')"
paulson@41693
   526
by (metis Un_mono analz_Un analz_subset_iff subset_trans)
paulson@13926
   527
paulson@14200
   528
lemma analz_cong:
paulson@17689
   529
     "[| analz G = analz G'; analz H = analz H' |] 
paulson@17689
   530
      ==> analz (G \<union> H) = analz (G' \<union> H')"
paulson@14200
   531
by (intro equalityI analz_subset_cong, simp_all) 
paulson@13926
   532
paulson@14200
   533
lemma analz_insert_cong:
paulson@14200
   534
     "analz H = analz H' ==> analz(insert X H) = analz(insert X H')"
paulson@13926
   535
by (force simp only: insert_def intro!: analz_cong)
paulson@13926
   536
wenzelm@61830
   537
text\<open>If there are no pairs or encryptions then analz does nothing\<close>
paulson@14200
   538
lemma analz_trivial:
wenzelm@61956
   539
     "[| \<forall>X Y. \<lbrace>X,Y\<rbrace> \<notin> H;  \<forall>X K. Crypt K X \<notin> H |] ==> analz H = H"
paulson@13926
   540
apply safe
paulson@13926
   541
apply (erule analz.induct, blast+)
paulson@13926
   542
done
paulson@13926
   543
wenzelm@61830
   544
text\<open>These two are obsolete (with a single Spy) but cost little to prove...\<close>
paulson@14200
   545
lemma analz_UN_analz_lemma:
paulson@14200
   546
     "X\<in> analz (\<Union>i\<in>A. analz (H i)) ==> X\<in> analz (\<Union>i\<in>A. H i)"
paulson@13926
   547
apply (erule analz.induct)
paulson@13926
   548
apply (blast intro: analz_mono [THEN [2] rev_subsetD])+
paulson@13926
   549
done
paulson@13926
   550
paulson@13926
   551
lemma analz_UN_analz [simp]: "analz (\<Union>i\<in>A. analz (H i)) = analz (\<Union>i\<in>A. H i)"
paulson@13926
   552
by (blast intro: analz_UN_analz_lemma analz_mono [THEN [2] rev_subsetD])
paulson@13926
   553
paulson@13926
   554
wenzelm@61830
   555
subsection\<open>Inductive relation "synth"\<close>
paulson@13926
   556
wenzelm@61830
   557
text\<open>Inductive definition of "synth" -- what can be built up from a set of
paulson@1839
   558
    messages.  A form of upward closure.  Pairs can be built, messages
paulson@3668
   559
    encrypted with known keys.  Agent names are public domain.
wenzelm@61830
   560
    Numbers can be guessed, but Nonces cannot be.\<close>
paulson@1839
   561
berghofe@23746
   562
inductive_set
berghofe@23746
   563
  synth :: "msg set => msg set"
berghofe@23746
   564
  for H :: "msg set"
berghofe@23746
   565
  where
paulson@11192
   566
    Inj    [intro]:   "X \<in> H ==> X \<in> synth H"
berghofe@23746
   567
  | Agent  [intro]:   "Agent agt \<in> synth H"
berghofe@23746
   568
  | Number [intro]:   "Number n  \<in> synth H"
berghofe@23746
   569
  | Hash   [intro]:   "X \<in> synth H ==> Hash X \<in> synth H"
wenzelm@61956
   570
  | MPair  [intro]:   "[|X \<in> synth H;  Y \<in> synth H|] ==> \<lbrace>X,Y\<rbrace> \<in> synth H"
berghofe@23746
   571
  | Crypt  [intro]:   "[|X \<in> synth H;  Key(K) \<in> H|] ==> Crypt K X \<in> synth H"
paulson@11189
   572
wenzelm@61830
   573
text\<open>Monotonicity\<close>
paulson@14200
   574
lemma synth_mono: "G\<subseteq>H ==> synth(G) \<subseteq> synth(H)"
paulson@16818
   575
  by (auto, erule synth.induct, auto)  
paulson@11189
   576
wenzelm@61830
   577
text\<open>NO \<open>Agent_synth\<close>, as any Agent name can be synthesized.  
wenzelm@61830
   578
  The same holds for @{term Number}\<close>
paulson@11189
   579
paulson@39216
   580
inductive_simps synth_simps [iff]:
paulson@39216
   581
 "Nonce n \<in> synth H"
paulson@39216
   582
 "Key K \<in> synth H"
paulson@39216
   583
 "Hash X \<in> synth H"
wenzelm@61956
   584
 "\<lbrace>X,Y\<rbrace> \<in> synth H"
paulson@39216
   585
 "Crypt K X \<in> synth H"
paulson@13926
   586
paulson@13926
   587
lemma synth_increasing: "H \<subseteq> synth(H)"
paulson@13926
   588
by blast
paulson@13926
   589
wenzelm@61830
   590
subsubsection\<open>Unions\<close>
paulson@13926
   591
wenzelm@61830
   592
text\<open>Converse fails: we can synth more from the union than from the 
wenzelm@61830
   593
  separate parts, building a compound message using elements of each.\<close>
paulson@13926
   594
lemma synth_Un: "synth(G) \<union> synth(H) \<subseteq> synth(G \<union> H)"
paulson@13926
   595
by (intro Un_least synth_mono Un_upper1 Un_upper2)
paulson@13926
   596
paulson@13926
   597
lemma synth_insert: "insert X (synth H) \<subseteq> synth(insert X H)"
paulson@13926
   598
by (blast intro: synth_mono [THEN [2] rev_subsetD])
paulson@13926
   599
wenzelm@61830
   600
subsubsection\<open>Idempotence and transitivity\<close>
paulson@13926
   601
paulson@13926
   602
lemma synth_synthD [dest!]: "X\<in> synth (synth H) ==> X\<in> synth H"
paulson@39216
   603
by (erule synth.induct, auto)
paulson@13926
   604
paulson@13926
   605
lemma synth_idem: "synth (synth H) = synth H"
paulson@13926
   606
by blast
paulson@13926
   607
paulson@17689
   608
lemma synth_subset_iff [simp]: "(synth G \<subseteq> synth H) = (G \<subseteq> synth H)"
paulson@35566
   609
by (metis subset_trans synth_idem synth_increasing synth_mono)
paulson@17689
   610
paulson@13926
   611
lemma synth_trans: "[| X\<in> synth G;  G \<subseteq> synth H |] ==> X\<in> synth H"
paulson@13926
   612
by (drule synth_mono, blast)
paulson@13926
   613
wenzelm@61830
   614
text\<open>Cut; Lemma 2 of Lowe\<close>
paulson@13926
   615
lemma synth_cut: "[| Y\<in> synth (insert X H);  X\<in> synth H |] ==> Y\<in> synth H"
paulson@13926
   616
by (erule synth_trans, blast)
paulson@13926
   617
paulson@14200
   618
lemma Crypt_synth_eq [simp]:
paulson@14200
   619
     "Key K \<notin> H ==> (Crypt K X \<in> synth H) = (Crypt K X \<in> H)"
paulson@13926
   620
by blast
paulson@13926
   621
paulson@13926
   622
paulson@13926
   623
lemma keysFor_synth [simp]: 
paulson@13926
   624
    "keysFor (synth H) = keysFor H \<union> invKey`{K. Key K \<in> H}"
paulson@14200
   625
by (unfold keysFor_def, blast)
paulson@13926
   626
paulson@13926
   627
wenzelm@61830
   628
subsubsection\<open>Combinations of parts, analz and synth\<close>
paulson@13926
   629
paulson@13926
   630
lemma parts_synth [simp]: "parts (synth H) = parts H \<union> synth H"
paulson@13926
   631
apply (rule equalityI)
paulson@13926
   632
apply (rule subsetI)
paulson@13926
   633
apply (erule parts.induct)
paulson@13926
   634
apply (blast intro: synth_increasing [THEN parts_mono, THEN subsetD] 
paulson@13926
   635
                    parts.Fst parts.Snd parts.Body)+
paulson@13926
   636
done
paulson@13926
   637
paulson@13926
   638
lemma analz_analz_Un [simp]: "analz (analz G \<union> H) = analz (G \<union> H)"
paulson@13926
   639
apply (intro equalityI analz_subset_cong)+
paulson@13926
   640
apply simp_all
paulson@13926
   641
done
paulson@13926
   642
paulson@13926
   643
lemma analz_synth_Un [simp]: "analz (synth G \<union> H) = analz (G \<union> H) \<union> synth G"
paulson@13926
   644
apply (rule equalityI)
paulson@13926
   645
apply (rule subsetI)
paulson@13926
   646
apply (erule analz.induct)
paulson@13926
   647
prefer 5 apply (blast intro: analz_mono [THEN [2] rev_subsetD])
paulson@13926
   648
apply (blast intro: analz.Fst analz.Snd analz.Decrypt)+
paulson@13926
   649
done
paulson@13926
   650
paulson@13926
   651
lemma analz_synth [simp]: "analz (synth H) = analz H \<union> synth H"
paulson@34185
   652
by (metis Un_empty_right analz_synth_Un)
paulson@13926
   653
paulson@13926
   654
wenzelm@61830
   655
subsubsection\<open>For reasoning about the Fake rule in traces\<close>
paulson@13926
   656
paulson@13926
   657
lemma parts_insert_subset_Un: "X\<in> G ==> parts(insert X H) \<subseteq> parts G \<union> parts H"
paulson@34185
   658
by (metis UnCI Un_upper2 insert_subset parts_Un parts_mono)
paulson@13926
   659
wenzelm@61830
   660
text\<open>More specifically for Fake. See also \<open>Fake_parts_sing\<close> below\<close>
paulson@14200
   661
lemma Fake_parts_insert:
paulson@14200
   662
     "X \<in> synth (analz H) ==>  
paulson@13926
   663
      parts (insert X H) \<subseteq> synth (analz H) \<union> parts H"
paulson@34185
   664
by (metis Un_commute analz_increasing insert_subset parts_analz parts_mono 
paulson@34185
   665
          parts_synth synth_mono synth_subset_iff)
paulson@13926
   666
paulson@14200
   667
lemma Fake_parts_insert_in_Un:
paulson@14200
   668
     "[|Z \<in> parts (insert X H);  X: synth (analz H)|] 
paulson@34185
   669
      ==> Z \<in>  synth (analz H) \<union> parts H"
paulson@34185
   670
by (metis Fake_parts_insert set_mp)
paulson@14200
   671
wenzelm@61830
   672
text\<open>@{term H} is sometimes @{term"Key ` KK \<union> spies evs"}, so can't put 
wenzelm@61830
   673
  @{term "G=H"}.\<close>
paulson@14200
   674
lemma Fake_analz_insert:
paulson@14200
   675
     "X\<in> synth (analz G) ==>  
paulson@13926
   676
      analz (insert X H) \<subseteq> synth (analz G) \<union> analz (G \<union> H)"
paulson@13926
   677
apply (rule subsetI)
paulson@34185
   678
apply (subgoal_tac "x \<in> analz (synth (analz G) \<union> H)", force)
paulson@34185
   679
apply (blast intro: analz_mono [THEN [2] rev_subsetD] analz_mono [THEN synth_mono, THEN [2] rev_subsetD])
paulson@13926
   680
done
paulson@13926
   681
paulson@14200
   682
lemma analz_conj_parts [simp]:
paulson@14200
   683
     "(X \<in> analz H & X \<in> parts H) = (X \<in> analz H)"
paulson@14145
   684
by (blast intro: analz_subset_parts [THEN subsetD])
paulson@13926
   685
paulson@14200
   686
lemma analz_disj_parts [simp]:
paulson@14200
   687
     "(X \<in> analz H | X \<in> parts H) = (X \<in> parts H)"
paulson@14145
   688
by (blast intro: analz_subset_parts [THEN subsetD])
paulson@13926
   689
wenzelm@61830
   690
text\<open>Without this equation, other rules for synth and analz would yield
wenzelm@61830
   691
  redundant cases\<close>
paulson@13926
   692
lemma MPair_synth_analz [iff]:
wenzelm@61956
   693
     "(\<lbrace>X,Y\<rbrace> \<in> synth (analz H)) =  
paulson@13926
   694
      (X \<in> synth (analz H) & Y \<in> synth (analz H))"
paulson@13926
   695
by blast
paulson@13926
   696
paulson@14200
   697
lemma Crypt_synth_analz:
paulson@14200
   698
     "[| Key K \<in> analz H;  Key (invKey K) \<in> analz H |]  
paulson@13926
   699
       ==> (Crypt K X \<in> synth (analz H)) = (X \<in> synth (analz H))"
paulson@13926
   700
by blast
paulson@13926
   701
paulson@13926
   702
paulson@14200
   703
lemma Hash_synth_analz [simp]:
paulson@14200
   704
     "X \<notin> synth (analz H)  
wenzelm@61956
   705
      ==> (Hash\<lbrace>X,Y\<rbrace> \<in> synth (analz H)) = (Hash\<lbrace>X,Y\<rbrace> \<in> analz H)"
paulson@13926
   706
by blast
paulson@13926
   707
paulson@13926
   708
wenzelm@61830
   709
subsection\<open>HPair: a combination of Hash and MPair\<close>
paulson@13926
   710
wenzelm@61830
   711
subsubsection\<open>Freeness\<close>
paulson@13926
   712
paulson@13926
   713
lemma Agent_neq_HPair: "Agent A ~= Hash[X] Y"
lp15@57394
   714
  unfolding HPair_def by simp
paulson@13926
   715
paulson@13926
   716
lemma Nonce_neq_HPair: "Nonce N ~= Hash[X] Y"
lp15@57394
   717
  unfolding HPair_def by simp
paulson@13926
   718
paulson@13926
   719
lemma Number_neq_HPair: "Number N ~= Hash[X] Y"
lp15@57394
   720
  unfolding HPair_def by simp
paulson@13926
   721
paulson@13926
   722
lemma Key_neq_HPair: "Key K ~= Hash[X] Y"
lp15@57394
   723
  unfolding HPair_def by simp
paulson@13926
   724
paulson@13926
   725
lemma Hash_neq_HPair: "Hash Z ~= Hash[X] Y"
lp15@57394
   726
  unfolding HPair_def by simp
paulson@13926
   727
paulson@13926
   728
lemma Crypt_neq_HPair: "Crypt K X' ~= Hash[X] Y"
lp15@57394
   729
  unfolding HPair_def by simp
paulson@13926
   730
paulson@13926
   731
lemmas HPair_neqs = Agent_neq_HPair Nonce_neq_HPair Number_neq_HPair 
paulson@13926
   732
                    Key_neq_HPair Hash_neq_HPair Crypt_neq_HPair
paulson@13926
   733
paulson@13926
   734
declare HPair_neqs [iff]
paulson@13926
   735
declare HPair_neqs [symmetric, iff]
paulson@13926
   736
paulson@13926
   737
lemma HPair_eq [iff]: "(Hash[X'] Y' = Hash[X] Y) = (X' = X & Y'=Y)"
paulson@13926
   738
by (simp add: HPair_def)
paulson@13926
   739
paulson@14200
   740
lemma MPair_eq_HPair [iff]:
wenzelm@61956
   741
     "(\<lbrace>X',Y'\<rbrace> = Hash[X] Y) = (X' = Hash\<lbrace>X,Y\<rbrace> & Y'=Y)"
paulson@13926
   742
by (simp add: HPair_def)
paulson@13926
   743
paulson@14200
   744
lemma HPair_eq_MPair [iff]:
wenzelm@61956
   745
     "(Hash[X] Y = \<lbrace>X',Y'\<rbrace>) = (X' = Hash\<lbrace>X,Y\<rbrace> & Y'=Y)"
paulson@13926
   746
by (auto simp add: HPair_def)
paulson@13926
   747
paulson@13926
   748
wenzelm@61830
   749
subsubsection\<open>Specialized laws, proved in terms of those for Hash and MPair\<close>
paulson@13926
   750
paulson@13926
   751
lemma keysFor_insert_HPair [simp]: "keysFor (insert (Hash[X] Y) H) = keysFor H"
paulson@13926
   752
by (simp add: HPair_def)
paulson@13926
   753
paulson@13926
   754
lemma parts_insert_HPair [simp]: 
paulson@13926
   755
    "parts (insert (Hash[X] Y) H) =  
wenzelm@61956
   756
     insert (Hash[X] Y) (insert (Hash\<lbrace>X,Y\<rbrace>) (parts (insert Y H)))"
paulson@13926
   757
by (simp add: HPair_def)
paulson@13926
   758
paulson@13926
   759
lemma analz_insert_HPair [simp]: 
paulson@13926
   760
    "analz (insert (Hash[X] Y) H) =  
wenzelm@61956
   761
     insert (Hash[X] Y) (insert (Hash\<lbrace>X,Y\<rbrace>) (analz (insert Y H)))"
paulson@13926
   762
by (simp add: HPair_def)
paulson@13926
   763
paulson@13926
   764
lemma HPair_synth_analz [simp]:
paulson@13926
   765
     "X \<notin> synth (analz H)  
paulson@13926
   766
    ==> (Hash[X] Y \<in> synth (analz H)) =  
wenzelm@61956
   767
        (Hash \<lbrace>X, Y\<rbrace> \<in> analz H & Y \<in> synth (analz H))"
paulson@39216
   768
by (auto simp add: HPair_def)
paulson@13926
   769
paulson@13926
   770
wenzelm@61830
   771
text\<open>We do NOT want Crypt... messages broken up in protocols!!\<close>
paulson@13926
   772
declare parts.Body [rule del]
paulson@13926
   773
paulson@13926
   774
wenzelm@61830
   775
text\<open>Rewrites to push in Key and Crypt messages, so that other messages can
wenzelm@61830
   776
    be pulled out using the \<open>analz_insert\<close> rules\<close>
paulson@13926
   777
wenzelm@45605
   778
lemmas pushKeys =
wenzelm@27225
   779
  insert_commute [of "Key K" "Agent C"]
wenzelm@27225
   780
  insert_commute [of "Key K" "Nonce N"]
wenzelm@27225
   781
  insert_commute [of "Key K" "Number N"]
wenzelm@27225
   782
  insert_commute [of "Key K" "Hash X"]
wenzelm@27225
   783
  insert_commute [of "Key K" "MPair X Y"]
wenzelm@27225
   784
  insert_commute [of "Key K" "Crypt X K'"]
wenzelm@45605
   785
  for K C N X Y K'
paulson@13926
   786
wenzelm@45605
   787
lemmas pushCrypts =
wenzelm@27225
   788
  insert_commute [of "Crypt X K" "Agent C"]
wenzelm@27225
   789
  insert_commute [of "Crypt X K" "Agent C"]
wenzelm@27225
   790
  insert_commute [of "Crypt X K" "Nonce N"]
wenzelm@27225
   791
  insert_commute [of "Crypt X K" "Number N"]
wenzelm@27225
   792
  insert_commute [of "Crypt X K" "Hash X'"]
wenzelm@27225
   793
  insert_commute [of "Crypt X K" "MPair X' Y"]
wenzelm@45605
   794
  for X K C N X' Y
paulson@13926
   795
wenzelm@61830
   796
text\<open>Cannot be added with \<open>[simp]\<close> -- messages should not always be
wenzelm@61830
   797
  re-ordered.\<close>
paulson@13926
   798
lemmas pushes = pushKeys pushCrypts
paulson@13926
   799
paulson@13926
   800
wenzelm@61830
   801
subsection\<open>The set of key-free messages\<close>
paulson@43582
   802
paulson@43582
   803
(*Note that even the encryption of a key-free message remains key-free.
paulson@43582
   804
  This concept is valuable because of the theorem analz_keyfree_into_Un, proved below. *)
paulson@43582
   805
paulson@43582
   806
inductive_set
paulson@43582
   807
  keyfree :: "msg set"
paulson@43582
   808
  where
paulson@43582
   809
    Agent:  "Agent A \<in> keyfree"
paulson@43582
   810
  | Number: "Number N \<in> keyfree"
paulson@43582
   811
  | Nonce:  "Nonce N \<in> keyfree"
paulson@43582
   812
  | Hash:   "Hash X \<in> keyfree"
wenzelm@61956
   813
  | MPair:  "[|X \<in> keyfree;  Y \<in> keyfree|] ==> \<lbrace>X,Y\<rbrace> \<in> keyfree"
paulson@43582
   814
  | Crypt:  "[|X \<in> keyfree|] ==> Crypt K X \<in> keyfree"
paulson@43582
   815
paulson@43582
   816
paulson@43582
   817
declare keyfree.intros [intro] 
paulson@43582
   818
paulson@43582
   819
inductive_cases keyfree_KeyE: "Key K \<in> keyfree"
wenzelm@61956
   820
inductive_cases keyfree_MPairE: "\<lbrace>X,Y\<rbrace> \<in> keyfree"
paulson@43582
   821
inductive_cases keyfree_CryptE: "Crypt K X \<in> keyfree"
paulson@43582
   822
paulson@43582
   823
lemma parts_keyfree: "parts (keyfree) \<subseteq> keyfree"
paulson@43582
   824
  by (clarify, erule parts.induct, auto elim!: keyfree_KeyE keyfree_MPairE keyfree_CryptE)
paulson@43582
   825
paulson@43582
   826
(*The key-free part of a set of messages can be removed from the scope of the analz operator.*)
paulson@43582
   827
lemma analz_keyfree_into_Un: "\<lbrakk>X \<in> analz (G \<union> H); G \<subseteq> keyfree\<rbrakk> \<Longrightarrow> X \<in> parts G \<union> analz H"
lp15@57394
   828
apply (erule analz.induct, auto dest: parts.Body)
huffman@44174
   829
apply (metis Un_absorb2 keyfree_KeyE parts_Un parts_keyfree UnI2)
paulson@43582
   830
done
paulson@43582
   831
wenzelm@61830
   832
subsection\<open>Tactics useful for many protocol proofs\<close>
paulson@13926
   833
ML
wenzelm@61830
   834
\<open>
paulson@13926
   835
(*Analysis of Fake cases.  Also works for messages that forward unknown parts,
paulson@13926
   836
  but this application is no longer necessary if analz_insert_eq is used.
paulson@13926
   837
  DEPENDS UPON "X" REFERRING TO THE FRADULENT MESSAGE *)
paulson@13926
   838
haftmann@32117
   839
fun impOfSubs th = th RSN (2, @{thm rev_subsetD})
haftmann@32117
   840
paulson@13926
   841
(*Apply rules to break down assumptions of the form
paulson@13926
   842
  Y \<in> parts(insert X H)  and  Y \<in> analz(insert X H)
paulson@13926
   843
*)
wenzelm@59498
   844
fun Fake_insert_tac ctxt = 
wenzelm@59498
   845
    dresolve_tac ctxt [impOfSubs @{thm Fake_analz_insert},
wenzelm@24122
   846
                  impOfSubs @{thm Fake_parts_insert}] THEN'
wenzelm@59498
   847
    eresolve_tac ctxt [asm_rl, @{thm synth.Inj}];
paulson@13926
   848
wenzelm@51717
   849
fun Fake_insert_simp_tac ctxt i = 
wenzelm@59498
   850
  REPEAT (Fake_insert_tac ctxt i) THEN asm_full_simp_tac ctxt i;
paulson@13926
   851
wenzelm@42474
   852
fun atomic_spy_analz_tac ctxt =
wenzelm@42793
   853
  SELECT_GOAL
wenzelm@51717
   854
   (Fake_insert_simp_tac ctxt 1 THEN
wenzelm@42793
   855
    IF_UNSOLVED
wenzelm@42793
   856
      (Blast.depth_tac
wenzelm@42793
   857
        (ctxt addIs [@{thm analz_insertI}, impOfSubs @{thm analz_subset_parts}]) 4 1));
paulson@13926
   858
wenzelm@42474
   859
fun spy_analz_tac ctxt i =
wenzelm@42793
   860
  DETERM
wenzelm@42793
   861
   (SELECT_GOAL
wenzelm@42793
   862
     (EVERY 
wenzelm@42793
   863
      [  (*push in occurrences of X...*)
wenzelm@42793
   864
       (REPEAT o CHANGED)
wenzelm@59780
   865
         (Rule_Insts.res_inst_tac ctxt [((("x", 1), Position.none), "X")] []
wenzelm@59780
   866
           (insert_commute RS ssubst) 1),
wenzelm@42793
   867
       (*...allowing further simplifications*)
wenzelm@51717
   868
       simp_tac ctxt 1,
wenzelm@59498
   869
       REPEAT (FIRSTGOAL (resolve_tac ctxt [allI,impI,notI,conjI,iffI])),
wenzelm@42793
   870
       DEPTH_SOLVE (atomic_spy_analz_tac ctxt 1)]) i);
wenzelm@61830
   871
\<close>
paulson@13926
   872
wenzelm@61830
   873
text\<open>By default only \<open>o_apply\<close> is built-in.  But in the presence of
paulson@16818
   874
eta-expansion this means that some terms displayed as @{term "f o g"} will be
wenzelm@61830
   875
rewritten, and others will not!\<close>
paulson@13926
   876
declare o_def [simp]
paulson@13926
   877
paulson@11189
   878
paulson@13922
   879
lemma Crypt_notin_image_Key [simp]: "Crypt K X \<notin> Key ` A"
paulson@13922
   880
by auto
paulson@13922
   881
paulson@13922
   882
lemma Hash_notin_image_Key [simp] :"Hash X \<notin> Key ` A"
paulson@13922
   883
by auto
paulson@13922
   884
paulson@14200
   885
lemma synth_analz_mono: "G\<subseteq>H ==> synth (analz(G)) \<subseteq> synth (analz(H))"
paulson@17689
   886
by (iprover intro: synth_mono analz_mono) 
paulson@13922
   887
paulson@13922
   888
lemma Fake_analz_eq [simp]:
paulson@13922
   889
     "X \<in> synth(analz H) ==> synth (analz (insert X H)) = synth (analz H)"
paulson@35566
   890
by (metis Fake_analz_insert Un_absorb Un_absorb1 Un_commute 
paulson@34185
   891
          subset_insertI synth_analz_mono synth_increasing synth_subset_iff)
paulson@13922
   892
wenzelm@61830
   893
text\<open>Two generalizations of \<open>analz_insert_eq\<close>\<close>
paulson@13922
   894
lemma gen_analz_insert_eq [rule_format]:
paulson@35566
   895
     "X \<in> analz H ==> ALL G. H \<subseteq> G --> analz (insert X G) = analz G"
paulson@13922
   896
by (blast intro: analz_cut analz_insertI analz_mono [THEN [2] rev_subsetD])
paulson@13922
   897
paulson@13922
   898
lemma synth_analz_insert_eq [rule_format]:
paulson@13922
   899
     "X \<in> synth (analz H) 
paulson@35566
   900
      ==> ALL G. H \<subseteq> G --> (Key K \<in> analz (insert X G)) = (Key K \<in> analz G)"
paulson@13922
   901
apply (erule synth.induct) 
paulson@13922
   902
apply (simp_all add: gen_analz_insert_eq subset_trans [OF _ subset_insertI]) 
paulson@13922
   903
done
paulson@13922
   904
paulson@13922
   905
lemma Fake_parts_sing:
paulson@34185
   906
     "X \<in> synth (analz H) ==> parts{X} \<subseteq> synth (analz H) \<union> parts H"
paulson@34185
   907
by (metis Fake_parts_insert empty_subsetI insert_mono parts_mono subset_trans)
paulson@13922
   908
paulson@14145
   909
lemmas Fake_parts_sing_imp_Un = Fake_parts_sing [THEN [2] rev_subsetD]
paulson@14145
   910
wenzelm@61830
   911
method_setup spy_analz = \<open>
wenzelm@61830
   912
    Scan.succeed (SIMPLE_METHOD' o spy_analz_tac)\<close>
paulson@11189
   913
    "for proving the Fake case when analz is involved"
paulson@1839
   914
wenzelm@61830
   915
method_setup atomic_spy_analz = \<open>
wenzelm@61830
   916
    Scan.succeed (SIMPLE_METHOD' o atomic_spy_analz_tac)\<close>
paulson@11264
   917
    "for debugging spy_analz"
paulson@11264
   918
wenzelm@61830
   919
method_setup Fake_insert_simp = \<open>
wenzelm@61830
   920
    Scan.succeed (SIMPLE_METHOD' o Fake_insert_simp_tac)\<close>
paulson@11264
   921
    "for debugging spy_analz"
paulson@11264
   922
paulson@1839
   923
end