From: Tollef Fog Heen Date: Thu, 17 Jul 2008 18:20:54 +0000 (+0200) Subject: More sha1 from gnulib updates; update the rest of the source tree too X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df66a0f6798098c384c222d2ab67b37d7275c58c;p=backuppcd More sha1 from gnulib updates; update the rest of the source tree too --- diff --git a/Makefile.am b/Makefile.am index 8b72750..76b1c48 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,5 +26,6 @@ backuppcd_tar_SOURCES = backuppcd-tar.c \ net.c \ backuppcd-common.c +backuppcd_passwd_LDADD = lib/libgnu.a #backuppcd_passwd_SOURCES = backuppcd-passwd.c \ # \ No newline at end of file diff --git a/backuppcd-passwd.c b/backuppcd-passwd.c index b6ba4f1..b05e385 100644 --- a/backuppcd-passwd.c +++ b/backuppcd-passwd.c @@ -1,7 +1,30 @@ #include "compat.h" -#include "sha1.h" +#include "lib/sha1.h" #include +static char * sha1sum(char *string) { + unsigned char digest[20]; + static char ret[(sizeof(digest) * 2) + 1] = {0}; + static char hexabet[] = "0123456789abcdef"; + struct sha1_ctx ctx; + int retcnt = 0, i; + + sha1_init_ctx(&ctx); + + sha1_process_bytes(string, strlen(string), &ctx); + + sha1_finish_ctx(&ctx, digest); + + for (i = 0; i < sizeof(digest); i++) { + ret[retcnt++] = hexabet[(digest[i] & 0xf0) >> 4]; + ret[retcnt++] = hexabet[digest[i] & 0xf]; + } + + ret[retcnt] = '\0'; + + return(ret); +} + int main(int argc, char **argv) { char *plaintext; char *fgets_ret; @@ -43,7 +66,7 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - printf("%s\n", SHA1sum(plaintext)); + printf("%s\n", sha1sum(plaintext)); return(EXIT_SUCCESS); } diff --git a/libbackuppcd.c b/libbackuppcd.c index c123fcc..099735d 100644 --- a/libbackuppcd.c +++ b/libbackuppcd.c @@ -2,7 +2,7 @@ #include "backuppcd.h" #include "backuppcd-common.h" #include "libbackuppcd.h" -#include "sha1.h" +#include "lib/sha1.h" #include "net.h" #define BPC_CMD_GET_DATA (BPC_CMD_GET | 0x100) @@ -1525,7 +1525,7 @@ int bpc_rdiffget(BPC_CONN *handle, const char *remote_src, const char *dest) { break; case BPC_HASH_SHA1: hash_ent_size = (160 / 8); - hash_handle = malloc(sizeof(SHA1_CTX)); + hash_handle = malloc(sizeof(struct sha1_ctx)); break; case BPC_HASH_BPC: hash_ent_size = (128 / 8); @@ -1567,8 +1567,8 @@ int bpc_rdiffget(BPC_CONN *handle, const char *remote_src, const char *dest) { case BPC_HASH_NONE: break; case BPC_HASH_SHA1: - SHA1Init(hash_handle); - SHA1Update(hash_handle, buf, read_ret); + sha1_init_ctx(hash_handle); + sha1_process_bytes(buf, read_ret, hash_handle); // SHA1Final(digest[20], hash_handle); break; case BPC_HASH_MD5: