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 These functions implement
60 the cryptographic hash functions MD4, MD5, and SHA1. The output of the
63 A hash is secure if, given the hashed data and the digest,
64 it is difficult to predict the change to the digest resulting
65 from some change to the data without rehashing
66 the whole data. Therefore, if a secret is part of the hashed
67 data, the digest can be used as an integrity check of the data by anyone
68 possessing the secret.
77 differ only in the length of the resulting digest
78 and in the security of the hash. Usage for each is the same.
79 The first call to the routine should have
83 parameter. This call returns a state which can be used to chain
85 The last call should have digest non-\fBnil\fR.
87 must point to a buffer of at least the size of the digest produced.
88 This last call will free the state and copy the result into
90 For example, to hash a single buffer using
94 uchar digest[MD5dlen];
96 md5(data, len, digest, nil);
99 To chain a number of buffers together,
100 bounded on each end by some secret:
104 uchar digest[MD5dlen];
107 s = md5("my password", 11, nil, nil);
108 while((n = read(fd, buf, 256)) > 0)
110 md5("drowssap ym", 11, digest, s);
118 define the lengths of the digests.
123 are used slightly differently. These hash algorithms are keyed and require
124 a key to be specified on every call.
125 The digest lengths for these hashes are
135 marshal the state of a digest for transmission.
139 unmarshal a pickled digest.
140 All four routines return a pointer to a newly