Arduino Cryptography Library
|
#include <ChaCha.h>
Public Member Functions | |
ChaCha (uint8_t numRounds=20) | |
Constructs a new ChaCha stream cipher. More... | |
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... | |
uint8_t | numRounds () const |
Returns the number of encryption rounds; usually 8, 12, or 20. More... | |
void | setNumRounds (uint8_t numRounds) |
Sets the number of encryption rounds. 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... | |
bool | setCounter (const uint8_t *counter, size_t len) |
Sets the starting counter for encryption. 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... | |
Static Public Member Functions | |
static void | hashCore (uint32_t *output, const uint32_t *input, uint8_t rounds) |
Executes the ChaCha hash core on an input memory block. More... | |
Friends | |
class | ChaChaPoly |
ChaCha stream cipher.
ChaCha is a stream cipher that takes a key, an 8-byte nonce/IV, and a counter and hashes them to generate a keystream to XOR with the plaintext. Variations on the ChaCha cipher use 8, 12, or 20 rounds of hashing operations with either 128-bit or 256-bit keys.
Reference: http://cr.yp.to/chacha.html
|
explicit |
Constructs a new ChaCha stream cipher.
numRounds | Number of encryption rounds to use; usually 8, 12, or 20. |
Definition at line 47 of file ChaCha.cpp.
|
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 218 of file ChaCha.cpp.
|
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.
Implements Cipher.
Definition at line 190 of file ChaCha.cpp.
|
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.
Implements Cipher.
Definition at line 158 of file ChaCha.cpp.
|
static |
Executes the ChaCha hash core on an input memory block.
output | Output memory block, must be at least 16 words in length and must not overlap with input. |
input | Input memory block, must be at least 16 words in length. |
rounds | Number of ChaCha rounds to perform; usually 8, 12, or 20. |
This function is provided for the convenience of applications that need access to the ChaCha hash core without the higher-level processing that turns the core into a stream cipher.
Definition at line 253 of file ChaCha.cpp.
|
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 65 of file ChaCha.cpp.
|
virtual |
|
inline |
Returns the number of encryption rounds; usually 8, 12, or 20.
bool ChaCha::setCounter | ( | const uint8_t * | counter, |
size_t | len | ||
) |
Sets the starting counter for encryption.
counter | A 4-byte or 8-byte value to use for the starting counter instead of the default value of zero. |
len | The length of the counter, which must be 4 or 8. |
This function must be called after setIV() and before the first call to encrypt(). It is used to specify a different starting value than zero for the counter portion of the hash input.
Definition at line 145 of file ChaCha.cpp.
|
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.
Implements Cipher.
Definition at line 111 of file ChaCha.cpp.
|
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.
Implements Cipher.
Definition at line 87 of file ChaCha.cpp.
|
inline |
Sets the number of encryption rounds.
numRounds | The number of encryption rounds; usually 8, 12, or 20. |