dedup

data deduplication program
git clone git://git.2f30.org/dedup.git
Log | Files | Refs | README | LICENSE

commit c5abbf4d7c2a0129c74f15540e47d58cbf09fb67
parent 6b656b00b35636ec242e9a9af7b8ede7467515a3
Author: sin <sin@2f30.org>
Date:   Fri, 12 Apr 2019 13:42:59 +0100

Factor out hashes to separate files

Diffstat:
MMakefile | 8++++++++
Mdedup.h | 20++++++++++++++++++++
Ahash-blake2b.c | 26++++++++++++++++++++++++++
Ahash-blake2bp.c | 26++++++++++++++++++++++++++
Ahash-blake2s.c | 26++++++++++++++++++++++++++
Ahash-blake2sp.c | 26++++++++++++++++++++++++++
Mhash.c | 90++-----------------------------------------------------------------------------
7 files changed, 134 insertions(+), 88 deletions(-)

diff --git a/Makefile b/Makefile @@ -24,6 +24,10 @@ SRC = \ compress-none.c \ compress-snappy.c \ compress.c \ + hash-blake2b.c \ + hash-blake2bp.c \ + hash-blake2s.c \ + hash-blake2sp.c \ hash.c \ icache.c \ pack.c \ @@ -42,6 +46,10 @@ OBJ = \ compress-none.o \ compress-snappy.o \ compress.o \ + hash-blake2b.o \ + hash-blake2bp.o \ + hash-blake2s.o \ + hash-blake2sp.o \ hash.o \ icache.o \ pack.o \ diff --git a/dedup.h b/dedup.h @@ -145,6 +145,26 @@ size_t decompr(struct compr_ctx *ctx, const void *in, void *out, int compr_final(struct compr_ctx *ctx); int compr_name2type(char *name); +/* hash-blake2b.c */ +int blake2bi(struct hash_ctx *ctx, size_t n); +int blake2bu(struct hash_ctx *ctx, const void *buf, size_t n); +int blake2bf(struct hash_ctx *ctx, void *buf, size_t n); + +/* hash-blake2bp.c */ +int blake2bpi(struct hash_ctx *ctx, size_t n); +int blake2bpu(struct hash_ctx *ctx, const void *buf, size_t n); +int blake2bpf(struct hash_ctx *ctx, void *buf, size_t n); + +/* hash-blake2s.c */ +int blake2si(struct hash_ctx *ctx, size_t n); +int blake2su(struct hash_ctx *ctx, const void *buf, size_t n); +int blake2sf(struct hash_ctx *ctx, void *buf, size_t n); + +/* hash-blake2sp.c */ +int blake2spi(struct hash_ctx *ctx, size_t n); +int blake2spu(struct hash_ctx *ctx, const void *buf, size_t n); +int blake2spf(struct hash_ctx *ctx, void *buf, size_t n); + /* hash.c */ int hash_init(struct hash_ctx *ctx, int type, size_t n); int hash_update(struct hash_ctx *ctx, const void *buf, size_t n); diff --git a/hash-blake2b.c b/hash-blake2b.c @@ -0,0 +1,26 @@ +#include <sys/types.h> + +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "blake2.h" +#include "dedup.h" + +int +blake2bi(struct hash_ctx *ctx, size_t n) +{ + return blake2b_init(&ctx->u.blake2b_ctx, n); +} + +int +blake2bu(struct hash_ctx *ctx, const void *buf, size_t n) +{ + return blake2b_update(&ctx->u.blake2b_ctx, buf, n); +} + +int +blake2bf(struct hash_ctx *ctx, void *buf, size_t n) +{ + return blake2b_final(&ctx->u.blake2b_ctx, buf, n); +} diff --git a/hash-blake2bp.c b/hash-blake2bp.c @@ -0,0 +1,26 @@ +#include <sys/types.h> + +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "blake2.h" +#include "dedup.h" + +int +blake2bpi(struct hash_ctx *ctx, size_t n) +{ + return blake2bp_init(&ctx->u.blake2bp_ctx, n); +} + +int +blake2bpu(struct hash_ctx *ctx, const void *buf, size_t n) +{ + return blake2bp_update(&ctx->u.blake2bp_ctx, buf, n); +} + +int +blake2bpf(struct hash_ctx *ctx, void *buf, size_t n) +{ + return blake2bp_final(&ctx->u.blake2bp_ctx, buf, n); +} diff --git a/hash-blake2s.c b/hash-blake2s.c @@ -0,0 +1,26 @@ +#include <sys/types.h> + +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "blake2.h" +#include "dedup.h" + +int +blake2si(struct hash_ctx *ctx, size_t n) +{ + return blake2s_init(&ctx->u.blake2s_ctx, n); +} + +int +blake2su(struct hash_ctx *ctx, const void *buf, size_t n) +{ + return blake2s_update(&ctx->u.blake2s_ctx, buf, n); +} + +int +blake2sf(struct hash_ctx *ctx, void *buf, size_t n) +{ + return blake2s_final(&ctx->u.blake2s_ctx, buf, n); +} diff --git a/hash-blake2sp.c b/hash-blake2sp.c @@ -0,0 +1,26 @@ +#include <sys/types.h> + +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "blake2.h" +#include "dedup.h" + +int +blake2spi(struct hash_ctx *ctx, size_t n) +{ + return blake2sp_init(&ctx->u.blake2sp_ctx, n); +} + +int +blake2spu(struct hash_ctx *ctx, const void *buf, size_t n) +{ + return blake2sp_update(&ctx->u.blake2sp_ctx, buf, n); +} + +int +blake2spf(struct hash_ctx *ctx, void *buf, size_t n) +{ + return blake2sp_final(&ctx->u.blake2sp_ctx, buf, n); +} diff --git a/hash.c b/hash.c @@ -1,3 +1,5 @@ +#include <sys/types.h> + #include <stdint.h> #include <stdlib.h> #include <string.h> @@ -6,22 +8,6 @@ #include "blake2.h" #include "dedup.h" -static int blake2bi(struct hash_ctx *ctx, size_t n); -static int blake2bu(struct hash_ctx *ctx, const void *buf, size_t n); -static int blake2bf(struct hash_ctx *ctx, void *buf, size_t n); - -static int blake2bpi(struct hash_ctx *ctx, size_t n); -static int blake2bpu(struct hash_ctx *ctx, const void *buf, size_t n); -static int blake2bpf(struct hash_ctx *ctx, void *buf, size_t n); - -static int blake2si(struct hash_ctx *ctx, size_t n); -static int blake2su(struct hash_ctx *ctx, const void *buf, size_t n); -static int blake2sf(struct hash_ctx *ctx, void *buf, size_t n); - -static int blake2spi(struct hash_ctx *ctx, size_t n); -static int blake2spu(struct hash_ctx *ctx, const void *buf, size_t n); -static int blake2spf(struct hash_ctx *ctx, void *buf, size_t n); - static struct hash_ops { int (*init)(struct hash_ctx *ctx, size_t n); int (*update)(struct hash_ctx *ctx, const void *buf, size_t n); @@ -60,78 +46,6 @@ static struct algomap { { .name = NULL }, }; -static int -blake2bi(struct hash_ctx *ctx, size_t n) -{ - return blake2b_init(&ctx->u.blake2b_ctx, n); -} - -static int -blake2bu(struct hash_ctx *ctx, const void *buf, size_t n) -{ - return blake2b_update(&ctx->u.blake2b_ctx, buf, n); -} - -static int -blake2bf(struct hash_ctx *ctx, void *buf, size_t n) -{ - return blake2b_final(&ctx->u.blake2b_ctx, buf, n); -} - -static int -blake2bpi(struct hash_ctx *ctx, size_t n) -{ - return blake2bp_init(&ctx->u.blake2bp_ctx, n); -} - -static int -blake2bpu(struct hash_ctx *ctx, const void *buf, size_t n) -{ - return blake2bp_update(&ctx->u.blake2bp_ctx, buf, n); -} - -static int -blake2bpf(struct hash_ctx *ctx, void *buf, size_t n) -{ - return blake2bp_final(&ctx->u.blake2bp_ctx, buf, n); -} - -static int -blake2si(struct hash_ctx *ctx, size_t n) -{ - return blake2s_init(&ctx->u.blake2s_ctx, n); -} - -static int -blake2su(struct hash_ctx *ctx, const void *buf, size_t n) -{ - return blake2s_update(&ctx->u.blake2s_ctx, buf, n); -} - -static int -blake2sf(struct hash_ctx *ctx, void *buf, size_t n) -{ - return blake2s_final(&ctx->u.blake2s_ctx, buf, n); -} - -static int -blake2spi(struct hash_ctx *ctx, size_t n) -{ - return blake2sp_init(&ctx->u.blake2sp_ctx, n); -} - -static int -blake2spu(struct hash_ctx *ctx, const void *buf, size_t n) -{ - return blake2sp_update(&ctx->u.blake2sp_ctx, buf, n); -} - -static int -blake2spf(struct hash_ctx *ctx, void *buf, size_t n) -{ - return blake2sp_final(&ctx->u.blake2sp_ctx, buf, n); -} - int hash_init(struct hash_ctx *ctx, int type, size_t n) {