mbedtls_chacha20_crypt() function
This function encrypts or decrypts data with ChaCha20 and the given key and nonce. Since ChaCha20 is a stream cipher, the same operation is used for encrypting and decrypting data. \warning You must never use the same (key, nonce) pair more than once. This would void any confidentiality guarantees for the messages encrypted with the same nonce and key.
Syntax
int mbedtls_chacha20_crypt(const unsigned char key[32],
const unsigned char nonce[12],
uint32_t counter,
size_t size,
const unsigned char *input,
unsigned char *output);
Arguments
key
The encryption/decryption key. This must be \c 32 Bytes in length.
nonce
The nonce. This must be \c 12 Bytes in size.
counter
The initial counter value. This is usually \c 0.
size
The length of the input data in Bytes.
input
The buffer holding the input data. This pointer can be \c NULL if `size == 0`.
output
The buffer holding the output data. This must be able to hold \p size Bytes. This pointer can be \c NULL if `size == 0`.
Return value
\c 0 on success. A negative error code on failure.
Notes
The \p input and \p output pointers must either be equal or point to non-overlapping buffers.
![]()
int mbedtls_chacha20_crypt(const unsigned char key[32],