The friendly Operating System for the Internet of Things
cbcmode.h File Reference

Headers of the implementation of the CBC Mode of Operation. More...

Detailed Description

Implementation of the CBC Mode of Operation with Ciphertext-Stealing for encryption.

Author
Freie Universitaet Berlin, Computer Systems & Telematics.
Nicolai Schmittberger nicol.nosp@m.ai.s.nosp@m.chmit.nosp@m.tber.nosp@m.ger@f.nosp@m.u-be.nosp@m.rlin..nosp@m.de
Zakaria Kasmi zkasm.nosp@m.i@in.nosp@m.f.fu-.nosp@m.berl.nosp@m.in.de

Definition in file cbcmode.h.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "crypto/ciphers.h"
+ Include dependency graph for cbcmode.h:

Go to the source code of this file.

Data Structures

struct  CBCModeContext
 The context for processing the en-/decryption in the CBC-Mode with CTS. More...
 
#define MIN(a, b)   ( ((a) < (b)) ? (a) : (b))
 
#define DBG_CRYPTO   1
 
#define FAIL   0
 
#define SUCCESS   1
 
enum  { CBCMODE_MAX_BLOCK_SIZE = 8, CBCMODE_MAX_BLOCK_SIZE_AES = 16 }
 
enum  { ONE_BLOCK, GENERAL, TWO_LEFT_A, TWO_LEFT_B }
 
typedef struct CBCModeContext CBCModeContext
 The context for processing the en-/decryption in the CBC-Mode with CTS. More...
 
int block_cipher_mode_init (CipherModeContext *context, uint8_t key_size, uint8_t *key)
 
int block_cipher_mode_init0 (CipherModeContext *context, uint8_t key_size, uint8_t *key, uint8_t cipher_index)
 same as BlockCipherMode_init but with the possibility to specify the index of the cipher in the archive More...
 
void dbg (uint8_t mode, const char *format,...)
 prints the debug-messages passed by dump_buffer More...
 
void dump_buffer (char *bufName, uint8_t *buf, uint8_t size)
 dumps the passed buffer to the console More...
 
int block_cipher_mode_encrypt (CipherModeContext *context, uint8_t *plain_blocks, uint8_t *cipher_blocks, uint16_t num_bytes, uint8_t *IV)
 Encrypts num_bytes of plaintext blocks (each of size blockSize) using the key from the init phase. More...
 
int block_cipher_mode_decrypt (CipherModeContext *context, uint8_t *cipher_blocks, uint8_t *plain_blocks, uint16_t num_bytes, uint8_t *IV)
 Decrypts num_bytes of ciphertext blocks (each of size blockSize) using the key from the init phase. More...
 

Typedef Documentation

Parameters
spill1test1

Function Documentation

int block_cipher_mode_decrypt ( CipherModeContext *  context,
uint8_t *  cipher_blocks,
uint8_t *  plain_blocks,
uint16_t  num_bytes,
uint8_t *  IV 
)

The IV is a pointer to the initialization vector (of size equal to the blockSize) which is used to initialize the decryption. In place decryption should work provided that the plain and and cipher buffer are the same. (they may either be the same or non-overlapping. partial overlaps are not supported).

Parameters
contextcontext object for this decryption
cipher_blocksan array of num_bytes * blockSize bytes that holds the cipher text
plain_blocksan array of num_bytes * blockSize bytes to hold the resulting plaintext.
num_bytesnumber of data blocks to encrypt
IVan array of the initialization vector. It should be of block size bytes
Returns
Whether the decryption was successful. Possible failure reasons include not calling init().
int block_cipher_mode_encrypt ( CipherModeContext *  context,
uint8_t *  plain_blocks,
uint8_t *  cipher_blocks,
uint16_t  num_bytes,
uint8_t *  IV 
)

The IV is a pointer to the initialization vector (of size equal to the blockSize) which is used to initialize the encryption. In place encryption should work provided that the plain and and cipher buffer are the same. (they may either be the same or non-overlapping. partial overlaps are not supported).

Parameters
contextcontext object for this encryption
plain_blocksa plaintext block numBlocks, where each block is of blockSize bytes
cipher_blocksan array of numBlocks * blockSize bytes to hold the resulting cyphertext
num_bytesnumber of data blocks to encrypt
IVan array of the initialization vector. It should be of block size bytes
Returns
Whether the encryption was successful. Possible failure reasons include not calling init().
int block_cipher_mode_init0 ( CipherModeContext *  context,
uint8_t  key_size,
uint8_t *  key,
uint8_t  cipher_index 
)
Parameters
contextstructure to hold the opaque data from this initialization call. It should be passed to future invocations of this module which use this particular key. It also contains the opaque context for the underlying BlockCipher as well.
key_sizekey size in bytes.
keypointer to the key.
cipher_indexthe index of the cipher-algorithm to init in the (cipher-)archive
Returns
Whether initialization was successful. The command may be unsuccessful if the key size is not valid for the given cipher implementation. It can also fail if the preferred block size of the cipher does not agree with the preferred size of the mode.
void dbg ( uint8_t  mode,
const char *  format,
  ... 
)
Parameters
modethe mode of the debug-message
formatpointer to the message
void dump_buffer ( char *  bufName,
uint8_t *  buf,
uint8_t  size 
)
Parameters
bufNamepointer to the name of the buffer
bufpointer to the buffer itself
sizethe size of the buffer in bytes