STRUCT AHASH_ALG(9)
π¦ NAME π¦
okay so bestie, this is the manual page for struct ahash_alg β it's the asynchronous message digest definition, and honestly it's giving "blueprint for how your crypto driver actually does hashing" π
β¨ SYNOPSIS β¨
the whole struct, verbatim, no cap:
struct ahash_alg {
int (*init)(struct ahash_request *req);
int (*update)(struct ahash_request *req);
int (*final)(struct ahash_request *req);
int (*finup)(struct ahash_request *req);
int (*digest)(struct ahash_request *req);
int (*export)(struct ahash_request *req, void *out);
int (*import)(struct ahash_request *req, const void *in);
int (*export_core)(struct ahash_request *req, void *out);
int (*import_core)(struct ahash_request *req, const void *in);
int (*setkey)(struct crypto_ahash *tfm, const u8 *key, unsigned int
keylen);
int (*init_tfm)(struct crypto_ahash *tfm);
void (*exit_tfm)(struct crypto_ahash *tfm);
struct hash_alg_common halg;
};
π Members π
okay this is the main character section, every callback explained, pls read it all fr fr π«Ά
initβ [mandatory] β Initialize the transformation context. It's only there to set up the state of the HASH transformation at the very beginning β think "getting ready" energy. It shall fill in the internal structures used during the entire duration of the whole transformation. No data processing happens at this point, none. And heads up: driver code implementation must not usereq->resulthere πupdateβ [mandatory] β Push a chunk of data into the driver for transformation. This one actually pushes blocks of data from upper layers into the driver, which then passes those to the hardware as seen fit. It must not finalize the HASH transformation by calculating the final message digest β because it's just adding more data into the transformation, that's it. It shall not modify the transformation context either, because this function may be called in parallel with the same transformation object (so like, keep your hands to yourself π). Data processing can happen synchronously[SHASH]or asynchronously[AHASH]at this point. Driver must not usereq->result. For block-only algorithms,updatemust return the number of bytes to store in the API partial block buffer πfinalβ [mandatory] β Retrieve result from the driver. It finalizes the transformation and retrieves the resulting hash from the driver, then pushes it back up to upper layers. No data processing happens at this point unless hardware requires it to finish the transformation β and if it does, then the data buffered by the device driver is processed πfinupβ [optional] Combination ofupdateandfinal. It's effectively a combination ofupdateandfinalcalls issued in sequence. Since some hardware literally cannot doupdateandfinalseparately, this callback was added so that such hardware can be used at least by IPsec. Data processing can happen synchronously[SHASH]or asynchronously[AHASH]at this point πdigestβ Combination ofinitandupdateandfinal. This one effectively behaves as the entire chain of operations βinit,updateandfinalissued in sequence. Just likefinup, it was added for hardware which cannot do even thefinup, but can only do the whole transformation in one single run π€ Data processing can happen synchronously[SHASH]or asynchronously[AHASH]at this point.exportβ Export partial state of the transformation. It dumps the entire state of the ongoing transformation into a provided block of data so it can beimport'ed back later on. Super useful when you wanna save a partial result of the transformation after processing a certain amount of data, and reload that partial result multiple times later on for multiple re-use, iykyk β¨ No data processing happens at this point. Driver must not usereq->result.importβ Import partial state of the transformation. Loads the entire state of the ongoing transformation from a provided block of data so the transformation can continue from this point onward π No data processing happens at this point. Driver must not usereq->result.export_coreβ Export partial state without partial block. Only defined for algorithms that are not block-only.import_coreβ Import partial state without partial block. Only defined for algorithms that are not block-only.setkeyβ Set optional key used by the hashing algorithm. Intended to push the optional key used by the hashing algorithm from upper layers into the driver. This function can store the key in the transformation context, or it can outright program it into the hardware π₯ In the former case you gotta be careful to program the key into the hardware at the appropriate time, and careful that.setkeycan be called multiple times during the existence of the transformation object. Not all hashing algorithms implement this function, since it's only needed for keyed message digests.SHAx/MDx/CRCxdo NOT implement this function.HMAC(MDx)/HMAC(SHAx)/CMAC(AES)do implement this function. This one must be called before any other ofinit,update,final,finup,digestis called. No data processing happens at this point πinit_tfmβ Initialize the cryptographic transformation object. Called only once at the instantiation time, right after the transformation context was allocated. If the cryptographic hardware has some special requirements that need to be handled by software, this function shall check for the precise requirement of the transformation and put any software fallbacks in place π§exit_tfmβ Deinitialize the cryptographic transformation object. It's the counterpart toinit_tfm, used to remove various changes set ininit_tfmπ¦halgβ seestruct hash_alg_common
π SEE ALSO π
the whole friend group, go say hi π
Kernel file ./include/crypto/hash.h Message Digest Algorithm Definitions(9)struct shash_alg(9)Asynchronous Message Digest API(9)crypto_alloc_ahash(9)crypto_free_ahash(9)crypto_has_ahash(9)crypto_ahash_blocksize(9)crypto_ahash_digestsize(9)crypto_ahash_statesize(9)crypto_ahash_reqtfm(9)crypto_ahash_reqsize(9)crypto_ahash_setkey(9)crypto_ahash_finup(9)crypto_ahash_final(9)crypto_ahash_digest(9)crypto_ahash_export(9)crypto_ahash_import(9)crypto_ahash_init(9)crypto_ahash_update(9)Asynchronous Hash Request Handle(9)ahash_request_set_tfm(9)ahash_request_alloc(9)ahash_request_free(9)ahash_request_set_callback(9)ahash_request_set_crypt(9)ahash_request_set_virt(9)Synchronous Message Digest API(9)crypto_alloc_shash(9)crypto_free_shash(9)crypto_shash_blocksize(9)crypto_shash_digestsize(9)crypto_shash_descsize(9)crypto_shash_setkey(9)crypto_shash_digest(9)crypto_shash_tfm_digest(9)crypto_shash_export(9)crypto_shash_import(9)crypto_shash_init(9)crypto_shash_finup(9)crypto_shash_update(9)crypto_shash_final(9)
and that's the whole page bestie, go forth and hash responsibly πΈ
this lil masterpiece lives in ./include/crypto, stamped October 2026 β mwah, slay, periodt π
π
π¦ 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