From 45a29b37173ab724d8b90af7e0b1a9fda3acbeb2 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sat, 27 Jan 2018 17:05:58 -0500 Subject: Data.Digest: Switch back to EVP Use the finalizer techniques demonstrated in 4e56c79b907da4a4654e5278bdcf94b08480a426 to safely allocate `EVP_MD_CTX` on the Haskell heap. This allows us to return to the high-level EVP API, eliminating much boilerplate code. --- src/Data/Digest/Sha2.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Data/Digest/Sha2.hs (limited to 'src/Data/Digest/Sha2.hs') diff --git a/src/Data/Digest/Sha2.hs b/src/Data/Digest/Sha2.hs new file mode 100644 index 0000000..965686c --- /dev/null +++ b/src/Data/Digest/Sha2.hs @@ -0,0 +1,30 @@ +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 -- cgit v1.2.3