Arduino Cryptography Library
Public Member Functions | List of all members
CBC< T > Class Template Reference

Implementation of the Cipher Block Chaining (CBC) mode for 128-bit block ciphers. More...

#include <CBC.h>

Inheritance diagram for CBC< T >:
CBCCommon Cipher

Public Member Functions

 CBC ()
 Constructs a new CBC object for the block cipher T.
 
- Public Member Functions inherited from CBCCommon
virtual ~CBCCommon ()
 Destroys this cipher object after clearing sensitive information.
 
size_t keySize () const
 Default size of the key for this cipher, in bytes. More...
 
size_t ivSize () const
 Size of the initialization vector for this cipher, in bytes. More...
 
bool setKey (const uint8_t *key, size_t len)
 Sets the key to use for future encryption and decryption operations. More...
 
bool setIV (const uint8_t *iv, size_t len)
 Sets the initialization vector to use for future encryption and decryption operations. More...
 
void encrypt (uint8_t *output, const uint8_t *input, size_t len)
 Encrypts an input buffer and writes the ciphertext to an output buffer. More...
 
void decrypt (uint8_t *output, const uint8_t *input, size_t len)
 Decrypts an input buffer and writes the plaintext to an output buffer. More...
 
void clear ()
 Clears all security-sensitive state from this cipher. More...
 
- Public Member Functions inherited from Cipher
 Cipher ()
 Constructs a new cipher object.
 
virtual ~Cipher ()
 Destroys this cipher object. More...
 

Additional Inherited Members

- Protected Member Functions inherited from CBCCommon
 CBCCommon ()
 Constructs a new cipher in CBC mode. More...
 
void setBlockCipher (BlockCipher *cipher)
 Sets the block cipher to use for this CBC object. More...
 

Detailed Description

template<typename T>
class CBC< T >

Implementation of the Cipher Block Chaining (CBC) mode for 128-bit block ciphers.

The template parameter T must be a concrete subclass of BlockCipher indicating the specific block cipher to use. T must have a block size of 16 bytes (128 bits).

For example, the following creates a CBC object using AES192 as the underlying cipher:

cbc.setKey(key, 24);
cbc.setIV(iv, 16);
cbc.encrypt(output, input, len);
void encrypt(uint8_t *output, const uint8_t *input, size_t len)
Encrypts an input buffer and writes the ciphertext to an output buffer.
Definition: CBC.cpp:86
bool setIV(const uint8_t *iv, size_t len)
Sets the initialization vector to use for future encryption and decryption operations.
Definition: CBC.cpp:77
bool setKey(const uint8_t *key, size_t len)
Sets the key to use for future encryption and decryption operations.
Definition: CBC.cpp:67
Implementation of the Cipher Block Chaining (CBC) mode for 128-bit block ciphers.
Definition: CBC.h:58

Decryption is similar:

cbc.setKey(key, 24);
cbc.setIV(iv, 16);
cbc.decrypt(output, input, len);
void decrypt(uint8_t *output, const uint8_t *input, size_t len)
Decrypts an input buffer and writes the plaintext to an output buffer.
Definition: CBC.cpp:99

The size of the ciphertext will always be the same as the size of the plaintext. Also, the length of the plaintext/ciphertext must be a multiple of 16. Extra bytes are ignored and not encrypted. The caller is responsible for padding the underlying data to a multiple of 16 using an appropriate padding scheme for the application.

Reference: http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation

See also
CTR, CFB, OFB

Definition at line 57 of file CBC.h.


The documentation for this class was generated from the following files: