Permalink
Browse files

expand tabs

  • Loading branch information...
1 parent e678128 commit 4f5ac6c38226dc4524d39dae4f698ea008c8e191 @vincenthz committed Nov 4, 2012
View
@@ -10,18 +10,18 @@
-- A module containing MD2 bindings
--
module Crypto.Hash.MD2
- ( Ctx(..)
- , MD2
+ ( Ctx(..)
+ , MD2
- -- * Incremental hashing Functions
- , init -- :: Ctx
- , update -- :: Ctx -> ByteString -> Ctx
- , finalize -- :: Ctx -> ByteString
+ -- * Incremental hashing Functions
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
- -- * Single Pass hashing
- , hash -- :: ByteString -> ByteString
- , hashlazy -- :: ByteString -> ByteString
- ) where
+ -- * Single Pass hashing
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
+ ) where
import Prelude hiding (init)
import System.IO.Unsafe (unsafePerformIO)
@@ -46,41 +46,43 @@ import Data.Tagged (Tagged(..))
import qualified Crypto.Classes as C (Hash(..))
instance C.Hash Ctx MD2 where
- outputLength = Tagged (16 * 8)
- blockLength = Tagged (16 * 8)
- initialCtx = init
- updateCtx = update
- finalize ctx bs = Digest . finalize $ update ctx bs
+ outputLength = Tagged (16 * 8)
+ blockLength = Tagged (16 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
instance Serialize MD2 where
- get = liftM Digest (getByteString digestSize)
- put (Digest d) = putByteString d
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
#endif
data Ctx = Ctx !ByteString
data MD2 = Digest !ByteString
- deriving (Eq,Ord,Show)
+ deriving (Eq,Ord,Show)
-digestSize, sizeCtx :: Int
+digestSize :: Int
digestSize = 16
+
+sizeCtx :: Int
sizeCtx = 96
instance Storable Ctx where
- sizeOf _ = sizeCtx
- alignment _ = 16
- poke ptr (Ctx b) = unsafeUseAsCString b (\cs -> memcpy (castPtr ptr) (castPtr cs) (fromIntegral sizeCtx))
+ sizeOf _ = sizeCtx
+ alignment _ = 16
+ poke ptr (Ctx b) = unsafeUseAsCString b (\cs -> memcpy (castPtr ptr) (castPtr cs) (fromIntegral sizeCtx))
- peek ptr = create sizeCtx (\bptr -> memcpy bptr (castPtr ptr) (fromIntegral sizeCtx)) >>= return . Ctx
+ peek ptr = create sizeCtx (\bptr -> memcpy bptr (castPtr ptr) (fromIntegral sizeCtx)) >>= return . Ctx
foreign import ccall unsafe "md2.h md2_init"
- c_md2_init :: Ptr Ctx -> IO ()
+ c_md2_init :: Ptr Ctx -> IO ()
foreign import ccall "md2.h md2_update"
- c_md2_update :: Ptr Ctx -> CString -> Word32 -> IO ()
+ c_md2_update :: Ptr Ctx -> CString -> Word32 -> IO ()
foreign import ccall unsafe "md2.h md2_finalize"
- c_md2_finalize :: Ptr Ctx -> CString -> IO ()
+ c_md2_finalize :: Ptr Ctx -> CString -> IO ()
allocInternal :: (Ptr Ctx -> IO a) -> IO a
allocInternal = alloca
@@ -90,11 +92,11 @@ allocInternalFrom ctx f = allocInternal $ \ptr -> (poke ptr ctx >> f ptr)
updateInternalIO :: Ptr Ctx -> ByteString -> IO ()
updateInternalIO ptr d =
- unsafeUseAsCStringLen d (\(cs, len) -> c_md2_update ptr cs (fromIntegral len))
+ unsafeUseAsCStringLen d (\(cs, len) -> c_md2_update ptr cs (fromIntegral len))
finalizeInternalIO :: Ptr Ctx -> IO ByteString
finalizeInternalIO ptr =
- allocaBytes digestSize (\cs -> c_md2_finalize ptr cs >> B.packCStringLen (cs, digestSize))
+ allocaBytes digestSize (\cs -> c_md2_finalize ptr cs >> B.packCStringLen (cs, digestSize))
{-# NOINLINE init #-}
-- | init a context
@@ -115,10 +117,10 @@ finalize ctx = unsafePerformIO $ allocInternalFrom ctx $ \ptr -> do finalizeInte
-- | hash a strict bytestring into a digest bytestring
hash :: ByteString -> ByteString
hash d = unsafePerformIO $ allocInternal $ \ptr -> do
- c_md2_init ptr >> updateInternalIO ptr d >> finalizeInternalIO ptr
+ c_md2_init ptr >> updateInternalIO ptr d >> finalizeInternalIO ptr
{-# NOINLINE hashlazy #-}
-- | hash a lazy bytestring into a digest bytestring
hashlazy :: L.ByteString -> ByteString
hashlazy l = unsafePerformIO $ allocInternal $ \ptr -> do
- c_md2_init ptr >> mapM_ (updateInternalIO ptr) (L.toChunks l) >> finalizeInternalIO ptr
+ c_md2_init ptr >> mapM_ (updateInternalIO ptr) (L.toChunks l) >> finalizeInternalIO ptr
View
@@ -10,18 +10,18 @@
-- A module containing MD4 bindings
--
module Crypto.Hash.MD4
- ( Ctx(..)
- , MD4
+ ( Ctx(..)
+ , MD4
- -- * Incremental hashing Functions
- , init -- :: Ctx
- , update -- :: Ctx -> ByteString -> Ctx
- , finalize -- :: Ctx -> ByteString
+ -- * Incremental hashing Functions
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
- -- * Single Pass hashing
- , hash -- :: ByteString -> ByteString
- , hashlazy -- :: ByteString -> ByteString
- ) where
+ -- * Single Pass hashing
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
+ ) where
import Prelude hiding (init)
import System.IO.Unsafe (unsafePerformIO)
@@ -46,41 +46,43 @@ import Data.Tagged (Tagged(..))
import qualified Crypto.Classes as C (Hash(..))
instance C.Hash Ctx MD4 where
- outputLength = Tagged (16 * 8)
- blockLength = Tagged (64 * 8)
- initialCtx = init
- updateCtx = update
- finalize ctx bs = Digest . finalize $ update ctx bs
+ outputLength = Tagged (16 * 8)
+ blockLength = Tagged (64 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
instance Serialize MD4 where
- get = liftM Digest (getByteString digestSize)
- put (Digest d) = putByteString d
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
#endif
data Ctx = Ctx !ByteString
data MD4 = Digest !ByteString
- deriving (Eq,Ord,Show)
+ deriving (Eq,Ord,Show)
-digestSize, sizeCtx :: Int
+digestSize :: Int
digestSize = 16
+
+sizeCtx :: Int
sizeCtx = 96
instance Storable Ctx where
- sizeOf _ = sizeCtx
- alignment _ = 16
- poke ptr (Ctx b) = unsafeUseAsCString b (\cs -> memcpy (castPtr ptr) (castPtr cs) (fromIntegral sizeCtx))
+ sizeOf _ = sizeCtx
+ alignment _ = 16
+ poke ptr (Ctx b) = unsafeUseAsCString b (\cs -> memcpy (castPtr ptr) (castPtr cs) (fromIntegral sizeCtx))
- peek ptr = create sizeCtx (\bptr -> memcpy bptr (castPtr ptr) (fromIntegral sizeCtx)) >>= return . Ctx
+ peek ptr = create sizeCtx (\bptr -> memcpy bptr (castPtr ptr) (fromIntegral sizeCtx)) >>= return . Ctx
foreign import ccall unsafe "md4.h md4_init"
- c_md4_init :: Ptr Ctx -> IO ()
+ c_md4_init :: Ptr Ctx -> IO ()
foreign import ccall "md4.h md4_update"
- c_md4_update :: Ptr Ctx -> CString -> Word32 -> IO ()
+ c_md4_update :: Ptr Ctx -> CString -> Word32 -> IO ()
foreign import ccall unsafe "md4.h md4_finalize"
- c_md4_finalize :: Ptr Ctx -> CString -> IO ()
+ c_md4_finalize :: Ptr Ctx -> CString -> IO ()
allocInternal :: (Ptr Ctx -> IO a) -> IO a
allocInternal = alloca
@@ -90,11 +92,11 @@ allocInternalFrom ctx f = allocInternal $ \ptr -> (poke ptr ctx >> f ptr)
updateInternalIO :: Ptr Ctx -> ByteString -> IO ()
updateInternalIO ptr d =
- unsafeUseAsCStringLen d (\(cs, len) -> c_md4_update ptr cs (fromIntegral len))
+ unsafeUseAsCStringLen d (\(cs, len) -> c_md4_update ptr cs (fromIntegral len))
finalizeInternalIO :: Ptr Ctx -> IO ByteString
finalizeInternalIO ptr =
- allocaBytes digestSize (\cs -> c_md4_finalize ptr cs >> B.packCStringLen (cs, digestSize))
+ allocaBytes digestSize (\cs -> c_md4_finalize ptr cs >> B.packCStringLen (cs, digestSize))
{-# NOINLINE init #-}
-- | init a context
@@ -115,10 +117,10 @@ finalize ctx = unsafePerformIO $ allocInternalFrom ctx $ \ptr -> do finalizeInte
-- | hash a strict bytestring into a digest bytestring
hash :: ByteString -> ByteString
hash d = unsafePerformIO $ allocInternal $ \ptr -> do
- c_md4_init ptr >> updateInternalIO ptr d >> finalizeInternalIO ptr
+ c_md4_init ptr >> updateInternalIO ptr d >> finalizeInternalIO ptr
{-# NOINLINE hashlazy #-}
-- | hash a lazy bytestring into a digest bytestring
hashlazy :: L.ByteString -> ByteString
hashlazy l = unsafePerformIO $ allocInternal $ \ptr -> do
- c_md4_init ptr >> mapM_ (updateInternalIO ptr) (L.toChunks l) >> finalizeInternalIO ptr
+ c_md4_init ptr >> mapM_ (updateInternalIO ptr) (L.toChunks l) >> finalizeInternalIO ptr
View
@@ -10,18 +10,18 @@
-- A module containing MD5 bindings
--
module Crypto.Hash.MD5
- ( Ctx(..)
- , MD5
+ ( Ctx(..)
+ , MD5
- -- * Incremental hashing Functions
- , init -- :: Ctx
- , update -- :: Ctx -> ByteString -> Ctx
- , finalize -- :: Ctx -> ByteString
+ -- * Incremental hashing Functions
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
- -- * Single Pass hashing
- , hash -- :: ByteString -> ByteString
- , hashlazy -- :: ByteString -> ByteString
- ) where
+ -- * Single Pass hashing
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
+ ) where
import Prelude hiding (init)
import System.IO.Unsafe (unsafePerformIO)
@@ -46,41 +46,43 @@ import Data.Tagged (Tagged(..))
import qualified Crypto.Classes as C (Hash(..))
instance C.Hash Ctx MD5 where
- outputLength = Tagged (16 * 8)
- blockLength = Tagged (64 * 8)
- initialCtx = init
- updateCtx = update
- finalize ctx bs = Digest . finalize $ update ctx bs
+ outputLength = Tagged (16 * 8)
+ blockLength = Tagged (64 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
instance Serialize MD5 where
- get = liftM Digest (getByteString digestSize)
- put (Digest d) = putByteString d
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
#endif
data Ctx = Ctx !ByteString
data MD5 = Digest !ByteString
- deriving (Eq,Ord,Show)
+ deriving (Eq,Ord,Show)
-digestSize, sizeCtx :: Int
+digestSize :: Int
digestSize = 16
+
+sizeCtx :: Int
sizeCtx = 96
instance Storable Ctx where
- sizeOf _ = sizeCtx
- alignment _ = 16
- poke ptr (Ctx b) = unsafeUseAsCString b (\cs -> memcpy (castPtr ptr) (castPtr cs) (fromIntegral sizeCtx))
+ sizeOf _ = sizeCtx
+ alignment _ = 16
+ poke ptr (Ctx b) = unsafeUseAsCString b (\cs -> memcpy (castPtr ptr) (castPtr cs) (fromIntegral sizeCtx))
- peek ptr = create sizeCtx (\bptr -> memcpy bptr (castPtr ptr) (fromIntegral sizeCtx)) >>= return . Ctx
+ peek ptr = create sizeCtx (\bptr -> memcpy bptr (castPtr ptr) (fromIntegral sizeCtx)) >>= return . Ctx
foreign import ccall unsafe "md5.h md5_init"
- c_md5_init :: Ptr Ctx -> IO ()
+ c_md5_init :: Ptr Ctx -> IO ()
foreign import ccall "md5.h md5_update"
- c_md5_update :: Ptr Ctx -> CString -> Word32 -> IO ()
+ c_md5_update :: Ptr Ctx -> CString -> Word32 -> IO ()
foreign import ccall unsafe "md5.h md5_finalize"
- c_md5_finalize :: Ptr Ctx -> CString -> IO ()
+ c_md5_finalize :: Ptr Ctx -> CString -> IO ()
allocInternal :: (Ptr Ctx -> IO a) -> IO a
allocInternal = alloca
@@ -90,11 +92,11 @@ allocInternalFrom ctx f = allocInternal $ \ptr -> (poke ptr ctx >> f ptr)
updateInternalIO :: Ptr Ctx -> ByteString -> IO ()
updateInternalIO ptr d =
- unsafeUseAsCStringLen d (\(cs, len) -> c_md5_update ptr cs (fromIntegral len))
+ unsafeUseAsCStringLen d (\(cs, len) -> c_md5_update ptr cs (fromIntegral len))
finalizeInternalIO :: Ptr Ctx -> IO ByteString
finalizeInternalIO ptr =
- allocaBytes digestSize (\cs -> c_md5_finalize ptr cs >> B.packCStringLen (cs, digestSize))
+ allocaBytes digestSize (\cs -> c_md5_finalize ptr cs >> B.packCStringLen (cs, digestSize))
{-# NOINLINE init #-}
-- | init a context
@@ -115,10 +117,10 @@ finalize ctx = unsafePerformIO $ allocInternalFrom ctx $ \ptr -> do finalizeInte
-- | hash a strict bytestring into a digest bytestring
hash :: ByteString -> ByteString
hash d = unsafePerformIO $ allocInternal $ \ptr -> do
- c_md5_init ptr >> updateInternalIO ptr d >> finalizeInternalIO ptr
+ c_md5_init ptr >> updateInternalIO ptr d >> finalizeInternalIO ptr
{-# NOINLINE hashlazy #-}
-- | hash a lazy bytestring into a digest bytestring
hashlazy :: L.ByteString -> ByteString
hashlazy l = unsafePerformIO $ allocInternal $ \ptr -> do
- c_md5_init ptr >> mapM_ (updateInternalIO ptr) (L.toChunks l) >> finalizeInternalIO ptr
+ c_md5_init ptr >> mapM_ (updateInternalIO ptr) (L.toChunks l) >> finalizeInternalIO ptr
Oops, something went wrong.

0 comments on commit 4f5ac6c

Please sign in to comment.