EVP_CHACHA20(3SSL)

πŸ’– EVP_CHACHA20 πŸ’–

okay bestie, sit down, hydrate, and let me tell you about EVP_chacha20 and EVP_chacha20_poly1305 β€” aka the EVP ChaCha20 stream cipher. this is from the OpenSSL manual crew and it's genuinely iconic, no cap. πŸ¦‹


✨ SYNOPSIS ✨

#include <openssl/evp.h>

const EVP_CIPHER *EVP_chacha20(void);
const EVP_CIPHER *EVP_chacha20_poly1305(void);

like, that's the whole vibe. two lil functions, both handing you back a const EVP_CIPHER *. slay. πŸ’…


🌸 DESCRIPTION 🌸

It's the ChaCha20 stream cipher, but for EVP. two flavors, both delicious:

πŸŽ€ EVP_chacha20()

The ChaCha20 stream cipher itself. the tea:

  • key length is 256 bits πŸ‘‘
  • the IV is 128 bits long
  • the first 64 bits of that IV is a counter in little-endian order, followed by a 64 bit nonce

so like, say your nonce is:

0000000000000002

and your initial counter is 42 (which is 2a in hex, cute right?). then the whole thing gets expressed as:

2a000000000000000000000000000002

see how the counter went first, lil-endian style, and the nonce is chillin' after it? that's the whole bit. 🫢

πŸ¦‹ EVP_chacha20_poly1305()

okay this one is the main character. it's authenticated encryption with ChaCha20-Poly1305. just like EVP_chacha20():

  • the key is 256 bits ✨
  • and the IV is 96 bits

this one supports additional authenticated data (AAD) and it produces a 128-bit authentication tag. so you get the encryption AND the "was this messed with" check in one go. if you want the full rundown, go read the "AEAD INTERFACE" section over in EVP_EncryptInit(3). iykyk. πŸ’œ


⚠️ NOTES ⚠️

bestie, listen, this part is important. 🚨

Devs should be aware of the negative performance implications of calling these functions multiple times. like, it's giving "why are you doing this repeatedly, love" 😭. instead, consider using EVP_CIPHER_fetch(3) together with EVP_CIPHER-CHACHA(7). for the full lore, check out "Performance" in crypto(7).

also, quick heads up: RFC 7539 (https://www.rfc-editor.org/rfc/rfc7539.html#section-2.4) uses a 32 bit counter and a 96 bit nonce for the IV. so like, if you were vibe-checking the IV layout above and something felt off β€” that's why. different spec, different shape. πŸ‘€


πŸ“ RETURN VALUES πŸ“

Both of these functions return an EVP_CIPHER structure that contains the implementation of the symmetric cipher. that's it. that's the return value. periodt. πŸ’…


🌈 SEE ALSO 🌈

go read those, they're the supporting cast and they ate. πŸ‘‘


Copyright 2017-2023 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at https://www.openssl.org/source/license.html.


and that's the whole page, bestie πŸ’– version 4.0.3, dated 2026-09-29, from the OpenSSL crew β€” now go forth and encrypt responsibly (and don't call these functions in a loop, i'm begging you 😭). πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from