3 md4, md5, sha1, hmac_md5, hmac_sha1, md5pickle, md5unpickle, sha1pickle, sha1unpickle \- cryptographically secure hashes
11 .B #include <libsec.h>
14 DigestState* md4(uchar *data, ulong dlen, uchar *digest,
19 DigestState* md5(uchar *data, ulong dlen, uchar *digest,
24 char* md5pickle(MD5state *state)
27 MD5state* md5unpickle(char *p);
30 DigestState* sha1(uchar *data, ulong dlen, uchar *digest,
35 char* sha1pickle(MD5state *state)
38 MD5state* sha1unpickle(char *p);
41 DigestState* hmac_md5(uchar *data, ulong dlen,
44 uchar *key, ulong klen,
47 uchar *digest, DigestState *state)
50 DigestState* hmac_sha1(uchar *data, ulong dlen,
53 uchar *key, ulong klen,
56 uchar *digest, DigestState *state)
59 We support several secure hash functions. The output of the
62 A hash is secure if, given the hashed data and the digest,
63 it is difficult to predict the change to the digest resulting
64 from some change to the data without rehashing
65 the whole data. Therefore, if a secret is part of the hashed
66 data, the digest can be used as an integrity check of the data by anyone
67 possessing the secret.
76 differ only in the length of the resulting digest
77 and in the security of the hash. Usage for each is the same.
78 The first call to the routine should have
82 parameter. This call returns a state which can be used to chain
84 The last call should have digest non-\fBnil\fR.
86 must point to a buffer of at least the size of the digest produced.
87 This last call will free the state and copy the result into
89 For example, to hash a single buffer using
93 uchar digest[MD5dlen];
95 md5(data, len, digest, nil);
98 To chain a number of buffers together,
99 bounded on each end by some secret:
103 uchar digest[MD5dlen];
106 s = md5("my password", 11, nil, nil);
107 while((n = read(fd, buf, 256)) > 0)
109 md5("drowssap ym", 11, digest, s);
117 define the lengths of the digests.
122 are used slightly differently. These hash algorithms are keyed and require
123 a key to be specified on every call.
124 The digest lengths for these hashes are
134 marshal the state of a digest for transmission.
138 unmarshal a pickled digest.
139 All four routines return a pointer to a newly
143 .B /usr/local/plan9/src/libsec