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.
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 require that struct crypto_alg is an array of count size. These functions simply loop over that array and register / unregister each individual algorithm. If an error occurs, the loop is terminated at the offending algorithm definition. That means, the algorithms prior to the offending algorithm are successfully registered. Note, the caller has no way of knowing which cipher implementations have successfully registered. If this is important to know, the caller should loop through the different implementations using the single instance *_alg functions for each individual implementation.