securemem 0.1.3 → 0.1.4
raw patch · 5 files changed
+44/−12 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/SecureMem.hs +20/−3
- LICENSE +1/−1
- README.md +21/−2
- cbits/utils.c +0/−4
- securemem.cabal +2/−2
Data/SecureMem.hs view
@@ -41,16 +41,32 @@ import Data.Word (Word8) import Data.Monoid import Control.Applicative-import Control.Monad (foldM, void)+import Control.Monad (foldM_) import Data.ByteString (ByteString) import Data.Byteable import qualified Data.ByteString.Internal as B +#if MIN_VERSION_base(4,4,0)+import System.IO.Unsafe (unsafeDupablePerformIO)+#else+import System.IO.Unsafe (unsafePerformIO)+#endif++pureIO :: IO a -> a+#if MIN_VERSION_base(4,4,0)+pureIO = unsafeDupablePerformIO+#else+pureIO = unsafePerformIO+#endif+ -- | SecureMem is a memory chunk which have the properties of: -- -- * Being scrubbed after its goes out of scope.+-- -- * A Show instance that doesn't actually show any content+-- -- * A Eq instance that is constant time+-- #if MIN_VERSION_base(4,6,0) newtype SecureMem = SecureMem { getForeignPtr :: ForeignPtr Word8 } #else@@ -91,7 +107,7 @@ !sz2 = secureMemGetSize s2 secureMemConcat :: [SecureMem] -> SecureMem-secureMemConcat l = unsafeCreateSecureMem total $ \dst -> void $ foldM copy dst l+secureMemConcat l = unsafeCreateSecureMem total $ \dst -> foldM_ copy dst l where total = sum $ map secureMemGetSize l copy dst s = withSecureMemPtr s $ \sp -> do B.memcpy dst sp (fromIntegral sz)@@ -207,7 +223,8 @@ -- | Create a new secure mem using inline perform IO to create a pure -- result. unsafeCreateSecureMem :: Int -> (Ptr Word8 -> IO ()) -> SecureMem-unsafeCreateSecureMem sz f = B.inlinePerformIO (createSecureMem sz f)+unsafeCreateSecureMem sz f = pureIO (createSecureMem sz f)+{-# NOINLINE unsafeCreateSecureMem #-} -- | This is a way to look at the pointer living inside a foreign object. This -- function takes a function which is applied to that pointer. The resulting IO
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013 Vincent Hanquez <vincent@snarc.org>+Copyright (c) 2013-2014 Vincent Hanquez <vincent@snarc.org> All rights reserved.
README.md view
@@ -1,9 +1,28 @@ securemem-=======+========= +[](https://travis-ci.org/vincenthz/hs-securemem)+[](http://en.wikipedia.org/wiki/BSD_licenses)+[](http://haskell.org)++Securemem provides memory chunks that allow auto-scrubbing of the memory after use,+and constant time equality.+ Documentation: [securemem on hackage](http://hackage.haskell.org/package/securemem) +Interacting with securemem+--------------------------++It's recommended to use the [Byteable instance](http://hackage.haskell.org/package/byteable)+when providing an interface that takes a securemem. It allow legacy code, and work in progress+code to interface with securemem more easily.+ older base ---------- -An older base, the memory is not scrubed: upgrade your GHC to 7.6.0 or above.+On older base, the memory is not scrubbed: upgrade your GHC to 7.6.0 or above.++TODO+----++* add a custom memory allocator that give mlocked memory chunks.
cbits/utils.c view
@@ -70,10 +70,6 @@ memset(ptr, 0xa5, sz); } -int constant_memeq16(uint8_t *p1, uint8_t *p2)-{-}- int compare_eq(uint32_t size, uint8_t *p1, uint8_t *p2) { uint32_t i;
securemem.cabal view
@@ -1,5 +1,5 @@ Name: securemem-Version: 0.1.3+Version: 0.1.4 Synopsis: abstraction to an auto scrubbing and const time eq, memory chunk. Description: SecureMem is similar to ByteString, except that it provides a memory chunk that@@ -27,4 +27,4 @@ source-repository head type: git- location: git://github.com/vincenthz/hs-securemem+ location: https://github.com/vincenthz/hs-securemem