Abstract base class for stream ciphers. More...
#include <Cipher.h>
Public Member Functions | |
Cipher () | |
Constructs a new cipher object. | |
virtual | ~Cipher () |
Destroys this cipher object. More... | |
virtual size_t | keySize () const =0 |
Default size of the key for this cipher, in bytes. More... | |
virtual size_t | ivSize () const =0 |
Size of the initialization vector for this cipher, in bytes. More... | |
virtual bool | setKey (const uint8_t *key, size_t len)=0 |
Sets the key to use for future encryption and decryption operations. More... | |
virtual bool | setIV (const uint8_t *iv, size_t len)=0 |
Sets the initialization vector to use for future encryption and decryption operations. More... | |
virtual void | encrypt (uint8_t *output, const uint8_t *input, size_t len)=0 |
Encrypts an input buffer and writes the ciphertext to an output buffer. More... | |
virtual void | decrypt (uint8_t *output, const uint8_t *input, size_t len)=0 |
Decrypts an input buffer and writes the plaintext to an output buffer. More... | |
virtual void | clear ()=0 |
Clears all security-sensitive state from this cipher. More... | |
Abstract base class for stream ciphers.
This class is intended for implementing ciphers that operate on arbitrary amounts of data. In particular, stream ciphers where the number of bytes that are input to encrypt() or decrypt() is exactly the same as the number of bytes that are output.
All of the stream ciphers such as ChaCha inherit directly from this class, together with block cipher modes such as CTR and CFB.
|
virtual |
Destroys this cipher object.
Subclasses are responsible for clearing temporary key schedules and other buffers so as to avoid leaking sensitive information.
Definition at line 53 of file Cipher.cpp.
|
pure virtual |
|
pure virtual |
Decrypts an input buffer and writes the plaintext to an output buffer.
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.
Implemented in CTRCommon.
|
pure virtual |
Encrypts an input buffer and writes the ciphertext to an output buffer.
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.
Implemented in CTRCommon.
|
pure 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.
Implemented in CTRCommon.
|
pure virtual |
|
pure virtual |
Sets the initialization vector to use for future encryption and decryption operations.
iv | The initialization vector to use. |
len | The length of the initialization vector in bytes. |
Initialization vectors should be set before the first call to encrypt() or decrypt() after a setKey() call. If the initialization vector is changed after encryption or decryption begins, then the behaviour is undefined.
Implemented in CTRCommon.
|
pure virtual |
Sets the key to use for future encryption and decryption operations.
key | The key to use. |
len | The length of the key in bytes. |
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.
Implemented in CTRCommon.