NAME
EVP_AEAD_CTX_init, EVP_AEAD_CTX_cleanup, EVP_AEAD_CTX_open, EVP_AEAD_CTX_seal, EVP_AEAD_key_length, EVP_AEAD_max_overhead, EVP_AEAD_max_tag_len, EVP_AEAD_nonce_length, EVP_aead_aes_128_gcm, EVP_aead_aes_256_gcm, EVP_aead_chacha20_poly1305 — authenticated encryption with additional dataSYNOPSIS
#include <openssl/evp.h>EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, const unsigned char *key, size_t key_len, size_t tag_len, ENGINE *impl);
EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx);
EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len, size_t max_out_len, const unsigned char *nonce, size_t nonce_len, const unsigned char *in, size_t in_len, const unsigned char *ad, size_t ad_len);
EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len, size_t max_out_len, const unsigned char *nonce, size_t nonce_len, const unsigned char *in, size_t in_len, const unsigned char *ad, size_t ad_len);
EVP_AEAD_key_length(const EVP_AEAD *aead);
EVP_AEAD_max_overhead(const EVP_AEAD *aead);
EVP_AEAD_max_tag_len(const EVP_AEAD *aead);
EVP_AEAD_nonce_length(const EVP_AEAD *aead);
EVP_aead_aes_128_gcm(void);
EVP_aead_aes_256_gcm(void);
EVP_aead_chacha20_poly1305(void);
DESCRIPTION
AEAD (Authenticated Encryption with Additional Data) couples confidentiality and integrity in a single primitive. AEAD algorithms take a key and can then seal and open individual messages. Each message has a unique, per-message nonce and, optionally, additional data which is authenticated but not included in the output.- EVP_aead_aes_128_gcm()
- AES-128 in Galois Counter Mode.
- EVP_aead_aes_256_gcm()
- AES-256 in Galois Counter Mode.
- EVP_aead_chacha20_poly1305()
- ChaCha20 with a Poly1305 authenticator.
RETURN VALUES
EVP_AEAD_CTX_init(), EVP_AEAD_CTX_open(), and EVP_AEAD_CTX_seal() return 1 for success or zero for failure.EXAMPLES
Encrypt a string using ChaCha20-Poly1305:const EVP_AEAD *aead = EVP_aead_chacha20_poly1305(); static const unsigned char nonce[32] = {0}; size_t buf_len, nonce_len; EVP_AEAD_CTX ctx; EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), EVP_AEAD_DEFAULT_TAG_LENGTH, NULL); nonce_len = EVP_AEAD_nonce_length(aead); EVP_AEAD_CTX_seal(&ctx, out, &out_len, BUFSIZE, nonce, nonce_len, in, in_len, NULL, 0); EVP_AEAD_CTX_cleanup(&ctx);