Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add definition for crypto-api and depends on it optionally for now.

  • Loading branch information...
commit 3d6bc5a62001241fe7275ba04b91b8a0a2f84425 1 parent 59f6a59
@vincenthz authored
View
45 Crypto/Hash/MD2.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.MD2
@@ -9,17 +9,18 @@
--
-- A module containing MD2 bindings
--
-module Crypto.Hash.MD2 (
- Ctx(..),
+module Crypto.Hash.MD2
+ ( Ctx(..)
+ , MD2
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+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
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize MD2 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data MD2 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 16
sizeCtx = 96
View
45 Crypto/Hash/MD4.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.MD4
@@ -9,17 +9,18 @@
--
-- A module containing MD4 bindings
--
-module Crypto.Hash.MD4 (
- Ctx(..),
+module Crypto.Hash.MD4
+ ( Ctx(..)
+ , MD4
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+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
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize MD4 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data MD4 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 16
sizeCtx = 96
View
45 Crypto/Hash/MD5.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.MD5
@@ -9,17 +9,18 @@
--
-- A module containing MD5 bindings
--
-module Crypto.Hash.MD5 (
- Ctx(..),
+module Crypto.Hash.MD5
+ ( Ctx(..)
+ , MD5
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+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
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize MD5 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data MD5 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 16
sizeCtx = 96
View
45 Crypto/Hash/RIPEMD160.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.RIPEMD160
@@ -9,17 +9,18 @@
--
-- A module containing RIPEMD160 bindings
--
-module Crypto.Hash.RIPEMD160 (
- Ctx(..),
+module Crypto.Hash.RIPEMD160
+ ( Ctx(..)
+ , RIPEMD160
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx RIPEMD160 where
+ outputLength = Tagged (20 * 8)
+ blockLength = Tagged (64 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize RIPEMD160 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data RIPEMD160 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 20
sizeCtx = 128
View
45 Crypto/Hash/SHA1.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.SHA1
@@ -9,17 +9,18 @@
--
-- A module containing SHA1 bindings
--
-module Crypto.Hash.SHA1 (
- Ctx(..),
+module Crypto.Hash.SHA1
+ ( Ctx(..)
+ , SHA1
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx SHA1 where
+ outputLength = Tagged (20 * 8)
+ blockLength = Tagged (64 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize SHA1 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data SHA1 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 20
sizeCtx = 96
View
45 Crypto/Hash/SHA224.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.SHA224
@@ -9,17 +9,18 @@
--
-- A module containing SHA224 bindings
--
-module Crypto.Hash.SHA224 (
- Ctx(..),
+module Crypto.Hash.SHA224
+ ( Ctx(..)
+ , SHA224
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx SHA224 where
+ outputLength = Tagged (28 * 8)
+ blockLength = Tagged (64 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize SHA224 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data SHA224 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 28
sizeCtx = 192
View
45 Crypto/Hash/SHA256.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.SHA256
@@ -9,17 +9,18 @@
--
-- A module containing SHA256 bindings
--
-module Crypto.Hash.SHA256 (
- Ctx(..),
+module Crypto.Hash.SHA256
+ ( Ctx(..)
+ , SHA256
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx SHA256 where
+ outputLength = Tagged (32 * 8)
+ blockLength = Tagged (64 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize SHA256 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data SHA256 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 32
sizeCtx = 192
View
45 Crypto/Hash/SHA384.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.SHA384
@@ -9,17 +9,18 @@
--
-- A module containing SHA384 bindings
--
-module Crypto.Hash.SHA384 (
- Ctx(..),
+module Crypto.Hash.SHA384
+ ( Ctx(..)
+ , SHA384
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx SHA384 where
+ outputLength = Tagged (48 * 8)
+ blockLength = Tagged (128 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize SHA384 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data SHA384 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 48
sizeCtx = 256
View
45 Crypto/Hash/SHA512.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.SHA512
@@ -9,17 +9,18 @@
--
-- A module containing SHA512 bindings
--
-module Crypto.Hash.SHA512 (
- Ctx(..),
+module Crypto.Hash.SHA512
+ ( Ctx(..)
+ , SHA512
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx SHA512 where
+ outputLength = Tagged (64 * 8)
+ blockLength = Tagged (128 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize SHA512 where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data SHA512 = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 64
sizeCtx = 256
View
41 Crypto/Hash/Skein256.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.Skein256
@@ -9,17 +9,18 @@
--
-- A module containing Skein256 bindings
--
-module Crypto.Hash.Skein256 (
- Ctx(..),
+module Crypto.Hash.Skein256
+ ( Ctx(..)
+ , Skein256
-- * Incremental hashing Functions
- init, -- :: Int -> Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Int -> Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: Int -> ByteString -> ByteString
- hashlazy -- :: Int -> ByteString -> ByteString
+ , hash -- :: Int -> ByteString -> ByteString
+ , hashlazy -- :: Int -> ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -32,7 +33,31 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx Skein256 where
+ outputLength = Tagged (32 * 8)
+ blockLength = Tagged (32 * 8)
+ initialCtx = init (32 * 8)
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
+
+instance Serialize Skein256 where
+ get = liftM Digest (getByteString 32)
+ put (Digest d) = putByteString d
+
+#endif
+
data Ctx = Ctx !ByteString
+data Skein256 = Digest !ByteString
+ deriving (Eq,Ord,Show)
sizeCtx :: Int
sizeCtx = 100
View
41 Crypto/Hash/Skein512.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.Skein512
@@ -9,17 +9,18 @@
--
-- A module containing Skein512 bindings
--
-module Crypto.Hash.Skein512 (
- Ctx(..),
+module Crypto.Hash.Skein512
+ ( Ctx(..)
+ , Skein512
-- * Incremental hashing Functions
- init, -- :: Int -> Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Int -> Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: Int -> ByteString -> ByteString
- hashlazy -- :: Int -> ByteString -> ByteString
+ , hash -- :: Int -> ByteString -> ByteString
+ , hashlazy -- :: Int -> ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -32,7 +33,31 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx Skein512 where
+ outputLength = Tagged (64 * 8)
+ blockLength = Tagged (64 * 8)
+ initialCtx = init (64 * 8)
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
+
+instance Serialize Skein512 where
+ get = liftM Digest (getByteString 64)
+ put (Digest d) = putByteString d
+
+#endif
+
data Ctx = Ctx !ByteString
+data Skein512 = Digest !ByteString
+ deriving (Eq,Ord,Show)
sizeCtx :: Int
sizeCtx = 160
View
45 Crypto/Hash/Tiger.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP, MultiParamTypeClasses #-}
-- |
-- Module : Crypto.Hash.Tiger
@@ -9,17 +9,18 @@
--
-- A module containing Tiger bindings
--
-module Crypto.Hash.Tiger (
- Ctx(..),
+module Crypto.Hash.Tiger
+ ( Ctx(..)
+ , Tiger
-- * Incremental hashing Functions
- init, -- :: Ctx
- update, -- :: Ctx -> ByteString -> Ctx
- finalize, -- :: Ctx -> ByteString
+ , init -- :: Ctx
+ , update -- :: Ctx -> ByteString -> Ctx
+ , finalize -- :: Ctx -> ByteString
-- * Single Pass hashing
- hash, -- :: ByteString -> ByteString
- hashlazy -- :: ByteString -> ByteString
+ , hash -- :: ByteString -> ByteString
+ , hashlazy -- :: ByteString -> ByteString
) where
import Prelude hiding (init)
@@ -31,11 +32,33 @@ import Data.ByteString (ByteString)
import Data.ByteString.Unsafe (unsafeUseAsCString, unsafeUseAsCStringLen)
import Data.ByteString.Internal (create, memcpy)
-data Ctx = Ctx !ByteString
+#ifdef HAVE_CRYPTOAPI
+
+import Control.Monad (liftM)
+import Data.Serialize (Serialize(..))
+import Data.Serialize.Get (getByteString)
+import Data.Serialize.Put (putByteString)
+import Data.Tagged (Tagged(..))
+import qualified Crypto.Classes as C (Hash(..))
+
+instance C.Hash Ctx Tiger where
+ outputLength = Tagged (24 * 8)
+ blockLength = Tagged (64 * 8)
+ initialCtx = init
+ updateCtx = update
+ finalize ctx bs = Digest . finalize $ update ctx bs
-digestSize :: Int
-sizeCtx :: Int
+instance Serialize Tiger where
+ get = liftM Digest (getByteString digestSize)
+ put (Digest d) = putByteString d
+
+#endif
+
+data Ctx = Ctx !ByteString
+data Tiger = Digest !ByteString
+ deriving (Eq,Ord,Show)
+digestSize, sizeCtx :: Int
digestSize = 24
sizeCtx = 96
View
9 cryptohash.cabal
@@ -27,6 +27,10 @@ Flag test
Description: Build unit test
Default: False
+Flag cryptoapi
+ Description: Defines crypto-api instances
+ Default: False
+
Library
Build-Depends: base >= 3 && < 5, bytestring
Extensions: ForeignFunctionInterface
@@ -69,7 +73,7 @@ Library
Executable Tests
Main-Is: Tests.hs
- Extensions: ForeignFunctionInterface
+ Extensions: ForeignFunctionInterface, CPP
C-sources: cbits/sha1.c
cbits/sha256.c
cbits/sha512.c
@@ -85,6 +89,9 @@ Executable Tests
Build-depends: base >= 4, HUnit, bytestring
else
Buildable: False
+ if flag(cryptoapi)
+ Build-depends: crypto-api >= 0.1, tagged >= 0.1, cereal >= 0.2
+ cpp-options: -DHAVE_CRYPTOAPI
source-repository head
type: git

0 comments on commit 3d6bc5a

Please sign in to comment.
Something went wrong with that request. Please try again.