Arduino Cryptography Library
|
Authenticated cipher based on ChaCha and Poly1305. More...
#include <ChaChaPoly.h>
Public Member Functions | |
ChaChaPoly () | |
Constructs a new ChaChaPoly authenticated cipher. | |
virtual | ~ChaChaPoly () |
Destroys this ChaChaPoly authenticated cipher. | |
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... | |
size_t | tagSize () const |
Returns the size of the authentication tag. 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 | addAuthData (const void *data, size_t len) |
Adds extra data that will be authenticated but not encrypted. More... | |
void | computeTag (void *tag, size_t len) |
Finalizes the encryption process and computes the authentication tag. More... | |
bool | checkTag (const void *tag, size_t len) |
Finalizes the decryption process and checks the authentication tag. More... | |
void | clear () |
Clears all security-sensitive state from this cipher. More... | |
Public Member Functions inherited from AuthenticatedCipher | |
AuthenticatedCipher () | |
Constructs a new authenticated cipher. | |
virtual | ~AuthenticatedCipher () |
Destroys this authenticated cipher. | |
Public Member Functions inherited from Cipher | |
Cipher () | |
Constructs a new cipher object. | |
virtual | ~Cipher () |
Destroys this cipher object. More... | |
Authenticated cipher based on ChaCha and Poly1305.
ChaChaPoly is an authenticated cipher based on a combination of ChaCha with 20 rounds for encryption and Poly1305 for authentication. The resulting cipher has a 256-bit key, a 64-bit or 96-bit initialization vector, and a 128-bit authentication tag.
Reference: https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10
Definition at line 30 of file ChaChaPoly.h.
|
virtual |
Adds extra data that will be authenticated but not encrypted.
data | The extra data to be authenticated. |
len | The number of bytes of extra data to be authenticated. |
This function must be called before the first call to encrypt() or decrypt(). That is, it is assumed that all extra data for authentication is available before the first payload data block and that it will be prepended to the payload for authentication. If the subclass needs to process the extra data after the payload, then it is responsible for saving data away until it is needed during computeTag() or checkTag().
This function can be called multiple times with separate extra data blocks for authentication. All such data will be concatenated into a single block for authentication purposes.
Implements AuthenticatedCipher.
Definition at line 127 of file ChaChaPoly.cpp.
|
virtual |
Finalizes the decryption process and checks the authentication tag.
tag | The tag value from the incoming ciphertext to be checked. |
len | The length of the tag value in bytes, which may be less than tagSize(). |
This function must be called after the final block of ciphertext is passed to decrypt() to determine if the data could be authenticated.
Implements AuthenticatedCipher.
Definition at line 150 of file ChaChaPoly.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 164 of file ChaChaPoly.cpp.
|
virtual |
Finalizes the encryption process and computes the authentication tag.
tag | Points to the buffer to write the tag to. |
len | The length of the tag, which may be less than tagSize() to truncate the tag to the first len bytes. |
Implements AuthenticatedCipher.
Definition at line 135 of file ChaChaPoly.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 116 of file ChaChaPoly.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 105 of file ChaChaPoly.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.
|
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.
Implements Cipher.
Definition at line 61 of file ChaChaPoly.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 84 of file ChaChaPoly.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 79 of file ChaChaPoly.cpp.
|
virtual |
Returns the size of the authentication tag.
By default this function should return the largest tag size supported by the authenticated cipher.
Implements AuthenticatedCipher.
Definition at line 73 of file ChaChaPoly.cpp.