<commit_before>{-# LANGUAGE ForeignFunctionInterface   #-}
{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE KindSignatures             #-}

-- | The portable C-implementation of Blake2b.
module Blake2b.CPortable where

import Foreign.Ptr                ( Ptr, castPtr )
import Control.Monad.IO.Class     ( liftIO       )
import Data.Word
import Data.Proxy
import Data.Bits                  ( complement   )

import Raaz.Core
import Raaz.Core.Transfer         ( transferSize, unsafeTransfer )
import Raaz.Core.Types.Internal
import Raaz.Primitive.HashMemory
import Raaz.Primitive.Blake2.Internal
import Raaz.Verse.Blake2b.C.Portable

name :: String
name = "blake2b-libverse-c"

description :: String
description = "Blake2b Implementation in C exposed by libverse"

type Prim                    = Blake2b
type Internals               = Blake2bMem
type BufferAlignment         = 32


additionalBlocks :: BLOCKS Blake2b
additionalBlocks = blocksOf 1 Proxy


------------------------ The foreign function calls  ---------------------

foreign import ccall unsafe
  "raaz/hash/blake2/common.h raazHashBlake2bPortableBlockCompress"
  c_blake2b_compress  :: AlignedPointer BufferAlignment
                      -> BLOCKS Prim
                      -> Ptr (BYTES Word64)
                      -> Ptr (BYTES Word64)
                      -> Ptr Blake2b
                      -> IO ()

foreign import ccall unsafe
  "raaz/hash/blake2/common.h raazHashBlake2bPortableLastBlock"
  c_blake2b_last   :: Pointer
                   -> BYTES Int
                   -> BYTES Word64
                   -> BYTES Word64
                   -> Word64
                   -> Word64
                   -> Ptr Blake2b
                   -> IO ()

--
processBlocks :: AlignedPointer BufferAlignment
              -> BLOCKS Blake2b
              -> MT Blake2bMem ()

processBlocks buf blks =
  do uPtr   <- castPtr <$> uLengthCellPointer
     lPtr   <- castPtr <$>lLengthCellPointer
     hshPtr <- castPtr <$> hashCell128Pointer
     let wblks  = toEnum  $ fromEnum blks
         blkPtr = castPtr $ forgetAlignment buf<commit_msg>remove unwanted foreign calls.<commit_after>{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE KindSignatures             #-}

-- | The portable C-implementation of Blake2b.
module Blake2b.CPortable where


import Control.Monad.IO.Class     ( liftIO       )
import Data.Proxy
import Data.Bits                  ( complement   )
import Foreign.Ptr                ( castPtr      )

import Raaz.Core
import Raaz.Core.Transfer         ( transferSize, unsafeTransfer )
import Raaz.Core.Types.Internal
import Raaz.Primitive.HashMemory
import Raaz.Primitive.Blake2.Internal
import Raaz.Verse.Blake2b.C.Portable

name :: String
name = "blake2b-libverse-c"

description :: String
description = "Blake2b Implementation in C exposed by libverse"

type Prim                    = Blake2b
type Internals               = Blake2bMem
type BufferAlignment         = 32


additionalBlocks :: BLOCKS Blake2b
additionalBlocks = blocksOf 1 Proxy


processBlocks :: AlignedPointer BufferAlignment
              -> BLOCKS Blake2b
              -> MT Blake2bMem ()

processBlocks buf blks =
  do uPtr   <- castPtr <$> uLengthCellPointer
     lPtr   <- castPtr <$>lLengthCellPointer
     hshPtr <- castPtr <$> hashCell128Pointer
     let wblks  = toEnum  $ fromEnum blks
         blkPtr = castPtr $ forgetAlignment buf
{'fraction_non_alphanumeric': 0.08751835535976506, 'fraction_numerical': 0.015859030837004406, 'mean_word_length': 2.00352733686067, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4210256', 'n_tokens_mistral': 1016, 'n_tokens_neox': 954, 'n_words': 244}