nettle: CFB
1
1 6.3.3 Cipher Feedback mode
1 --------------------------
1
1 Cipher Feedback mode (CFB) being a close relative to both CBC mode and
1 CTR mode borrows some characteristics from stream ciphers.
1
1 The message is divided into ‘n’ blocks ‘M_1’,... ‘M_n’, where ‘M_n’
1 is of size ‘m’ which may be smaller than the block size. Except for the
1 last block, all the message blocks must be of size equal to the cipher’s
1 block size.
1
1 If ‘E_k’ is the encryption function of a block cipher, ‘IV’ is the
1 initialization vector, then the ‘n’ plaintext blocks are transformed
1 into ‘n’ ciphertext blocks ‘C_1’,... ‘C_n’ as follows:
1
1 C_1 = E_k(IV) XOR M_1
1 C_2 = E_k(C_1) XOR M_2
1
1 ...
1
1 C_(n-1) = E_k(C_(n - 2)) XOR M_(n-1)
1 C_n = E_k(C_(n - 1)) [1..m] XOR M_n
1
1 Nettle’s includes two functions for applying a block cipher in Cipher
1 Feedback (CFB) mode, one for encryption and one for decryption. These
1 functions uses ‘void *’ to pass cipher contexts around.
1
1 -- Function: void cfb_encrypt (const void *CTX, nettle_cipher_func *F,
1 size_t BLOCK_SIZE, uint8_t *IV, size_t LENGTH, uint8_t *DST,
1 const uint8_t *SRC)
1 -- Function: void cfb_decrypt (const void *CTX, nettle_cipher_func *F,
1 size_t BLOCK_SIZE, uint8_t *IV, size_t LENGTH, uint8_t *DST,
1 const uint8_t *SRC)
1
1 Applies the encryption or decryption function F in CFB mode. The
1 final ciphertext block processed is copied into IV before
1 returning, so that a large message can be processed by a sequence
1 of calls to ‘cfb_encrypt’. Note that for CFB mode internally uses
1 encryption only function and hence F should always be the
1 encryption function for the underlying block cipher.
1
1 When a message is encrypted using a sequence of calls to
1 ‘cfb_encrypt’, all but the last call _must_ use a length that is a
1 multiple of the block size.
1
1 Like for CBC, there are also a couple of helper macros.
1
1 -- Macro: CFB_CTX (CONTEXT_TYPE, BLOCK_SIZE)
1 Expands to
1 {
1 context_type ctx;
1 uint8_t iv[block_size];
1 }
1
1 -- Macro: CFB_SET_IV(CTX, IV)
1 First argument is a pointer to a context struct as defined by
1 ‘CFB_CTX’, and the second is a pointer to an initialization vector
1 that is copied into that context.
1
1 -- Macro: CFB_ENCRYPT (CTX, F, LENGTH, DST, SRC)
1 A simpler way to invoke ‘cfb_encrypt’. The first argument is a
1 pointer to a context struct as defined by ‘CFB_CTX’, and the second
1 argument is an encryption function following Nettle’s conventions.
1 The last three arguments define the source and destination area for
1 the operation.
1
1 -- Macro: CFB_DECRYPT (CTX, F, LENGTH, DST, SRC)
1 A simpler way to invoke ‘cfb_decrypt’. The first argument is a
1 pointer to a context struct as defined by ‘CFB_CTX’, and the second
1 argument is an encryption function following Nettle’s conventions.
1 The last three arguments define the source and destination area for
1 the operation.
1