KCAPI_CIPHER_ENC_AES(3)

๐Ÿ’– KCAPI_CIPHER_ENC_AES_CBC โ€” okay bestie, let's talk AES CBC โœจ

Manual page kcapi_cipher_enc_aes_cbc โ€” from the Programming Interface crew, no cap. This is the group chat where the C library talks back ๐Ÿ’…


๐ŸŒธ NAME ๐ŸŒธ

kcapi_cipher_enc_aes_cbc โ€” the convenience function for AES CBC encryption. It's giving "one function, zero drama" ๐ŸŽ€


โœจ SYNOPSIS โœจ

ssize_t kcapi_cipher_enc_aes_cbc(const uint8_t * key, uint32_t keylen,
                                 const uint8_t * in, size_t inlen,
                                 const uint8_t * iv, uint8_t * out,
                                 size_t outlen);

๐Ÿซถ ARGUMENTS ๐Ÿซถ

Every single one of these is a main character, so let's do intros ๐Ÿ‘‘

  • key โ€” [in] the key buffer. Literally the key. The blueprint. The lore ๐Ÿ’œ
  • keylen โ€” [in] length of that key buffer. How many bytes of blueprint we're working with ๐Ÿ“
  • in โ€” [in] the plaintext data buffer. This is the tea before it gets scrambled โ˜•
  • inlen โ€” [in] length of the in buffer. Count the bytes, bestie ๐Ÿงฎ
  • iv โ€” [in] the IV to be used for the cipher operation. Yes you need it, no you can't skip it ๐ŸŒˆ
  • out โ€” [out] the ciphertext data buffer. Where the glow-up lands ๐Ÿ’ซ
  • outlen โ€” [in] length of the out buffer. Make sure it's big enough, fr fr ๐Ÿซฃ

๐Ÿ’… DESCRIPTION ๐Ÿ’…

So like, this convenience function performs an AES CBC encryption operation using the provided key, the given input buffer, and the given iv. The output gets stored in the out buffer. Slay ๐Ÿ’–

โš ๏ธ Heads up bestie: AES CBC requires input data that is a multiple of 16 bytes. That's not a vibe, that's the rules.

If you've got data that is not guaranteed to be multiples of 16 bytes, you have two moves:

  1. Add zero bytes at the end of the buffer to pad it up to a multiple of 16 bytes ๐ŸŽ€
  2. Otherwise, the CTR mode encryption operation may be usable ๐Ÿ”ฅ

Also, the out buffer must be at least as large as the in buffer. No shrinkflation allowed, periodt ๐Ÿ“‰

And the iv? It must be exactly 16 bytes in size. Exactly. Not 15, not 17. Sixteen. Iconic and precise โœจ

The AES type (AES-128, AES-192 or AES-256) is determined by the size of the given key, and the way that works is:

  • key is 16 bytes long โ†’ AES-128 is used ๐Ÿ’™
  • key is 24 bytes long โ†’ AES-192 is implied ๐Ÿ’š
  • key is 32 bytes long โ†’ AES-256 is implied ๐Ÿงก

And the return value, bestie? Listen up ๐Ÿ‘‚

  • On success: the number of bytes generated ๐ŸŽ‰
  • On error: a negative errno-style error code ๐Ÿ˜ญ

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Stephan Mueller <smueller@chronox.de>

  • Author. Certified legend, respectfully ๐Ÿซก

This is from the libkcapi Manual, version 1.5.0, dated July 2025 ๐ŸŒธ


Okay that's the whole page, you ate it, go encrypt something responsibly ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹๐ŸŒธ๐Ÿ’…๐Ÿซถ

๐Ÿ“ฆ where this page comes from