module SPure where import Data.Char import SecLib.LatticeLH import SecLib.Untrustworthy -- f1 reimplemented using Sec s monad f1 :: (Sec H Char, Int) -> (Sec H Char, Int) f1 (sec_c,i) = (do c <- sec_c return $ chr(ord c + i) , i) -- f2 cannot be reimplemented since it does not satisfy non-interference -- Try to see if you can make it work! -- f2 :: (Sec H Char, Int) -> (Sec H Char, Int) -- f2 (sec_c, i) = ( do c <- sec_c -- return $ chr(ord c + i) -- , do c <- sec_c -- return $ ord c) fup :: Sec L Int -> Sec H Char fup sec_i = do i <- up sec_i return $ chr i -- Making instances that break the security lattice structure instance Less H L where -- If you uncomment the following line, it is not possible to compile the code. -- However, as you see, we are able to indicate that H is lower than L. -- less _ _ = () secret_char :: Sec H Char secret_char = return 'A' fhack :: Sec H Char -> Sec L Int fhack sec_c = do c <- up sec_c return $ ord c -- let's try to run our fhack function to see what happens! test = fhack secret_char `seq` True