1-- | 2-- Module : Crypto.Hash.Blake2s 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-- Blake2s cryptographic hash. 10-- 11{-# LANGUAGE ForeignFunctionInterface #-} 12{-# LANGUAGE DeriveDataTypeable #-} 13{-# LANGUAGE DataKinds #-} 14{-# LANGUAGE TypeFamilies #-} 15module Crypto.Hash.Blake2s 16 ( Blake2s_160 (..), Blake2s_224 (..), Blake2s_256 (..) 17 ) where 18 19import Crypto.Hash.Types 20import Foreign.Ptr (Ptr) 21import Data.Data 22import Data.Word (Word8, Word32) 23 24 25-- | Blake2s (160 bits) cryptographic hash algorithm 26data Blake2s_160 = Blake2s_160 27 deriving (Show,Data) 28 29instance HashAlgorithm Blake2s_160 where 30 type HashBlockSize Blake2s_160 = 64 31 type HashDigestSize Blake2s_160 = 20 32 type HashInternalContextSize Blake2s_160 = 136 33 hashBlockSize _ = 64 34 hashDigestSize _ = 20 35 hashInternalContextSize _ = 136 36 hashInternalInit p = c_blake2s_init p 160 37 hashInternalUpdate = c_blake2s_update 38 hashInternalFinalize p = c_blake2s_finalize p 160 39 40-- | Blake2s (224 bits) cryptographic hash algorithm 41data Blake2s_224 = Blake2s_224 42 deriving (Show,Data) 43 44instance HashAlgorithm Blake2s_224 where 45 type HashBlockSize Blake2s_224 = 64 46 type HashDigestSize Blake2s_224 = 28 47 type HashInternalContextSize Blake2s_224 = 136 48 hashBlockSize _ = 64 49 hashDigestSize _ = 28 50 hashInternalContextSize _ = 136 51 hashInternalInit p = c_blake2s_init p 224 52 hashInternalUpdate = c_blake2s_update 53 hashInternalFinalize p = c_blake2s_finalize p 224 54 55-- | Blake2s (256 bits) cryptographic hash algorithm 56data Blake2s_256 = Blake2s_256 57 deriving (Show,Data) 58 59instance HashAlgorithm Blake2s_256 where 60 type HashBlockSize Blake2s_256 = 64 61 type HashDigestSize Blake2s_256 = 32 62 type HashInternalContextSize Blake2s_256 = 136 63 hashBlockSize _ = 64 64 hashDigestSize _ = 32 65 hashInternalContextSize _ = 136 66 hashInternalInit p = c_blake2s_init p 256 67 hashInternalUpdate = c_blake2s_update 68 hashInternalFinalize p = c_blake2s_finalize p 256 69 70 71foreign import ccall unsafe "cryptonite_blake2s_init" 72 c_blake2s_init :: Ptr (Context a) -> Word32 -> IO () 73 74foreign import ccall "cryptonite_blake2s_update" 75 c_blake2s_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () 76 77foreign import ccall unsafe "cryptonite_blake2s_finalize" 78 c_blake2s_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () 79