1-- |
2-- Module      : Crypto.Hash.Blake2sp
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-- Blake2sp cryptographic hash.
10--
11{-# LANGUAGE ForeignFunctionInterface #-}
12{-# LANGUAGE DeriveDataTypeable #-}
13{-# LANGUAGE DataKinds #-}
14{-# LANGUAGE TypeFamilies #-}
15module Crypto.Hash.Blake2sp
16    (  Blake2sp_224 (..), Blake2sp_256 (..)
17    ) where
18
19import           Crypto.Hash.Types
20import           Foreign.Ptr (Ptr)
21import           Data.Data
22import           Data.Word (Word8, Word32)
23
24
25-- | Blake2sp (224 bits) cryptographic hash algorithm
26data Blake2sp_224 = Blake2sp_224
27    deriving (Show,Data)
28
29instance HashAlgorithm Blake2sp_224 where
30    type HashBlockSize           Blake2sp_224 = 64
31    type HashDigestSize          Blake2sp_224 = 28
32    type HashInternalContextSize Blake2sp_224 = 1752
33    hashBlockSize  _          = 64
34    hashDigestSize _          = 28
35    hashInternalContextSize _ = 1752
36    hashInternalInit p        = c_blake2sp_init p 224
37    hashInternalUpdate        = c_blake2sp_update
38    hashInternalFinalize p    = c_blake2sp_finalize p 224
39
40-- | Blake2sp (256 bits) cryptographic hash algorithm
41data Blake2sp_256 = Blake2sp_256
42    deriving (Show,Data)
43
44instance HashAlgorithm Blake2sp_256 where
45    type HashBlockSize           Blake2sp_256 = 64
46    type HashDigestSize          Blake2sp_256 = 32
47    type HashInternalContextSize Blake2sp_256 = 1752
48    hashBlockSize  _          = 64
49    hashDigestSize _          = 32
50    hashInternalContextSize _ = 1752
51    hashInternalInit p        = c_blake2sp_init p 256
52    hashInternalUpdate        = c_blake2sp_update
53    hashInternalFinalize p    = c_blake2sp_finalize p 256
54
55
56foreign import ccall unsafe "cryptonite_blake2sp_init"
57    c_blake2sp_init :: Ptr (Context a) -> Word32 -> IO ()
58
59foreign import ccall "cryptonite_blake2sp_update"
60    c_blake2sp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
61
62foreign import ccall unsafe "cryptonite_blake2sp_finalize"
63    c_blake2sp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
64