src/HOL/Auth/Message.thy
changeset 67443 3abf6a722518
parent 62390 842917225d56
child 67613 ce654b0e6d69
equal deleted inserted replaced
67442:f075640b8868 67443:3abf6a722518
    18 
    18 
    19 type_synonym
    19 type_synonym
    20   key = nat
    20   key = nat
    21 
    21 
    22 consts
    22 consts
    23   all_symmetric :: bool        \<comment>\<open>true if all keys are symmetric\<close>
    23   all_symmetric :: bool        \<comment> \<open>true if all keys are symmetric\<close>
    24   invKey        :: "key=>key"  \<comment>\<open>inverse of a symmetric key\<close>
    24   invKey        :: "key=>key"  \<comment> \<open>inverse of a symmetric key\<close>
    25 
    25 
    26 specification (invKey)
    26 specification (invKey)
    27   invKey [simp]: "invKey (invKey K) = K"
    27   invKey [simp]: "invKey (invKey K) = K"
    28   invKey_symmetric: "all_symmetric --> invKey = id"
    28   invKey_symmetric: "all_symmetric --> invKey = id"
    29     by (rule exI [of _ id], auto)
    29     by (rule exI [of _ id], auto)
    33       is the private key and vice versa\<close>
    33       is the private key and vice versa\<close>
    34 
    34 
    35 definition symKeys :: "key set" where
    35 definition symKeys :: "key set" where
    36   "symKeys == {K. invKey K = K}"
    36   "symKeys == {K. invKey K = K}"
    37 
    37 
    38 datatype  \<comment>\<open>We allow any number of friendly agents\<close>
    38 datatype  \<comment> \<open>We allow any number of friendly agents\<close>
    39   agent = Server | Friend nat | Spy
    39   agent = Server | Friend nat | Spy
    40 
    40 
    41 datatype
    41 datatype
    42      msg = Agent  agent     \<comment>\<open>Agent names\<close>
    42      msg = Agent  agent     \<comment> \<open>Agent names\<close>
    43          | Number nat       \<comment>\<open>Ordinary integers, timestamps, ...\<close>
    43          | Number nat       \<comment> \<open>Ordinary integers, timestamps, ...\<close>
    44          | Nonce  nat       \<comment>\<open>Unguessable nonces\<close>
    44          | Nonce  nat       \<comment> \<open>Unguessable nonces\<close>
    45          | Key    key       \<comment>\<open>Crypto keys\<close>
    45          | Key    key       \<comment> \<open>Crypto keys\<close>
    46          | Hash   msg       \<comment>\<open>Hashing\<close>
    46          | Hash   msg       \<comment> \<open>Hashing\<close>
    47          | MPair  msg msg   \<comment>\<open>Compound messages\<close>
    47          | MPair  msg msg   \<comment> \<open>Compound messages\<close>
    48          | Crypt  key msg   \<comment>\<open>Encryption, public- or shared-key\<close>
    48          | Crypt  key msg   \<comment> \<open>Encryption, public- or shared-key\<close>
    49 
    49 
    50 
    50 
    51 text\<open>Concrete syntax: messages appear as \<open>\<lbrace>A,B,NA\<rbrace>\<close>, etc...\<close>
    51 text\<open>Concrete syntax: messages appear as \<open>\<lbrace>A,B,NA\<rbrace>\<close>, etc...\<close>
    52 syntax
    52 syntax
    53   "_MTuple" :: "['a, args] \<Rightarrow> 'a * 'b"  ("(2\<lbrace>_,/ _\<rbrace>)")
    53   "_MTuple" :: "['a, args] \<Rightarrow> 'a * 'b"  ("(2\<lbrace>_,/ _\<rbrace>)")
    55   "\<lbrace>x, y, z\<rbrace>" \<rightleftharpoons> "\<lbrace>x, \<lbrace>y, z\<rbrace>\<rbrace>"
    55   "\<lbrace>x, y, z\<rbrace>" \<rightleftharpoons> "\<lbrace>x, \<lbrace>y, z\<rbrace>\<rbrace>"
    56   "\<lbrace>x, y\<rbrace>" \<rightleftharpoons> "CONST MPair x y"
    56   "\<lbrace>x, y\<rbrace>" \<rightleftharpoons> "CONST MPair x y"
    57 
    57 
    58 
    58 
    59 definition HPair :: "[msg,msg] => msg" ("(4Hash[_] /_)" [0, 1000]) where
    59 definition HPair :: "[msg,msg] => msg" ("(4Hash[_] /_)" [0, 1000]) where
    60     \<comment>\<open>Message Y paired with a MAC computed with the help of X\<close>
    60     \<comment> \<open>Message Y paired with a MAC computed with the help of X\<close>
    61     "Hash[X] Y == \<lbrace>Hash\<lbrace>X,Y\<rbrace>, Y\<rbrace>"
    61     "Hash[X] Y == \<lbrace>Hash\<lbrace>X,Y\<rbrace>, Y\<rbrace>"
    62 
    62 
    63 definition keysFor :: "msg set => key set" where
    63 definition keysFor :: "msg set => key set" where
    64     \<comment>\<open>Keys useful to decrypt elements of a message set\<close>
    64     \<comment> \<open>Keys useful to decrypt elements of a message set\<close>
    65   "keysFor H == invKey ` {K. \<exists>X. Crypt K X \<in> H}"
    65   "keysFor H == invKey ` {K. \<exists>X. Crypt K X \<in> H}"
    66 
    66 
    67 
    67 
    68 subsubsection\<open>Inductive Definition of All Parts" of a Message\<close>
    68 subsubsection\<open>Inductive Definition of All Parts" of a Message\<close>
    69 
    69 
   315   case (Nonce n)
   315   case (Nonce n)
   316     show ?case
   316     show ?case
   317       by simp (metis Suc_n_not_le_n)
   317       by simp (metis Suc_n_not_le_n)
   318 next
   318 next
   319   case (MPair X Y)
   319   case (MPair X Y)
   320     then show ?case \<comment>\<open>metis works out the necessary sum itself!\<close>
   320     then show ?case \<comment> \<open>metis works out the necessary sum itself!\<close>
   321       by (simp add: parts_insert2) (metis le_trans nat_le_linear)
   321       by (simp add: parts_insert2) (metis le_trans nat_le_linear)
   322 qed auto
   322 qed auto
   323 
   323 
   324 subsection\<open>Inductive relation "analz"\<close>
   324 subsection\<open>Inductive relation "analz"\<close>
   325 
   325