aes_ctr(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… aes_ctr(9) β€” like, the AES-CTR en/decryption page, bestie πŸŽ€

okay so this is aes_ctr from the Kernel API Manual, and no cap it's a short one but every single word is doing WORK. let's get into it ✨


✨ NAME ✨

aes_ctr β€” AES-CTR en/decryption. that's it. that's the vibe. πŸ’–


🌸 SYNOPSIS 🌸

void aes_ctr (u8 *dst , const u8 *src , size_t len , u8 ctr[static
AES_BLOCK_SIZE] , aes_encrypt_arg key );

like, look at her. iconic signature. πŸ‘‘


πŸ¦‹ ARGUMENTS πŸ¦‹

  • dst β€” the destination buffer, bestie. it can be in-place OR out-of-place, both are valid, it's flexible like that πŸ’…. but for other overlaps? the behavior is unspecified β€” so like, don't, and if you do, that's on you πŸ™ˆ
  • src β€” the source data. the raw material. the moment. ✨
  • len β€” number of bytes to en/decrypt. how much we're cookin' πŸ”₯
  • ctr β€” the counter. it will be incremented by ceil(len / AES_BLOCK_SIZE). yes, ceil β€” they're rounding UP, not down, don't get cute πŸŽ€
  • key β€” the key, already prepared using aes_preparekey or aes_prepareenckey. already prepared!! do NOT hand this function a raw un-prepped key, that's not the assignment πŸ™…β€β™€οΈ

πŸ’œ DESCRIPTION πŸ’œ

so this implements AES in counter mode with a 128-bit big endian counter. big endian. she's old school like that 🧚

this exists only for use by the implementation of modes built on top of CTR (e.g., GCM and CCM) and some legacy protocols that use CTR mode directly. so like, if you're just some random caller showing up to use this directly, read the next part VERY carefully πŸ‘€

callers are expected to know how to use CTR mode appropriately, including choosing (key, counter) pairs appropriately to avoid keystream reuse. that's the whole ballgame, fr fr β€” the function is not gonna hold your hand and it is not gonna check. keystream reuse is giving πŸ’€ and the manpage is trusting you to not do it.

this supports incremental en/decryption 🫢. the length of each non-final chunk must be a multiple of AES_BLOCK_SIZE, and the updated ctr must be passed in each time. so like: chunk, feed back the new counter, chunk again, feed back the new counter. keep the chain going, bestie πŸ”—

⚠️ real talk: this is lowkey a footgun if you don't already know CTR mode. the "callers are expected to know" line is doing a LOT of heavy lifting. know your mode, choose your (key, counter) pairs right, and please please please don't reuse the keystream. 😭

🌈 CONTEXT 🌈

any context. literally any. she's flexible. slay. ⭐


πŸ“ SEE ALSO πŸ“

  • Kernel file ./include/crypto/aes-ctr.h
  • aes_xctr(9) β€” her cousin πŸ’–

πŸ’€ so yeah that's the whole page β€” short, sweet, and absolutely unhinged about the keystream reuse thing, as she should be.

this lil gem lives in ./include/crypto, dated October 2026, and it's aes_ctr(9) signing off β€” mwah πŸ’‹ stay safe out there and don't reuse your keystreams 🫢✨

πŸ“¦ where this page comes from