Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- data Cxt n = Cxt {
- cxtInternals :: Internals
- cxtBuf :: Buffer n
- cxtAvailableBytes :: MemoryCell (BYTES Int)
- cxtSize :: KnownNat n => Proxy (Cxt n) -> BYTES Int
- cxtBlockCount :: KnownNat n => Proxy (Cxt n) -> BlockCount Prim
- unsafeSetCxtEmpty :: Cxt n -> IO ()
- unsafeSetCxtFull :: KnownNat n => Cxt n -> IO ()
- unsafeGenerateBlocks :: KnownNat n => (BufferPtr -> BlockCount Prim -> Internals -> IO ()) -> Cxt n -> IO ()
- unsafeConsumeBlocks :: KnownNat n => (BufferPtr -> BlockCount Prim -> Internals -> IO ()) -> Cxt n -> IO ()
- unsafeWriteTo :: KnownNat n => BYTES Int -> Dest (Ptr Word8) -> Cxt n -> IO (BYTES Int)
- unsafeFillFrom :: (KnownNat n, ByteSource src) => src -> Cxt n -> IO (FillResult src)
- unsafeUpdate :: (KnownNat n, ByteSource src) => (BufferPtr -> BlockCount Prim -> Internals -> IO ()) -> src -> Cxt n -> IO ()
- unsafeFinalise :: KnownNat n => (BufferPtr -> BYTES Int -> Internals -> IO ()) -> Cxt n -> IO ()
Documentation
There are two cases where incremental processing of bytes are desired.
- For incremental message digest or message auth computation. We call this the hashing mode.
- 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.
Cxt | |
|
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.
:: 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.
:: 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.