1-- |
2-- Module      : Crypto.Hash.Blake2bp
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-- Blake2bp cryptographic hash.
10--
11{-# LANGUAGE ForeignFunctionInterface #-}
12{-# LANGUAGE DeriveDataTypeable #-}
13{-# LANGUAGE DataKinds #-}
14{-# LANGUAGE TypeFamilies #-}
15module Crypto.Hash.Blake2bp
16    (  Blake2bp_512 (..)
17    ) where
18
19import           Crypto.Hash.Types
20import           Foreign.Ptr (Ptr)
21import           Data.Data
22import           Data.Word (Word8, Word32)
23
24
25-- | Blake2bp (512 bits) cryptographic hash algorithm
26data Blake2bp_512 = Blake2bp_512
27    deriving (Show,Data)
28
29instance HashAlgorithm Blake2bp_512 where
30    type HashBlockSize           Blake2bp_512 = 128
31    type HashDigestSize          Blake2bp_512 = 64
32    type HashInternalContextSize Blake2bp_512 = 1768
33    hashBlockSize  _          = 128
34    hashDigestSize _          = 64
35    hashInternalContextSize _ = 1768
36    hashInternalInit p        = c_blake2bp_init p 512
37    hashInternalUpdate        = c_blake2bp_update
38    hashInternalFinalize p    = c_blake2bp_finalize p 512
39
40
41foreign import ccall unsafe "cryptonite_blake2bp_init"
42    c_blake2bp_init :: Ptr (Context a) -> Word32 -> IO ()
43
44foreign import ccall "cryptonite_blake2bp_update"
45    c_blake2bp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()
46
47foreign import ccall unsafe "cryptonite_blake2bp_finalize"
48    c_blake2bp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
49