...
authoralex <[email protected]>
Fri, 22 Oct 2021 05:41:51 +0000 (22:41 -0700)
committeralex <[email protected]>
Fri, 22 Oct 2021 05:41:51 +0000 (22:41 -0700)
Makefile.am
inc/add.h
inc/file.h
inc/hash.h [new file with mode: 0644]
src/add.c
src/file.c
src/hash.c [new file with mode: 0644]
src/main.c

index 5556a769819e48aa9e8f10117e2ffbe88b68254e..c9390b3ba6220db7c4216b1da9f4628a717b8657 100644 (file)
@@ -15,6 +15,7 @@ seederd_SOURCES = \
        src/add.c \
        src/default.c \
        src/file.c \
+       src/hash.c \
        src/hashmap.c \
        src/init.c \
        src/log.c \
@@ -42,6 +43,7 @@ seederd_SOURCES += \
        inc/add.h \
        inc/default.h \
        inc/file.h \
+       inc/hash.h \
        inc/hashmap.h \
        inc/init.h \
        inc/log.h \
index ba80d5eddc691a9839812f8f2d31aff1ea87dffc..89c4d0a059284f3f0c7afc0a5db4f6fa7f526580 100644 (file)
--- a/inc/add.h
+++ b/inc/add.h
@@ -3,6 +3,7 @@
 
 #include<ftw.h>
 
+#include<hash.h>
 #include<hashmap.h>
 #include<log.h>
 #include<util.h>
index c7eaee58c8f5ec246a17a45168b250721271bc9a..272852911981a303a1d184b0cc721cd5b8fc161b 100644 (file)
@@ -6,9 +6,12 @@
 #include<stdlib.h>
 #include<string.h>
 
+#include<sodium.h>
+
 struct file {
        char *name;
        char *path;
+       unsigned char root[crypto_hash_sha256_BYTES];
 };
 
 void file_free(struct file*);
diff --git a/inc/hash.h b/inc/hash.h
new file mode 100644 (file)
index 0000000..c61ae69
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __HASH_H_
+#define __HASH_H_
+
+#include<sodium.h>
+
+int hash(void*,size_t,unsigned char*,size_t);
+int hash_init(crypto_hash_sha256_state*);
+int hash_update(crypto_hash_sha256_state*,const void*,size_t);
+int hash_final(crypto_hash_sha256_state*,unsigned char*,size_t);
+
+#endif
index 3beb3df199b68f64b267e1545ef5f644afbed0ca..2b61a9c7b2a107ba6fea03d43e96bd5698197665 100644 (file)
--- a/src/add.c
+++ b/src/add.c
@@ -71,6 +71,16 @@ static void *add_hash(void *unused) {
                p = get_next();
                pthread_mutex_unlock(&adding_mutex);
 
+               if(hash(
+                       p->path,
+                       strlen(p->path),
+                       p->root,
+                       crypto_hash_sha256_BYTES
+                               )<0) {
+                       log_err("hash failed\n");
+                       return NULL;
+               }
+
                if(NULL==p) { return NULL; }
                log_info("to add: %s\n",p->path);
        }
index c34a9dc628ba7fd62dd52252aa05ab592c5e4746..c9866b5cd0cf03cf583c4184ec45441765336833 100644 (file)
@@ -31,5 +31,7 @@ int file_init(struct file **p, const char *path) {
        
        (*p)->name = strdup(b);
 
+       memset((*p)->root,0,crypto_hash_sha256_BYTES);
+
        return 1;
 }
diff --git a/src/hash.c b/src/hash.c
new file mode 100644 (file)
index 0000000..71f4a91
--- /dev/null
@@ -0,0 +1,31 @@
+#include<hash.h>
+
+int hash(void *data, size_t data_len, unsigned char *out, size_t out_size) {
+       if(crypto_hash_sha256(out,data,data_len)!=0) { return -1; }
+
+       return 1;
+}
+
+int hash_init(crypto_hash_sha256_state *state) {
+       if(crypto_hash_sha256_init(state)!=0) { return -1; }
+
+       return 1;
+}
+
+int hash_update(crypto_hash_sha256_state *state, const void *data, size_t data_len) {
+       if(crypto_hash_sha256_update(
+               state,
+               (const unsigned char*)data,
+               (unsigned long long) data_len
+                       )!=0) {
+               return -1;
+       }
+
+       return 1;
+}
+
+int hash_final(crypto_hash_sha256_state *state, unsigned char *out, size_t out_len) {
+       if(crypto_hash_sha256_final(state,out)!=0) { return -1; }
+
+       return 1;
+}
index ded065cfced055dd7fbad7c85ed0d5b86e5cb271..eb0ff1f0457805468c570c7cd0fea2dfce053d7a 100644 (file)
@@ -8,7 +8,6 @@ int main(int argc, char **argv) {
        if(add()<0) { return EXIT_FAILURE; }
 
        log_err("this is a test %d %s\n",10,"what?");
-       //while(1) { }
 
        return EXIT_FAILURE;
 }