raaz-0.2.1: The raaz cryptographic library.

Safe Haskell | None
Language | Haskell2010

Raaz.Core.Types

Contents

- Overview.
- Timing safe equality checking.
- Endianess aware types.
  - Endian explicit word types.
  - Helper functions for endian aware storing and loading.
- Pointers, offsets, and alignment
  - Type safe length units.
    - Some length arithmetic
  - Types measuring alignment
  - Allocation functions.
  - Some buffer operations
- Types to force alignment.
- Length encoded tuples
  - Unsafe operations

Description

This module exposes some core types used through out the Raaz library. One of the major goals of the raaz cryptographic library is to use the type safety of Haskell to catch some common bugs at compile time.

WARNING: If you are just a user of this library, it is unlikely that you will need to import this module. It is only required if you are a developer and want to define a new cryptographic data type.

Synopsis

- class Equality a where
  - eq :: a -> a -> Result
- (===) :: Equality a => a -> a -> Bool
- data Result
- class Storable w => EndianStore w where
  - store :: Ptr w -> w -> IO ()
  - load :: Ptr w -> IO w
  - adjustEndian :: Ptr w -> Int -> IO ()
- copyFromBytes :: EndianStore w => Dest (Ptr w) -> Src Pointer -> Int -> IO ()
- copyToBytes :: EndianStore w => Dest Pointer -> Src (Ptr w) -> Int -> IO ()
- data LE w
- data BE w
- littleEndian :: w -> LE w
- bigEndian :: w -> BE w
- storeAt :: (EndianStore w, LengthUnit offset) => Ptr w -> offset -> w -> IO ()
- storeAtIndex :: EndianStore w => Ptr w -> Int -> w -> IO ()
- loadFrom :: (EndianStore w, LengthUnit offset) => Ptr w -> offset -> IO w
- loadFromIndex :: EndianStore w => Ptr w -> Int -> IO w
- type Pointer = Ptr Align
- class (Enum u, Monoid u) => LengthUnit u where
  - inBytes :: u -> BYTES Int
- newtype BYTES a = BYTES a
- newtype BITS a = BITS a
- inBits :: LengthUnit u => u -> BITS Word64
- sizeOf :: Storable a => a -> BYTES Int
- bitsQuotRem :: LengthUnit u => BITS Word64 -> (u, BITS Word64)
- bytesQuotRem :: LengthUnit u => BYTES Int -> (u, BYTES Int)
- bitsQuot :: LengthUnit u => BITS Word64 -> u
- bytesQuot :: LengthUnit u => BYTES Int -> u
- atLeast :: (LengthUnit src, LengthUnit dest) => src -> dest
- atLeastAligned :: LengthUnit l => l -> Alignment -> ALIGN
- atMost :: (LengthUnit src, LengthUnit dest) => src -> dest
- data Alignment
- wordAlignment :: Alignment
- data ALIGN
- alignment :: Storable a => a -> Alignment
- alignPtr :: Ptr a -> Alignment -> Ptr a
- movePtr :: LengthUnit l => Ptr a -> l -> Ptr a
- alignedSizeOf :: Storable a => a -> ALIGN
- nextAlignedPtr :: Storable a => Ptr a -> Ptr a
- peekAligned :: Storable a => Ptr a -> IO a
- pokeAligned :: Storable a => Ptr a -> a -> IO ()
- allocaAligned :: LengthUnit l => Alignment -> l -> (Pointer -> IO b) -> IO b
- allocaSecureAligned :: LengthUnit l => Alignment -> l -> (Pointer -> IO a) -> IO a
- allocaBuffer :: LengthUnit l => l -> (Pointer -> IO b) -> IO b
- allocaSecure :: LengthUnit l => l -> (Pointer -> IO b) -> IO b
- mallocBuffer :: LengthUnit l => l -> IO Pointer
- memset :: (MonadIO m, LengthUnit l) => Pointer -> Word8 -> l -> m ()
- memmove :: (MonadIO m, LengthUnit l) => Dest Pointer -> Src Pointer -> l -> m ()
- memcpy :: (MonadIO m, LengthUnit l) => Dest Pointer -> Src Pointer -> l -> m ()
- hFillBuf :: LengthUnit bufSize => Handle -> Pointer -> bufSize -> IO (BYTES Int)
- data Aligned (align :: Nat) w
- unAligned :: Aligned align w -> w
- aligned16Bytes :: w -> Aligned 16 w
- aligned32Bytes :: w -> Aligned 32 w
- aligned64Bytes :: w -> Aligned 64 w
- data Tuple (dim :: Nat) a
- type Dimension (dim :: Nat) = KnownNat dim
- dimension :: Dimension dim => Tuple dim a -> Int
- initial :: (Unbox a, Dimension dim0) => Tuple dim1 a -> Tuple dim0 a
- diagonal :: (Unbox a, Dimension dim) => a -> Tuple dim a
- repeatM :: (Functor m, Monad m, Unbox a, Dimension dim) => m a -> m (Tuple dim a)
- zipWith :: (Unbox a, Unbox b, Unbox c) => (a -> b -> c) -> Tuple dim a -> Tuple dim b -> Tuple dim c
- unsafeFromList :: (Unbox a, Dimension dim) => [a] -> Tuple dim a
- data Dest a
- data Src a
- source :: a -> Src a
- destination :: a -> Dest a
- class Describable d where
  - name :: d -> String
  - description :: d -> String

# Overview.

A lot of cryptographic code is low level and involves quite a bit of boilerplate and are therefore fertile grounds for bugs. This module describes types specific to raaz that are designed to catch bugs in such low level code. The three principles that we follow in the design are:

1. Define distinct types for semantically different objects. For example, distinguish between buffer length/pointer offset in bytes versus other units (see `LengthUnit`) or make endian aware variants of standard word types (see `BE` and `LE`) etc.
2. Make sure that the low level functions are sensitive to these types. For example, the function `sizeOf` exposed here returns ``BYTES` `Int`` instead of just `Int` and functions like `allocaBuffer` are generic enough to work with any length units.
3. Provide obvious instances for some basic type and have and idiom/design pattern to build such interfaces for user defined types. For example, we have a very specific way to build timing safe equality functions for arbitrary types. Most of the time, in our case it just amounts to handling product types.

## Role of Monoids.

Monoids play an important role in facilitating the top down approach to type safety that we mentioned above. Some types described here have a natural monoid semantics. For example, when dealing with pointer offsets and buffer sizes, we use type safe length units like `BYTES`. These length units are instances of monoids where the underlying operation is addition. On the other hand, when it comes to pointer alignment which is captured by the type `Alignment`, the monoid operation is taking the lowest common multiple.

# Timing safe equality checking.

Many cryptographic setting require comparing two secrets and such comparisons should be timing safe, i.e. the time taken to make the comparison should not depend on the actual values that are compared. Unfortunately, the equality comparison of may Haskell types like `ByteString`, provided via the class `Eq` is not timing safe. In raaz we take special care in defining the `Eq` instance of all cryptographically sensitive types which make them timing safe . For example, if we compare two digests `dgst1 == dgst2`, the `Eq` instance is defined in such a way that the time taken is constant irrespective of the actual values. We also give a mechanism to build timing safe equality for more complicated types that user might need to define in her use cases as we now describe.

The starting point of defining such timing safe equality is the class `Equality` which plays the role `Eq`. The member function `eq` playing the role of (`==`) with an important difference. The comparison function `eq` returns the type type `Result` instead of `Bool` and it is timing safe. The `Eq` instance is then defined by making use of the operator (`===`). Thus a user of the library can stick to the familiar `Eq` class and get the benefits of timing safe comparison

## Building timing safe equality for Custom types.

For basic types like `Word32`, `Word64` this module defines instances of `Equality`. The `Tuple` type inherits the `Equality` instance from its base type. As a developer, new crypto-primitives or protocols often need to define timing safe equality for types other than those exported here. This is done in two stages.

1. Define an instance of `Equality`.
2. Make use of the above instance to define `Eq` instance as follows.

    data SomeSensitiveType = ...

    instance Equality SomeSensitiveType where
             eq a b = ...

    instance Eq SomeSensitiveType where
         (==) a b = a === b

### Combining multiple comparisons using Monoid operations

The `Result` type is an opaque type and does not allow inspection via a pattern match or conversion to `Bool`. However, while defining the `Equality` instance, we often need to perform an AND of multiple comparison (think of comparing a tuple). This is where the monoid instance of `Result` is useful. If `r1` and `r2` are the results of two comparisons then `r1 `mappend` r2` essentially takes the AND of these results. However, unlike in the case of AND-ing in `Bool`, `mappend` on the `Result` type does not short-circuit. In fact, the whole point of using `Result` type instead of `Bool` is to avoid this short circuiting.

To illustrate, we have the following code fragment

    data Foo = Foo Word32 Word64

    instance Equality Foo where
       eq (Foo a b) (Foo c d) = eq a c `mapped` eq b d

    instance Eq Foo where
       (=) = (===)

## Automatic deriving of `Equality` instances.

We often find ourselves wrapping existing types in new types keeping in line with the philosophy of distinguishing sematically distinct data with their types. It would be tedious to repeat the above process for each such type. Often, we can get away by just deriving these instances thereby saving a lot of boilerplate. For example, consider a data type that needs to keep a 128-byte secret. A simple deriving class would work in such cases.

    newtype Secret = Secret (Tuple 128 Word8) deriving (Equality, Eq)

The `Eq` instance here would be timing safe because it is essentially the `Eq` instance of tuples. The deriving `Equality` is not strictly required here. However, we suggest keeping it so that on can define timing safe equality for other types that contain a component of type `Secret`.

### Beware: deriving clause can be dangerous

The deriving clause that we defined above while convenient, hides a danger when not used properly. For example, consider the following definitions.

    data    Bad      = Bad Bar Biz deriving Eq
    newtype BadAgain = BadAgain (Bar, Biz) deriving (Eq, Equality)

The comparison for the elements of the type `Bad` would leak some timing information even when `Bar` and `Biz` are instances of `Equality` and thus have timing safe equalities themselves. This is because the automatic derivation of `Eq` instances in the above two cases performs a component by component comparison and combines the result using ``and``. Due to boolean short circuiting, this will lead to timing information being leaked.

For product types, we can safely derive the `Equality` instance and use it to define the `Eq` instance as follows

    newtype Okey2 = Okey (Foo, Bar) deriving Equality

    instance Eq Okey2 where
       (=) = (===)

class Equality a where Source #

All types that support timing safe equality are instances of this class.

Methods

eq :: a -> a -> Result Source #

Instances

Equality Word Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: Word -> Word -> Result Source #
Equality Word8 Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: Word8 -> Word8 -> Result Source #
Equality Word16 Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: Word16 -> Word16 -> Result Source #
Equality Word32 Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: Word32 -> Word32 -> Result Source #
Equality Word64 Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: Word64 -> Word64 -> Result Source #
Equality SHA1 Source # |
Instance details Defined in Raaz.Hash.Sha1.Internal Methods eq :: SHA1 -> SHA1 -> Result Source #
Equality SHA224 Source # |
Instance details Defined in Raaz.Hash.Sha224.Internal Methods eq :: SHA224 -> SHA224 -> Result Source #
Equality SHA256 Source # |
Instance details Defined in Raaz.Hash.Sha256.Internal Methods eq :: SHA256 -> SHA256 -> Result Source #
Equality SHA384 Source # |
Instance details Defined in Raaz.Hash.Sha384.Internal Methods eq :: SHA384 -> SHA384 -> Result Source #
Equality SHA512 Source # |
Instance details Defined in Raaz.Hash.Sha512.Internal Methods eq :: SHA512 -> SHA512 -> Result Source #
Equality a => Equality (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods eq :: BITS a -> BITS a -> Result Source #
Equality a => Equality (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods eq :: BYTES a -> BYTES a -> Result Source #
Equality w => Equality (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods eq :: BE w -> BE w -> Result Source #
Equality w => Equality (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods eq :: LE w -> LE w -> Result Source #
(Equality a, Equality b) => Equality (a, b) Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: (a, b) -> (a, b) -> Result Source #
(Unbox a, Equality a) => Equality (Tuple dim a) Source # |
Instance details Defined in Raaz.Core.Types.Tuple Methods eq :: Tuple dim a -> Tuple dim a -> Result Source #
(Equality a, Equality b, Equality c) => Equality (a, b, c) Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: (a, b, c) -> (a, b, c) -> Result Source #
(Equality a, Equality b, Equality c, Equality d) => Equality (a, b, c, d) Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: (a, b, c, d) -> (a, b, c, d) -> Result Source #
(Equality a, Equality b, Equality c, Equality d, Equality e) => Equality (a, b, c, d, e) Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: (a, b, c, d, e) -> (a, b, c, d, e) -> Result Source #
(Equality a, Equality b, Equality c, Equality d, Equality e, Equality f) => Equality (a, b, c, d, e, f) Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Result Source #
(Equality a, Equality b, Equality c, Equality d, Equality e, Equality f, Equality g) => Equality (a, b, c, d, e, f, g) Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods eq :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Result Source #

(===) :: Equality a => a -> a -> Bool Source #

Check whether two values are equal using the timing safe `eq` function. Use this function when defining the `Eq` instance for a Sensitive data type.

data Result Source #

The result of a comparison. This is an opaque type and the monoid instance essentially takes AND of two comparisons in a timing safe way.

Instances

Semigroup Result Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods (<>) :: Result -> Result -> Result Source # sconcat :: NonEmpty Result -> Result Source # stimes :: Integral b => b -> Result -> Result Source #
Monoid Result Source # |
Instance details Defined in Raaz.Core.Types.Equality Methods mempty :: Result Source # mappend :: Result -> Result -> Result Source # mconcat :: [Result] -> Result Source #
Unbox Result Source # |
Instance details Defined in Raaz.Core.Types.Equality
Vector Vector Result Source # |

Instance details

Defined in Raaz.Core.Types.Equality

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) Result -> m (Vector Result) Source #

basicUnsafeThaw :: PrimMonad m => Vector Result -> m (Mutable Vector (PrimState m) Result) Source #

basicLength :: Vector Result -> Int Source #

basicUnsafeSlice :: Int -> Int -> Vector Result -> Vector Result Source #

basicUnsafeIndexM :: Monad m => Vector Result -> Int -> m Result Source #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) Result -> Vector Result -> m () Source #

elemseq :: Vector Result -> Result -> b -> b Source #

MVector MVector Result Source # |

Instance details

Defined in Raaz.Core.Types.Equality

Methods

basicLength :: MVector s Result -> Int Source #

basicUnsafeSlice :: Int -> Int -> MVector s Result -> MVector s Result Source #

basicOverlaps :: MVector s Result -> MVector s Result -> Bool Source #

basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) Result) Source #

basicInitialize :: PrimMonad m => MVector (PrimState m) Result -> m () Source #

basicUnsafeReplicate :: PrimMonad m => Int -> Result -> m (MVector (PrimState m) Result) Source #

basicUnsafeRead :: PrimMonad m => MVector (PrimState m) Result -> Int -> m Result Source #

basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) Result -> Int -> Result -> m () Source #

basicClear :: PrimMonad m => MVector (PrimState m) Result -> m () Source #

basicSet :: PrimMonad m => MVector (PrimState m) Result -> Result -> m () Source #

basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) Result -> MVector (PrimState m) Result -> m () Source #

basicUnsafeMove :: PrimMonad m => MVector (PrimState m) Result -> MVector (PrimState m) Result -> m () Source #

basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) Result -> Int -> m (MVector (PrimState m) Result) Source #

newtype Vector Result Source # | Vector of Results.
Instance details Defined in Raaz.Core.Types.Equality newtype Vector Result = V_Result (Vector Word)
newtype MVector s Result Source # | MVector for Results.
Instance details Defined in Raaz.Core.Types.Equality newtype MVector s Result = MV_Result (MVector s Word)

# Endianess aware types.

Cryptographic primitives often consider their input as an array of words of a particular endianness. Endianness is only relevant when serialising to (or de-serialising from) their encoding to the outside world. Raaz strives to use types to provide an endian agnostic interface to all data that is relevant to the outside world.

The starting point of an endian agnostic interface is the class `EndianStore`. Instances of this class support an endian agnostic `load` and `store`. Endian adjusted copying is also provided for these types through the helper functions `copyFromBytes` and `copyToBytes`.

It is tedious to think about endianness for each new type one might encounter. As before, we have a top down approach to defining such an interface. To start with, the library exposes endian aware variants of `Word32` and `Word64` and functions `littleEndian` and `bigEndian` for conversions. The `Tuple` type inherits the endianness of its element type, i.e for example `Tuple 10 (LE Word32)` when loded (or stored) will load (or store) 10 32-bit words assuming that the words are expressed in little endian. Other types are then built out of these endian aware types. For example, cryptographic type `SHA512` is defined as.

    newtype SHA512 = SHA512 (Tuple 8 (BE Word64))
                         deriving (Equality, Eq, Storable, EndianStore)

class Storable w => EndianStore w where Source #

This class captures types which provides an endian agnostic way of loading from and storing to data buffers. Any multi-byte type that is meant to be serialised to the outside world should be an instance of this class. When defining the `load`, `store`, `adjustEndian` member functions, care should be taken to ensure proper endian conversion.

Methods

store Source #

Arguments

:: Ptr w | the location.
-> w | value to store
-> IO () |

The action `store ptr w` stores `w` at the location pointed by `ptr`. Endianness of the type `w` is taken care of when storing. For example, irrespective of the endianness of the machine, `store ptr (0x01020304 :: BE Word32)` will store the bytes `0x01`, `0x02`, `0x03`, `0x04` respectively at locations `ptr`, `ptr +1`, `ptr+2` and `ptr+3`. On the other hand `store ptr (0x01020304 :: LE Word32)` would store `0x04`, `0x03`, `0x02`, `0x01` at the above locations.

load :: Ptr w -> IO w Source #

The action `load ptr` loads the value stored at the `ptr`. Like store, it takes care of the endianness of the data type. For example, if `ptr` points to a buffer containing the bytes `0x01`, `0x02`, `0x03`, `0x04`, irrespective of the endianness of the machine, `load ptr :: IO (BE Word32)` will load the vale `0x01020304` of type `BE Word32` and `load ptr :: IO (LE Word32)` will load `0x04030201` of type `LE Word32`.

adjustEndian Source #

Arguments

:: Ptr w | buffer pointers,
-> Int | how many w's are present,
-> IO () |

The action `adjustEndian ptr n` adjusts the encoding of bytes stored at the location `ptr` to conform with the endianness of the underlying data type. For example, assume that `ptr` points to a buffer containing the bytes `0x01 0x02 0x03 0x04`, and we are on a big endian machine, then `adjustEndian (ptr :: Ptr (LE Word32)) 1` will result in `ptr` pointing to the sequence `0x04 0x03 0x02 0x01`. On the other hand if we were on a little endian machine, the sequence should remain the same. In particular, the following equalities should hold.

    store ptr w          = poke ptr w >> adjustEndian ptr 1

Similarly the value loaded by `load ptr` should be same as the value returned by `adjustEndian ptr 1 >> peak ptr`, although the former does not change the contents stored at `ptr` where as the latter might does modify the contents pointed by `ptr` if the endianness of the machine and the time do not agree.

The action `adjustEndian ptr n >> adjustEndian ptr n` should be equivalent to `return ()`.

Instances

EndianStore Word8 Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr Word8 -> Word8 -> IO () Source # load :: Ptr Word8 -> IO Word8 Source # adjustEndian :: Ptr Word8 -> Int -> IO () Source #
EndianStore KEY Source # |
Instance details Defined in Raaz.Cipher.ChaCha20.Internal Methods store :: Ptr KEY -> KEY -> IO () Source # load :: Ptr KEY -> IO KEY Source # adjustEndian :: Ptr KEY -> Int -> IO () Source #
EndianStore Counter Source # |
Instance details Defined in Raaz.Cipher.ChaCha20.Internal Methods store :: Ptr Counter -> Counter -> IO () Source # load :: Ptr Counter -> IO Counter Source # adjustEndian :: Ptr Counter -> Int -> IO () Source #
EndianStore IV Source # |
Instance details Defined in Raaz.Cipher.ChaCha20.Internal Methods store :: Ptr IV -> IV -> IO () Source # load :: Ptr IV -> IO IV Source # adjustEndian :: Ptr IV -> Int -> IO () Source #
EndianStore SHA1 Source # |
Instance details Defined in Raaz.Hash.Sha1.Internal Methods store :: Ptr SHA1 -> SHA1 -> IO () Source # load :: Ptr SHA1 -> IO SHA1 Source # adjustEndian :: Ptr SHA1 -> Int -> IO () Source #
EndianStore SHA224 Source # |
Instance details Defined in Raaz.Hash.Sha224.Internal Methods store :: Ptr SHA224 -> SHA224 -> IO () Source # load :: Ptr SHA224 -> IO SHA224 Source # adjustEndian :: Ptr SHA224 -> Int -> IO () Source #
EndianStore SHA256 Source # |
Instance details Defined in Raaz.Hash.Sha256.Internal Methods store :: Ptr SHA256 -> SHA256 -> IO () Source # load :: Ptr SHA256 -> IO SHA256 Source # adjustEndian :: Ptr SHA256 -> Int -> IO () Source #
EndianStore SHA384 Source # |
Instance details Defined in Raaz.Hash.Sha384.Internal Methods store :: Ptr SHA384 -> SHA384 -> IO () Source # load :: Ptr SHA384 -> IO SHA384 Source # adjustEndian :: Ptr SHA384 -> Int -> IO () Source #
EndianStore SHA512 Source # |
Instance details Defined in Raaz.Hash.Sha512.Internal Methods store :: Ptr SHA512 -> SHA512 -> IO () Source # load :: Ptr SHA512 -> IO SHA512 Source # adjustEndian :: Ptr SHA512 -> Int -> IO () Source #
EndianStore IV Source # |
Instance details Defined in Raaz.Cipher.AES.Internal Methods store :: Ptr IV -> IV -> IO () Source # load :: Ptr IV -> IO IV Source # adjustEndian :: Ptr IV -> Int -> IO () Source #
EndianStore KEY256 Source # |
Instance details Defined in Raaz.Cipher.AES.Internal Methods store :: Ptr KEY256 -> KEY256 -> IO () Source # load :: Ptr KEY256 -> IO KEY256 Source # adjustEndian :: Ptr KEY256 -> Int -> IO () Source #
EndianStore KEY192 Source # |
Instance details Defined in Raaz.Cipher.AES.Internal Methods store :: Ptr KEY192 -> KEY192 -> IO () Source # load :: Ptr KEY192 -> IO KEY192 Source # adjustEndian :: Ptr KEY192 -> Int -> IO () Source #
EndianStore KEY128 Source # |
Instance details Defined in Raaz.Cipher.AES.Internal Methods store :: Ptr KEY128 -> KEY128 -> IO () Source # load :: Ptr KEY128 -> IO KEY128 Source # adjustEndian :: Ptr KEY128 -> Int -> IO () Source #
EndianStore w => EndianStore (BYTES w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (BYTES w) -> BYTES w -> IO () Source # load :: Ptr (BYTES w) -> IO (BYTES w) Source # adjustEndian :: Ptr (BYTES w) -> Int -> IO () Source #
EndianStore (BE Word32) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (BE Word32) -> BE Word32 -> IO () Source # load :: Ptr (BE Word32) -> IO (BE Word32) Source # adjustEndian :: Ptr (BE Word32) -> Int -> IO () Source #
EndianStore (BE Word64) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (BE Word64) -> BE Word64 -> IO () Source # load :: Ptr (BE Word64) -> IO (BE Word64) Source # adjustEndian :: Ptr (BE Word64) -> Int -> IO () Source #
EndianStore (LE Word32) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (LE Word32) -> LE Word32 -> IO () Source # load :: Ptr (LE Word32) -> IO (LE Word32) Source # adjustEndian :: Ptr (LE Word32) -> Int -> IO () Source #
EndianStore (LE Word64) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (LE Word64) -> LE Word64 -> IO () Source # load :: Ptr (LE Word64) -> IO (LE Word64) Source # adjustEndian :: Ptr (LE Word64) -> Int -> IO () Source #
EndianStore h => EndianStore (HMAC h) Source # |
Instance details Defined in Raaz.Hash.Internal.HMAC Methods store :: Ptr (HMAC h) -> HMAC h -> IO () Source # load :: Ptr (HMAC h) -> IO (HMAC h) Source # adjustEndian :: Ptr (HMAC h) -> Int -> IO () Source #
(Unbox a, EndianStore a, Dimension dim) => EndianStore (Tuple dim a) Source # |
Instance details Defined in Raaz.Core.Types.Tuple Methods store :: Ptr (Tuple dim a) -> Tuple dim a -> IO () Source # load :: Ptr (Tuple dim a) -> IO (Tuple dim a) Source # adjustEndian :: Ptr (Tuple dim a) -> Int -> IO () Source #

copyFromBytes Source #

Arguments

:: EndianStore w |
=> Dest (Ptr w) |
-> Src Pointer |
-> Int | How many items.
-> IO () |

For the type `w`, the action `copyFromBytes dest src n` copies `n`-elements from `src` to `dest`. Copy performed by this combinator accounts for the endianness of the data in `dest` and is therefore not a mere copy of `n * sizeOf(w)` bytes. This action does not modify the `src` pointer in any way.

copyToBytes :: EndianStore w => Dest Pointer -> Src (Ptr w) -> Int -> IO () Source #

Similar to `copyFromBytes` but the transfer is done in the other direction. The copy takes care of performing the appropriate endian encoding.

## Endian explicit word types.

data LE w Source #

Little endian version of the word type `w`

Instances

Functor LE Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods fmap :: (a -> b) -> LE a -> LE b Source # (<$) :: a -> LE b -> LE a Source #
Show BLAKE2s Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods showsPrec :: Int -> BLAKE2s -> ShowS Source # show :: BLAKE2s -> String Source # showList :: [BLAKE2s] -> ShowS Source #
Show BLAKE2b Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods showsPrec :: Int -> BLAKE2b -> ShowS Source # show :: BLAKE2b -> String Source # showList :: [BLAKE2b] -> ShowS Source #
IsString BLAKE2s Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods fromString :: String -> BLAKE2s Source #
IsString BLAKE2b Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods fromString :: String -> BLAKE2b Source #
Encodable BLAKE2s Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods toByteString :: BLAKE2s -> ByteString Source # fromByteString :: ByteString -> Maybe BLAKE2s Source # unsafeFromByteString :: ByteString -> BLAKE2s Source #
Encodable BLAKE2b Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods toByteString :: BLAKE2b -> ByteString Source # fromByteString :: ByteString -> Maybe BLAKE2b Source # unsafeFromByteString :: ByteString -> BLAKE2b Source #
Recommendation BLAKE2s Source # | Recommended implementation for balke2s.
Instance details Defined in Raaz.Hash.Blake2.Recommendation Methods recommended :: BLAKE2s -> Implementation BLAKE2s Source #
Recommendation BLAKE2b Source # | Recommended implementation for blake2b.
Instance details Defined in Raaz.Hash.Blake2.Recommendation Methods recommended :: BLAKE2b -> Implementation BLAKE2b Source #
Primitive BLAKE2s Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Associated Types type Implementation BLAKE2s :: Type Source # Methods blockSize :: BLAKE2s -> BYTES Int Source #
Primitive BLAKE2b Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Associated Types type Implementation BLAKE2b :: Type Source # Methods blockSize :: BLAKE2b -> BYTES Int Source #
Hash BLAKE2s Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods additionalPadBlocks :: BLAKE2s -> BLOCKS BLAKE2s Source #
Hash BLAKE2b Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal Methods additionalPadBlocks :: BLAKE2b -> BLOCKS BLAKE2b Source #
Unbox w => Vector Vector (LE w) Source # |

Instance details

Defined in Raaz.Core.Types.Endian

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (LE w) -> m (Vector (LE w)) Source #

basicUnsafeThaw :: PrimMonad m => Vector (LE w) -> m (Mutable Vector (PrimState m) (LE w)) Source #

basicLength :: Vector (LE w) -> Int Source #

basicUnsafeSlice :: Int -> Int -> Vector (LE w) -> Vector (LE w) Source #

basicUnsafeIndexM :: Monad m => Vector (LE w) -> Int -> m (LE w) Source #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (LE w) -> Vector (LE w) -> m () Source #

elemseq :: Vector (LE w) -> LE w -> b -> b Source #

Unbox w => MVector MVector (LE w) Source # |

Instance details

Defined in Raaz.Core.Types.Endian

Methods

basicLength :: MVector s (LE w) -> Int Source #

basicUnsafeSlice :: Int -> Int -> MVector s (LE w) -> MVector s (LE w) Source #

basicOverlaps :: MVector s (LE w) -> MVector s (LE w) -> Bool Source #

basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (LE w)) Source #

basicInitialize :: PrimMonad m => MVector (PrimState m) (LE w) -> m () Source #

basicUnsafeReplicate :: PrimMonad m => Int -> LE w -> m (MVector (PrimState m) (LE w)) Source #

basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (LE w) -> Int -> m (LE w) Source #

basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (LE w) -> Int -> LE w -> m () Source #

basicClear :: PrimMonad m => MVector (PrimState m) (LE w) -> m () Source #

basicSet :: PrimMonad m => MVector (PrimState m) (LE w) -> LE w -> m () Source #

basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (LE w) -> MVector (PrimState m) (LE w) -> m () Source #

basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (LE w) -> MVector (PrimState m) (LE w) -> m () Source #

basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (LE w) -> Int -> m (MVector (PrimState m) (LE w)) Source #

Bounded w => Bounded (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods minBound :: LE w Source # maxBound :: LE w Source #
Enum w => Enum (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods succ :: LE w -> LE w Source # pred :: LE w -> LE w Source # toEnum :: Int -> LE w Source # fromEnum :: LE w -> Int Source # enumFrom :: LE w -> [LE w] Source # enumFromThen :: LE w -> LE w -> [LE w] Source # enumFromTo :: LE w -> LE w -> [LE w] Source # enumFromThenTo :: LE w -> LE w -> LE w -> [LE w] Source #
Eq w => Eq (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods (==) :: LE w -> LE w -> Bool Source # (/=) :: LE w -> LE w -> Bool Source #
Integral w => Integral (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods quot :: LE w -> LE w -> LE w Source # rem :: LE w -> LE w -> LE w Source # div :: LE w -> LE w -> LE w Source # mod :: LE w -> LE w -> LE w Source # quotRem :: LE w -> LE w -> (LE w, LE w) Source # divMod :: LE w -> LE w -> (LE w, LE w) Source # toInteger :: LE w -> Integer Source #
Num w => Num (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods (+) :: LE w -> LE w -> LE w Source # (-) :: LE w -> LE w -> LE w Source # (*) :: LE w -> LE w -> LE w Source # negate :: LE w -> LE w Source # abs :: LE w -> LE w Source # signum :: LE w -> LE w Source # fromInteger :: Integer -> LE w Source #
Ord w => Ord (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods compare :: LE w -> LE w -> Ordering Source # (<) :: LE w -> LE w -> Bool Source # (<=) :: LE w -> LE w -> Bool Source # (>) :: LE w -> LE w -> Bool Source # (>=) :: LE w -> LE w -> Bool Source # max :: LE w -> LE w -> LE w Source # min :: LE w -> LE w -> LE w Source #
Read w => Read (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods readsPrec :: Int -> ReadS (LE w) Source # readList :: ReadS [LE w] Source # readPrec :: ReadPrec (LE w) Source # readListPrec :: ReadPrec [LE w] Source #
Real w => Real (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods toRational :: LE w -> Rational Source #
Show w => Show (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods showsPrec :: Int -> LE w -> ShowS Source # show :: LE w -> String Source # showList :: [LE w] -> ShowS Source #
Storable w => Storable (LE w) Source # |

Instance details

Defined in Raaz.Core.Types.Endian

Methods

sizeOf :: LE w -> Int Source #

alignment :: LE w -> Int Source #

peekElemOff :: Ptr (LE w) -> Int -> IO (LE w) Source #

pokeElemOff :: Ptr (LE w) -> Int -> LE w -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (LE w) Source #

pokeByteOff :: Ptr b -> Int -> LE w -> IO () Source #

peek :: Ptr (LE w) -> IO (LE w) Source #

poke :: Ptr (LE w) -> LE w -> IO () Source #

Bits w => Bits (LE w) Source # |

Instance details

Defined in Raaz.Core.Types.Endian

Methods

(.&.) :: LE w -> LE w -> LE w Source #

(.|.) :: LE w -> LE w -> LE w Source #

xor :: LE w -> LE w -> LE w Source #

complement :: LE w -> LE w Source #

shift :: LE w -> Int -> LE w Source #

rotate :: LE w -> Int -> LE w Source #

zeroBits :: LE w Source #

bit :: Int -> LE w Source #

setBit :: LE w -> Int -> LE w Source #

clearBit :: LE w -> Int -> LE w Source #

complementBit :: LE w -> Int -> LE w Source #

testBit :: LE w -> Int -> Bool Source #

bitSizeMaybe :: LE w -> Maybe Int Source #

bitSize :: LE w -> Int Source #

isSigned :: LE w -> Bool Source #

shiftL :: LE w -> Int -> LE w Source #

unsafeShiftL :: LE w -> Int -> LE w Source #

shiftR :: LE w -> Int -> LE w Source #

unsafeShiftR :: LE w -> Int -> LE w Source #

rotateL :: LE w -> Int -> LE w Source #

rotateR :: LE w -> Int -> LE w Source #

popCount :: LE w -> Int Source #

NFData w => NFData (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods rnf :: LE w -> () Source #
Unbox w => Unbox (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian
Equality w => Equality (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods eq :: LE w -> LE w -> Result Source #
EndianStore (LE Word32) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (LE Word32) -> LE Word32 -> IO () Source # load :: Ptr (LE Word32) -> IO (LE Word32) Source # adjustEndian :: Ptr (LE Word32) -> Int -> IO () Source #
EndianStore (LE Word64) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (LE Word64) -> LE Word64 -> IO () Source # load :: Ptr (LE Word64) -> IO (LE Word64) Source # adjustEndian :: Ptr (LE Word64) -> Int -> IO () Source #
Encodable (LE Word32) Source # |
Instance details Defined in Raaz.Core.Encode.Internal Methods toByteString :: LE Word32 -> ByteString Source # fromByteString :: ByteString -> Maybe (LE Word32) Source # unsafeFromByteString :: ByteString -> LE Word32 Source #
Encodable (LE Word64) Source # |
Instance details Defined in Raaz.Core.Encode.Internal Methods toByteString :: LE Word64 -> ByteString Source # fromByteString :: ByteString -> Maybe (LE Word64) Source # unsafeFromByteString :: ByteString -> LE Word64 Source #
RandomStorable w => RandomStorable (LE w) Source # |
Instance details Defined in Raaz.Random Methods fillRandomElements :: Memory mem => Int -> Ptr (LE w) -> RT mem () Source #
type Implementation BLAKE2s Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal type Implementation BLAKE2s = SomeHashI BLAKE2s
type Implementation BLAKE2b Source # |
Instance details Defined in Raaz.Hash.Blake2.Internal type Implementation BLAKE2b = SomeHashI BLAKE2b
newtype MVector s (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian newtype MVector s (LE w) = MV_LE (MVector s w)
newtype Vector (LE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian newtype Vector (LE w) = V_LE (Vector w)

data BE w Source #

Big endian version of the word type `w`

Instances

Functor BE Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods fmap :: (a -> b) -> BE a -> BE b Source # (<$) :: a -> BE b -> BE a Source #
Unbox w => Vector Vector (BE w) Source # |

Instance details

Defined in Raaz.Core.Types.Endian

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (BE w) -> m (Vector (BE w)) Source #

basicUnsafeThaw :: PrimMonad m => Vector (BE w) -> m (Mutable Vector (PrimState m) (BE w)) Source #

basicLength :: Vector (BE w) -> Int Source #

basicUnsafeSlice :: Int -> Int -> Vector (BE w) -> Vector (BE w) Source #

basicUnsafeIndexM :: Monad m => Vector (BE w) -> Int -> m (BE w) Source #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (BE w) -> Vector (BE w) -> m () Source #

elemseq :: Vector (BE w) -> BE w -> b -> b Source #

Unbox w => MVector MVector (BE w) Source # |

Instance details

Defined in Raaz.Core.Types.Endian

Methods

basicLength :: MVector s (BE w) -> Int Source #

basicUnsafeSlice :: Int -> Int -> MVector s (BE w) -> MVector s (BE w) Source #

basicOverlaps :: MVector s (BE w) -> MVector s (BE w) -> Bool Source #

basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (BE w)) Source #

basicInitialize :: PrimMonad m => MVector (PrimState m) (BE w) -> m () Source #

basicUnsafeReplicate :: PrimMonad m => Int -> BE w -> m (MVector (PrimState m) (BE w)) Source #

basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (BE w) -> Int -> m (BE w) Source #

basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (BE w) -> Int -> BE w -> m () Source #

basicClear :: PrimMonad m => MVector (PrimState m) (BE w) -> m () Source #

basicSet :: PrimMonad m => MVector (PrimState m) (BE w) -> BE w -> m () Source #

basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (BE w) -> MVector (PrimState m) (BE w) -> m () Source #

basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (BE w) -> MVector (PrimState m) (BE w) -> m () Source #

basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (BE w) -> Int -> m (MVector (PrimState m) (BE w)) Source #

Bounded w => Bounded (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods minBound :: BE w Source # maxBound :: BE w Source #
Enum w => Enum (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods succ :: BE w -> BE w Source # pred :: BE w -> BE w Source # toEnum :: Int -> BE w Source # fromEnum :: BE w -> Int Source # enumFrom :: BE w -> [BE w] Source # enumFromThen :: BE w -> BE w -> [BE w] Source # enumFromTo :: BE w -> BE w -> [BE w] Source # enumFromThenTo :: BE w -> BE w -> BE w -> [BE w] Source #
Eq w => Eq (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods (==) :: BE w -> BE w -> Bool Source # (/=) :: BE w -> BE w -> Bool Source #
Integral w => Integral (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods quot :: BE w -> BE w -> BE w Source # rem :: BE w -> BE w -> BE w Source # div :: BE w -> BE w -> BE w Source # mod :: BE w -> BE w -> BE w Source # quotRem :: BE w -> BE w -> (BE w, BE w) Source # divMod :: BE w -> BE w -> (BE w, BE w) Source # toInteger :: BE w -> Integer Source #
Num w => Num (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods (+) :: BE w -> BE w -> BE w Source # (-) :: BE w -> BE w -> BE w Source # (*) :: BE w -> BE w -> BE w Source # negate :: BE w -> BE w Source # abs :: BE w -> BE w Source # signum :: BE w -> BE w Source # fromInteger :: Integer -> BE w Source #
Ord w => Ord (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods compare :: BE w -> BE w -> Ordering Source # (<) :: BE w -> BE w -> Bool Source # (<=) :: BE w -> BE w -> Bool Source # (>) :: BE w -> BE w -> Bool Source # (>=) :: BE w -> BE w -> Bool Source # max :: BE w -> BE w -> BE w Source # min :: BE w -> BE w -> BE w Source #
Read w => Read (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods readsPrec :: Int -> ReadS (BE w) Source # readList :: ReadS [BE w] Source # readPrec :: ReadPrec (BE w) Source # readListPrec :: ReadPrec [BE w] Source #
Real w => Real (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods toRational :: BE w -> Rational Source #
Show w => Show (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods showsPrec :: Int -> BE w -> ShowS Source # show :: BE w -> String Source # showList :: [BE w] -> ShowS Source #
Storable w => Storable (BE w) Source # |

Instance details

Defined in Raaz.Core.Types.Endian

Methods

sizeOf :: BE w -> Int Source #

alignment :: BE w -> Int Source #

peekElemOff :: Ptr (BE w) -> Int -> IO (BE w) Source #

pokeElemOff :: Ptr (BE w) -> Int -> BE w -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (BE w) Source #

pokeByteOff :: Ptr b -> Int -> BE w -> IO () Source #

peek :: Ptr (BE w) -> IO (BE w) Source #

poke :: Ptr (BE w) -> BE w -> IO () Source #

Bits w => Bits (BE w) Source # |

Instance details

Defined in Raaz.Core.Types.Endian

Methods

(.&.) :: BE w -> BE w -> BE w Source #

(.|.) :: BE w -> BE w -> BE w Source #

xor :: BE w -> BE w -> BE w Source #

complement :: BE w -> BE w Source #

shift :: BE w -> Int -> BE w Source #

rotate :: BE w -> Int -> BE w Source #

zeroBits :: BE w Source #

bit :: Int -> BE w Source #

setBit :: BE w -> Int -> BE w Source #

clearBit :: BE w -> Int -> BE w Source #

complementBit :: BE w -> Int -> BE w Source #

testBit :: BE w -> Int -> Bool Source #

bitSizeMaybe :: BE w -> Maybe Int Source #

bitSize :: BE w -> Int Source #

isSigned :: BE w -> Bool Source #

shiftL :: BE w -> Int -> BE w Source #

unsafeShiftL :: BE w -> Int -> BE w Source #

shiftR :: BE w -> Int -> BE w Source #

unsafeShiftR :: BE w -> Int -> BE w Source #

rotateL :: BE w -> Int -> BE w Source #

rotateR :: BE w -> Int -> BE w Source #

popCount :: BE w -> Int Source #

NFData w => NFData (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods rnf :: BE w -> () Source #
Unbox w => Unbox (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian
Equality w => Equality (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods eq :: BE w -> BE w -> Result Source #
EndianStore (BE Word32) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (BE Word32) -> BE Word32 -> IO () Source # load :: Ptr (BE Word32) -> IO (BE Word32) Source # adjustEndian :: Ptr (BE Word32) -> Int -> IO () Source #
EndianStore (BE Word64) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (BE Word64) -> BE Word64 -> IO () Source # load :: Ptr (BE Word64) -> IO (BE Word64) Source # adjustEndian :: Ptr (BE Word64) -> Int -> IO () Source #
Encodable (BE Word32) Source # |
Instance details Defined in Raaz.Core.Encode.Internal Methods toByteString :: BE Word32 -> ByteString Source # fromByteString :: ByteString -> Maybe (BE Word32) Source # unsafeFromByteString :: ByteString -> BE Word32 Source #
Encodable (BE Word64) Source # |
Instance details Defined in Raaz.Core.Encode.Internal Methods toByteString :: BE Word64 -> ByteString Source # fromByteString :: ByteString -> Maybe (BE Word64) Source # unsafeFromByteString :: ByteString -> BE Word64 Source #
RandomStorable w => RandomStorable (BE w) Source # |
Instance details Defined in Raaz.Random Methods fillRandomElements :: Memory mem => Int -> Ptr (BE w) -> RT mem () Source #
newtype MVector s (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian newtype MVector s (BE w) = MV_BE (MVector s w)
newtype Vector (BE w) Source # |
Instance details Defined in Raaz.Core.Types.Endian newtype Vector (BE w) = V_BE (Vector w)

littleEndian :: w -> LE w Source #

Convert to the little endian variant.

bigEndian :: w -> BE w Source #

Convert to the big endian variants.

## Helper functions for endian aware storing and loading.

storeAt Source #

Arguments

:: (EndianStore w, LengthUnit offset) |
=> Ptr w | the pointer
-> offset | the absolute offset in type safe length units.
-> w | value to store
-> IO () |

Store the given value at an offset from the crypto pointer. The offset is given in type safe units.

storeAtIndex Source #

Arguments

:: EndianStore w |
=> Ptr w | the pointer to the first element of the array
-> Int | the index of the array
-> w | the value to store
-> IO () |

Store the given value as the `n`-th element of the array pointed by the crypto pointer.

loadFrom Source #

Arguments

:: (EndianStore w, LengthUnit offset) |
=> Ptr w | the pointer
-> offset | the offset
-> IO w |

Load from a given offset. The offset is given in type safe units.

loadFromIndex Source #

Arguments

:: EndianStore w |
=> Ptr w | the pointer to the first element of the array
-> Int | the index of the array
-> IO w |

Load the `n`-th value of an array pointed by the crypto pointer.

# Pointers, offsets, and alignment

type Pointer = Ptr Align Source #

The pointer type used by all cryptographic library.

## Type safe length units.

class (Enum u, Monoid u) => LengthUnit u where Source #

In cryptographic settings, we need to measure pointer offsets and buffer sizes. The smallest of length/offset that we have is bytes measured using the type `BYTES`. In various other circumstances, it would be more natural to measure these in multiples of bytes. For example, when allocating buffer to use encrypt using a block cipher it makes sense to measure the buffer size in multiples of block of the cipher. Explicit conversion between these length units, while allocating or moving pointers, involves a lot of low level scaling that is also error prone. To avoid these errors due to unit conversions, we distinguish between different length units at the type level. This type class capturing all such types, i.e. types that stand of length units. Allocation functions and pointer arithmetic are generalised to these length units.

All instances of a `LengthUnit` are required to be instances of `Monoid` where the monoid operation gives these types the natural size/offset addition semantics: i.e. shifting a pointer by offset `a `mappend` b` is same as shifting it by `a` and then by `b`.

Methods

inBytes :: u -> BYTES Int Source #

Express the length units in bytes.

Instances

LengthUnit ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods inBytes :: ALIGN -> BYTES Int Source #
LengthUnit (BYTES Int) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods inBytes :: BYTES Int -> BYTES Int Source #
Primitive p => LengthUnit (BLOCKS p) Source # |
Instance details Defined in Raaz.Core.Primitives Methods inBytes :: BLOCKS p -> BYTES Int Source #

newtype BYTES a Source #

Type safe lengths/offsets in units of bytes.

Constructors

BYTES a |

Instances

Bounded a => Bounded (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods minBound :: BYTES a Source # maxBound :: BYTES a Source #
Enum a => Enum (BYTES a) Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

succ :: BYTES a -> BYTES a Source #

pred :: BYTES a -> BYTES a Source #

toEnum :: Int -> BYTES a Source #

fromEnum :: BYTES a -> Int Source #

enumFrom :: BYTES a -> [BYTES a] Source #

enumFromThen :: BYTES a -> BYTES a -> [BYTES a] Source #

enumFromTo :: BYTES a -> BYTES a -> [BYTES a] Source #

enumFromThenTo :: BYTES a -> BYTES a -> BYTES a -> [BYTES a] Source #

Eq a => Eq (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (==) :: BYTES a -> BYTES a -> Bool Source # (/=) :: BYTES a -> BYTES a -> Bool Source #
Integral a => Integral (BYTES a) Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

quot :: BYTES a -> BYTES a -> BYTES a Source #

rem :: BYTES a -> BYTES a -> BYTES a Source #

div :: BYTES a -> BYTES a -> BYTES a Source #

mod :: BYTES a -> BYTES a -> BYTES a Source #

quotRem :: BYTES a -> BYTES a -> (BYTES a, BYTES a) Source #

divMod :: BYTES a -> BYTES a -> (BYTES a, BYTES a) Source #

toInteger :: BYTES a -> Integer Source #

Num a => Num (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (+) :: BYTES a -> BYTES a -> BYTES a Source # (-) :: BYTES a -> BYTES a -> BYTES a Source # (*) :: BYTES a -> BYTES a -> BYTES a Source # negate :: BYTES a -> BYTES a Source # abs :: BYTES a -> BYTES a Source # signum :: BYTES a -> BYTES a Source # fromInteger :: Integer -> BYTES a Source #
Ord a => Ord (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods compare :: BYTES a -> BYTES a -> Ordering Source # (<) :: BYTES a -> BYTES a -> Bool Source # (<=) :: BYTES a -> BYTES a -> Bool Source # (>) :: BYTES a -> BYTES a -> Bool Source # (>=) :: BYTES a -> BYTES a -> Bool Source # max :: BYTES a -> BYTES a -> BYTES a Source # min :: BYTES a -> BYTES a -> BYTES a Source #
Real a => Real (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods toRational :: BYTES a -> Rational Source #
Show a => Show (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods showsPrec :: Int -> BYTES a -> ShowS Source # show :: BYTES a -> String Source # showList :: [BYTES a] -> ShowS Source #
Num a => Semigroup (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (<>) :: BYTES a -> BYTES a -> BYTES a Source # sconcat :: NonEmpty (BYTES a) -> BYTES a Source # stimes :: Integral b => b -> BYTES a -> BYTES a Source #
Num a => Monoid (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods mempty :: BYTES a Source # mappend :: BYTES a -> BYTES a -> BYTES a Source # mconcat :: [BYTES a] -> BYTES a Source #
Storable a => Storable (BYTES a) Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

sizeOf :: BYTES a -> Int Source #

alignment :: BYTES a -> Int Source #

peekElemOff :: Ptr (BYTES a) -> Int -> IO (BYTES a) Source #

pokeElemOff :: Ptr (BYTES a) -> Int -> BYTES a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (BYTES a) Source #

pokeByteOff :: Ptr b -> Int -> BYTES a -> IO () Source #

peek :: Ptr (BYTES a) -> IO (BYTES a) Source #

poke :: Ptr (BYTES a) -> BYTES a -> IO () Source #

Equality a => Equality (BYTES a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods eq :: BYTES a -> BYTES a -> Result Source #
LengthUnit (BYTES Int) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods inBytes :: BYTES Int -> BYTES Int Source #
EndianStore w => EndianStore (BYTES w) Source # |
Instance details Defined in Raaz.Core.Types.Endian Methods store :: Ptr (BYTES w) -> BYTES w -> IO () Source # load :: Ptr (BYTES w) -> IO (BYTES w) Source # adjustEndian :: Ptr (BYTES w) -> Int -> IO () Source #
Encodable a => Encodable (BYTES a) Source # |
Instance details Defined in Raaz.Core.Encode.Internal Methods toByteString :: BYTES a -> ByteString Source # fromByteString :: ByteString -> Maybe (BYTES a) Source # unsafeFromByteString :: ByteString -> BYTES a Source #

newtype BITS a Source #

Type safe lengths/offsets in units of bits.

Constructors

BITS a |

Instances

Bounded a => Bounded (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods minBound :: BITS a Source # maxBound :: BITS a Source #
Enum a => Enum (BITS a) Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

succ :: BITS a -> BITS a Source #

pred :: BITS a -> BITS a Source #

toEnum :: Int -> BITS a Source #

fromEnum :: BITS a -> Int Source #

enumFrom :: BITS a -> [BITS a] Source #

enumFromThen :: BITS a -> BITS a -> [BITS a] Source #

enumFromTo :: BITS a -> BITS a -> [BITS a] Source #

enumFromThenTo :: BITS a -> BITS a -> BITS a -> [BITS a] Source #

Eq a => Eq (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (==) :: BITS a -> BITS a -> Bool Source # (/=) :: BITS a -> BITS a -> Bool Source #
Integral a => Integral (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods quot :: BITS a -> BITS a -> BITS a Source # rem :: BITS a -> BITS a -> BITS a Source # div :: BITS a -> BITS a -> BITS a Source # mod :: BITS a -> BITS a -> BITS a Source # quotRem :: BITS a -> BITS a -> (BITS a, BITS a) Source # divMod :: BITS a -> BITS a -> (BITS a, BITS a) Source # toInteger :: BITS a -> Integer Source #
Num a => Num (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (+) :: BITS a -> BITS a -> BITS a Source # (-) :: BITS a -> BITS a -> BITS a Source # (*) :: BITS a -> BITS a -> BITS a Source # negate :: BITS a -> BITS a Source # abs :: BITS a -> BITS a Source # signum :: BITS a -> BITS a Source # fromInteger :: Integer -> BITS a Source #
Ord a => Ord (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods compare :: BITS a -> BITS a -> Ordering Source # (<) :: BITS a -> BITS a -> Bool Source # (<=) :: BITS a -> BITS a -> Bool Source # (>) :: BITS a -> BITS a -> Bool Source # (>=) :: BITS a -> BITS a -> Bool Source # max :: BITS a -> BITS a -> BITS a Source # min :: BITS a -> BITS a -> BITS a Source #
Real a => Real (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods toRational :: BITS a -> Rational Source #
Show a => Show (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods showsPrec :: Int -> BITS a -> ShowS Source # show :: BITS a -> String Source # showList :: [BITS a] -> ShowS Source #
Storable a => Storable (BITS a) Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

sizeOf :: BITS a -> Int Source #

alignment :: BITS a -> Int Source #

peekElemOff :: Ptr (BITS a) -> Int -> IO (BITS a) Source #

pokeElemOff :: Ptr (BITS a) -> Int -> BITS a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (BITS a) Source #

pokeByteOff :: Ptr b -> Int -> BITS a -> IO () Source #

peek :: Ptr (BITS a) -> IO (BITS a) Source #

poke :: Ptr (BITS a) -> BITS a -> IO () Source #

Equality a => Equality (BITS a) Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods eq :: BITS a -> BITS a -> Result Source #
Encodable a => Encodable (BITS a) Source # |
Instance details Defined in Raaz.Core.Encode.Internal Methods toByteString :: BITS a -> ByteString Source # fromByteString :: ByteString -> Maybe (BITS a) Source # unsafeFromByteString :: ByteString -> BITS a Source #

inBits :: LengthUnit u => u -> BITS Word64 Source #

Express the length units in bits.

sizeOf :: Storable a => a -> BYTES Int Source #

Compute the size of a storable element.

### Some length arithmetic

bitsQuotRem :: LengthUnit u => BITS Word64 -> (u, BITS Word64) Source #

Function similar to `bytesQuotRem` but works with bits instead.

bytesQuotRem :: LengthUnit u => BYTES Int -> (u, BYTES Int) Source #

A length unit `u` is usually a multiple of bytes. The function `bytesQuotRem` is like `quotRem`: the value `byteQuotRem bytes` is a tuple `(x,r)`, where `x` is `bytes` expressed in the unit `u` with `r` being the reminder.

bitsQuot :: LengthUnit u => BITS Word64 -> u Source #

Function similar to `bitsQuotRem` but returns only the quotient.

bytesQuot :: LengthUnit u => BYTES Int -> u Source #

Function similar to `bytesQuotRem` but returns only the quotient.

atLeast :: (LengthUnit src, LengthUnit dest) => src -> dest Source #

Express length unit `src` in terms of length unit `dest` rounding upwards.

atLeastAligned :: LengthUnit l => l -> Alignment -> ALIGN Source #

Often we want to allocate a buffer of size `l`. We also want to make sure that the buffer starts at an alignment boundary `a`. However, the standard word allocation functions might return a pointer that is not aligned as desired. The `atLeastAligned l a` returns a length `n` such the length `n` is big enough to ensure that there is at least `l` length of valid buffer starting at the next pointer aligned at boundary `a`. If the alignment required in `a` then allocating @l + a - 1 should do the trick.

atMost :: (LengthUnit src, LengthUnit dest) => src -> dest Source #

Express length unit `src` in terms of length unit `dest` rounding downwards.

## Types measuring alignment

data Alignment Source #

Types to measure alignment in units of bytes.

Instances

Enum Alignment Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

succ :: Alignment -> Alignment Source #

pred :: Alignment -> Alignment Source #

toEnum :: Int -> Alignment Source #

fromEnum :: Alignment -> Int Source #

enumFrom :: Alignment -> [Alignment] Source #

enumFromThen :: Alignment -> Alignment -> [Alignment] Source #

enumFromTo :: Alignment -> Alignment -> [Alignment] Source #

enumFromThenTo :: Alignment -> Alignment -> Alignment -> [Alignment] Source #

Eq Alignment Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (==) :: Alignment -> Alignment -> Bool Source # (/=) :: Alignment -> Alignment -> Bool Source #
Integral Alignment Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

quot :: Alignment -> Alignment -> Alignment Source #

rem :: Alignment -> Alignment -> Alignment Source #

div :: Alignment -> Alignment -> Alignment Source #

mod :: Alignment -> Alignment -> Alignment Source #

quotRem :: Alignment -> Alignment -> (Alignment, Alignment) Source #

divMod :: Alignment -> Alignment -> (Alignment, Alignment) Source #

toInteger :: Alignment -> Integer Source #

Num Alignment Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (+) :: Alignment -> Alignment -> Alignment Source # (-) :: Alignment -> Alignment -> Alignment Source # (*) :: Alignment -> Alignment -> Alignment Source # negate :: Alignment -> Alignment Source # abs :: Alignment -> Alignment Source # signum :: Alignment -> Alignment Source # fromInteger :: Integer -> Alignment Source #
Ord Alignment Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

compare :: Alignment -> Alignment -> Ordering Source #

(<) :: Alignment -> Alignment -> Bool Source #

(<=) :: Alignment -> Alignment -> Bool Source #

(>) :: Alignment -> Alignment -> Bool Source #

(>=) :: Alignment -> Alignment -> Bool Source #

max :: Alignment -> Alignment -> Alignment Source #

min :: Alignment -> Alignment -> Alignment Source #

Real Alignment Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods toRational :: Alignment -> Rational Source #
Show Alignment Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods showsPrec :: Int -> Alignment -> ShowS Source # show :: Alignment -> String Source # showList :: [Alignment] -> ShowS Source #
Semigroup Alignment Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (<>) :: Alignment -> Alignment -> Alignment Source # sconcat :: NonEmpty Alignment -> Alignment Source # stimes :: Integral b => b -> Alignment -> Alignment Source #
Monoid Alignment Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods mempty :: Alignment Source # mappend :: Alignment -> Alignment -> Alignment Source # mconcat :: [Alignment] -> Alignment Source #

wordAlignment :: Alignment Source #

The default alignment to use is word boundary.

data ALIGN Source #

Type safe length unit that measures offsets in multiples of word length. This length unit can be used if one wants to make sure that all offsets are word aligned.

Instances

Enum ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods succ :: ALIGN -> ALIGN Source # pred :: ALIGN -> ALIGN Source # toEnum :: Int -> ALIGN Source # fromEnum :: ALIGN -> Int Source # enumFrom :: ALIGN -> [ALIGN] Source # enumFromThen :: ALIGN -> ALIGN -> [ALIGN] Source # enumFromTo :: ALIGN -> ALIGN -> [ALIGN] Source # enumFromThenTo :: ALIGN -> ALIGN -> ALIGN -> [ALIGN] Source #
Eq ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (==) :: ALIGN -> ALIGN -> Bool Source # (/=) :: ALIGN -> ALIGN -> Bool Source #
Integral ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods quot :: ALIGN -> ALIGN -> ALIGN Source # rem :: ALIGN -> ALIGN -> ALIGN Source # div :: ALIGN -> ALIGN -> ALIGN Source # mod :: ALIGN -> ALIGN -> ALIGN Source # quotRem :: ALIGN -> ALIGN -> (ALIGN, ALIGN) Source # divMod :: ALIGN -> ALIGN -> (ALIGN, ALIGN) Source # toInteger :: ALIGN -> Integer Source #
Num ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (+) :: ALIGN -> ALIGN -> ALIGN Source # (-) :: ALIGN -> ALIGN -> ALIGN Source # (*) :: ALIGN -> ALIGN -> ALIGN Source # negate :: ALIGN -> ALIGN Source # abs :: ALIGN -> ALIGN Source # signum :: ALIGN -> ALIGN Source # fromInteger :: Integer -> ALIGN Source #
Ord ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods compare :: ALIGN -> ALIGN -> Ordering Source # (<) :: ALIGN -> ALIGN -> Bool Source # (<=) :: ALIGN -> ALIGN -> Bool Source # (>) :: ALIGN -> ALIGN -> Bool Source # (>=) :: ALIGN -> ALIGN -> Bool Source # max :: ALIGN -> ALIGN -> ALIGN Source # min :: ALIGN -> ALIGN -> ALIGN Source #
Real ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods toRational :: ALIGN -> Rational Source #
Show ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods showsPrec :: Int -> ALIGN -> ShowS Source # show :: ALIGN -> String Source # showList :: [ALIGN] -> ShowS Source #
Semigroup ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods (<>) :: ALIGN -> ALIGN -> ALIGN Source # sconcat :: NonEmpty ALIGN -> ALIGN Source # stimes :: Integral b => b -> ALIGN -> ALIGN Source #
Monoid ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods mempty :: ALIGN Source # mappend :: ALIGN -> ALIGN -> ALIGN Source # mconcat :: [ALIGN] -> ALIGN Source #
Storable ALIGN Source # |

Instance details

Defined in Raaz.Core.Types.Pointer

Methods

sizeOf :: ALIGN -> Int Source #

alignment :: ALIGN -> Int Source #

peekElemOff :: Ptr ALIGN -> Int -> IO ALIGN Source #

pokeElemOff :: Ptr ALIGN -> Int -> ALIGN -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO ALIGN Source #

pokeByteOff :: Ptr b -> Int -> ALIGN -> IO () Source #

peek :: Ptr ALIGN -> IO ALIGN Source #

poke :: Ptr ALIGN -> ALIGN -> IO () Source #

LengthUnit ALIGN Source # |
Instance details Defined in Raaz.Core.Types.Pointer Methods inBytes :: ALIGN -> BYTES Int Source #

alignment :: Storable a => a -> Alignment Source #

Compute the alignment for a storable object.

alignPtr :: Ptr a -> Alignment -> Ptr a Source #

Align a pointer to the appropriate alignment.

movePtr :: LengthUnit l => Ptr a -> l -> Ptr a Source #

Move the given pointer with a specific offset.

alignedSizeOf :: Storable a => a -> ALIGN Source #

Size of the buffer to be allocated to store an element of type `a` so as to guarantee that there exist enough space to store the element after aligning the pointer. If the size of the element is `s` and its alignment is `a` then this quantity is essentially equal to `s + a - 1`. All units measured in word alignment.

nextAlignedPtr :: Storable a => Ptr a -> Ptr a Source #

Compute the next aligned pointer starting from the given pointer location.

peekAligned :: Storable a => Ptr a -> IO a Source #

Peek the element from the next aligned location.

pokeAligned :: Storable a => Ptr a -> a -> IO () Source #

Poke the element from the next aligned location.

## Allocation functions.

allocaAligned Source #

Arguments

:: LengthUnit l |
=> Alignment | the alignment of the buffer
-> l | size of the buffer
-> (Pointer -> IO b) | the action to run
-> IO b |

The expression `allocaAligned a l action` allocates a local buffer of length `l` and alignment `a` and passes it on to the IO action `action`. No explicit freeing of the memory is required as the memory is allocated locally and freed once the action finishes. It is better to use this function than ``allocaBytesAligned`` as it does type safe scaling and alignment.

allocaSecureAligned :: LengthUnit l => Alignment -> l -> (Pointer -> IO a) -> IO a Source #

This function allocates a chunk of "secure" memory of a given size and runs the action. The memory (1) exists for the duration of the action (2) will not be swapped during that time and (3) will be wiped clean and deallocated when the action terminates either directly or indirectly via errors. While this is mostly secure, there can be strange situations in multi-threaded application where the memory is not wiped out. For example if you run a crypto-sensitive action inside a child thread and the main thread gets exists, then the child thread is killed (due to the demonic nature of haskell threads) immediately and might not give it chance to wipe the memory clean. This is a problem inherent to how the `bracket` combinator works inside a child thread.

TODO: File this insecurity in the wiki.

allocaBuffer Source #

Arguments

:: LengthUnit l |
=> l | buffer length
-> (Pointer -> IO b) | the action to run
-> IO b |

A less general version of `allocaAligned` where the pointer passed is aligned to word boundary.

allocaSecure :: LengthUnit l => l -> (Pointer -> IO b) -> IO b Source #

A less general version of `allocaSecureAligned` where the pointer passed is aligned to word boundary

mallocBuffer Source #

Arguments

:: LengthUnit l |
=> l | buffer length
-> IO Pointer |

Creates a memory of given size. It is better to use over ``mallocBytes`` as it uses typesafe length.

## Some buffer operations

memset Source #

Arguments

:: (MonadIO m, LengthUnit l) |
=> Pointer | Target
-> Word8 | Value byte to set
-> l | Number of bytes to set
-> m () |

Sets the given number of Bytes to the specified value.

memmove Source #

Arguments

:: (MonadIO m, LengthUnit l) |
=> Dest Pointer | destination
-> Src Pointer | source
-> l | Number of Bytes to copy
-> m () |

Move between pointers.

memcpy Source #

Arguments

:: (MonadIO m, LengthUnit l) |
=> Dest Pointer | destination
-> Src Pointer | src
-> l | Number of Bytes to copy
-> m () |

Copy between pointers.

hFillBuf :: LengthUnit bufSize => Handle -> Pointer -> bufSize -> IO (BYTES Int) Source #

A version of `hGetBuf` which works for any type safe length units.

# Types to force alignment.

data Aligned (align :: Nat) w Source #

A type `w` forced to be aligned to the alignment boundary `alg`

Instances

(Storable a, AlignBoundary alg) => Storable (Aligned alg a) Source # |

Instance details

Defined in Raaz.Core.Types.Aligned

Methods

sizeOf :: Aligned alg a -> Int Source #

alignment :: Aligned alg a -> Int Source #

peekElemOff :: Ptr (Aligned alg a) -> Int -> IO (Aligned alg a) Source #

pokeElemOff :: Ptr (Aligned alg a) -> Int -> Aligned alg a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (Aligned alg a) Source #

pokeByteOff :: Ptr b -> Int -> Aligned alg a -> IO () Source #

peek :: Ptr (Aligned alg a) -> IO (Aligned alg a) Source #

poke :: Ptr (Aligned alg a) -> Aligned alg a -> IO () Source #

unAligned :: Aligned align w -> w Source #

The underlying unAligned value.

aligned16Bytes :: w -> Aligned 16 w Source #

Align the value to 16-byte boundary

aligned32Bytes :: w -> Aligned 32 w Source #

Align the value to 32-byte boundary

aligned64Bytes :: w -> Aligned 64 w Source #

Align the value to 64-byte boundary

# Length encoded tuples

data Tuple (dim :: Nat) a Source #

Tuples that encode their length in their types. For tuples, we call the length its dimension.

Instances

(Unbox a, Equality a) => Eq (Tuple dim a) Source # | Equality checking is timing safe.
Instance details Defined in Raaz.Core.Types.Tuple Methods (==) :: Tuple dim a -> Tuple dim a -> Bool Source # (/=) :: Tuple dim a -> Tuple dim a -> Bool Source #
(Show a, Unbox a) => Show (Tuple dim a) Source # |
Instance details Defined in Raaz.Core.Types.Tuple Methods showsPrec :: Int -> Tuple dim a -> ShowS Source # show :: Tuple dim a -> String Source # showList :: [Tuple dim a] -> ShowS Source #
(Unbox a, Storable a, Dimension dim) => Storable (Tuple dim a) Source # |

Instance details

Defined in Raaz.Core.Types.Tuple

Methods

sizeOf :: Tuple dim a -> Int Source #

alignment :: Tuple dim a -> Int Source #

peekElemOff :: Ptr (Tuple dim a) -> Int -> IO (Tuple dim a) Source #

pokeElemOff :: Ptr (Tuple dim a) -> Int -> Tuple dim a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (Tuple dim a) Source #

pokeByteOff :: Ptr b -> Int -> Tuple dim a -> IO () Source #

peek :: Ptr (Tuple dim a) -> IO (Tuple dim a) Source #

poke :: Ptr (Tuple dim a) -> Tuple dim a -> IO () Source #

(Unbox a, Equality a) => Equality (Tuple dim a) Source # |
Instance details Defined in Raaz.Core.Types.Tuple Methods eq :: Tuple dim a -> Tuple dim a -> Result Source #
(Unbox a, EndianStore a, Dimension dim) => EndianStore (Tuple dim a) Source # |
Instance details Defined in Raaz.Core.Types.Tuple Methods store :: Ptr (Tuple dim a) -> Tuple dim a -> IO () Source # load :: Ptr (Tuple dim a) -> IO (Tuple dim a) Source # adjustEndian :: Ptr (Tuple dim a) -> Int -> IO () Source #
(Dimension d, Unbox w, RandomStorable w) => RandomStorable (Tuple d w) Source # |
Instance details Defined in Raaz.Random Methods fillRandomElements :: Memory mem => Int -> Ptr (Tuple d w) -> RT mem () Source #

type Dimension (dim :: Nat) = KnownNat dim Source #

Function that returns the dimension of the tuple. The dimension is calculated without inspecting the tuple and hence the term ``dimension` (undefined :: Tuple 5 Int)` will evaluate to 5.

The constaint on the dimension of the tuple (since base 4.7.0)

dimension :: Dimension dim => Tuple dim a -> Int Source #

This combinator returns the dimension of the tuple.

initial :: (Unbox a, Dimension dim0) => Tuple dim1 a -> Tuple dim0 a Source #

Computes the initial fragment of a tuple. No length needs to be given as it is infered from the types.

diagonal :: (Unbox a, Dimension dim) => a -> Tuple dim a Source #

The `diagonal a` gives a tuple, all of whose entries is `a`.

repeatM :: (Functor m, Monad m, Unbox a, Dimension dim) => m a -> m (Tuple dim a) Source #

Construct a tuple by repeating a monadic action.

zipWith :: (Unbox a, Unbox b, Unbox c) => (a -> b -> c) -> Tuple dim a -> Tuple dim b -> Tuple dim c Source #

A zipwith function for tuples

## Unsafe operations

unsafeFromList :: (Unbox a, Dimension dim) => [a] -> Tuple dim a Source #

Construct a tuple out of the list. This function is unsafe and will result in run time error if the list is not of the correct dimension.

data Dest a Source #

The destination of a copy operation.

Note to Developers of Raaz: Since the `Dest` type inherits the Storable instance of the base type, one can use this type in foreign functions.

Instances

Functor Dest Source # |
Instance details Defined in Raaz.Core.Types.Copying Methods fmap :: (a -> b) -> Dest a -> Dest b Source # (<$) :: a -> Dest b -> Dest a Source #
Storable a => Storable (Dest a) Source # |

Instance details

Defined in Raaz.Core.Types.Copying

Methods

sizeOf :: Dest a -> Int Source #

alignment :: Dest a -> Int Source #

peekElemOff :: Ptr (Dest a) -> Int -> IO (Dest a) Source #

pokeElemOff :: Ptr (Dest a) -> Int -> Dest a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (Dest a) Source #

pokeByteOff :: Ptr b -> Int -> Dest a -> IO () Source #

peek :: Ptr (Dest a) -> IO (Dest a) Source #

poke :: Ptr (Dest a) -> Dest a -> IO () Source #

data Src a Source #

The source of a copy operation.

Instances

Functor Src Source # |
Instance details Defined in Raaz.Core.Types.Copying Methods fmap :: (a -> b) -> Src a -> Src b Source # (<$) :: a -> Src b -> Src a Source #
Storable a => Storable (Src a) Source # |

Instance details

Defined in Raaz.Core.Types.Copying

Methods

sizeOf :: Src a -> Int Source #

alignment :: Src a -> Int Source #

peekElemOff :: Ptr (Src a) -> Int -> IO (Src a) Source #

pokeElemOff :: Ptr (Src a) -> Int -> Src a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (Src a) Source #

pokeByteOff :: Ptr b -> Int -> Src a -> IO () Source #

peek :: Ptr (Src a) -> IO (Src a) Source #

poke :: Ptr (Src a) -> Src a -> IO () Source #

source :: a -> Src a Source #

smart constructor for source

destination :: a -> Dest a Source #

smart constructor for destionation.

class Describable d where Source #

This class captures all types that have some sort of description attached to it.

Methods

name :: d -> String Source #

Short name that describes the object.

description :: d -> String Source #

Longer description

Instances

Describable ChaCha20 Source # |
Instance details Defined in Raaz.Cipher.ChaCha20.Internal Methods name :: ChaCha20 -> String Source # description :: ChaCha20 -> String Source #
Describable (SomeCipherI cipher) Source # |
Instance details Defined in Raaz.Cipher.Internal Methods name :: SomeCipherI cipher -> String Source # description :: SomeCipherI cipher -> String Source #
Describable (SomeHashI h) Source # |
Instance details Defined in Raaz.Hash.Internal Methods name :: SomeHashI h -> String Source # description :: SomeHashI h -> String Source #
Describable (HashI h m) Source # |
Instance details Defined in Raaz.Hash.Internal Methods name :: HashI h m -> String Source # description :: HashI h m -> String Source #
Describable (AES 128 CBC) Source # |
Instance details Defined in Raaz.Cipher.AES.Internal Methods name :: AES 128 CBC -> String Source # description :: AES 128 CBC -> String Source #
Describable (AES 192 CBC) Source # |
Instance details Defined in Raaz.Cipher.AES.Internal Methods name :: AES 192 CBC -> String Source # description :: AES 192 CBC -> String Source #
Describable (AES 256 CBC) Source # |
Instance details Defined in Raaz.Cipher.AES.Internal Methods name :: AES 256 CBC -> String Source # description :: AES 256 CBC -> String Source #
Describable (CipherI cipher encMem decMem) Source # |
Instance details Defined in Raaz.Cipher.Internal Methods name :: CipherI cipher encMem decMem -> String Source # description :: CipherI cipher encMem decMem -> String Source #