1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Hashing [HASH]</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="Development.html" title="Chapter&#160;3.&#160;Developing Cipher Algorithms"><link rel="prev" href="ch03s03.html" title="Multi-Block Ciphers [BLKCIPHER] [ABLKCIPHER]"><link rel="next" href="User.html" title="Chapter&#160;4.&#160;User Space Interface"></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">Hashing [HASH]</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;3.&#160;Developing Cipher Algorithms</th><td width="20%" align="right">&#160;<a accesskey="n" href="User.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idp1097336068"></a>Hashing [HASH]</h2></div></div></div><div class="toc"><dl class="toc"><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></div><p>
2     Example of transformations: crc32, md5, sha1, sha256,...
3    </p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp1097336588"></a>Registering And Unregistering The Transformation</h3></div></div></div><p>
4      There are multiple ways to register a HASH transformation,
5      depending on whether the transformation is synchronous [SHASH]
6      or asynchronous [AHASH] and the amount of HASH transformations
7      we are registering. You can find the prototypes defined in
8      include/crypto/internal/hash.h:
9     </p><pre class="programlisting">
10   int crypto_register_ahash(struct ahash_alg *alg);
11
12   int crypto_register_shash(struct shash_alg *alg);
13   int crypto_register_shashes(struct shash_alg *algs, int count);
14     </pre><p>
15      The respective counterparts for unregistering the HASH
16      transformation are as follows:
17     </p><pre class="programlisting">
18   int crypto_unregister_ahash(struct ahash_alg *alg);
19
20   int crypto_unregister_shash(struct shash_alg *alg);
21   int crypto_unregister_shashes(struct shash_alg *algs, int count);
22     </pre></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp1097338788"></a>Cipher Definition With struct shash_alg and ahash_alg</h3></div></div></div><p>
23      Here are schematics of how these functions are called when
24      operated from other part of the kernel. Note that the .setkey()
25      call might happen before or after any of these schematics happen,
26      but must not happen during any of these are in-flight. Please note
27      that calling .init() followed immediately by .finish() is also a
28      perfectly valid transformation.
29     </p><pre class="programlisting">
30   I)   DATA -----------.
31                        v
32         .init() -&gt; .update() -&gt; .final()      ! .update() might not be called
33                     ^    |         |            at all in this scenario.
34                     '----'         '---&gt; HASH
35
36   II)  DATA -----------.-----------.
37                        v           v
38         .init() -&gt; .update() -&gt; .finup()      ! .update() may not be called
39                     ^    |         |            at all in this scenario.
40                     '----'         '---&gt; HASH
41
42   III) DATA -----------.
43                        v
44                    .digest()                  ! The entire process is handled
45                        |                        by the .digest() call.
46                        '---------------&gt; HASH
47     </pre><p>
48      Here is a schematic of how the .export()/.import() functions are
49      called when used from another part of the kernel.
50     </p><pre class="programlisting">
51   KEY--.                 DATA--.
52        v                       v                  ! .update() may not be called
53    .setkey() -&gt; .init() -&gt; .update() -&gt; .export()   at all in this scenario.
54                             ^     |         |
55                             '-----'         '--&gt; PARTIAL_HASH
56
57   ----------- other transformations happen here -----------
58
59   PARTIAL_HASH--.   DATA1--.
60                 v          v
61             .import -&gt; .update() -&gt; .final()     ! .update() may not be called
62                         ^    |         |           at all in this scenario.
63                         '----'         '--&gt; HASH1
64
65   PARTIAL_HASH--.   DATA2-.
66                 v         v
67             .import -&gt; .finup()
68                           |
69                           '---------------&gt; HASH2
70     </pre></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="idp1097344228"></a>Specifics Of Asynchronous HASH Transformation</h3></div></div></div><p>
71      Some of the drivers will want to use the Generic ScatterWalk
72      in case the implementation needs to be fed separate chunks of the
73      scatterlist which contains the input data. The buffer containing
74      the resulting hash will always be properly aligned to
75      .cra_alignmask so there is no need to worry about this.
76     </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="Development.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="User.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Multi-Block Ciphers [BLKCIPHER] [ABLKCIPHER]&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Chapter&#160;4.&#160;User Space Interface</td></tr></table></div></body></html>
77