raaz-0.2.0: The raaz cryptographic library.

Safe HaskellNone
LanguageHaskell2010

Raaz.Core.Primitives

Contents

Description

Generic cryptographic block primtives and their implementations. This module exposes low-level generic code used in the raaz system. Most likely, one would not need to stoop so low and it might be better to use a more high level interface.

Synopsis

Primtives and their implementations.

class BlockAlgorithm (Implementation p) => Primitive p where #

The type class that captures an abstract block cryptographic primitive. Bulk cryptographic primitives like hashes, ciphers etc often acts on blocks of data. The size of the block is captured by the member blockSize.

As a library, raaz believes in providing multiple implementations for a given primitive. The associated type Implementation captures implementations of the primitive.

For use in production code, the library recommends a particular implementation using the Recommendation class. By default this is the implementation used when no explicit implementation is specified.

Minimal complete definition

blockSize

Associated Types

type Implementation p :: * #

Associated type that captures an implementation of this primitive.

Methods

blockSize :: p -> BYTES Int #

The block size.

Instances

Primitive ChaCha20 # 

Associated Types

type Implementation ChaCha20 :: * #

Primitive BLAKE2s # 

Associated Types

type Implementation BLAKE2s :: * #

Methods

blockSize :: BLAKE2s -> BYTES Int #

Primitive BLAKE2b # 

Associated Types

type Implementation BLAKE2b :: * #

Methods

blockSize :: BLAKE2b -> BYTES Int #

Primitive SHA1 # 

Associated Types

type Implementation SHA1 :: * #

Methods

blockSize :: SHA1 -> BYTES Int #

Primitive SHA224 # 

Associated Types

type Implementation SHA224 :: * #

Methods

blockSize :: SHA224 -> BYTES Int #

Primitive SHA256 # 

Associated Types

type Implementation SHA256 :: * #

Methods

blockSize :: SHA256 -> BYTES Int #

Primitive SHA384 # 

Associated Types

type Implementation SHA384 :: * #

Methods

blockSize :: SHA384 -> BYTES Int #

Primitive SHA512 # 

Associated Types

type Implementation SHA512 :: * #

Methods

blockSize :: SHA512 -> BYTES Int #

Primitive (AES 128 CBC) #

The 128-bit aes cipher in cbc mode.

Associated Types

type Implementation (AES 128 CBC) :: * #

Methods

blockSize :: AES 128 CBC -> BYTES Int #

Primitive (AES 192 CBC) #

The 192-bit aes cipher in cbc mode.

Associated Types

type Implementation (AES 192 CBC) :: * #

Methods

blockSize :: AES 192 CBC -> BYTES Int #

Primitive (AES 256 CBC) #

The 256-bit aes cipher in cbc mode.

Associated Types

type Implementation (AES 256 CBC) :: * #

Methods

blockSize :: AES 256 CBC -> BYTES Int #

class Describable a => BlockAlgorithm a where #

Implementation of block primitives work on buffers. Often for optimal performance, and in some case for safety, we need restrictions on the size and alignment of the buffer pointer. This type class captures such restrictions.

Minimal complete definition

bufferStartAlignment

Methods

bufferStartAlignment :: a -> Alignment #

The alignment expected for the buffer pointer.

Instances

type family Key prim :: * #

Some primitives like ciphers have an encryption/decryption key. This type family captures the key associated with a primitive if it has any.

Instances

type Key ChaCha20 # 
type Key (HMAC h) # 
type Key (HMAC h)
type Key (AES 128 CBC) # 
type Key (AES 128 CBC) = (KEY128, IV)
type Key (AES 192 CBC) # 
type Key (AES 192 CBC) = (KEY192, IV)
type Key (AES 256 CBC) # 
type Key (AES 256 CBC) = (KEY256, IV)

class Primitive p => Recommendation p where #

Primitives that have a recommended implementations.

Minimal complete definition

recommended

Methods

recommended :: p -> Implementation p #

The recommended implementation for the primitive.

data BLOCKS p #

Type safe message length in units of blocks of the primitive. When dealing with buffer lengths for a primitive, it is often better to use the type safe units BLOCKS. Functions in the raaz package that take lengths usually allow any type safe length as long as they can be converted to bytes. This can avoid a lot of tedious and error prone length calculations.

Instances

Enum (BLOCKS p) # 

Methods

succ :: BLOCKS p -> BLOCKS p #

pred :: BLOCKS p -> BLOCKS p #

toEnum :: Int -> BLOCKS p #

fromEnum :: BLOCKS p -> Int #

enumFrom :: BLOCKS p -> [BLOCKS p] #

enumFromThen :: BLOCKS p -> BLOCKS p -> [BLOCKS p] #

enumFromTo :: BLOCKS p -> BLOCKS p -> [BLOCKS p] #

enumFromThenTo :: BLOCKS p -> BLOCKS p -> BLOCKS p -> [BLOCKS p] #

Eq (BLOCKS p) # 

Methods

(==) :: BLOCKS p -> BLOCKS p -> Bool #

(/=) :: BLOCKS p -> BLOCKS p -> Bool #

Ord (BLOCKS p) # 

Methods

compare :: BLOCKS p -> BLOCKS p -> Ordering #

(<) :: BLOCKS p -> BLOCKS p -> Bool #

(<=) :: BLOCKS p -> BLOCKS p -> Bool #

(>) :: BLOCKS p -> BLOCKS p -> Bool #

(>=) :: BLOCKS p -> BLOCKS p -> Bool #

max :: BLOCKS p -> BLOCKS p -> BLOCKS p #

min :: BLOCKS p -> BLOCKS p -> BLOCKS p #

Show (BLOCKS p) # 

Methods

showsPrec :: Int -> BLOCKS p -> ShowS #

show :: BLOCKS p -> String #

showList :: [BLOCKS p] -> ShowS #

Monoid (BLOCKS p) # 

Methods

mempty :: BLOCKS p #

mappend :: BLOCKS p -> BLOCKS p -> BLOCKS p #

mconcat :: [BLOCKS p] -> BLOCKS p #

Primitive p => LengthUnit (BLOCKS p) # 

Methods

inBytes :: BLOCKS p -> BYTES Int #

blocksOf :: Int -> p -> BLOCKS p #

The expression n blocksOf p specifies the message lengths in units of the block length of the primitive p. This expression is sometimes required to make the type checker happy.

allocBufferFor :: Primitive prim => Implementation prim -> BLOCKS prim -> (Pointer -> IO b) -> IO b #

Allocate a buffer a particular implementation of a primitive prim. algorithm algo. It ensures that the memory passed is aligned according to the demands of the implementation.