196 lines
8.2 KiB
HTML
196 lines
8.2 KiB
HTML
|
|
<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 – 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 <u.h><br>
|
||
|
|
#include <libc.h><br>
|
||
|
|
#include <mp.h><br>
|
||
|
|
#include <libsec.h>
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>DigestState* md4(uchar *data, ulong dlen, uchar *digest, DigestState
|
||
|
|
*state)
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>DigestState* md5(uchar *data, ulong dlen, uchar *digest, DigestState
|
||
|
|
*state)
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>char* md5pickle(MD5state *state)
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>MD5state* md5unpickle(char *p);
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>DigestState* sha1(uchar *data, ulong dlen, uchar *digest, DigestState
|
||
|
|
*state)
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>char* sha1pickle(MD5state *state)
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>MD5state* sha1unpickle(char *p);
|
||
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
||
|
|
</font></tt>
|
||
|
|
<tt><font size=+1>DigestState* 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* 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("my password", 11, nil, nil);<br>
|
||
|
|
while((n = read(fd, buf, 256)) > 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("drowssap ym", 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>’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>
|