diff options
author | Benjamin Barenblat <bbaren@google.com> | 2018-01-26 21:33:25 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2018-01-26 21:33:25 -0500 |
commit | 22b58e03dbf030d7fa0c34f5677bda341405fe07 (patch) | |
tree | b3bafdc910e1314e8413cb9b467abce280b63d71 /src | |
parent | 676eca28e802b602b399b2965ffb15cb8a7a42ae (diff) |
Implement MD5
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/Digest/Md5.hsc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Data/Digest/Md5.hsc b/src/Data/Digest/Md5.hsc new file mode 100644 index 0000000..2a1303d --- /dev/null +++ b/src/Data/Digest/Md5.hsc @@ -0,0 +1,38 @@ +{-# LANGUAGE CApiFFI #-} +{-# OPTIONS_GHC -Wno-missing-methods #-} + +module Data.Digest.Md5 + ( md5 + ) where + +import Data.ByteString.Lazy (ByteString) +import Foreign (Ptr, Storable(alignment, sizeOf)) +import Foreign.C.Types + +import Data.Digest.Internal + +#include <openssl/md5.h> + +data Md5Ctx + +instance Storable Md5Ctx where + sizeOf _ = #size MD5_CTX + alignment _ = #alignment MD5_CTX + +foreign import capi "openssl/md5.h value MD5_DIGEST_LENGTH" + md5DigestLength :: CSize + +foreign import ccall "openssl/md5.h MD5_Init" + md5Init :: Ptr Md5Ctx -> IO CInt + +foreign import ccall "openssl/md5.h MD5_Update" + md5Update :: Ptr Md5Ctx -> Ptr a -> CSize -> IO CInt + +foreign import ccall "openssl/md5.h MD5_Final" + md5Final :: Ptr CUChar -> Ptr Md5Ctx -> IO CInt + +md5Algo :: Algo +md5Algo = Algo md5DigestLength md5Init md5Update md5Final + +md5 :: ByteString -> Digest +md5 = hash md5Algo |