STRUCT AES_ENCKEY(9)
π 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:16for AES-128,24for AES-192, and32for AES-256. pick your fighter πnroundsβ how many rounds you're doing:10for AES-128,12for AES-192,14for 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 thatoffsetof(k)is a multiple of16. that way, if you align this struct to a 16-byte boundary,kends 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 fouru32words. 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:
- it's rare that modes need decryption-only, and
- some AES implementations use the same
kfor both encryption and decryption β either always, or conditionally. in that conditional case, bothkandinv_kare 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms