4
static void encode(uchar*, u32int*, ulong);
6
extern void _sha1block(uchar*, ulong, u32int*);
9
* we require len to be a multiple of 64 for all but
10
* the last call. There must be room in the input buffer
14
sha1(uchar *p, ulong len, uchar *digest, SHA1state *s)
22
s = malloc(sizeof(*s));
25
memset(s, 0, sizeof(*s));
30
/* seed the state, these constants would look nicer big-endian */
31
s->state[0] = 0x67452301;
32
s->state[1] = 0xefcdab89;
33
s->state[2] = 0x98badcfe;
34
s->state[3] = 0x10325476;
35
s->state[4] = 0xc3d2e1f0;
39
/* fill out the partial 64 byte block from previous calls */
44
memmove(s->buf + s->blen, p, i);
49
_sha1block(s->buf, s->blen, s->state);
55
/* do 64 byte blocks */
58
_sha1block(p, i, s->state);
64
/* save the left overs if not last call */
67
memmove(s->buf, p, len);
74
* this is the last time through, pad what's left with 0x80,
75
* 0's, and the input count to create a multiple of 64 bytes
94
/* append the count */
99
/* digest the last part */
100
_sha1block(p, len+8, s->state);
103
/* return result and free state */
104
encode(digest, s->state, SHA1dlen);
111
* encodes input (ulong) into output (uchar). Assumes len is
115
encode(uchar *output, u32int *input, ulong len)
120
for(e = output + len; output < e;) {