billstclair / elm-crypto-string / Crypto.Strings.Types

Shared types used by all the Crypto.Strings modules.

Types


type alias Passphrase =
String

Another name for String, to aid in documentation.


type alias Plaintext =
String

Another name for String, to aid in documentation.


type alias Ciphertext =
String

Another name for String, to aid in documentation.


type alias KeyExpander key =
{ keySize : Basics.Int
, expander : Array Basics.Int -> Result String key 
}

Describe key expansion for a particular block encryption algorithm.

keySize is the number of bytes in a raw key.

expander is a function to turn an array of that size into a key.


type Key key
    = Key key

A portable name for block encryption algorithm specific keys.


type alias Config key state randomState =
{ encryption : Encryption key
, keyEncoding : KeyEncoding
, chaining : Chaining key state randomState
, encoding : Encoding 
}

Configuration for the block chaining and string encoding


type alias BlockSize =
Basics.Int

An alternative name for Int to make docs clearer.


type alias Block =
Array Basics.Int

One block for a block encryption algorithm.


type alias Encryption key =
{ name : String
, blockSize : BlockSize
, keyExpander : KeyExpander key
, encryptor : Encryptor key
, decryptor : Decryptor key 
}

Package up information about a block encryption algorithm.


type alias Encryptor key =
key -> Block -> Block

An encryption function for a particular low-level block algorithm.


type alias Decryptor key =
key -> Block -> Block

A decryption function for a particular low-level block algorithm.


type alias RandomGenerator randomState =
BlockSize -> ( Block
, randomState 
}

Create a random byte array of a given length


type alias KeyEncoding =
{ name : String
, encoder : KeyEncoder 
}

Describe a KeyEncoder for a Config.

Not all KeyEncodings will be compatible with all block Encryption types.


type alias KeyEncoder =
BlockSize -> Passphrase -> Block

Turn a passphrase into an IV.


type alias Encoding =
{ name : String
, encoder : Encoder
, decoder : Decoder 
}

Encoder and decoder for translating between strings and blocks.


type alias Encoder =
List Basics.Int -> String

A string encoding algorithm.


type alias Decoder =
String -> Result String (List Basics.Int)

A string decoding algorithm.


type alias Chaining key state randomState =
{ name : String
, initializer : ChainingInitializer state randomState
, encryptor : Chainer key state
, decryptor : Chainer key state
, adjoiner : ChainingStateAdjoiner state
, separator : ChainingStateSeparator state 
}

Package up all the information needed to do block chaining.


type alias ChainingInitializer state randomState =
RandomGenerator randomState -> BlockSize -> ( state
, randomState 
}

Create an initial chaining state for encryption.


type alias Chainer key state =
state -> ( Encryptor key
, Decryptor key ) -> key -> Block -> ( Block
, state 
}

A block chaining algorithm.


type alias ChainingStateAdjoiner state =
state -> List Basics.Int -> List Basics.Int

Adjoin chaining state to a list of ciphertext blocks.


type alias ChainingStateSeparator state =
BlockSize -> List Basics.Int -> ( List Basics.Int
, state 
}

Remove the adjoined state from a list of cipher blocks and turn it into a state.