Function esp_idf_sys::mbedtls_chachapoly_init
source ยท pub unsafe extern "C" fn mbedtls_chachapoly_init(
ctx: *mut mbedtls_chachapoly_context,
)
Expand description
\brief This function initializes the specified ChaCha20-Poly1305 context.
It must be the first API called before using
the context. It must be followed by a call to
\c mbedtls_chachapoly_setkey() before any operation can be
done, and to \c mbedtls_chachapoly_free() once all
operations with that context have been finished.
In order to encrypt or decrypt full messages at once, for
each message you should make a single call to
\c mbedtls_chachapoly_crypt_and_tag() or
\c mbedtls_chachapoly_auth_decrypt().
In order to encrypt messages piecewise, for each
message you should make a call to
\c mbedtls_chachapoly_starts(), then 0 or more calls to
\c mbedtls_chachapoly_update_aad(), then 0 or more calls to
\c mbedtls_chachapoly_update(), then one call to
\c mbedtls_chachapoly_finish().
\warning Decryption with the piecewise API is discouraged! Always use \c mbedtls_chachapoly_auth_decrypt() when possible!
If however this is not possible because the data is too
large to fit in memory, you need to:
- call \c mbedtls_chachapoly_starts() and (if needed)
\c mbedtls_chachapoly_update_aad() as above,
- call \c mbedtls_chachapoly_update() multiple times and
ensure its output (the plaintext) is NOT used in any other
way than placing it in temporary storage at this point,
- call \c mbedtls_chachapoly_finish() to compute the
authentication tag and compared it in constant time to the
tag received with the ciphertext.
If the tags are not equal, you must immediately discard
all previous outputs of \c mbedtls_chachapoly_update(),
otherwise you can now safely use the plaintext.
\param ctx The ChachaPoly context to initialize. Must not be \c NULL.