EVP_CHACHA20(3)
π EVP_CHACHA20(3) π
okay so bestie, this is a page from the Library Functions Manual for libcrypto, and it's literally the ChaCha20 stream cipher for EVP. grab a strawberry drink π and let's get into it.
β¨ NAME β¨
EVP_chacha20, EVP_chacha20_poly1305 β ChaCha20 stream cipher for EVP π
πΈ SYNOPSIS πΈ
it lives in library βlibcryptoβ, and yeah you gotta include the header:
#include <openssl/evp.h>
const EVP_CIPHER *
EVP_chacha20(void);
const EVP_CIPHER *
EVP_chacha20_poly1305(void);
π¦ DESCRIPTION π¦
the plain ChaCha20 one π
EVP_chacha20() provides the ChaCha20 stream cipher in the EVP framework. EVP_EncryptInit_ex(3), EVP_DecryptInit_ex(3), and EVP_CipherInit_ex(3) take a key argument of 32 bytes = 256 bits and an iv argument of 16 bytes = 128 bits, internally using ChaCha_set_key(3) and ChaCha_set_iv(3). the lower 8 bytes = 64 bits of iv are used as counter and the remaining 8 bytes are used as the initialization vector of ChaCha_set_iv(3). ngl that split is a whole vibe. EVP_EncryptUpdate(3), EVP_EncryptFinal_ex(3), EVP_DecryptUpdate(3), and EVP_DecryptFinal_ex(3) internally use ChaCha(3) to perform encryption and decryption. and EVP_CIPHER_CTX_ctrl(3) always fails for ctx objects created from EVP_chacha20() β not me being dramatic, it literally always fails π
the poly1305 one, iykyk π₯
EVP_chacha20_poly1305() provides authenticated encryption with ChaCha20-Poly1305. unless compatibility with other implementations like OpenSSL or BoringSSL is required, using EVP_AEAD_CTX_init(3) with EVP_aead_chacha20_poly1305(3) is recommended instead because the code then becomes transparent to the AEAD cipher used, more flexible, and less error prone. like, it's giving glow-up β¨
with EVP_chacha20_poly1305(), EVP_EncryptInit_ex(3), EVP_DecryptInit_ex(3), and EVP_CipherInit_ex(3) take a key argument of 32 bytes = 256 bits and an iv argument of 12 bytes = 96 bits. this supports additional authenticated data (AAD) and produces a 128-bit authentication tag. the constant EVP_CHACHAPOLY_TLS_TAG_LEN specifies the length of the authentication tag in bytes and has a value of 16 π
the type arguments for EVP_CIPHER_CTX_ctrl(3) π
these are the supported ones, one bullet each because we're organized like that:
EVP_CTRL_AEAD_GET_TAGβ copy the number of bytes indicated by the arg argument from the tag to the location indicated by the ptr argument; to be called afterEVP_EncryptFinal_ex(3). this control operation fails if the ctx is not configured for encryption or if arg is less than1or greater than16.EVP_CTRL_AEAD_SET_TAGβ copy the number of bytes indicated by the arg argument from the location indicated by the ptr argument and designate them as the expected tag length and tag, causing subsequentEVP_DecryptFinal_ex(3)to fail if the tag calculated during decryption does not match. it is strongly recommended to specify arg as exactly16. otherwise, only the initial part of the tag may be compared and mismatches near the end of the tag may get silently ignored π this control operation fails if the ctx is configured for encryption or if arg is less than1or greater than16. if the ptr argument is aNULLpointer, this control operation succeeds without having any effect.EVP_CTRL_AEAD_SET_IV_FIXEDβ set the initialization vector by reading the12bytes pointed to by the ptr argument, independently ofEVP_EncryptInit_ex(3),EVP_DecryptInit_ex(3), andEVP_CipherInit_ex(3). this control operation fails if the arg argument is not exactly12.EVP_CTRL_AEAD_SET_IVLENβ instruct subsequentEVP_EncryptInit_ex(3),EVP_DecryptInit_ex(3), orEVP_CipherInit_ex(3)to expect an iv argument shorter than the default of12bytes; the arg argument specifies the number of bytes to be used. the initialization functions will only read the specified smaller number of bytes from iv and internally zero-pad them on the left. using this is not recommended because it is likely more fragile and less often tested than the equivalent method of simply providing a full-sized iv. this control operation fails if arg is less than1or greater than16.EVP_CTRL_INITβ set the length of the initialization vector to the default value of12bytes and clear the Poly1305 internal state. the application program usually does not need to invoke this control operation manually because it is automatically called internally byEVP_EncryptInit_ex(3),EVP_DecryptInit_ex(3), andEVP_CipherInit_ex(3). so like, it's handled, bestie π«Ά
π RETURN VALUES π
EVP_chacha20() and EVP_chacha20_poly1305() return pointers to static EVP_CIPHER objects that contain the implementations of the symmetric cipher.
if ctx was created from EVP_chacha20() or EVP_chacha20_poly1305(), EVP_CIPHER_CTX_ctrl(3) returns 1 for success or 0 for failure. simple as π
πΈ SEE ALSO πΈ
ChaCha(3), evp(3), EVP_aead_chacha20_poly1305(3), EVP_CIPHER_meth_new(3), EVP_EncryptInit(3) β go read these next, fr fr π
β STANDARDS β
A. Langley, W. Chang, N. Mavrogiannopoulos, J. Strombergson, and S. Josefsson, ChaCha20-Poly1305 Cipher Suites for Transport Layer Security (TLS), RFC 7905, June 2016.
π§ HISTORY π§
EVP_chacha20() first appeared in OpenBSD 5.6.
EVP_chacha20_poly1305() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 7.2.
π CAVEATS π
okay so the original publications and code by Adam Langley used a modified AEAD construction that is incompatible with the common style used by AEAD in TLS and incompatible with RFC 7905:
A. Langley and W. Chang, ChaCha20 and Poly1305 based Cipher Suites for TLS, draft-agl-tls-chacha20poly1305-04, November 2013.
Y. Nir and A. Langley, ChaCha20 and Poly1305 for IETF Protocols, RFC 8439, May 2018.
in particular, the original version used a nonce of 8 instead of 12 bytes. β οΈ
π«Ά cute little sign-off: this slay of a page is from Debian, dated June 8, 2025, and the whole thing is filed under EVP_CHACHA20(3). periodt. π
β¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2023 Ingo Schwarze <schwarze@openbsd.org>
- Copyright (c) 2017 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms