AES_ENCRYPT(3)
π AES_ENCRYPT(3) π
or: the low-level interface to the AES symmetric cipher, explained by your favorite unix girlie
okay bestie, so this one is from section 3 of the library functions manual and it's literally all about AES_set_encrypt_key, AES_set_decrypt_key, AES_encrypt, AES_decrypt, and AES_cbc_encrypt π β yes, all five, we're doing the whole squad.
β¨ NAME β¨
AES_set_encrypt_key, AES_set_decrypt_key, AES_encrypt, AES_decrypt, AES_cbc_encrypt β the low-level interface to the AES symmetric cipher. that's the vibe π
πΈ SYNOPSIS πΈ
#include <openssl/aes.h>
int
AES_set_encrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key);
int
AES_set_decrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key);
void
AES_encrypt(const unsigned char *in, unsigned char *out,
const AES_KEY *key);
void
AES_decrypt(const unsigned char *in, unsigned char *out,
const AES_KEY *key);
void
AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
size_t length, const AES_KEY *key, unsigned char *ivec,
const int enc);
like, copy that verbatim into your editor, do not retype it from memory, i'm begging π
π¦ DESCRIPTION π¦
so these functions provide a low-level interface to the AES symmetric cipher algorithm β it's also called Rijndael, which is honestly such a main character name π. but here's the tea: for reasons of flexibility, it is recommended that application programs use the high-level interface described in EVP_EncryptInit(3) and EVP_aes_128_cbc(3) instead whenever possible. like, the low-level one is right there, but the high-level one ate π«Ά
AES_KEY is a structure that can hold up to 60 int values and a number of rounds. that's it, that's the struct lore π
AES_set_encrypt_key() expands the userKey, which is bits long, into the key structure to prepare for encryption. and the way the numbers line up?? obsessed. here's the full breakdown β the number of bits and bytes read from userKey, the number of int values stored into key, and the number of rounds:
bits128βbytes16,ints44,rounds10bits192βbytes24,ints52,rounds12bits256βbytes32,ints60,rounds14
AES_set_decrypt_key() does the same, but in preparation for decryption. literally the same ritual, different direction β¨
AES_encrypt() reads a single 16 byte block from *in, encrypts it with the key, and writes the 16 resulting bytes to *out. and the cute part?? the 16 byte buffers starting at in and out can overlap, and in and out can even point to the same memory location π iconic behavior, no notes.
AES_decrypt() decrypts a single block and is otherwise identical to AES_encrypt(). same girl, opposite direction π
If enc is non-zero, AES_cbc_encrypt() encrypts len bytes at in to out using the 128 bit key and the 128 bit initialization vector ivec in CBC mode. If enc is 0, AES_cbc_encrypt() performs the corresponding decryption. so like... enc is the switch, bestie, don't fumble it π
π RETURN VALUES π
AES_set_encrypt_key() and AES_set_decrypt_key() return 0 for success, -1 if userKey or key is NULL, or -2 if the number of bits is unsupported.
so: 0 = slay, -1 = you passed a NULL π, -2 = that bit count is not invited to the party π. that's the whole return value situation.
π₯ SEE ALSO π₯
go read those next, i'm serious, the high-level ones are the moment π«Ά
β STANDARDS β
ISO/IEC 18033-3:2010 Information technology β Security techniques β Encryption algorithms β Part 3: Block ciphers
yes the whole title, em dashes and all, i'm not paraphrasing a standard π
π HISTORY π
These functions first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2. veterans fr fr πΈ
π§ AUTHORS π§
- Vincent Rijmen
- Antoon Bosselaers
- Paulo Barreto
the literal legends, we stan π
ok one last vibe check before you go: this is the low-level interface. if you can useEVP_EncryptInit(3)andEVP_aes_128_cbc(3), please do β the manpage itself says so, i'm just the messenger π¦
mwah, go encrypt something responsibly π β¨
this page came from the Debian crew, dated August 28, 2019 β aes_encrypt(3), still serving looks π
π¦ where this page comes from
- opensuse-leap 16.0: libressl-devel-doc 4.1.0-bp160.1.1 Β· OpenSSL
- Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms