From bbd8e95a445bcdfe91099d67f2b83d3e0627cae3 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 12 Apr 2011 22:16:35 +0200 Subject: [PATCH] Removes explicit references to MD5. --- check.c | 12 ++++++------ elem.h | 2 +- snapraid.c | 12 ++++++------ state.c | 8 ++++---- sync.c | 8 ++++---- util.c | 2 +- util.h | 8 ++++---- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/check.c b/check.c index 701b9c0d..4d075e0a 100644 --- a/check.c +++ b/check.c @@ -121,7 +121,7 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity /* for each disk, process the block */ for(j=0;jhash, MD5_SIZE) != 0) { + if (memcmp(hash, block->hash, HASH_SIZE) != 0) { /* save the failed block for the parity check */ ++failed; if (!block->file->is_filtered) { @@ -255,7 +255,7 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity ++recovered_error; } } else if (failed == 1) { - unsigned char hash[MD5_SIZE]; + unsigned char hash[HASH_SIZE]; unsigned failed_size; int ret; int fixable; @@ -275,10 +275,10 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity failed_size = block_file_size(failed_block, state->block_size); /* now compute the hash */ - memmd5(hash, block_buffer, failed_size); + memhash(hash, block_buffer, failed_size); /* compare the hash */ - if (memcmp(hash, failed_block->hash, MD5_SIZE) != 0) { + if (memcmp(hash, failed_block->hash, HASH_SIZE) != 0) { fprintf(stderr, "%u: Parity data error\n", i); fprintf(stderr, "%u: UNRECOVERABLE erros for this block\n", i); ++unrecoverable_error; diff --git a/elem.h b/elem.h index 8a241ce1..21b210a3 100644 --- a/elem.h +++ b/elem.h @@ -66,7 +66,7 @@ struct snapraid_block { block_off_t parity_pos; /**< Position of the block in the parity. */ unsigned flag; /**< If the hash of the block is valid. */ struct snapraid_file* file; /**< Back pointer to the file owning this block. */ - unsigned char hash[MD5_SIZE]; /**< Hash of the block. */ + unsigned char hash[HASH_SIZE]; /**< Hash of the block. */ }; /** diff --git a/snapraid.c b/snapraid.c index 025eaf6f..a442bea4 100644 --- a/snapraid.c +++ b/snapraid.c @@ -46,7 +46,7 @@ */ struct test_vector { const char* data; - unsigned char digest[MD5_SIZE]; + unsigned char digest[HASH_SIZE]; } TEST[] = { { "", { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } }, { "a", { 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 } }, @@ -72,9 +72,9 @@ void selftest(void) /* test vectors for MD5. It could be dynamically linked, so we have to test it at runtime */ for(i=0;TEST[i].data;++i) { - unsigned char digest[MD5_SIZE]; - memmd5(digest, TEST[i].data, strlen(TEST[i].data)); - if (memcmp(digest, TEST[i].digest, MD5_SIZE) != 0) { + unsigned char digest[HASH_SIZE]; + memhash(digest, TEST[i].data, strlen(TEST[i].data)); + if (memcmp(digest, TEST[i].digest, HASH_SIZE) != 0) { fprintf(stderr, "Failed MD5 test vector\n"); exit(EXIT_FAILURE); } @@ -88,7 +88,7 @@ void speed(void) int64_t ds; int64_t dt; unsigned i; - unsigned char digest[MD5_SIZE]; + unsigned char digest[HASH_SIZE]; unsigned count = 10000; unsigned blocksize = 256 * 1024; @@ -107,7 +107,7 @@ void speed(void) gettimeofday(&start, 0); for(i=0;ihash, MD5_SIZE, hash); + e = strdechex(block->hash, HASH_SIZE, hash); if (e) { fprintf(stderr, "Invalid 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); @@ -460,9 +460,9 @@ void state_write(struct snapraid_state* state) } if (bit_has(block->flag, BLOCK_HAS_HASH)) { - char s_hash[MD5_SIZE*2+1]; - strenchex(s_hash, block->hash, MD5_SIZE); - s_hash[MD5_SIZE*2] = 0; + char s_hash[HASH_SIZE*2+1]; + strenchex(s_hash, block->hash, HASH_SIZE); + s_hash[HASH_SIZE*2] = 0; ret = fprintf(f, "%s %u %s\n", tag, block->parity_pos, s_hash); } else { ret = fprintf(f, "%s %u\n", tag, block->parity_pos); diff --git a/sync.c b/sync.c index 957f8ece..1716daa5 100644 --- a/sync.c +++ b/sync.c @@ -103,7 +103,7 @@ static int state_sync_process(struct snapraid_state* state, int parity_f, block_ /* for each disk, process the block */ for(j=0;jflag, BLOCK_HAS_HASH)) { /* compare the hash */ - if (memcmp(hash, block->hash, MD5_SIZE) != 0) { + if (memcmp(hash, block->hash, HASH_SIZE) != 0) { fprintf(stderr, "%u: Data error for file %s at position %u\n", i, block->file->sub, block_file_pos(block)); fprintf(stderr, "DANGER! Unexpected data error in a data disk, it isn't possible to sync.\n"); fprintf(stderr, "Stopping to allow recovery. Try with 'snapraid -s %u check'\n", i); @@ -173,7 +173,7 @@ static int state_sync_process(struct snapraid_state* state, int parity_f, block_ } else { /* copy the hash, but doesn't mark the block as hashed */ /* this allow on error to do not save the failed computation */ - memcpy(block->hash, hash, MD5_SIZE); + memcpy(block->hash, hash, HASH_SIZE); } /* compute the parity */ diff --git a/util.c b/util.c index 4510765f..51106eee 100644 --- a/util.c +++ b/util.c @@ -263,7 +263,7 @@ void memxor(unsigned char* xor, const unsigned char* block, unsigned size) #include "md5.c" #endif -void memmd5(void* digest, const void* src, unsigned size) +void memhash(void* digest, const void* src, unsigned size) { #if HAVE_LIBCRYPTO MD5((void*)src, size, digest); diff --git a/util.h b/util.h index a2fba660..a20d8ddc 100644 --- a/util.h +++ b/util.h @@ -127,15 +127,15 @@ void* malloc_nofail(size_t size); void memxor(unsigned char* xor, const unsigned char* block, unsigned size); /** - * Size of MD5 digest. + * Size of the hash. */ -#define MD5_SIZE 16 +#define HASH_SIZE 16 /** - * Computes the MD5 of a memory block. + * Computes the hash of a memory block. */ -void memmd5(void* digest, const void* src, unsigned size); +void memhash(void* digest, const void* src, unsigned size); #endif