5 * rfc1321 requires that I include this. The code is new. The constants
6 * all come from the rfc (hence the copyright). We trade a table for the
7 * macros in rfc. The total size is a lot less. -- presotto
9 * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
12 * License to copy and use this software is granted provided that it
13 * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
14 * Algorithm" in all material mentioning or referencing this software
17 * License is also granted to make and use derivative works provided
18 * that such works are identified as "derived from the RSA Data
19 * Security, Inc. MD5 Message-Digest Algorithm" in all material
20 * mentioning or referencing the derived work.
22 * RSA Data Security, Inc. makes no representations concerning either
23 * the merchantability of this software or the suitability of this
24 * software forany particular purpose. It is provided "as is"
25 * without express or implied warranty of any kind.
26 * These notices must be retained in any copies of any part of this
27 * documentation and/or software.
30 static void encode(uchar*, u32int*, ulong);
32 extern void _md5block(uchar*, ulong, u32int*);
35 md5(uchar *p, ulong len, uchar *digest, MD5state *s)
43 s = malloc(sizeof(*s));
46 memset(s, 0, sizeof(*s));
51 /* seed the state, these constants would look nicer big-endian */
52 s->state[0] = 0x67452301;
53 s->state[1] = 0xefcdab89;
54 s->state[2] = 0x98badcfe;
55 s->state[3] = 0x10325476;
59 /* fill out the partial 64 byte block from previous calls */
64 memmove(s->buf + s->blen, p, i);
69 _md5block(s->buf, s->blen, s->state);
75 /* do 64 byte blocks */
78 _md5block(p, i, s->state);
84 /* save the left overs if not last call */
87 memmove(s->buf, p, len);
94 * this is the last time through, pad what's left with 0x80,
95 * 0's, and the input count to create a multiple of 64 bytes
101 memmove(buf, p, len);
114 /* append the count */
119 /* digest the last part */
120 _md5block(p, len+8, s->state);
123 /* return result and free state */
124 encode(digest, s->state, MD5dlen);
131 * encodes input (u32int) into output (uchar). Assumes len is
135 encode(uchar *output, u32int *input, ulong len)
140 for(e = output + len; output < e;) {