sha1_update(&hd, buffer, length);
memcpy(outbuf, sha1_final(&hd), SHA1_SIZE);
}
-
-#ifdef TEST
-
-#include <stdio.h>
-#include <unistd.h>
-#include <ucw/string.h>
-
-int main(void)
-{
- sha1_context hd;
- byte buf[3];
- int cnt;
-
- sha1_init(&hd);
- while ((cnt = read(0, buf, sizeof(buf))) > 0)
- sha1_update(&hd, buf, cnt);
-
- char text[SHA1_HEX_SIZE];
- mem_to_hex(text, sha1_final(&hd), SHA1_SIZE, 0);
- puts(text);
-
- return 0;
-}
-
-#endif
byte *osha = sha1_hmac_final(&hd);
memcpy(outbuf, osha, SHA1_SIZE);
}
-
-#ifdef TEST
-
-#include <stdio.h>
-#include <ucw/string.h>
-
-static uint rd(char *dest)
-{
- char buf[1024];
- if (!fgets(buf, sizeof(buf), stdin))
- die("fgets()");
- *strchr(buf, '\n') = 0;
- if (buf[0] == '0' && buf[1] == 'x')
- {
- const char *e = hex_to_mem(dest, buf+2, 1024, 0);
- ASSERT(!*e);
- return (e-buf-2)/2;
- }
- else
- {
- strcpy(dest, buf);
- return strlen(dest);
- }
-}
-
-int main(void)
-{
- char key[1024], data[1024];
- byte hmac[SHA1_SIZE];
- uint kl = rd(key);
- uint dl = rd(data);
- sha1_hmac(hmac, key, kl, data, dl);
- mem_to_hex(data, hmac, SHA1_SIZE, 0);
- puts(data);
- return 0;
-}
-
-#endif