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