aboutsummaryrefslogtreecommitdiff
path: root/man/man3/sechash.html
blob: 2e055465e2297f1e0304193aede86a45e1c44d40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<head>
<title>sechash(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>SECHASH(3)</b><td align=right><b>SECHASH(3)</b>
<tr><td width=20><td colspan=2>
    <br>
<p><font size=+1><b>NAME     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    md4, md5, sha1, hmac_md5, hmac_sha1, md5pickle, md5unpickle, sha1pickle,
    sha1unpickle &ndash; cryptographically secure hashes<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>#include &lt;u.h&gt;<br>
    #include &lt;libc.h&gt;<br>
    #include &lt;mp.h&gt;<br>
    #include &lt;libsec.h&gt; 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>DigestState* &nbsp;&nbsp;&nbsp;&nbsp;md4(uchar *data, ulong dlen, uchar *digest,    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DigestState
    *state) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>DigestState* &nbsp;&nbsp;&nbsp;&nbsp;md5(uchar *data, ulong dlen, uchar *digest,    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DigestState
    *state) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>char*  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;md5pickle(MD5state *state) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>MD5state*  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;md5unpickle(char *p); 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>DigestState* &nbsp;&nbsp;&nbsp;&nbsp;sha1(uchar *data, ulong dlen, uchar *digest,    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DigestState
    *state) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>char*  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sha1pickle(MD5state *state) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>MD5state*  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sha1unpickle(char *p); 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>DigestState* &nbsp;&nbsp;&nbsp;&nbsp;hmac_md5(uchar *data, ulong dlen,<br>
       
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            uchar *key, ulong klen,<br>
               uchar *digest, DigestState *state) 
            <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
            
        </table>
        
    </table>
    </font></tt>
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            
            
        </table>
        
    </table>
    <tt><font size=+1>DigestState* &nbsp;&nbsp;&nbsp;&nbsp;hmac_sha1(uchar *data, ulong dlen,<br>
       
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            uchar *key, ulong klen,<br>
               uchar *digest, DigestState *state)<br>
            
        </table>
        
    </table>
    </font></tt>
</table>
<p><font size=+1><b>DESCRIPTION     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>


<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    These functions implement the cryptographic hash functions MD4,
    MD5, and SHA1. The output of the hash is called a <i>digest</i>. A hash
    is secure if, given the hashed data and the digest, it is difficult
    to predict the change to the digest resulting from some change
    to the data without rehashing the whole data. Therefore, if
    a secret is part of the hashed data, the digest can be used as
    an integrity check of the data by anyone possessing the secret.
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The routines <i>md4</i>, <i>md5</i>, <i>sha1</i>, <i>hmac_md5</i>, and <i>hmac_sha1</i> differ only
    in the length of the resulting digest and in the security of the
    hash. Usage for each is the same. The first call to the routine
    should have <tt><font size=+1>nil</font></tt> as the <i>state</i> parameter. This call returns a state
    which can be used to chain subsequent calls. The last call
    should have digest non-nil. <i>Digest</i> must point to a buffer of at
    least the size of the digest produced. This last call will free
    the state and copy the result into <i>digest</i>. For example, to hash
    a single buffer using <i>md5</i>:<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>uchar digest[MD5dlen];<br>
        md5(data, len, digest, nil);<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    To chain a number of buffers together, bounded on each end by
    some secret:<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>char buf[256];<br>
        uchar digest[MD5dlen];<br>
        DigestState *s;<br>
        s = md5(&quot;my password&quot;, 11, nil, nil);<br>
        while((n = read(fd, buf, 256)) &gt; 0)<br>
         
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            md5(buf, n, nil, s);<br>
            
        </table>
        md5(&quot;drowssap ym&quot;, 11, digest, s);<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
        </font></tt>
        
    </table>
    The constants <i>MD4dlen</i>, <i>MD5dlen</i>, and <i>SHA1dlen</i> define the lengths
    of the digests. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Hmac_md5</i> and <i>hmac_sha1</i> are used slightly differently. These hash
    algorithms are keyed and require a key to be specified on every
    call. The digest lengths for these hashes are <i>MD5dlen</i> and <i>SHA1dlen</i>
    respectively. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The functions <i>md5pickle</i> and <i>sha1pickle</i> marshal the state of a
    digest for transmission. <i>Md5unpickle</i> and <i>sha1unpickle</i> unmarshal
    a pickled digest. All four routines return a pointer to a newly
    <a href="../man3/malloc.html"><i>malloc</i>(3)</a>&#8217;d object.<br>
    
</table>
<p><font size=+1><b>SOURCE     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/usr/local/plan9/src/libsec<br>
    </font></tt>
</table>
<p><font size=+1><b>SEE ALSO    </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <a href="../man3/aes.html"><i>aes</i>(3)</a>, <a href="../man3/blowfish.html"><i>blowfish</i>(3)</a>, <a href="../man3/des.html"><i>des</i>(3)</a>, <a href="../man3/elgamal.html"><i>elgamal</i>(3)</a>, <a href="../man3/rc4.html"><i>rc4</i>(3)</a>, <a href="../man3/rsa.html"><i>rsa</i>(3)</a><br>
    
</table>

<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>