AES_ENCRYPT(3)

πŸ“¦ version 4.1.0, in opensuse-leap 16.0

πŸ’– 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:

  • bits 128 β€” bytes 16, ints 44, rounds 10
  • bits 192 β€” bytes 24, ints 52, rounds 12
  • bits 256 β€” bytes 32, ints 60, rounds 14

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 use EVP_EncryptInit(3) and EVP_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