raaz-0.3.2: Fast and type safe cryptography.
Safe HaskellNone
LanguageHaskell2010

Context

Description

Contexts are useful when computing message digests of streaming input, i.e needs incremental processing. It consists of the internal state of the primitive, a buffer for intermediate data, and a memory cell for keeping track of the total number of data that is remaining.

Synopsis

Documentation

data Cxt n Source #

There are two cases where incremental processing of bytes are desired.

  1. For incremental message digest or message auth computation. We call this the hashing mode.
  2. For CSPRG. We call this the csprg mode.

In both cases, we need a buffer, the internal memory state and a count of how much data is remaining in the context. This is captured by the Cxt type.

Constructors

Cxt 

Fields

Instances

Instances details
KnownNat n => Memory (Cxt n) Source # 
Instance details

Defined in Context

Methods

memoryAlloc :: Alloc (Cxt n)

unsafeToPointer :: Cxt n -> Ptr Word8

cxtSize :: KnownNat n => Proxy (Cxt n) -> BYTES Int Source #

Gives the size of the context buffer

cxtBlockCount :: KnownNat n => Proxy (Cxt n) -> BlockCount Prim Source #

Gives the number of blocks that can fit in the context.

unsafeSetCxtEmpty :: Cxt n -> IO () Source #

Set the context to the empty state.

unsafeSetCxtFull :: KnownNat n => Cxt n -> IO () Source #

Set the context to the full state.

unsafeGenerateBlocks Source #

Arguments

:: KnownNat n 
=> (BufferPtr -> BlockCount Prim -> Internals -> IO ())

Blocks generator

-> Cxt n 
-> IO () 

Typically used in CSPRG mode, this combinator generates blocks to fill the context buffer. All the current bytes in the context gets overwritten and hence is an unsafe operation. The result of this combinator is a context that is filled with generated bytes ready to be given out.

unsafeConsumeBlocks :: KnownNat n => (BufferPtr -> BlockCount Prim -> Internals -> IO ()) -> Cxt n -> IO () Source #

Typically used in the Hashing mode, this combinator assumes that the context is full and consumes these blocks. This action does not check whether the context is full and hence is unsafe. The result of this action is an empty context ready to receive further bytes.

unsafeWriteTo Source #

Arguments

:: KnownNat n 
=> BYTES Int

How many bytes to send to destination.

-> Dest (Ptr Word8)

destination pointer

-> Cxt n 
-> IO (BYTES Int) 

This action writes out to the given pointer buffer, bytes from the context. The copy of the bytes written in the context buffer is wiped so that looking at the context it is impossible to predict what was written out. The return value is the actual number of bytes written out which may be less than the amount demanded.

unsafeFillFrom :: (KnownNat n, ByteSource src) => src -> Cxt n -> IO (FillResult src) Source #

unsafeUpdate :: (KnownNat n, ByteSource src) => (BufferPtr -> BlockCount Prim -> Internals -> IO ()) -> src -> Cxt n -> IO () Source #

Update the context with data coming from the byte source. Used typically in the digest mode.

unsafeFinalise :: KnownNat n => (BufferPtr -> BYTES Int -> Internals -> IO ()) -> Cxt n -> IO () Source #