STRUCT CIPHER_ALG(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 at git 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 with git 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 be cra_blocksize big. this always operates on a full cra_blocksize β€” you literally cannot encrypt a block of smaller size, so the supplied buffers have to be at least cra_blocksize too. both input and output buffers are always aligned to cra_alignmask. and if either buffer supplied by the user of the crypto API isn't aligned to cra_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 the cra_init call, 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 to cia_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