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