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