Stream ciphers
==============

A stream cipher normally generates a deterministic, random looking stream of bits, known as key stream. For encryption purpose this key stream is XORed with the data stream. So decryption is exactly the same as encryption. The data-stream is XORed with the key stream giving the plaintext. So both sides need exactly the same stream cipher in the same state.

List of available stream ciphers
--------------------------------

The following stream ciphers are currently implemented:

  * ARCFOUR (RC4 compatibel)

  * Trivium

  * Grain

  * MUGI

  * Mickey-128 (v2)

High frequent parameters
------------------------

output-size
     8 bit, 1 bit

keysize
     64 bit, 80 bit, 128 bit

IVsize
     64 bit

Parts of a stream cipher
------------------------

  * generation algorithm

  * initialization algorithm

  * state

As we can see all stream ciphers seem to utilize an internal state which determines the output. This state is initialized by the initialization algorithm with a key and an IV (initialization vector). It is very important for security that _never_ the same key with the same IV is used again. The IV is not required to be kept secret.

API of stream ciphers
---------------------

The API is not always consistent due to the fact that we tried to optimize the code for size (flash, heap and stack) and speed (runtime of the different components).

Generally the API of the implemented stream ciphers consists of:

*_init
     function, which implements the initialization

*_gen
     function, which implements the streamcipher algorithm and generates a keystream output

*_ctx_t
     context type, which contains internal state information

*_init function
...............

The *_init function generally takes a pointer to the key as first parameter. For ciphers where the keysize is not fixed the second parameter gives the keysize (in bits regularly) followed by a pointer to the IV and a length parameter for not fixed IV sizes (both are omitted if the algorithm does not specify IV handling, in this case a part of the key should be used as IV). The last parameter points to the context variable to fill.

*_gen function
..............

The *_gen function updates the internal state to which a pointer is given as parameter and returns a fixed length part of the keystream as return value.

Stream cipher abstraction layer (SCAL)
--------------------------------------