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