2 * SHA-1 implementation.
4 * Copyright (C) 2005 Paul Mackerras <paulus@samba.org>
6 * This version assumes we are running on a big-endian machine.
7 * It calls an external sha1_core() to process blocks of 64 bytes.
13 extern void sha1_core(uint32_t *hash, const unsigned char *p,
14 unsigned int nblocks);
16 int SHA1_Init(SHA_CTX *c)
18 c->hash[0] = 0x67452301;
19 c->hash[1] = 0xEFCDAB89;
20 c->hash[2] = 0x98BADCFE;
21 c->hash[3] = 0x10325476;
22 c->hash[4] = 0xC3D2E1F0;
28 int SHA1_Update(SHA_CTX *c, const void *ptr, unsigned long n)
31 const unsigned char *p = ptr;
35 if (c->cnt || n < 64) {
39 memcpy(&c->buf.b[c->cnt], p, nb);
40 if ((c->cnt += nb) == 64) {
41 sha1_core(c->hash, c->buf.b, 1);
46 sha1_core(c->hash, p, nb);
55 int SHA1_Final(unsigned char *hash, SHA_CTX *c)
57 unsigned int cnt = c->cnt;
59 c->buf.b[cnt++] = 0x80;
62 memset(&c->buf.b[cnt], 0, 64 - cnt);
63 sha1_core(c->hash, c->buf.b, 1);
67 memset(&c->buf.b[cnt], 0, 56 - cnt);
69 sha1_core(c->hash, c->buf.b, 1);
70 memcpy(hash, c->hash, 20);