STRUCT CRYPTO_ALG(9)
π struct crypto_alg(9) π
okay so bestie, welcome to the Kernel API Manual β today we're meeting struct crypto_alg, like, the blueprint of a cryptographic cipher algorithm. this is the main character struct. the blueprint of the blueprint. iykyk β¨
πΈ NAME πΈ
struct crypto_alg β definition of a cryptograpic cipher algorithm π
(yes, that's how the page spells it, and we're keeping it, don't come for me)
π¦ SYNOPSIS π¦
struct crypto_alg {
struct list_head cra_list;
struct list_head cra_users;
u32 cra_flags;
unsigned int cra_blocksize;
unsigned int cra_ctxsize;
unsigned int cra_alignmask;
unsigned int cra_reqsize;
int cra_priority;
refcount_t cra_refcnt;
char cra_name[CRYPTO_MAX_ALG_NAME];
char cra_driver_name[CRYPTO_MAX_ALG_NAME];
const struct crypto_type *cra_type;
union {
struct cipher_alg cipher;
} cra_u;
int (*cra_init)(struct crypto_tfm *tfm);
void (*cra_exit)(struct crypto_tfm *tfm);
void (*cra_destroy)(struct crypto_alg *alg);
struct module *cra_module;
};
like, look at her. every field a lil icon π
π Members π
okay so here's the field-by-field tea, no skipping, we stan a complete list π
cra_listβ internally used π (that's it, that's the whole vibe, it's not for you)cra_usersβ internally used, same deal, hands off bestie πcra_flagsβ flags that describe this transformation, fr. peep theinclude/linux/crypto.hCRYPTO_ALG_*flags for the ones that go in here β those are what fine-tune the description of the transformation algorithm β¨cra_blocksizeβ minimum block size of this transformation, aka the size in bytes of the smallest possible unit that can actually be transformed with this algorithm. users must respect this value, no cap. in the case of HASH transformation, it's possible for a smaller block thancra_blocksizeto be passed to the crypto API for transformation β but for any other transformation type, an error gets returned on any attempt to transform chunks smaller thancra_blocksizeπcra_ctxsizeβ size of the operational context of the transformation. this value tells the kernel crypto API how much memory needs to be allocated for the transformation context π§cra_alignmaskβ for cipher, skcipher, lskcipher, and aead algorithms, this is 1 less than the alignment (in bytes) that the algorithm implementation requires for input and output buffers. when the crypto API is invoked with buffers that aren't aligned to this alignment, the crypto API automatically busts out appropriately aligned temporary buffers to comply with what the algorithm needs (for scatterlists this only happens if the algorithm uses theskcipher_walkhelper functions). this misalignment handling carries a performance penalty, so it's preferred that algorithms do not set a nonzero alignmask. also, crypto API users may wish to allocate buffers aligned to the alignmask of the algorithm being used, so the API doesn't have to realign them. note: the alignmask is not supported for hash algorithms and is always0for them π«Άcra_reqsizeβ size of the request context for this algorithm βcra_priorityβ priority of this transformation implementation. if multiple transformations with the samecra_nameare available to the Crypto API, the kernel uses the one with the highestcra_priority. highest wins, it's giving competition arc π₯cra_refcntβ internally used πcra_nameβ generic name (usable by multiple implementations) of the transformation algorithm. this is the name of the transformation itself. the kernel uses this field when looking up the providers of a particular transformation πcra_driver_nameβ unique name of the transformation provider. this is the name of the provider of the transformation. it can be any arbitrary value, but usually it contains the name of the chip or provider and the name of the transformation algorithm π·οΈcra_typeβ type of the cryptographic transformation. this is a pointer tostruct crypto_type, which implements callbacks common to all transformation types. multiple options exist, likecrypto_skcipher_type,crypto_ahash_type,crypto_rng_type. this field might be empty β in that case there are no common callbacks, which is the case for: cipher π¦cra_uβ callbacks implementing the transformation. this is a union of multiple structures. depending on the type of transformation selected bycra_typeandcra_flagsabove, the associated structure must be filled with callbacks. this field might be empty β that's the case for ahash, shash πcra_u.cipherβ union member containing a single-block symmetric cipher definition. seestruct cipher_algπcra_initβ deprecated, do not use π«cra_exitβ deprecated, do not use π« (yes both of them, leave them alone)cra_destroyβ internally used πcra_moduleβ owner of this transformation implementation. set it toTHIS_MODULEπ
β¨ Description β¨
the struct crypto_alg describes a generic Crypto API algorithm and is common for all of the transformations π«
any variable not documented here shall not be used by a cipher implementation, because it's internal to the Crypto API. like, don't touch what you didn't read about, bestie β that's the whole rule π
π SEE ALSO π
- Kernel file
./include/linux/crypto.h - Block Cipher Context Data Structures(9)
- Block Cipher Algorithm Definitions(9)
struct cipher_alg(9)
and that's the whole page, periodt π go read those see-alsos, they're literally linked in spirit β and if you ever need to find this again, it lives in ./include/linux, dated October 2026, slaying in the Kernel API Manual forever π«ΆπΈβ¨
π¦ 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