STRUCT CIPHER_ALG(9)
π struct cipher_alg(9) β Kernel API Manual, bestie edition β¨
okay so picture this: you're deep in the kernel, right, and you need to teach the crypto subsystem about a brand-new single-block symmetric cipher. This struct? This is literally the whole personality profile you hand over. It's giving "here's my key sizes, here's how you set a key, here's how you encrypt, here's how you decrypt." That's the entire vibe. π
β¨ NAME β¨
struct cipher_alg β the definition of single-block symmetric ciphers. no cap, that's it, that's the whole thing π¦
πΈ SYNOPSIS πΈ
struct cipher_alg {
unsigned int cia_min_keysize;
unsigned int cia_max_keysize;
int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key, unsigned
int keylen);
void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
};
like, look at her. five fields. every single one mandatory. main character struct fr fr π
π§ Members π§
cia_min_keysizeβ the smallest key length this transformation algorithm can handle. tiny key energy. and listen β this must be set to one of the pre-defined values, because it is not hardware specific, okay? you can't just make one up. possible values for this field live atgit grep "_MIN_KEY_SIZE" include/crypto/β go look, i'll wait πcia_max_keysizeβ the largest key length this transformation algorithm supports. big key energy. same rule tho: must be one of the pre-defined values, again because it's not hardware specific. find the possible values withgit grep "_MAX_KEY_SIZE" include/crypto/β¨cia_setkeyβ sets the key for the transformation. this is the function that either programs a supplied key straight into the hardware, or stashes the key in the transformation context so it can be programmed later. heads up: this function does modify the transformation context π and it can be called multiple times during the lifetime of the transformation object, so you'd better make sure the key actually gets properly reprogrammed into the hardware each time. also, this function is the one responsible for checking the key length for validity. no pressure bestie π«Άcia_encryptβ encrypts a single block. the data block must becra_blocksizebig. this always operates on a fullcra_blocksizeβ you literally cannot encrypt a block of smaller size, so the supplied buffers have to be at leastcra_blocksizetoo. both input and output buffers are always aligned tocra_alignmask. and if either buffer supplied by the user of the crypto API isn't aligned tocra_alignmask? the crypto API re-aligns for you, iconically. what that means in practice: a new buffer gets allocated, the data gets copied into the new buffer, the processing happens on the new buffer, the data gets copied back into the original buffer, and finally the new buffer gets freed. that's the whole little journey π also β if a software fallback was put in place in thecra_initcall, this function might need to use that fallback when the algorithm doesn't support all of the key sizes. and if the key was stored in the transformation context, it might need to be reprogrammed into the hardware right here in this function. big one: this function shall not modify the transformation context, because it may be called in parallel with the same transformation object. do not touch. periodt πcia_decryptβ decrypts a single block. it's the reverse counterpart tocia_encrypt, and the conditions are exactly the same. mirror mirror πͺ
π₯ Description π₯
All fields are mandatory and must be filled. every single one. no skipping, no "i'll do it later", no leaving one blank and hoping nobody notices π fill them in. all of them. π₯
π SEE ALSO π
- Kernel file
./include/linux/crypto.h - Block Cipher Context Data Structures(9)
- Block Cipher Algorithm Definitions(9)
struct crypto_alg(9)
β lowkey reminder: mandatory means mandatory, bestie. the kernel does not do vibes-based validation. π
k bye ily, this page came to you straight out of ./include/linux, dated October 2026 β go forth and cipher correctly π¦π
π¦ 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