diff options
Diffstat (limited to 'src/Data/Digest')
-rw-r--r-- | src/Data/Digest/Internal.hsc | 12 | ||||
-rw-r--r-- | src/Data/Digest/Md5.hs | 12 | ||||
-rw-r--r-- | src/Data/Digest/Sha1.hs | 12 | ||||
-rw-r--r-- | src/Data/Digest/Sha2.hs | 30 |
4 files changed, 6 insertions, 60 deletions
diff --git a/src/Data/Digest/Internal.hsc b/src/Data/Digest/Internal.hsc index 73edbd9..a7f19d7 100644 --- a/src/Data/Digest/Internal.hsc +++ b/src/Data/Digest/Internal.hsc @@ -31,9 +31,6 @@ data Engine -- | The BoringSSL @EVP_MD@ type, representing a hash algorithm. data EvpMd --- | A convenience alias for @Ptr EvpMd@. -type Algo = Ptr EvpMd - -- | The BoringSSL @EVP_MD_CTX@ type, representing the state of a pending -- hashing operation. data EvpMdCtx @@ -103,6 +100,9 @@ foreign import ccall "&btlsFinalizeEvpMdCtx" -- Finally, we're ready to actually implement the hashing interface. +-- | A cryptographic hash function. +newtype Algorithm = Algorithm (Ptr EvpMd) + -- | The result of a hash operation. newtype Digest = Digest ByteString @@ -115,9 +115,9 @@ instance Show Digest where hexit (b `shiftR` 4 .&. 0x0f) : hexit (b .&. 0x0f) : xs hexit = intToDigit . fromIntegral :: Word8 -> Char --- | Hashes according to the given 'Algo'. -hash :: Algo -> LazyByteString -> Digest -hash md bytes = +-- | Hashes according to the given 'Algorithm'. +hash :: Algorithm -> LazyByteString -> Digest +hash (Algorithm md) bytes = unsafeLocalState $ do ctxFP <- mallocEvpMdCtx withForeignPtr ctxFP $ \ctx -> do diff --git a/src/Data/Digest/Md5.hs b/src/Data/Digest/Md5.hs deleted file mode 100644 index 194633b..0000000 --- a/src/Data/Digest/Md5.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Data.Digest.Md5 - ( md5 - ) where - -import Data.ByteString.Lazy (ByteString) - -import Data.Digest.Internal - -foreign import ccall "openssl/digest.h EVP_md5" evpMd5 :: Algo - -md5 :: ByteString -> Digest -md5 = hash evpMd5 diff --git a/src/Data/Digest/Sha1.hs b/src/Data/Digest/Sha1.hs deleted file mode 100644 index 16101b0..0000000 --- a/src/Data/Digest/Sha1.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Data.Digest.Sha1 - ( sha1 - ) where - -import Data.ByteString.Lazy (ByteString) - -import Data.Digest.Internal - -foreign import ccall "openssl/digest.h EVP_sha1" evpSha1 :: Algo - -sha1 :: ByteString -> Digest -sha1 = hash evpSha1 diff --git a/src/Data/Digest/Sha2.hs b/src/Data/Digest/Sha2.hs deleted file mode 100644 index 965686c..0000000 --- a/src/Data/Digest/Sha2.hs +++ /dev/null @@ -1,30 +0,0 @@ -module Data.Digest.Sha2 - ( sha224 - , sha256 - , sha384 - , sha512 - ) where - -import Data.ByteString.Lazy (ByteString) - -import Data.Digest.Internal - -foreign import ccall "openssl/digest.h EVP_sha224" evpSha224 :: Algo - -foreign import ccall "openssl/digest.h EVP_sha256" evpSha256 :: Algo - -foreign import ccall "openssl/digest.h EVP_sha384" evpSha384 :: Algo - -foreign import ccall "openssl/digest.h EVP_sha512" evpSha512 :: Algo - -sha224 :: ByteString -> Digest -sha224 = hash evpSha224 - -sha256 :: ByteString -> Digest -sha256 = hash evpSha256 - -sha384 :: ByteString -> Digest -sha384 = hash evpSha384 - -sha512 :: ByteString -> Digest -sha512 = hash evpSha512 |