about summary refs log tree commit diff stats
path: root/src/common.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-06-01 22:42:10 +0100
committerJames Booth <boothj5@gmail.com>2014-06-01 22:42:10 +0100
commit575b6acdd257d153901b248e55eea3b35a6ad441 (patch)
treed4f782f0e365d76da853c1a8e24d161654f69177 /src/common.c
parent355cd27f6c3f34f0fef17fdbbfc7bc8222c8451a (diff)
downloadprofani-tty-575b6acdd257d153901b248e55eea3b35a6ad441.tar.gz
Use public domain SHA1 code, remove libgcrypt dependency
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/common.c b/src/common.c
index 287572f9..67fd8a95 100644
--- a/src/common.c
+++ b/src/common.c
@@ -31,7 +31,8 @@
 #include <curl/curl.h>
 #include <curl/easy.h>
 #include <glib.h>
-#include <gcrypt.h>
+
+#include "tools/sha1.h"
 
 #include "log.h"
 #include "common.h"
@@ -416,12 +417,17 @@ generate_unique_id(char *prefix)
 char *
 sha1_hash(char *str)
 {
-   int msg_length = strlen(str);
-   int hash_length = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
-   unsigned char hash[ hash_length ];
-   gcry_md_hash_buffer(GCRY_MD_SHA1, hash, str, msg_length);
+    SHA1_CTX ctx;
+    uint8_t digest[20];
+    uint8_t *input = (uint8_t*)malloc(strlen(str) + 1);
+    memcpy(input, str, strlen(str) + 1);
+
+    SHA1_Init(&ctx);
+    SHA1_Update(&ctx, input, strlen(str));
+    SHA1_Final(&ctx, digest);
 
-   return g_base64_encode(hash, sizeof(hash));
+    free(input);
+    return g_base64_encode(digest, sizeof(digest));
 }
 
 int