ChaCha20#
Encrypt#
To test a function that encrypts with ChaCha20 only, its name must conform to the following convention:
CC_ChaCha20_encrypt
Its signature must be:
- void CC_ChaCha20_encrypt(
- uint8_t *buffer,
- size_t buffer_size,
- const uint8_t key[32],
- const uint8_t *nonce,
- size_t nonce_size,
- uint64_t init_counter,
- Parameters:
buffer – [In/Out] A buffer containing the plaintext to encrypt, and to store the resulting ciphertext.
buffer_size – [In] The size of the buffer in bytes.
key – [In] The 32-byte symmetric key.
nonce – [In] The nonce.
nonce_size – [In] The size of the nonce in bytes.
init_counter – [In] An absolute position within the keystream in bytes to seek before encrypting.
Example:
void CC_ChaCha20_encrypt(uint8_t *buffer, size_t buffer_size,
const uint8_t key[32],
const uint8_t *nonce, size_t nonce_size,
uint64_t init_counter);
Decrypt#
To test a function that decrypts with ChaCha20 only, its name must conform to the following convention:
CC_ChaCha20_decrypt
Its signature must be:
- void CC_ChaCha20_decrypt(
- uint8_t *buffer,
- size_t buffer_size,
- const uint8_t key[32],
- const uint8_t *nonce,
- size_t nonce_size,
- uint64_t init_counter,
- Parameters:
buffer – [In/Out] A buffer containing the ciphertext to decrypt, and to store the resulting plaintext.
buffer_size – [In] The size of the buffer in bytes.
key – [In] The 32-byte symmetric key.
nonce – [In] The nonce.
nonce_size – [In] The size of the nonce in bytes.
init_counter – [In] An absolute position within the keystream in bytes to seek before decrypting.
Example:
void CC_ChaCha20_encrypt(uint8_t *buffer, size_t buffer_size,
const uint8_t key[32],
const uint8_t *nonce, size_t nonce_size,
uint64_t init_counter);
Encrypt with Poly1305#
To test a function that encrypts with ChaCha20-Poly1305, its name must conform to the following convention:
CC_ChaCha20_Poly1305_encrypt
Its signature must be:
- void CC_ChaCha20_Poly1305_encrypt(
- uint8_t *buffer,
- size_t buffer_size,
- uint8_t mac[16],
- const uint8_t key[32],
- const uint8_t *nonce,
- size_t nonce_size,
- const uint8_t *aad,
- size_t aad_size,
- Parameters:
buffer – [In/Out] A buffer containing the plaintext to encrypt, and to store the resulting ciphertext.
buffer_size – [In] The size of the buffer in bytes.
mac – [Out] A buffer to store the resulting 16-byte MAC tag.
key – [In] The 32-byte symmetric key.
nonce – [In] The nonce.
nonce_size – [In] The size of the nonce in bytes.
aad – [In] The optional associated data. NULL if not used.
aad_size – [In] The size of the associated data. 0 if not used.
Example:
void CC_ChaCha20_Poly1305_encrypt(uint8_t *buffer, size_t buffer_size,
uint8_t mac[16],
const uint8_t key[32],
const uint8_t *nonce, size_t nonce_size,
const uint8_t *aad, size_t aad_size);
Decrypt with Poly1305#
To test a function that decrypts with ChaCha20-Poly1305, its name must conform to the following convention:
CC_ChaCha20_Poly1305_decrypt
Its signature must be:
- int CC_ChaCha20_Poly1305_decrypt(
- uint8_t *buffer,
- size_t buffer_size,
- const uint8_t key[32],
- const uint8_t *nonce,
- size_t nonce_size,
- const uint8_t *aad,
- size_t aad_size,
- const uint8_t mac[16],
- Parameters:
buffer – [In/Out] A buffer containing the ciphertext to decrypt, and to store the resulting plaintext. It is ignored if the function returns -2.
buffer_size – [In] The size of the buffer in bytes.
key – [In] The 32-byte symmetric key.
nonce – [In] The nonce.
nonce_size – [In] The size of the nonce in bytes.
aad – [In] The optional associated data. NULL if not used.
aad_size – [In] The size of the associated data. 0 if not used.
mac – [In] The 16-byte MAC tag to verify.
- Returns:
A status value.
- Return values:
0 – OK.
-1 – The MAC verification failed.
Example:
int CC_ChaCha20_Poly1305_decrypt(uint8_t *buffer, size_t buffer_size,
const uint8_t key[32],
const uint8_t *nonce, size_t nonce_size,
const uint8_t *aad, size_t aad_size,
const uint8_t mac[16]);