-- |
-- Module      : Crypto.Hash.Skein256
-- License     : BSD-style
-- Maintainer  : Vincent Hanquez <vincent@snarc.org>
-- Stability   : experimental
-- Portability : unknown
--
-- Module containing the binding functions to work with the
-- Skein256 cryptographic hash.
--
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
module Crypto.Hash.Skein256
    (  Skein256_224 (..), Skein256_256 (..)
    ) where

import           Crypto.Hash.Types
import           Foreign.Ptr (Ptr)
import           Data.Data
import           Data.Word (Word8, Word32)


-- | Skein256 (224 bits) cryptographic hash algorithm
data Skein256_224 = Skein256_224
    deriving (Int -> Skein256_224 -> ShowS
[Skein256_224] -> ShowS
Skein256_224 -> String
(Int -> Skein256_224 -> ShowS)
-> (Skein256_224 -> String)
-> ([Skein256_224] -> ShowS)
-> Show Skein256_224
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Skein256_224 -> ShowS
showsPrec :: Int -> Skein256_224 -> ShowS
$cshow :: Skein256_224 -> String
show :: Skein256_224 -> String
$cshowList :: [Skein256_224] -> ShowS
showList :: [Skein256_224] -> ShowS
Show,Typeable Skein256_224
Typeable Skein256_224 =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Skein256_224 -> c Skein256_224)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Skein256_224)
-> (Skein256_224 -> Constr)
-> (Skein256_224 -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Skein256_224))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c Skein256_224))
-> ((forall b. Data b => b -> b) -> Skein256_224 -> Skein256_224)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Skein256_224 -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Skein256_224 -> r)
-> (forall u. (forall d. Data d => d -> u) -> Skein256_224 -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Skein256_224 -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224)
-> Data Skein256_224
Skein256_224 -> Constr
Skein256_224 -> DataType
(forall b. Data b => b -> b) -> Skein256_224 -> Skein256_224
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Skein256_224 -> u
forall u. (forall d. Data d => d -> u) -> Skein256_224 -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_224 -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_224 -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Skein256_224
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Skein256_224 -> c Skein256_224
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Skein256_224)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Skein256_224)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Skein256_224 -> c Skein256_224
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Skein256_224 -> c Skein256_224
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Skein256_224
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Skein256_224
$ctoConstr :: Skein256_224 -> Constr
toConstr :: Skein256_224 -> Constr
$cdataTypeOf :: Skein256_224 -> DataType
dataTypeOf :: Skein256_224 -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Skein256_224)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Skein256_224)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Skein256_224)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Skein256_224)
$cgmapT :: (forall b. Data b => b -> b) -> Skein256_224 -> Skein256_224
gmapT :: (forall b. Data b => b -> b) -> Skein256_224 -> Skein256_224
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_224 -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_224 -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_224 -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_224 -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Skein256_224 -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Skein256_224 -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Skein256_224 -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Skein256_224 -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_224 -> m Skein256_224
Data)

instance HashAlgorithm Skein256_224 where
    type HashBlockSize           Skein256_224 = 32
    type HashDigestSize          Skein256_224 = 28
    type HashInternalContextSize Skein256_224 = 96
    hashBlockSize :: Skein256_224 -> Int
hashBlockSize  Skein256_224
_          = Int
32
    hashDigestSize :: Skein256_224 -> Int
hashDigestSize Skein256_224
_          = Int
28
    hashInternalContextSize :: Skein256_224 -> Int
hashInternalContextSize Skein256_224
_ = Int
96
    hashInternalInit :: Ptr (Context Skein256_224) -> IO ()
hashInternalInit Ptr (Context Skein256_224)
p        = Ptr (Context Skein256_224) -> Word32 -> IO ()
forall a. Ptr (Context a) -> Word32 -> IO ()
c_skein256_init Ptr (Context Skein256_224)
p Word32
224
    hashInternalUpdate :: Ptr (Context Skein256_224) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context Skein256_224) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_skein256_update
    hashInternalFinalize :: Ptr (Context Skein256_224) -> Ptr (Digest Skein256_224) -> IO ()
hashInternalFinalize Ptr (Context Skein256_224)
p    = Ptr (Context Skein256_224)
-> Word32 -> Ptr (Digest Skein256_224) -> IO ()
forall a. Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
c_skein256_finalize Ptr (Context Skein256_224)
p Word32
224

-- | Skein256 (256 bits) cryptographic hash algorithm
data Skein256_256 = Skein256_256
    deriving (Int -> Skein256_256 -> ShowS
[Skein256_256] -> ShowS
Skein256_256 -> String
(Int -> Skein256_256 -> ShowS)
-> (Skein256_256 -> String)
-> ([Skein256_256] -> ShowS)
-> Show Skein256_256
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Skein256_256 -> ShowS
showsPrec :: Int -> Skein256_256 -> ShowS
$cshow :: Skein256_256 -> String
show :: Skein256_256 -> String
$cshowList :: [Skein256_256] -> ShowS
showList :: [Skein256_256] -> ShowS
Show,Typeable Skein256_256
Typeable Skein256_256 =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Skein256_256 -> c Skein256_256)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Skein256_256)
-> (Skein256_256 -> Constr)
-> (Skein256_256 -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Skein256_256))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c Skein256_256))
-> ((forall b. Data b => b -> b) -> Skein256_256 -> Skein256_256)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Skein256_256 -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Skein256_256 -> r)
-> (forall u. (forall d. Data d => d -> u) -> Skein256_256 -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Skein256_256 -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256)
-> Data Skein256_256
Skein256_256 -> Constr
Skein256_256 -> DataType
(forall b. Data b => b -> b) -> Skein256_256 -> Skein256_256
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Skein256_256 -> u
forall u. (forall d. Data d => d -> u) -> Skein256_256 -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_256 -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_256 -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Skein256_256
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Skein256_256 -> c Skein256_256
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Skein256_256)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Skein256_256)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Skein256_256 -> c Skein256_256
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Skein256_256 -> c Skein256_256
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Skein256_256
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Skein256_256
$ctoConstr :: Skein256_256 -> Constr
toConstr :: Skein256_256 -> Constr
$cdataTypeOf :: Skein256_256 -> DataType
dataTypeOf :: Skein256_256 -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Skein256_256)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Skein256_256)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Skein256_256)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c Skein256_256)
$cgmapT :: (forall b. Data b => b -> b) -> Skein256_256 -> Skein256_256
gmapT :: (forall b. Data b => b -> b) -> Skein256_256 -> Skein256_256
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_256 -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_256 -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_256 -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Skein256_256 -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Skein256_256 -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Skein256_256 -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Skein256_256 -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Skein256_256 -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Skein256_256 -> m Skein256_256
Data)

instance HashAlgorithm Skein256_256 where
    type HashBlockSize           Skein256_256 = 32
    type HashDigestSize          Skein256_256 = 32
    type HashInternalContextSize Skein256_256 = 96
    hashBlockSize :: Skein256_256 -> Int
hashBlockSize  Skein256_256
_          = Int
32
    hashDigestSize :: Skein256_256 -> Int
hashDigestSize Skein256_256
_          = Int
32
    hashInternalContextSize :: Skein256_256 -> Int
hashInternalContextSize Skein256_256
_ = Int
96
    hashInternalInit :: Ptr (Context Skein256_256) -> IO ()
hashInternalInit Ptr (Context Skein256_256)
p        = Ptr (Context Skein256_256) -> Word32 -> IO ()
forall a. Ptr (Context a) -> Word32 -> IO ()
c_skein256_init Ptr (Context Skein256_256)
p Word32
256
    hashInternalUpdate :: Ptr (Context Skein256_256) -> Ptr Word8 -> Word32 -> IO ()
hashInternalUpdate        = Ptr (Context Skein256_256) -> Ptr Word8 -> Word32 -> IO ()
forall a. Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
c_skein256_update
    hashInternalFinalize :: Ptr (Context Skein256_256) -> Ptr (Digest Skein256_256) -> IO ()
hashInternalFinalize Ptr (Context Skein256_256)
p    = Ptr (Context Skein256_256)
-> Word32 -> Ptr (Digest Skein256_256) -> IO ()
forall a. Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
c_skein256_finalize Ptr (Context Skein256_256)
p Word32
256


foreign import ccall unsafe "cryptonite_skein256_init"
    c_skein256_init :: Ptr (Context a) -> Word32 -> IO ()

foreign import ccall "cryptonite_skein256_update"
    c_skein256_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()

foreign import ccall unsafe "cryptonite_skein256_finalize"
    c_skein256_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()