src/HOL/Auth/Message.thy
author paulson
Mon Aug 03 10:37:34 1998 +0200 (1998-08-03)
changeset 5234 701fa0ed77b7
parent 5183 89f162de39cf
child 5652 fe5f5510aef4
permissions -rw-r--r--
Better comments
paulson@1839
     1
(*  Title:      HOL/Auth/Message
paulson@1839
     2
    ID:         $Id$
paulson@1839
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@1839
     4
    Copyright   1996  University of Cambridge
paulson@1839
     5
paulson@1839
     6
Datatypes of agents and messages;
paulson@1913
     7
Inductive relations "parts", "analz" and "synth"
paulson@1839
     8
*)
paulson@1839
     9
berghofe@5183
    10
Message = Datatype +
paulson@1839
    11
paulson@1839
    12
(*Is there a difference between a nonce and arbitrary numerical data?
paulson@1839
    13
  Do we need a type of nonces?*)
paulson@1839
    14
paulson@1839
    15
types 
paulson@1839
    16
  key = nat
paulson@1839
    17
paulson@1839
    18
consts
paulson@1839
    19
  invKey :: key=>key
paulson@1839
    20
paulson@1839
    21
rules
paulson@1839
    22
  invKey "invKey (invKey K) = K"
paulson@1839
    23
paulson@1839
    24
  (*The inverse of a symmetric key is itself;
paulson@1839
    25
    that of a public key is the private key and vice versa*)
paulson@1839
    26
paulson@1839
    27
constdefs
paulson@1839
    28
  isSymKey :: key=>bool
paulson@1839
    29
  "isSymKey K == (invKey K = K)"
paulson@1839
    30
paulson@1839
    31
datatype  (*We allow any number of friendly agents*)
paulson@2032
    32
  agent = Server | Friend nat | Spy
paulson@1839
    33
paulson@5234
    34
paulson@5234
    35
(*Datatype msg is (awkwardly) split into two parts to avoid having freeness
paulson@5234
    36
  expressed using natural numbers.*)
paulson@3668
    37
datatype  
paulson@3668
    38
  atomic = AGENT  agent	(*Agent names*)
paulson@3668
    39
         | NUMBER nat   (*Ordinary integers, timestamps, ...*)
paulson@3668
    40
         | NONCE  nat   (*Unguessable nonces*)
paulson@3668
    41
         | KEY    key   (*Crypto keys*)
paulson@3668
    42
paulson@3668
    43
datatype
paulson@5234
    44
     msg = Atomic atomic
paulson@5234
    45
	 | Hash   msg       (*Hashing*)
paulson@5234
    46
	 | MPair  msg msg   (*Compound messages*)
paulson@5234
    47
	 | Crypt  key msg   (*Encryption, public- or shared-key*)
paulson@1839
    48
paulson@5234
    49
(*These translations complete the illustion that "msg" has seven constructors*)
paulson@1839
    50
syntax
paulson@5234
    51
  Agent       :: agent => msg
paulson@5234
    52
  Number      :: nat   => msg
paulson@5234
    53
  Nonce       :: nat   => msg
paulson@5234
    54
  Key         :: key   => msg
paulson@5234
    55
paulson@5234
    56
translations
paulson@5234
    57
  "Agent x"   == "Atomic (AGENT x)"
paulson@5234
    58
  "Number x"  == "Atomic (NUMBER x)"
paulson@5234
    59
  "Nonce x"   == "Atomic (NONCE x)"
paulson@5234
    60
  "Key x"     == "Atomic (KEY x)"
paulson@5234
    61
  "Key``x"    == "Atomic `` (KEY `` x)"
paulson@5234
    62
paulson@5234
    63
paulson@5234
    64
(*Concrete syntax: messages appear as {|A,B,NA|}, etc...*)
paulson@5234
    65
syntax
paulson@2516
    66
  "@MTuple"      :: "['a, args] => 'a * 'b"       ("(2{|_,/ _|})")
paulson@1839
    67
paulson@1839
    68
translations
paulson@1839
    69
  "{|x, y, z|}"   == "{|x, {|y, z|}|}"
paulson@1839
    70
  "{|x, y|}"      == "MPair x y"
paulson@1839
    71
paulson@1839
    72
paulson@2484
    73
constdefs
paulson@2484
    74
  (*Message Y, paired with a MAC computed with the help of X*)
paulson@2516
    75
  HPair :: "[msg,msg]=>msg"                       ("(4Hash[_] /_)" [0, 1000])
paulson@2516
    76
    "Hash[X] Y == {| Hash{|X,Y|}, Y|}"
paulson@2484
    77
paulson@2484
    78
  (*Keys useful to decrypt elements of a message set*)
paulson@1839
    79
  keysFor :: msg set => key set
paulson@2284
    80
  "keysFor H == invKey `` {K. EX X. Crypt K X : H}"
paulson@1839
    81
paulson@1839
    82
(** Inductive definition of all "parts" of a message.  **)
paulson@1839
    83
paulson@1839
    84
consts  parts   :: msg set => msg set
paulson@1839
    85
inductive "parts H"
paulson@1839
    86
  intrs 
paulson@2373
    87
    Inj     "X: H  ==>  X: parts H"
paulson@2373
    88
    Fst     "{|X,Y|}   : parts H ==> X : parts H"
paulson@2373
    89
    Snd     "{|X,Y|}   : parts H ==> Y : parts H"
paulson@2284
    90
    Body    "Crypt K X : parts H ==> X : parts H"
paulson@1839
    91
paulson@1839
    92
paulson@1913
    93
(** Inductive definition of "analz" -- what can be broken down from a set of
paulson@1839
    94
    messages, including keys.  A form of downward closure.  Pairs can
paulson@1839
    95
    be taken apart; messages decrypted with known keys.  **)
paulson@1839
    96
paulson@1913
    97
consts  analz   :: msg set => msg set
paulson@1913
    98
inductive "analz H"
paulson@1839
    99
  intrs 
paulson@1913
   100
    Inj     "X: H ==> X: analz H"
paulson@1913
   101
    Fst     "{|X,Y|} : analz H ==> X : analz H"
paulson@1913
   102
    Snd     "{|X,Y|} : analz H ==> Y : analz H"
paulson@2284
   103
    Decrypt "[| Crypt K X : analz H; Key(invKey K): analz H |] ==> X : analz H"
paulson@1839
   104
paulson@1839
   105
paulson@1913
   106
(** Inductive definition of "synth" -- what can be built up from a set of
paulson@1839
   107
    messages.  A form of upward closure.  Pairs can be built, messages
paulson@3668
   108
    encrypted with known keys.  Agent names are public domain.
paulson@3668
   109
    Numbers can be guessed, but Nonces cannot be.  **)
paulson@1839
   110
paulson@1913
   111
consts  synth   :: msg set => msg set
paulson@1913
   112
inductive "synth H"
paulson@1839
   113
  intrs 
paulson@1913
   114
    Inj     "X: H ==> X: synth H"
paulson@1913
   115
    Agent   "Agent agt : synth H"
paulson@3668
   116
    Number  "Number n  : synth H"
paulson@2373
   117
    Hash    "X: synth H ==> Hash X : synth H"
paulson@1913
   118
    MPair   "[| X: synth H;  Y: synth H |] ==> {|X,Y|} : synth H"
paulson@2373
   119
    Crypt   "[| X: synth H;  Key(K) : H |] ==> Crypt K X : synth H"
paulson@1839
   120
paulson@1839
   121
end