Skinny-C
 All Data Structures Files Functions Variables Groups Pages
Public Member Functions
CTR< T > Class Template Reference

Implementation of the Counter (CTR) mode for 128-bit block ciphers. More...

#include <CTR.h>

Inheritance diagram for CTR< T >:
CTRCommon Cipher

Public Member Functions

 CTR ()
 Constructs a new CTR object for the 128-bit block cipher T.
 
- Public Member Functions inherited from CTRCommon
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 setCounterSize (size_t size)
 Sets the counter size for the IV. 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 initial counter value 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 CTRCommon
 CTRCommon ()
 Constructs a new cipher in CTR mode. More...
 
void setBlockCipher (BlockCipher *cipher)
 Sets the block cipher to use for this CTR object. More...
 

Detailed Description

template<typename T>
class CTR< T >

Implementation of the Counter (CTR) mode for 128-bit block ciphers.

Counter mode converts a block cipher into a stream cipher. The specific block cipher is passed as the template parameter T and the key is specified via the setKey() function.

Keystream blocks are generated by encrypting an increasing counter value and XOR'ing it with each byte of input. The encrypt() and decrypt() operations are identical.

The template parameter T must be a concrete subclass of BlockCipher indicating the specific block cipher to use. For example, the following creates a CTR object using AES256 as the underlying cipher:

ctr.setKey(key, 32);
ctr.setIV(iv, 16);
ctr.encrypt(output, input, len);

In this example, the last 4 bytes of the IV are incremented to count blocks. The remaining bytes are left unchanged from block to block.

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

See Also
CFB, OFB, CBC

Definition at line 60 of file CTR.h.


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