STRUCT AES_ENCKEY(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct aes_enckey(9) β€” from the Kernel API Manual πŸŽ€

okay bestie sit down because today we're talking about struct aes_enckey, and it is exactly what it sounds like: an AES key that's been prepared for encryption. that's it, that's the whole vibe. it's the glowed-up, encryption-only version of a key, and honestly? she's iconic for knowing what she is. ✨


✨ SYNOPSIS ✨

here's the whole struct, no cap, copied exactly so you can trust me:

struct aes_enckey {
    u32 len;
    u32 nrounds;
    u32 padding[2];
    union aes_enckey_arch k;
 };

🌸 Members 🌸 (the cast of characters)

  • len β€” the key length in bytes, and she comes in exactly three flavors: 16 for AES-128, 24 for AES-192, and 32 for AES-256. pick your fighter πŸ’–
  • nrounds β€” how many rounds you're doing: 10 for AES-128, 12 for AES-192, 14 for AES-256. mathematically it's '6 + len / 4', and it's cached here on purpose so that AES implementations which need it don't have to keep recomputing it for every single en/decryption. the way she saves you from doing the same math over and over… queen behavior tbh πŸ‘‘
  • padding β€” pure structural self-care 🧚: it pads things out so that offsetof(k) is a multiple of 16. that way, if you align this struct to a 16-byte boundary, k ends up 16-byte aligned too. to be clear: users aren't required to align this struct to 16 bytes β€” but doing it may slightly improve performance, so like… consider it a little treat. ⭐
  • k β€” the actual key material. typically this holds the AES round keys as an array of 'nrounds + 1' groups of four u32 words. BUT 🫢 architecture-specific implementations of AES may store something else here entirely β€” for example, just the raw key, if that's all they need. she contains multitudes.

πŸ’œ DESCRIPTION πŸ’œ

first thing's first: this struct is about half the size of struct aes_key. and she's deliberately separate from struct aes_key for one very good reason β€” so that modes which only need AES encryption (think AES-GCM, AES-CTR, AES-CMAC, and the tweak key in AES-XTS) don't have to eat the time and space overhead of computing and caching all the decryption round keys. why pay for the whole closet when you only need one outfit? πŸ’…πŸ”₯

also, before anyone asks in the group chat: there is no decryption-only equivalent. like, there's no such thing as "struct aes_deckey". and there are two reasons why:

  1. it's rare that modes need decryption-only, and
  2. some AES implementations use the same k for both encryption and decryption β€” either always, or conditionally. in that conditional case, both k and inv_k are needed. so a decryption-only struct would be a whole messy situation. πŸ™ˆ
ngl bestie, if you were about to invent a struct aes_deckey, don't. that's the whole warning. it just doesn't fit the vision. 😭

⭐ SEE ALSO ⭐

go read these next, iykyk β€” Kernel file ./include/crypto/aes.h, struct aes_key(9), aes_expandkey(9), aes_preparekey(9), aes_prepareenckey(9), aes_encrypt(9), aes_decrypt(9)


and that's the page, bestie!! πŸ¦‹ this lil masterpiece lives in ./include/crypto and it's dated October 2026 β€” so yeah, mark your calendars, she's a whole era. stay encrypted, stay aligned to 16 bytes when you can, and slay πŸ’–βœ¨πŸŒˆ

πŸ“¦ where this page comes from