raaz-0.2.1: The raaz cryptographic library.

Safe Haskell | None
Language | Haskell2010

Raaz.Core.Primitives

Contents

- Primtives and their implementations.

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

- class BlockAlgorithm (Implementation p) => Primitive p where
  - type Implementation p :: *
  - blockSize :: p -> BYTES Int
- class Describable a => BlockAlgorithm a where
  - bufferStartAlignment :: a -> Alignment
- type family Key prim :: *
- class Primitive p => Recommendation p where
  - recommended :: p -> Implementation p
- data BLOCKS p
- blocksOf :: Int -> p -> BLOCKS p
- allocBufferFor :: Primitive prim => Implementation prim -> BLOCKS prim -> (Pointer -> IO b) -> IO b

# Primtives and their implementations.

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

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.

Associated Types

type Implementation p :: * Source #

Associated type that captures an implementation of this primitive.

Methods

blockSize :: p -> BYTES Int Source #

The block size.

Instances

Primitive ChaCha20 Source # |
Instance details Defined in Raaz.Cipher.ChaCha20.Internal Associated Types type Implementation ChaCha20 :: Type Source # Methods blockSize :: ChaCha20 -> BYTES Int 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 #
Primitive SHA1 Source # |
Instance details Defined in Raaz.Hash.Sha1.Internal Associated Types type Implementation SHA1 :: Type Source # Methods blockSize :: SHA1 -> BYTES Int Source #
Primitive SHA224 Source # |
Instance details Defined in Raaz.Hash.Sha224.Internal Associated Types type Implementation SHA224 :: Type Source # Methods blockSize :: SHA224 -> BYTES Int Source #
Primitive SHA256 Source # |
Instance details Defined in Raaz.Hash.Sha256.Internal Associated Types type Implementation SHA256 :: Type Source # Methods blockSize :: SHA256 -> BYTES Int Source #
Primitive SHA384 Source # |
Instance details Defined in Raaz.Hash.Sha384.Internal Associated Types type Implementation SHA384 :: Type Source # Methods blockSize :: SHA384 -> BYTES Int Source #
Primitive SHA512 Source # |
Instance details Defined in Raaz.Hash.Sha512.Internal Associated Types type Implementation SHA512 :: Type Source # Methods blockSize :: SHA512 -> BYTES Int Source #
Primitive (AES 128 CBC) Source # | The 128-bit aes cipher in cbc mode.
Instance details Defined in Raaz.Cipher.AES.Internal Associated Types type Implementation (AES 128 CBC) :: Type Source # Methods blockSize :: AES 128 CBC -> BYTES Int Source #
Primitive (AES 192 CBC) Source # | The 192-bit aes cipher in cbc mode.
Instance details Defined in Raaz.Cipher.AES.Internal Associated Types type Implementation (AES 192 CBC) :: Type Source # Methods blockSize :: AES 192 CBC -> BYTES Int Source #
Primitive (AES 256 CBC) Source # | The 256-bit aes cipher in cbc mode.
Instance details Defined in Raaz.Cipher.AES.Internal Associated Types type Implementation (AES 256 CBC) :: Type Source # Methods blockSize :: AES 256 CBC -> BYTES Int Source #

class Describable a => BlockAlgorithm a where Source #

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.

Methods

bufferStartAlignment :: a -> Alignment Source #

The alignment expected for the buffer pointer.

Instances

BlockAlgorithm (SomeCipherI cipher) Source # |
Instance details Defined in Raaz.Cipher.Internal Methods bufferStartAlignment :: SomeCipherI cipher -> Alignment Source #
BlockAlgorithm (SomeHashI h) Source # |
Instance details Defined in Raaz.Hash.Internal Methods bufferStartAlignment :: SomeHashI h -> Alignment Source #
BlockAlgorithm (HashI h m) Source # |
Instance details Defined in Raaz.Hash.Internal Methods bufferStartAlignment :: HashI h m -> Alignment Source #
BlockAlgorithm (CipherI cipher encMem decMem) Source # |
Instance details Defined in Raaz.Cipher.Internal Methods bufferStartAlignment :: CipherI cipher encMem decMem -> Alignment Source #

type family Key prim :: * Source #

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 Source # | The key for ChaCha20.
Instance details Defined in Raaz.Cipher.ChaCha20.Internal type Key ChaCha20 = (KEY, IV, Counter)
type Key (HMAC h) Source # |
Instance details Defined in Raaz.Hash.Internal.HMAC type Key (HMAC h)
type Key (AES 128 CBC) Source # | Key is `(`KEY128`,`IV`)` pair.
Instance details Defined in Raaz.Cipher.AES.Internal type Key (AES 128 CBC) = (KEY128, IV)
type Key (AES 192 CBC) Source # | Key is `(`KEY192`,`IV`)` pair.
Instance details Defined in Raaz.Cipher.AES.Internal type Key (AES 192 CBC) = (KEY192, IV)
type Key (AES 256 CBC) Source # | Key is `(`KEY256`,`IV`)` pair.
Instance details Defined in Raaz.Cipher.AES.Internal type Key (AES 256 CBC) = (KEY256, IV)

class Primitive p => Recommendation p where Source #

Primitives that have a recommended implementations.

Methods

recommended :: p -> Implementation p Source #

The recommended implementation for the primitive.

Instances

Recommendation ChaCha20 Source # |
Instance details Defined in Raaz.Cipher.ChaCha20.Recommendation Methods recommended :: ChaCha20 -> Implementation ChaCha20 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 #
Recommendation SHA1 Source # | Recommended implementation for SHA1.
Instance details Defined in Raaz.Hash.Sha1.Recommendation Methods recommended :: SHA1 -> Implementation SHA1 Source #
Recommendation SHA224 Source # | Recommended implementation for SHA224.
Instance details Defined in Raaz.Hash.Sha224.Recommendation Methods recommended :: SHA224 -> Implementation SHA224 Source #
Recommendation SHA256 Source # | Recommended implementation for SHA256.
Instance details Defined in Raaz.Hash.Sha256.Recommendation Methods recommended :: SHA256 -> Implementation SHA256 Source #
Recommendation SHA384 Source # | Recommended implementation for SHA384.
Instance details Defined in Raaz.Hash.Sha384.Recommendation Methods recommended :: SHA384 -> Implementation SHA384 Source #
Recommendation SHA512 Source # | Recommend implementation for SHA512.
Instance details Defined in Raaz.Hash.Sha512.Recommendation Methods recommended :: SHA512 -> Implementation SHA512 Source #
Recommendation (AES 128 CBC) Source # | Recommended implementation of AES-128 cbc
Instance details Defined in Raaz.Cipher.AES.Recommendation Methods recommended :: AES 128 CBC -> Implementation (AES 128 CBC) Source #
Recommendation (AES 192 CBC) Source # | Recommended implementation of AES-192 cbc
Instance details Defined in Raaz.Cipher.AES.Recommendation Methods recommended :: AES 192 CBC -> Implementation (AES 192 CBC) Source #
Recommendation (AES 256 CBC) Source # | Recommended implementation of AES-256 cbc
Instance details Defined in Raaz.Cipher.AES.Recommendation Methods recommended :: AES 256 CBC -> Implementation (AES 256 CBC) Source #

data BLOCKS p Source #

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) Source # |

Instance details

Defined in Raaz.Core.Primitives

Methods

succ :: BLOCKS p -> BLOCKS p Source #

pred :: BLOCKS p -> BLOCKS p Source #

toEnum :: Int -> BLOCKS p Source #

fromEnum :: BLOCKS p -> Int Source #

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

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

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

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

Eq (BLOCKS p) Source # |
Instance details Defined in Raaz.Core.Primitives Methods (==) :: BLOCKS p -> BLOCKS p -> Bool Source # (/=) :: BLOCKS p -> BLOCKS p -> Bool Source #
Ord (BLOCKS p) Source # |
Instance details Defined in Raaz.Core.Primitives Methods compare :: BLOCKS p -> BLOCKS p -> Ordering Source # (<) :: BLOCKS p -> BLOCKS p -> Bool Source # (<=) :: BLOCKS p -> BLOCKS p -> Bool Source # (>) :: BLOCKS p -> BLOCKS p -> Bool Source # (>=) :: BLOCKS p -> BLOCKS p -> Bool Source # max :: BLOCKS p -> BLOCKS p -> BLOCKS p Source # min :: BLOCKS p -> BLOCKS p -> BLOCKS p Source #
Show (BLOCKS p) Source # |
Instance details Defined in Raaz.Core.Primitives Methods showsPrec :: Int -> BLOCKS p -> ShowS Source # show :: BLOCKS p -> String Source # showList :: [BLOCKS p] -> ShowS Source #
Semigroup (BLOCKS p) Source # |
Instance details Defined in Raaz.Core.Primitives Methods (<>) :: BLOCKS p -> BLOCKS p -> BLOCKS p Source # sconcat :: NonEmpty (BLOCKS p) -> BLOCKS p Source # stimes :: Integral b => b -> BLOCKS p -> BLOCKS p Source #
Monoid (BLOCKS p) Source # |
Instance details Defined in Raaz.Core.Primitives Methods mempty :: BLOCKS p Source # mappend :: BLOCKS p -> BLOCKS p -> BLOCKS p Source # mconcat :: [BLOCKS p] -> BLOCKS p Source #
Primitive p => LengthUnit (BLOCKS p) Source # |
Instance details Defined in Raaz.Core.Primitives Methods inBytes :: BLOCKS p -> BYTES Int Source #

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

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 Source #

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.