src/HOL/Auth/Message.thy
author paulson
Fri, 02 Mar 2001 13:18:31 +0100
changeset 11189 1ea763a5d186
parent 10833 c0844a30ea4e
child 11192 5fd02b905a9a
permissions -rw-r--r--
conversion of Message.thy to Isar format
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
     1
(*  Title:      HOL/Auth/Message
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
     2
    ID:         $Id$
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
     4
    Copyright   1996  University of Cambridge
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
     5
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
     6
Datatypes of agents and messages;
1913
2809adb15eb0 Renaming of functions, and tidying
paulson
parents: 1839
diff changeset
     7
Inductive relations "parts", "analz" and "synth"
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
     8
*)
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
     9
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    10
theory Message = Main
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    11
files ("Message_lemmas.ML"):
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    12
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    13
(*Eliminates a commonly-occurring expression*)
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    14
lemma [simp] : "~ (ALL x. x~=y)"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    15
by blast
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    16
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    17
(*Needed occasionally with spy_analz_tac, e.g. in analz_insert_Key_newK*)
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    18
lemma [simp] : "A Un (B Un A) = B Un A"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    19
by blast
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    20
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    21
types 
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    22
  key = nat
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    23
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    24
consts
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    25
  invKey :: "key=>key"
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    26
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    27
axioms
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    28
  invKey [simp] : "invKey (invKey K) = K"
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    29
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    30
  (*The inverse of a symmetric key is itself;
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    31
    that of a public key is the private key and vice versa*)
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    32
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    33
constdefs
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    34
  isSymKey :: "key=>bool"
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    35
  "isSymKey K == (invKey K = K)"
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    36
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    37
datatype  (*We allow any number of friendly agents*)
2032
1bbf1bdcaf56 Introduction of "lost" argument
paulson
parents: 2010
diff changeset
    38
  agent = Server | Friend nat | Spy
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    39
3668
a39baf59ea47 Split base cases from "msg" to "atomic" in order
paulson
parents: 2516
diff changeset
    40
datatype
7057
b9ddbb925939 tweaked proofs to handle new freeness reasoning for data c onstructors
paulson
parents: 6807
diff changeset
    41
     msg = Agent  agent	    (*Agent names*)
b9ddbb925939 tweaked proofs to handle new freeness reasoning for data c onstructors
paulson
parents: 6807
diff changeset
    42
         | Number nat       (*Ordinary integers, timestamps, ...*)
b9ddbb925939 tweaked proofs to handle new freeness reasoning for data c onstructors
paulson
parents: 6807
diff changeset
    43
         | Nonce  nat       (*Unguessable nonces*)
b9ddbb925939 tweaked proofs to handle new freeness reasoning for data c onstructors
paulson
parents: 6807
diff changeset
    44
         | Key    key       (*Crypto keys*)
5234
701fa0ed77b7 Better comments
paulson
parents: 5183
diff changeset
    45
	 | Hash   msg       (*Hashing*)
701fa0ed77b7 Better comments
paulson
parents: 5183
diff changeset
    46
	 | MPair  msg msg   (*Compound messages*)
701fa0ed77b7 Better comments
paulson
parents: 5183
diff changeset
    47
	 | Crypt  key msg   (*Encryption, public- or shared-key*)
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    48
5234
701fa0ed77b7 Better comments
paulson
parents: 5183
diff changeset
    49
701fa0ed77b7 Better comments
paulson
parents: 5183
diff changeset
    50
(*Concrete syntax: messages appear as {|A,B,NA|}, etc...*)
701fa0ed77b7 Better comments
paulson
parents: 5183
diff changeset
    51
syntax
2516
4d68fbe6378b Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents: 2484
diff changeset
    52
  "@MTuple"      :: "['a, args] => 'a * 'b"       ("(2{|_,/ _|})")
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    53
9686
87b460d72e80 xsymbols for {| and |}
paulson
parents: 7057
diff changeset
    54
syntax (xsymbols)
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    55
  "@MTuple"      :: "['a, args] => 'a * 'b"       ("(2\<lbrace>_,/ _\<rbrace>)")
9686
87b460d72e80 xsymbols for {| and |}
paulson
parents: 7057
diff changeset
    56
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    57
translations
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    58
  "{|x, y, z|}"   == "{|x, {|y, z|}|}"
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    59
  "{|x, y|}"      == "MPair x y"
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    60
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    61
2484
596a5b5a68ff Incorporation of HPair into Message
paulson
parents: 2373
diff changeset
    62
constdefs
596a5b5a68ff Incorporation of HPair into Message
paulson
parents: 2373
diff changeset
    63
  (*Message Y, paired with a MAC computed with the help of X*)
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    64
  HPair :: "[msg,msg] => msg"                       ("(4Hash[_] /_)" [0, 1000])
2516
4d68fbe6378b Now with Andy Gordon's treatment of freshness to replace newN/K
paulson
parents: 2484
diff changeset
    65
    "Hash[X] Y == {| Hash{|X,Y|}, Y|}"
2484
596a5b5a68ff Incorporation of HPair into Message
paulson
parents: 2373
diff changeset
    66
596a5b5a68ff Incorporation of HPair into Message
paulson
parents: 2373
diff changeset
    67
  (*Keys useful to decrypt elements of a message set*)
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    68
  keysFor :: "msg set => key set"
10833
c0844a30ea4e `` -> ` and ``` -> ``
nipkow
parents: 9686
diff changeset
    69
  "keysFor H == invKey ` {K. EX X. Crypt K X : H}"
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    70
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    71
(** Inductive definition of all "parts" of a message.  **)
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    72
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    73
consts  parts   :: "msg set => msg set"
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    74
inductive "parts H"
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    75
  intros 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    76
    Inj [intro]          : "X: H  ==> X : parts H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    77
    Fst:     "{|X,Y|}   : parts H ==> X : parts H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    78
    Snd:     "{|X,Y|}   : parts H ==> Y : parts H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    79
    Body:    "Crypt K X : parts H ==> X : parts H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    80
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    81
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    82
(*Monotonicity*)
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    83
lemma parts_mono: "G<=H ==> parts(G) <= parts(H)"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    84
apply auto
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    85
apply (erule parts.induct) 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    86
apply (auto dest: Fst Snd Body) 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    87
done
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    88
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    89
1913
2809adb15eb0 Renaming of functions, and tidying
paulson
parents: 1839
diff changeset
    90
(** Inductive definition of "analz" -- what can be broken down from a set of
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    91
    messages, including keys.  A form of downward closure.  Pairs can
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    92
    be taken apart; messages decrypted with known keys.  **)
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
    93
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    94
consts  analz   :: "msg set => msg set"
1913
2809adb15eb0 Renaming of functions, and tidying
paulson
parents: 1839
diff changeset
    95
inductive "analz H"
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    96
  intros 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    97
    Inj [intro,simp] :    "X: H ==> X: analz H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    98
    Fst:     "{|X,Y|} : analz H ==> X : analz H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
    99
    Snd:     "{|X,Y|} : analz H ==> Y : analz H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   100
    Decrypt [dest]: 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   101
             "[|Crypt K X : analz H; Key(invKey K): analz H|] ==> X : analz H"
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
   102
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
   103
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   104
(*Monotonicity; Lemma 1 of Lowe's paper*)
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   105
lemma analz_mono: "G<=H ==> analz(G) <= analz(H)"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   106
apply auto
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   107
apply (erule analz.induct) 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   108
apply (auto dest: Fst Snd) 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   109
done
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   110
1913
2809adb15eb0 Renaming of functions, and tidying
paulson
parents: 1839
diff changeset
   111
(** Inductive definition of "synth" -- what can be built up from a set of
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
   112
    messages.  A form of upward closure.  Pairs can be built, messages
3668
a39baf59ea47 Split base cases from "msg" to "atomic" in order
paulson
parents: 2516
diff changeset
   113
    encrypted with known keys.  Agent names are public domain.
a39baf59ea47 Split base cases from "msg" to "atomic" in order
paulson
parents: 2516
diff changeset
   114
    Numbers can be guessed, but Nonces cannot be.  **)
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
   115
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   116
consts  synth   :: "msg set => msg set"
1913
2809adb15eb0 Renaming of functions, and tidying
paulson
parents: 1839
diff changeset
   117
inductive "synth H"
11189
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   118
  intros 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   119
    Inj    [intro]:   "X: H ==> X: synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   120
    Agent  [intro]:   "Agent agt : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   121
    Number [intro]:   "Number n  : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   122
    Hash   [intro]:   "X: synth H ==> Hash X : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   123
    MPair  [intro]:   "[|X: synth H;  Y: synth H|] ==> {|X,Y|} : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   124
    Crypt  [intro]:   "[|X: synth H;  Key(K) : H|] ==> Crypt K X : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   125
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   126
(*Monotonicity*)
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   127
lemma synth_mono: "G<=H ==> synth(G) <= synth(H)"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   128
apply auto
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   129
apply (erule synth.induct) 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   130
apply (auto dest: Fst Snd Body) 
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   131
done
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   132
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   133
(*NO Agent_synth, as any Agent name can be synthesized.  Ditto for Number*)
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   134
inductive_cases Nonce_synth [elim!]: "Nonce n : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   135
inductive_cases Key_synth   [elim!]: "Key K : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   136
inductive_cases Hash_synth  [elim!]: "Hash X : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   137
inductive_cases MPair_synth [elim!]: "{|X,Y|} : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   138
inductive_cases Crypt_synth [elim!]: "Crypt K X : synth H"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   139
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   140
use "Message_lemmas.ML"
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   141
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   142
method_setup spy_analz = {*
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   143
    Method.no_args (Method.METHOD (fn facts => spy_analz_tac 1)) *}
1ea763a5d186 conversion of Message.thy to Isar format
paulson
parents: 10833
diff changeset
   144
    "for proving the Fake case when analz is involved"
1839
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
   145
199243afac2b Proving safety properties of authentication protocols
paulson
parents:
diff changeset
   146
end