Concrete base class to assist with implementing CTR mode for 128-bit block ciphers.
More...
#include <CTR.h>
|
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...
|
|
| Cipher () |
| Constructs a new cipher object.
|
|
virtual | ~Cipher () |
| Destroys this cipher object. More...
|
|
Concrete base class to assist with implementing CTR mode for 128-bit block ciphers.
Reference: http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation
- See Also
- CTR
Definition at line 29 of file CTR.h.
Constructs a new cipher in CTR mode.
This constructor should be followed by a call to setBlockCipher().
Definition at line 42 of file CTR.cpp.
void CTRCommon::clear |
( |
| ) |
|
|
virtual |
Clears all security-sensitive state from this cipher.
Security-sensitive information includes key schedules, initialization vectors, and any temporary state that is used by encrypt() or decrypt() which is stored in the cipher itself.
Implements Cipher.
Definition at line 165 of file CTR.cpp.
void CTRCommon::decrypt |
( |
uint8_t * |
output, |
|
|
const uint8_t * |
input, |
|
|
size_t |
len |
|
) |
| |
|
virtual |
Decrypts an input buffer and writes the plaintext to an output buffer.
- Parameters
-
output | The output buffer to write to, which may be the same buffer as input. The output buffer must have at least as many bytes as the input buffer. |
input | The input buffer to read from. |
len | The number of bytes to decrypt. |
The decrypt() function can be called multiple times with different regions of the ciphertext data.
- See Also
- encrypt()
Implements Cipher.
Definition at line 160 of file CTR.cpp.
void CTRCommon::encrypt |
( |
uint8_t * |
output, |
|
|
const uint8_t * |
input, |
|
|
size_t |
len |
|
) |
| |
|
virtual |
Encrypts an input buffer and writes the ciphertext to an output buffer.
- Parameters
-
output | The output buffer to write to, which may be the same buffer as input. The output buffer must have at least as many bytes as the input buffer. |
input | The input buffer to read from. |
len | The number of bytes to encrypt. |
The encrypt() function can be called multiple times with different regions of the plaintext data.
- See Also
- decrypt()
Implements Cipher.
Definition at line 128 of file CTR.cpp.
size_t CTRCommon::ivSize |
( |
| ) |
const |
|
virtual |
Size of the initialization vector for this cipher, in bytes.
If the cipher does not need an initialization vector, this function will return zero.
Implements Cipher.
Definition at line 62 of file CTR.cpp.
size_t CTRCommon::keySize |
( |
| ) |
const |
|
virtual |
Default size of the key for this cipher, in bytes.
If the cipher supports variable-sized keys, keySize() indicates the default or recommended key size. The cipher may support other key sizes.
- See Also
- setKey(), ivSize()
Implements Cipher.
Definition at line 57 of file CTR.cpp.
Sets the block cipher to use for this CTR object.
- Parameters
-
cipher | The block cipher to use to implement CTR mode, which must have a block size of 16 bytes (128 bits). |
- Note
- This class only works with block ciphers whose block size is 16 bytes (128 bits). If the cipher has a different block size, then setKey() will fail and return false.
Definition at line 49 of file CTR.h.
bool CTRCommon::setCounterSize |
( |
size_t |
size | ) |
|
Sets the counter size for the IV.
- Parameters
-
size | The number of bytes on the end of the counter block that are relevant when incrementing, between 1 and 16. |
- Returns
- Returns false if the size value is not between 1 and 16.
When the counter is incremented during encrypt(), only the last size bytes are considered relevant. This can be useful to improve performance when the higher level protocol specifies that only the least significant N bytes "count". The high level protocol should explicitly generate a new initial counter value and key long before the size bytes overflow and wrap around.
By default, the counter size is 16 which is the same as the block size of the underlying block cipher.
- See Also
- setIV()
Definition at line 86 of file CTR.cpp.
bool CTRCommon::setIV |
( |
const uint8_t * |
iv, |
|
|
size_t |
len |
|
) |
| |
|
virtual |
Sets the initial counter value to use for future encryption and decryption operations.
- Parameters
-
iv | The initial counter value which must contain exactly 16 bytes. |
len | The length of the counter value, which mut be 16. |
- Returns
- Returns false if len is not exactly 16.
The precise method to generate the initial counter is not defined by this class. Usually higher level protocols like SSL/TLS and SSH specify how to construct the initial counter value. This class merely increments the counter every time a new block of keystream data is needed.
- See Also
- encrypt(), setCounterSize()
Implements Cipher.
Definition at line 119 of file CTR.cpp.
bool CTRCommon::setKey |
( |
const uint8_t * |
key, |
|
|
size_t |
len |
|
) |
| |
|
virtual |
Sets the key to use for future encryption and decryption operations.
- Parameters
-
key | The key to use. |
len | The length of the key in bytes. |
- Returns
- Returns false if the key length is not supported, or the key is somehow "weak" and unusable by this cipher.
Use clear() or the destructor to remove the key and any other sensitive data from the object once encryption or decryption is complete.
Calling setKey() resets the cipher. Any temporary data that was being retained for encrypting partial blocks will be abandoned.
- See Also
- keySize(), clear()
Implements Cipher.
Definition at line 94 of file CTR.cpp.
The documentation for this class was generated from the following files: