# Module Cryptmodes_64

    module Cryptmodes_64: sig .. end

OVERVIEW:

A block cipher encrypts or decrypts a fixed amount of bits on every invocation. Here, we assume that the underlying cipher handles 64 bit blocks as elementary units. If you have a message which is a multiple of 64 bits, you could encrypt every block independently. IT IS STRONGLY RECOMMENDED NOT TO USE THIS SIMPLE APPROACH. This method, often called ECB ("electronic code book"), is vulnerable by plaintext attacks, even if a strong cipher is used. This module implements the following, much better alternatives.

--------------------- CIPHER BLOCK CHAINING ---------------------

USAGE, LIMITATIONS:

- buffer size: the buffer to be en/decrypted must be a multiple of 64 bits.
- initialization vector: the ivec used for encryption must be same as the ivec for decryption. The ivec is not secret, it can be transmitted along with the ciphertext. It is recommended to use the timestamp as ivec, or some random bits.

SECURITY:

- good: plaintext patterns (i.e. text structure in the plaintext) is hidden in the ciphertext
- bad: some manipulations in the ciphertext at the end of the message are possible. To avoid this, compute an MD5 hash of the message, and PREPEND the hash value to the message.

FAULT-TOLERANCE:

- a bit error in the ciphertext affects the corresponding plaintext and the following block
- no recovery from synchronisation errors possible (missing or extra bits)

-------------------- CIPHER-FEEDBACK MODE --------------------

USAGE, LIMITATIONS:

- buffer size: no restrictions
- initialization vector: the ivec used for encryption must be same as the ivec for decryption. The ivec is not secret, it can be transmitted along with the ciphertext. A different ivec must be used for every transmitted message, e.g. MD5(timestamp + serial number).

SECURITY:

- good: plaintext patterns (i.e. text structure in the plaintext) is hidden in the ciphertext
- bad: some manipulations in the ciphertext at the end of the message are possible. To avoid this, compute an MD5 hash of the message, and PREPEND the hash value to the message.

FAULT TOLERANCE:

- a bit error in the ciphertext affects the corresponding plaintext and the following block
- n-bit CFB can recover from missing n or extra n bits.

-------------------- OUTPUT-FEEDBACK MODE --------------------

USAGE, LIMITATIONS:

- buffer size: no restrictions
- initialization vector: the ivec used for encryption must be same as the ivec for decryption. The ivec is not secret, it can be transmitted along with the ciphertext. A different ivec must be used for every transmitted message, e.g. MD5(timestamp + serial number).

SECURITY:

- good: plaintext patterns (i.e. text structure in the plaintext) is hidden in the ciphertext
- bad: manipulation of bits in the ciphertext directly affects the corresponding bits in the plaintext

FAULT TOLERANCE:

- a bit error in the ciphertext affects only corresponding plaintext bit
- n-bit CFB cannot recover from missing or extra bits.

-------------- RECOMMENDATION --------------

- If the encrypted messages are transmitted on a serial line, use CFB-8. This is the only mode which can recover from synchronization errors on byte level.
- If your message is a multiple of 64 bits, use CBC. If possible, pad the message to fill up to the next 64 bit multiple, and send the length of the message, too.
- Otherwise, use CFB-64.

    module type T = sig .. end

Derives the other modes from the basic ECB mode:

Make_modes: This version is efficient for cryptsystems based on encrypt_ecb Make_modes_int32: This version is efficient for cryptsystems based on encrypt_ecb_int32

Both functors behave in an equivalent way; the only difference is that Make_modes is fast if M.encrypt_ecb is fast, and that Make_modes_int32 is fast if M.encrypt_ecb_int32 is fast.

    module Make_modes: functor (M : Cryptsystem_64.T) -> T  with type key = M.key

    module Make_modes_int32: functor (M : Cryptsystem_64.T) -> T  with type key = M.key