Table of Contents
There are three distinct types of registration functions in the Crypto API. One is used to register a generic cryptographic transformation, while the other two are specific to HASH transformations and COMPRESSion. We will discuss the latter two in a separate chapter, here we will only look at the generic ones.
Before discussing the register functions, the data structure to be filled with each, struct crypto_alg, must be considered -- see below for a description of this data structure.
The generic registration functions can be found in include/linux/crypto.h and their definition can be seen below. The former function registers a single transformation, while the latter works on an array of transformation descriptions. The latter is useful when registering transformations in bulk, for example when a driver implements multiple transformations.
int crypto_register_alg(struct crypto_alg *alg); int crypto_register_algs(struct crypto_alg *algs, int count);
The counterparts to those functions are listed below.
int crypto_unregister_alg(struct crypto_alg *alg); int crypto_unregister_algs(struct crypto_alg *algs, int count);
Notice that both registration and unregistration functions do return a value, so make sure to handle errors. A return code of zero implies success. Any return code < 0 implies an error.
The bulk registration/unregistration functions register/unregister each transformation in the given array of length count. They handle errors as follows:
crypto_register_algs() succeeds if and only if it successfully registers all the given transformations. If an error occurs partway through, then it rolls back successful registrations before returning the error code. Note that if a driver needs to handle registration errors for individual transformations, then it will need to use the non-bulk function crypto_register_alg() instead.
crypto_unregister_algs() tries to unregister all the given transformations, continuing on error. It logs errors and always returns zero.