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