1-- |
2-- Module      : Crypto.Hash.Skein256
3-- License     : BSD-style
4-- Maintainer  : Vincent Hanquez <vincent@snarc.org>
5-- Stability   : experimental
6-- Portability : unknown
7--
8-- Module containing the binding functions to work with the
9-- Skein256 cryptographic hash.
10--
11{-# LANGUAGE ForeignFunctionInterface #-}
12{-# LANGUAGE DeriveDataTypeable #-}
13{-# LANGUAGE DataKinds #-}
14{-# LANGUAGE TypeFamilies #-}
15module Crypto.Hash.Skein256
16    (  Skein256_224 (..), Skein256_256 (..)
17    ) where
18
19import           Crypto.Hash.Types
20import           Foreign.Ptr (Ptr)
21import           Data.Data
22import           Data.Word (Word8, Word32)
23
24
25-- | Skein256 (224 bits) cryptographic hash algorithm
26data Skein256_224 = Skein256_224
27    deriving (Show,Data)
28
29instance HashAlgorithm Skein256_224 where
30    type HashBlockSize           Skein256_224 = 32
31    type HashDigestSize          Skein256_224 = 28
32    type HashInternalContextSize Skein256_224 = 96
33    hashBlockSize  _          = 32
34    hashDigestSize _          = 28
35    hashInternalContextSize _ = 96
36    hashInternalInit p        = c_skein256_init p 224
37    hashInternalUpdate        = c_skein256_update
38    hashInternalFinalize p    = c_skein256_finalize p 224
39
40-- | Skein256 (256 bits) cryptographic hash algorithm
41data Skein256_256 = Skein256_256
42    deriving (Show,Data)
43
44instance HashAlgorithm Skein256_256 where
45    type HashBlockSize           Skein256_256 = 32
46    type HashDigestSize          Skein256_256 = 32
47    type HashInternalContextSize Skein256_256 = 96
48    hashBlockSize  _          = 32
49    hashDigestSize _          = 32
50    hashInternalContextSize _ = 96
51    hashInternalInit p        = c_skein256_init p 256
52    hashInternalUpdate        = c_skein256_update
53    hashInternalFinalize p    = c_skein256_finalize p 256
54
55
56foreign import ccall unsafe "cryptonite_skein256_init"
57    c_skein256_init :: Ptr (Context a) -> Word32 -> IO ()
58
59foreign import ccall "cryptonite_skein256_update"
60    c_skein256_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
61
62foreign import ccall unsafe "cryptonite_skein256_finalize"
63    c_skein256_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
64