diff --git a/Crypto/Cipher/ChaCha.hs b/Crypto/Cipher/ChaCha.hs index cb4e007..6895390 100644 --- a/Crypto/Cipher/ChaCha.hs +++ b/Crypto/Cipher/ChaCha.hs @@ -59,7 +59,7 @@ initialize nbRounds key nonce | not (kLen `elem` [16,32]) = error "ChaCha: key length should be 128 or 256 bits" | not (nonceLen `elem` [8,12]) = error "ChaCha: nonce length should be 64 or 96 bits" | not (nbRounds `elem` [8,12,20]) = error "ChaCha: rounds should be 8, 12 or 20" - | otherwise = unsafePerformIO $ do + | otherwise = unsafeDoIO $ do stPtr <- createSecureMem 64 $ \stPtr -> withBytePtr nonce $ \noncePtr -> withBytePtr key $ \keyPtr -> diff --git a/Crypto/Cipher/RC4.hs b/Crypto/Cipher/RC4.hs index bc80db1..1d5f85f 100644 --- a/Crypto/Cipher/RC4.hs +++ b/Crypto/Cipher/RC4.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE ForeignFunctionInterface, CPP #-} +{-# LANGUAGE ForeignFunctionInterface #-} -- | -- Module : Crypto.Cipher.RC4 -- License : BSD-style @@ -25,18 +25,12 @@ import Data.Byteable import Data.SecureMem import Foreign.Ptr import Foreign.ForeignPtr -import System.IO.Unsafe import Data.ByteString (ByteString) import qualified Data.ByteString as B import qualified Data.ByteString.Internal as B ---------------------------------------------------------------------- -unsafeDoIO :: IO a -> a -#if __GLASGOW_HASKELL__ > 704 -unsafeDoIO = unsafeDupablePerformIO -#else -unsafeDoIO = unsafePerformIO -#endif +import Crypto.Internal.Compat -- | The encryption state for RC4 newtype State = State SecureMem diff --git a/Crypto/Cipher/Salsa.hs b/Crypto/Cipher/Salsa.hs index 4e6effc..da4c2bb 100644 --- a/Crypto/Cipher/Salsa.hs +++ b/Crypto/Cipher/Salsa.hs @@ -18,6 +18,7 @@ import Data.SecureMem import Data.ByteString (ByteString) import qualified Data.ByteString.Internal as B import qualified Data.ByteString as B +import Crypto.Internal.Compat import Data.Byteable import Data.Word import Data.Bits (xor) @@ -50,7 +51,7 @@ initialize nbRounds key nonce | not (kLen `elem` [16,32]) = error "Salsa: key length should be 128 or 256 bits" | not (nonceLen `elem` [8,12]) = error "Salsa: nonce length should be 64 or 96 bits" | not (nbRounds `elem` [8,12,20]) = error "Salsa: rounds should be 8, 12 or 20" - | otherwise = unsafePerformIO $ do + | otherwise = unsafeDoIO $ do stPtr <- createSecureMem 64 $ \stPtr -> withBytePtr nonce $ \noncePtr -> withBytePtr key $ \keyPtr ->