src/HOL/IMP/Sec_Type_Expr.thy
author wenzelm
Sun Nov 02 18:21:45 2014 +0100 (2014-11-02)
changeset 58889 5b7a9633cfa8
parent 53015 a1119cf551e8
child 67406 23307fd33906
permissions -rw-r--r--
modernized header uniformly as section;
wenzelm@58889
     1
section "Security Type Systems"
kleing@43158
     2
kleing@43158
     3
theory Sec_Type_Expr imports Big_Step
kleing@43158
     4
begin
kleing@43158
     5
kleing@43158
     6
subsection "Security Levels and Expressions"
kleing@43158
     7
kleing@43158
     8
type_synonym level = nat
kleing@43158
     9
nipkow@50342
    10
class sec =
nipkow@50342
    11
fixes sec :: "'a \<Rightarrow> nat"
nipkow@50342
    12
kleing@43158
    13
text{* The security/confidentiality level of each variable is globally fixed
kleing@43158
    14
for simplicity. For the sake of examples --- the general theory does not rely
kleing@43158
    15
on it! --- a variable of length @{text n} has security level @{text n}: *}
kleing@43158
    16
nipkow@50342
    17
instantiation list :: (type)sec
nipkow@50342
    18
begin
nipkow@50342
    19
nipkow@50342
    20
definition "sec(x :: 'a list) = length x"
nipkow@50342
    21
nipkow@50342
    22
instance ..
nipkow@50342
    23
nipkow@50342
    24
end
nipkow@50342
    25
nipkow@50342
    26
instantiation aexp :: sec
nipkow@50342
    27
begin
kleing@43158
    28
kleing@43158
    29
fun sec_aexp :: "aexp \<Rightarrow> level" where
nipkow@50342
    30
"sec (N n) = 0" |
nipkow@50342
    31
"sec (V x) = sec x" |
wenzelm@53015
    32
"sec (Plus a\<^sub>1 a\<^sub>2) = max (sec a\<^sub>1) (sec a\<^sub>2)"
nipkow@50342
    33
nipkow@50342
    34
instance ..
nipkow@50342
    35
nipkow@50342
    36
end
nipkow@50342
    37
nipkow@50342
    38
instantiation bexp :: sec
nipkow@50342
    39
begin
kleing@43158
    40
kleing@43158
    41
fun sec_bexp :: "bexp \<Rightarrow> level" where
nipkow@50342
    42
"sec (Bc v) = 0" |
nipkow@50342
    43
"sec (Not b) = sec b" |
wenzelm@53015
    44
"sec (And b\<^sub>1 b\<^sub>2) = max (sec b\<^sub>1) (sec b\<^sub>2)" |
wenzelm@53015
    45
"sec (Less a\<^sub>1 a\<^sub>2) = max (sec a\<^sub>1) (sec a\<^sub>2)"
nipkow@50342
    46
nipkow@50342
    47
instance ..
nipkow@50342
    48
nipkow@50342
    49
end
kleing@43158
    50
kleing@43158
    51
kleing@43158
    52
abbreviation eq_le :: "state \<Rightarrow> state \<Rightarrow> level \<Rightarrow> bool"
kleing@43158
    53
  ("(_ = _ '(\<le> _'))" [51,51,0] 50) where
kleing@43158
    54
"s = s' (\<le> l) == (\<forall> x. sec x \<le> l \<longrightarrow> s x = s' x)"
kleing@43158
    55
kleing@43158
    56
abbreviation eq_less :: "state \<Rightarrow> state \<Rightarrow> level \<Rightarrow> bool"
kleing@43158
    57
  ("(_ = _ '(< _'))" [51,51,0] 50) where
kleing@43158
    58
"s = s' (< l) == (\<forall> x. sec x < l \<longrightarrow> s x = s' x)"
kleing@43158
    59
kleing@43158
    60
lemma aval_eq_if_eq_le:
wenzelm@53015
    61
  "\<lbrakk> s\<^sub>1 = s\<^sub>2 (\<le> l);  sec a \<le> l \<rbrakk> \<Longrightarrow> aval a s\<^sub>1 = aval a s\<^sub>2"
kleing@43158
    62
by (induct a) auto
kleing@43158
    63
kleing@43158
    64
lemma bval_eq_if_eq_le:
wenzelm@53015
    65
  "\<lbrakk> s\<^sub>1 = s\<^sub>2 (\<le> l);  sec b \<le> l \<rbrakk> \<Longrightarrow> bval b s\<^sub>1 = bval b s\<^sub>2"
kleing@43158
    66
by (induct b) (auto simp add: aval_eq_if_eq_le)
kleing@43158
    67
kleing@43158
    68
end