1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;3.&#160;Developing Cipher Algorithms</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Kernel Crypto API"><link rel="up" href="index.html" title="Linux Kernel Crypto API"><link rel="prev" href="ch02s07.html" title="Internal Structure of Kernel Crypto API"><link rel="next" href="ch03s02.html" title="Single-Block Symmetric Ciphers [CIPHER]"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;3.&#160;Developing Cipher Algorithms</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s07.html">Prev</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch03s02.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="Development"></a>Chapter&#160;3.&#160;Developing Cipher Algorithms</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="Development.html#idp1094439628">Registering And Unregistering Transformation</a></span></dt><dt><span class="sect1"><a href="ch03s02.html">Single-Block Symmetric Ciphers [CIPHER]</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch03s02.html#idp1094347492">Registration specifics</a></span></dt><dt><span class="sect2"><a href="ch03s02.html#idp1094348476">Cipher Definition With struct cipher_alg</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch03s03.html">Multi-Block Ciphers [BLKCIPHER] [ABLKCIPHER]</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch03s03.html#idp1094352900">Registration Specifics</a></span></dt><dt><span class="sect2"><a href="ch03s03.html#idp1097333636">Cipher Definition With struct blkcipher_alg and ablkcipher_alg</a></span></dt><dt><span class="sect2"><a href="ch03s03.html#idp1097334796">Specifics Of Asynchronous Multi-Block Cipher</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch03s04.html">Hashing [HASH]</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch03s04.html#idp1097336588">Registering And Unregistering The Transformation</a></span></dt><dt><span class="sect2"><a href="ch03s04.html#idp1097338788">Cipher Definition With struct shash_alg and ahash_alg</a></span></dt><dt><span class="sect2"><a href="ch03s04.html#idp1097344228">Specifics Of Asynchronous HASH Transformation</a></span></dt></dl></dd></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idp1094439628"></a>Registering And Unregistering Transformation</h2></div></div></div><p>
2     There are three distinct types of registration functions in
3     the Crypto API. One is used to register a generic cryptographic
4     transformation, while the other two are specific to HASH
5     transformations and COMPRESSion. We will discuss the latter
6     two in a separate chapter, here we will only look at the
7     generic ones.
8    </p><p>
9     Before discussing the register functions, the data structure
10     to be filled with each, struct crypto_alg, must be considered
11     -- see below for a description of this data structure.
12    </p><p>
13     The generic registration functions can be found in
14     include/linux/crypto.h and their definition can be seen below.
15     The former function registers a single transformation, while
16     the latter works on an array of transformation descriptions.
17     The latter is useful when registering transformations in bulk.
18    </p><pre class="programlisting">
19   int crypto_register_alg(struct crypto_alg *alg);
20   int crypto_register_algs(struct crypto_alg *algs, int count);
21    </pre><p>
22     The counterparts to those functions are listed below.
23    </p><pre class="programlisting">
24   int crypto_unregister_alg(struct crypto_alg *alg);
25   int crypto_unregister_algs(struct crypto_alg *algs, int count);
26    </pre><p>
27     Notice that both registration and unregistration functions
28     do return a value, so make sure to handle errors. A return
29     code of zero implies success. Any return code &lt; 0 implies
30     an error.
31    </p><p>
32     The bulk registration / unregistration functions require
33     that struct crypto_alg is an array of count size. These
34     functions simply loop over that array and register /
35     unregister each individual algorithm. If an error occurs,
36     the loop is terminated at the offending algorithm definition.
37     That means, the algorithms prior to the offending algorithm
38     are successfully registered. Note, the caller has no way of
39     knowing which cipher implementations have successfully
40     registered. If this is important to know, the caller should
41     loop through the different implementations using the single
42     instance *_alg functions for each individual implementation.
43    </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s07.html">Prev</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="ch03s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Internal Structure of Kernel Crypto API&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Single-Block Symmetric Ciphers [CIPHER]</td></tr></table></div></body></html>
44