src/add.c \
src/default.c \
src/file.c \
+ src/hash.c \
src/hashmap.c \
src/init.c \
src/log.c \
inc/add.h \
inc/default.h \
inc/file.h \
+ inc/hash.h \
inc/hashmap.h \
inc/init.h \
inc/log.h \
#include<ftw.h>
+#include<hash.h>
#include<hashmap.h>
#include<log.h>
#include<util.h>
#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*);
--- /dev/null
+#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
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);
}
(*p)->name = strdup(b);
+ memset((*p)->root,0,crypto_hash_sha256_BYTES);
+
return 1;
}
--- /dev/null
+#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;
+}
if(add()<0) { return EXIT_FAILURE; }
log_err("this is a test %d %s\n",10,"what?");
- //while(1) { }
return EXIT_FAILURE;
}