1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Message Digest API</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="User.html" title="Chapter&#160;4.&#160;User Space Interface"><link rel="prev" href="ch04s03.html" title="In-place Cipher operation"><link rel="next" href="ch04s05.html" title="Symmetric Cipher API"></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">Message Digest API</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s03.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;4.&#160;User Space Interface</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch04s05.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idp1097356436"></a>Message Digest API</h2></div></div></div><p>
2     The message digest type to be used for the cipher operation is
3     selected when invoking the bind syscall. bind requires the caller
4     to provide a filled struct sockaddr data structure. This data
5     structure must be filled as follows:
6    </p><pre class="programlisting">
7struct sockaddr_alg sa = {
8	.salg_family = AF_ALG,
9	.salg_type = "hash", /* this selects the hash logic in the kernel */
10	.salg_name = "sha1" /* this is the cipher name */
11};
12    </pre><p>
13     The salg_type value "hash" applies to message digests and keyed
14     message digests. Though, a keyed message digest is referenced by
15     the appropriate salg_name. Please see below for the setsockopt
16     interface that explains how the key can be set for a keyed message
17     digest.
18    </p><p>
19     Using the send() system call, the application provides the data that
20     should be processed with the message digest. The send system call
21     allows the following flags to be specified:
22    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
23       MSG_MORE: If this flag is set, the send system call acts like a
24       message digest update function where the final hash is not
25       yet calculated. If the flag is not set, the send system call
26       calculates the final message digest immediately.
27      </p></li></ul></div><p>
28     With the recv() system call, the application can read the message
29     digest from the kernel crypto API. If the buffer is too small for the
30     message digest, the flag MSG_TRUNC is set by the kernel.
31    </p><p>
32     In order to set a message digest key, the calling application must use
33     the setsockopt() option of ALG_SET_KEY. If the key is not set the HMAC
34     operation is performed without the initial HMAC state change caused by
35     the key.
36    </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s03.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="User.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch04s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">In-place Cipher operation&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Symmetric Cipher API</td></tr></table></div></body></html>
37