Commit 0fd8c6c5 authored by Mark Fasheh's avatar Mark Fasheh

Add csum-sha256, using the polarssl implementation I imported in the

previous patch.

csum-gcrypt is disabled by default.
Signed-off-by: 's avatarMark Fasheh <mfasheh@suse.de>
parent edb3a81d
......@@ -7,13 +7,23 @@ MANPAGES=duperemove.8 btrfs-extent-same.8 hashstats.8 show-shared-extents.8
HEADERS=csum.h hash-tree.h results-tree.h kernel.h list.h rbtree.h dedupe.h \
btrfs-ioctl.h filerec.h btrfs-util.h debug.h util.h serialize.h \
memstats.h file_scan.h find_dupes.h run_dedupe.h xxhash.h
memstats.h file_scan.h find_dupes.h run_dedupe.h xxhash.h \
sha256.h sha256-config.h
CFILES=duperemove.c hash-tree.c results-tree.c rbtree.c dedupe.c filerec.c \
btrfs-util.c util.c serialize.c memstats.c file_scan.c find_dupes.c \
run_dedupe.c csum.c
hash_CFILES=csum-gcrypt.c csum-xxhash.c xxhash.c csum-murmur3.c
hash_CFILES=csum-xxhash.c xxhash.c csum-murmur3.c
ifdef USE_GCRYPT
hash_CFILES += csum-gcrypt.c
hash_CFLAGS=$(shell libgcrypt-config --cflags)
hash_LIBS=$(shell libgcrypt-config --libs)
extra_hash_DIST = csum-sha256.c sha256.c
else
hash_CFILES += csum-sha256.c sha256.c
extra_hash_DIST = csum-gcrypt.c
endif
CFILES += $(hash_CFILES)
hashstats_CFILES=hashstats.c
......@@ -21,7 +31,7 @@ btrfs_extent_same_CFILES=btrfs-extent-same.c
csum_test_CFILES=csum-test.c
DIST_CFILES:=$(CFILES) $(hashstats_CFILES) $(btrfs_extent_same_CFILES) \
$(csum_test_CFILES)
$(csum_test_CFILES) $(extra_hash_DIST)
DIST_SOURCES:=$(DIST_CFILES) $(HEADERS) LICENSE LICENSE.xxhash Makefile \
rbtree.txt README.md $(MANPAGES) SubmittingPatches FAQ.md
DIST=duperemove-$(RELEASE)
......
/*
* csum-sha256.c
*
* Copyright (C) 2014 SUSE. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include "sha256.h"
#include "csum.h"
#include "debug.h"
#define HASH_TYPE_SHA256 "SHA256 "
#define DIGEST_LEN_SHA256 32
static void sha256_checksum_block(char *buf, int len, unsigned char *digest)
{
sha256((unsigned char *)buf, len, digest, 0);
}
static int sha256_init_hash(unsigned int *ret_digest_len)
{
*ret_digest_len = DIGEST_LEN_SHA256;
return 0;
}
struct sha256_running_checksum {
sha256_context ctx;
};
DECLARE_RUNNING_CSUM_CAST_FUNCS(sha256_running_checksum);
static struct running_checksum *sha256_start_running_checksum(void)
{
struct sha256_running_checksum *c =
calloc(1, sizeof(struct sha256_running_checksum));
if (c) {
sha256_init(&c->ctx);
sha256_starts(&c->ctx, 0);
}
return priv_to_rc(c);
}
static void sha256_add_to_running_checksum(struct running_checksum *_c,
unsigned int len, unsigned char *buf)
{
struct sha256_running_checksum *c = rc_to_priv(_c);
sha256_update(&c->ctx, buf, len);
}
static void sha256_finish_running_checksum(struct running_checksum *_c,
unsigned char *digest)
{
struct sha256_running_checksum *c = rc_to_priv(_c);
sha256_finish(&c->ctx, digest);
sha256_free(&c->ctx);
free(c);
}
struct csum_module_ops ops_sha256 = {
.init = sha256_init_hash,
.checksum_block = sha256_checksum_block,
.start_running_checksum = sha256_start_running_checksum,
.add_to_running_checksum = sha256_add_to_running_checksum,
.finish_running_checksum = sha256_finish_running_checksum,
};
struct csum_module csum_module_sha256 = {
.name = "SHA256",
.hash_type = HASH_TYPE_SHA256,
.ops = &ops_sha256,
};
......@@ -675,7 +675,7 @@
*
* Enable functions that use the filesystem.
*/
#define POLARSSL_FS_IO
//#define POLARSSL_FS_IO
/**
* \def POLARSSL_NO_DEFAULT_ENTROPY_SOURCES
......@@ -2175,6 +2175,6 @@
/* \} name SECTION: Module configuration options */
#include "check_config.h"
//#include "check_config.h"
#endif /* POLARSSL_CONFIG_H */
......@@ -28,6 +28,9 @@
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
*/
#define POLARSSL_CONFIG_FILE "sha256-config.h"
#define POLARSSL_SHA256_C
#if !defined(POLARSSL_CONFIG_FILE)
#include "polarssl/config.h"
#else
......@@ -36,18 +39,21 @@
#if defined(POLARSSL_SHA256_C)
#include "polarssl/sha256.h"
#include "sha256.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
#endif
/*
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
*/
#define polarssl_printf printf
/*
#endif
*/
/* Implementation that should never be optimized out by the compiler */
static void polarssl_zeroize( void *v, size_t n ) {
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
......
......@@ -27,6 +27,7 @@
#ifndef POLARSSL_SHA256_H
#define POLARSSL_SHA256_H
#define POLARSSL_CONFIG_FILE "sha256-config.h"
#if !defined(POLARSSL_CONFIG_FILE)
#include "config.h"
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment