1 cfa37a7b 2004-04-10 devnull .TH SECHASH 3
3 cfa37a7b 2004-04-10 devnull md4, md5, sha1, hmac_md5, hmac_sha1, md5pickle, md5unpickle, sha1pickle, sha1unpickle \- cryptographically secure hashes
4 cfa37a7b 2004-04-10 devnull .SH SYNOPSIS
5 cfa37a7b 2004-04-10 devnull .B #include <u.h>
7 cfa37a7b 2004-04-10 devnull .B #include <libc.h>
9 cfa37a7b 2004-04-10 devnull .B #include <mp.h>
11 cfa37a7b 2004-04-10 devnull .B #include <libsec.h>
14 cfa37a7b 2004-04-10 devnull DigestState* md4(uchar *data, ulong dlen, uchar *digest,
16 c8b6342d 2005-01-13 devnull DigestState *state)
19 cfa37a7b 2004-04-10 devnull DigestState* md5(uchar *data, ulong dlen, uchar *digest,
21 c8b6342d 2005-01-13 devnull DigestState *state)
24 cfa37a7b 2004-04-10 devnull char* md5pickle(MD5state *state)
27 c8b6342d 2005-01-13 devnull MD5state* md5unpickle(char *p);
30 cfa37a7b 2004-04-10 devnull DigestState* sha1(uchar *data, ulong dlen, uchar *digest,
32 c8b6342d 2005-01-13 devnull DigestState *state)
35 cfa37a7b 2004-04-10 devnull char* sha1pickle(MD5state *state)
38 c8b6342d 2005-01-13 devnull MD5state* sha1unpickle(char *p);
41 cfa37a7b 2004-04-10 devnull DigestState* hmac_md5(uchar *data, ulong dlen,
44 c8b6342d 2005-01-13 devnull uchar *key, ulong klen,
47 c8b6342d 2005-01-13 devnull uchar *digest, DigestState *state)
50 cfa37a7b 2004-04-10 devnull DigestState* hmac_sha1(uchar *data, ulong dlen,
53 c8b6342d 2005-01-13 devnull uchar *key, ulong klen,
56 c8b6342d 2005-01-13 devnull uchar *digest, DigestState *state)
57 cfa37a7b 2004-04-10 devnull .SH DESCRIPTION
59 c8b6342d 2005-01-13 devnull These functions implement
60 c8b6342d 2005-01-13 devnull the cryptographic hash functions MD4, MD5, and SHA1. The output of the
61 cfa37a7b 2004-04-10 devnull hash is called a
62 cfa37a7b 2004-04-10 devnull .IR digest .
63 cfa37a7b 2004-04-10 devnull A hash is secure if, given the hashed data and the digest,
64 cfa37a7b 2004-04-10 devnull it is difficult to predict the change to the digest resulting
65 cfa37a7b 2004-04-10 devnull from some change to the data without rehashing
66 cfa37a7b 2004-04-10 devnull the whole data. Therefore, if a secret is part of the hashed
67 cfa37a7b 2004-04-10 devnull data, the digest can be used as an integrity check of the data by anyone
68 cfa37a7b 2004-04-10 devnull possessing the secret.
70 cfa37a7b 2004-04-10 devnull The routines
71 cfa37a7b 2004-04-10 devnull .IR md4 ,
72 cfa37a7b 2004-04-10 devnull .IR md5 ,
73 cfa37a7b 2004-04-10 devnull .IR sha1 ,
74 cfa37a7b 2004-04-10 devnull .IR hmac_md5 ,
76 cfa37a7b 2004-04-10 devnull .I hmac_sha1
77 cfa37a7b 2004-04-10 devnull differ only in the length of the resulting digest
78 cfa37a7b 2004-04-10 devnull and in the security of the hash. Usage for each is the same.
79 cfa37a7b 2004-04-10 devnull The first call to the routine should have
83 cfa37a7b 2004-04-10 devnull parameter. This call returns a state which can be used to chain
84 cfa37a7b 2004-04-10 devnull subsequent calls.
85 cfa37a7b 2004-04-10 devnull The last call should have digest non-\fBnil\fR.
86 cfa37a7b 2004-04-10 devnull .I Digest
87 cfa37a7b 2004-04-10 devnull must point to a buffer of at least the size of the digest produced.
88 cfa37a7b 2004-04-10 devnull This last call will free the state and copy the result into
89 cfa37a7b 2004-04-10 devnull .IR digest .
90 cfa37a7b 2004-04-10 devnull For example, to hash a single buffer using
91 cfa37a7b 2004-04-10 devnull .IR md5 :
94 cfa37a7b 2004-04-10 devnull uchar digest[MD5dlen];
96 cfa37a7b 2004-04-10 devnull md5(data, len, digest, nil);
99 cfa37a7b 2004-04-10 devnull To chain a number of buffers together,
100 cfa37a7b 2004-04-10 devnull bounded on each end by some secret:
103 cfa37a7b 2004-04-10 devnull char buf[256];
104 cfa37a7b 2004-04-10 devnull uchar digest[MD5dlen];
105 cfa37a7b 2004-04-10 devnull DigestState *s;
107 cfa37a7b 2004-04-10 devnull s = md5("my password", 11, nil, nil);
108 cfa37a7b 2004-04-10 devnull while((n = read(fd, buf, 256)) > 0)
109 cfa37a7b 2004-04-10 devnull md5(buf, n, nil, s);
110 cfa37a7b 2004-04-10 devnull md5("drowssap ym", 11, digest, s);
113 cfa37a7b 2004-04-10 devnull The constants
114 cfa37a7b 2004-04-10 devnull .IR MD4dlen ,
115 cfa37a7b 2004-04-10 devnull .IR MD5dlen ,
117 cfa37a7b 2004-04-10 devnull .I SHA1dlen
118 cfa37a7b 2004-04-10 devnull define the lengths of the digests.
120 cfa37a7b 2004-04-10 devnull .I Hmac_md5
122 cfa37a7b 2004-04-10 devnull .I hmac_sha1
123 cfa37a7b 2004-04-10 devnull are used slightly differently. These hash algorithms are keyed and require
124 cfa37a7b 2004-04-10 devnull a key to be specified on every call.
125 cfa37a7b 2004-04-10 devnull The digest lengths for these hashes are
126 cfa37a7b 2004-04-10 devnull .I MD5dlen
128 cfa37a7b 2004-04-10 devnull .I SHA1dlen
129 cfa37a7b 2004-04-10 devnull respectively.
131 cfa37a7b 2004-04-10 devnull The functions
132 cfa37a7b 2004-04-10 devnull .I md5pickle
134 cfa37a7b 2004-04-10 devnull .I sha1pickle
135 cfa37a7b 2004-04-10 devnull marshal the state of a digest for transmission.
136 cfa37a7b 2004-04-10 devnull .I Md5unpickle
138 cfa37a7b 2004-04-10 devnull .I sha1unpickle
139 cfa37a7b 2004-04-10 devnull unmarshal a pickled digest.
140 cfa37a7b 2004-04-10 devnull All four routines return a pointer to a newly
141 bf8a59fa 2004-04-11 devnull .IR malloc (3)'d
143 cfa37a7b 2004-04-10 devnull .SH SOURCE
144 c3674de4 2005-01-11 devnull .B \*9/src/libsec
145 cfa37a7b 2004-04-10 devnull .SH SEE ALSO
146 bf8a59fa 2004-04-11 devnull .IR aes (3),
147 bf8a59fa 2004-04-11 devnull .IR blowfish (3),
148 bf8a59fa 2004-04-11 devnull .IR des (3),
149 bf8a59fa 2004-04-11 devnull .IR elgamal (3),
150 bf8a59fa 2004-04-11 devnull .IR rc4 (3),
151 bf8a59fa 2004-04-11 devnull .IR rsa (3)