mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-20 23:16:28 -05:00
Removes explicit references to MD5.
This commit is contained in:
parent
21569be70d
commit
bbd8e95a44
7 changed files with 26 additions and 26 deletions
12
check.c
12
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 each disk, process the block */
|
||||||
for(j=0;j<diskmax;++j) {
|
for(j=0;j<diskmax;++j) {
|
||||||
int read_size;
|
int read_size;
|
||||||
unsigned char hash[MD5_SIZE];
|
unsigned char hash[HASH_SIZE];
|
||||||
struct snapraid_block* block;
|
struct snapraid_block* block;
|
||||||
|
|
||||||
block = disk_block_get(handle[j].disk, i);
|
block = disk_block_get(handle[j].disk, i);
|
||||||
|
|
@ -187,10 +187,10 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now compute the hash */
|
/* now compute the hash */
|
||||||
memmd5(hash, block_buffer, read_size);
|
memhash(hash, block_buffer, read_size);
|
||||||
|
|
||||||
/* compare the hash */
|
/* compare the hash */
|
||||||
if (memcmp(hash, block->hash, MD5_SIZE) != 0) {
|
if (memcmp(hash, block->hash, HASH_SIZE) != 0) {
|
||||||
/* save the failed block for the parity check */
|
/* save the failed block for the parity check */
|
||||||
++failed;
|
++failed;
|
||||||
if (!block->file->is_filtered) {
|
if (!block->file->is_filtered) {
|
||||||
|
|
@ -255,7 +255,7 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
||||||
++recovered_error;
|
++recovered_error;
|
||||||
}
|
}
|
||||||
} else if (failed == 1) {
|
} else if (failed == 1) {
|
||||||
unsigned char hash[MD5_SIZE];
|
unsigned char hash[HASH_SIZE];
|
||||||
unsigned failed_size;
|
unsigned failed_size;
|
||||||
int ret;
|
int ret;
|
||||||
int fixable;
|
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);
|
failed_size = block_file_size(failed_block, state->block_size);
|
||||||
|
|
||||||
/* now compute the hash */
|
/* now compute the hash */
|
||||||
memmd5(hash, block_buffer, failed_size);
|
memhash(hash, block_buffer, failed_size);
|
||||||
|
|
||||||
/* compare the hash */
|
/* 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: Parity data error\n", i);
|
||||||
fprintf(stderr, "%u: UNRECOVERABLE erros for this block\n", i);
|
fprintf(stderr, "%u: UNRECOVERABLE erros for this block\n", i);
|
||||||
++unrecoverable_error;
|
++unrecoverable_error;
|
||||||
|
|
|
||||||
2
elem.h
2
elem.h
|
|
@ -66,7 +66,7 @@ struct snapraid_block {
|
||||||
block_off_t parity_pos; /**< Position of the block in the parity. */
|
block_off_t parity_pos; /**< Position of the block in the parity. */
|
||||||
unsigned flag; /**< If the hash of the block is valid. */
|
unsigned flag; /**< If the hash of the block is valid. */
|
||||||
struct snapraid_file* file; /**< Back pointer to the file owning this block. */
|
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. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
12
snapraid.c
12
snapraid.c
|
|
@ -46,7 +46,7 @@
|
||||||
*/
|
*/
|
||||||
struct test_vector {
|
struct test_vector {
|
||||||
const char* data;
|
const char* data;
|
||||||
unsigned char digest[MD5_SIZE];
|
unsigned char digest[HASH_SIZE];
|
||||||
} TEST[] = {
|
} TEST[] = {
|
||||||
{ "", { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } },
|
{ "", { 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 } },
|
{ "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 */
|
/* test vectors for MD5. It could be dynamically linked, so we have to test it at runtime */
|
||||||
for(i=0;TEST[i].data;++i) {
|
for(i=0;TEST[i].data;++i) {
|
||||||
unsigned char digest[MD5_SIZE];
|
unsigned char digest[HASH_SIZE];
|
||||||
memmd5(digest, TEST[i].data, strlen(TEST[i].data));
|
memhash(digest, TEST[i].data, strlen(TEST[i].data));
|
||||||
if (memcmp(digest, TEST[i].digest, MD5_SIZE) != 0) {
|
if (memcmp(digest, TEST[i].digest, HASH_SIZE) != 0) {
|
||||||
fprintf(stderr, "Failed MD5 test vector\n");
|
fprintf(stderr, "Failed MD5 test vector\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ void speed(void)
|
||||||
int64_t ds;
|
int64_t ds;
|
||||||
int64_t dt;
|
int64_t dt;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
unsigned char digest[MD5_SIZE];
|
unsigned char digest[HASH_SIZE];
|
||||||
|
|
||||||
unsigned count = 10000;
|
unsigned count = 10000;
|
||||||
unsigned blocksize = 256 * 1024;
|
unsigned blocksize = 256 * 1024;
|
||||||
|
|
@ -107,7 +107,7 @@ void speed(void)
|
||||||
|
|
||||||
gettimeofday(&start, 0);
|
gettimeofday(&start, 0);
|
||||||
for(i=0;i<count;++i)
|
for(i=0;i<count;++i)
|
||||||
memmd5(digest, block, blocksize);
|
memhash(digest, block, blocksize);
|
||||||
gettimeofday(&stop, 0);
|
gettimeofday(&stop, 0);
|
||||||
|
|
||||||
ds = blocksize * (int64_t)count;
|
ds = blocksize * (int64_t)count;
|
||||||
|
|
|
||||||
8
state.c
8
state.c
|
|
@ -255,7 +255,7 @@ void state_read(struct snapraid_state* state)
|
||||||
|
|
||||||
/* set the hash only if present */
|
/* set the hash only if present */
|
||||||
if (*hash != 0) {
|
if (*hash != 0) {
|
||||||
e = strdechex(block->hash, MD5_SIZE, hash);
|
e = strdechex(block->hash, HASH_SIZE, hash);
|
||||||
if (e) {
|
if (e) {
|
||||||
fprintf(stderr, "Invalid 'blk' specification in '%s' at line %u\n", path, line);
|
fprintf(stderr, "Invalid 'blk' specification in '%s' at line %u\n", path, line);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
@ -460,9 +460,9 @@ void state_write(struct snapraid_state* state)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bit_has(block->flag, BLOCK_HAS_HASH)) {
|
if (bit_has(block->flag, BLOCK_HAS_HASH)) {
|
||||||
char s_hash[MD5_SIZE*2+1];
|
char s_hash[HASH_SIZE*2+1];
|
||||||
strenchex(s_hash, block->hash, MD5_SIZE);
|
strenchex(s_hash, block->hash, HASH_SIZE);
|
||||||
s_hash[MD5_SIZE*2] = 0;
|
s_hash[HASH_SIZE*2] = 0;
|
||||||
ret = fprintf(f, "%s %u %s\n", tag, block->parity_pos, s_hash);
|
ret = fprintf(f, "%s %u %s\n", tag, block->parity_pos, s_hash);
|
||||||
} else {
|
} else {
|
||||||
ret = fprintf(f, "%s %u\n", tag, block->parity_pos);
|
ret = fprintf(f, "%s %u\n", tag, block->parity_pos);
|
||||||
|
|
|
||||||
8
sync.c
8
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 each disk, process the block */
|
||||||
for(j=0;j<diskmax;++j) {
|
for(j=0;j<diskmax;++j) {
|
||||||
int read_size;
|
int read_size;
|
||||||
unsigned char hash[MD5_SIZE];
|
unsigned char hash[HASH_SIZE];
|
||||||
struct snapraid_block* block;
|
struct snapraid_block* block;
|
||||||
|
|
||||||
block = disk_block_get(handle[j].disk, i);
|
block = disk_block_get(handle[j].disk, i);
|
||||||
|
|
@ -159,11 +159,11 @@ static int state_sync_process(struct snapraid_state* state, int parity_f, block_
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now compute the hash */
|
/* now compute the hash */
|
||||||
memmd5(hash, block_buffer, read_size);
|
memhash(hash, block_buffer, read_size);
|
||||||
|
|
||||||
if (bit_has(block->flag, BLOCK_HAS_HASH)) {
|
if (bit_has(block->flag, BLOCK_HAS_HASH)) {
|
||||||
/* compare the 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, "%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, "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);
|
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 {
|
} else {
|
||||||
/* copy the hash, but doesn't mark the block as hashed */
|
/* copy the hash, but doesn't mark the block as hashed */
|
||||||
/* this allow on error to do not save the failed computation */
|
/* 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 */
|
/* compute the parity */
|
||||||
|
|
|
||||||
2
util.c
2
util.c
|
|
@ -263,7 +263,7 @@ void memxor(unsigned char* xor, const unsigned char* block, unsigned size)
|
||||||
#include "md5.c"
|
#include "md5.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void memmd5(void* digest, const void* src, unsigned size)
|
void memhash(void* digest, const void* src, unsigned size)
|
||||||
{
|
{
|
||||||
#if HAVE_LIBCRYPTO
|
#if HAVE_LIBCRYPTO
|
||||||
MD5((void*)src, size, digest);
|
MD5((void*)src, size, digest);
|
||||||
|
|
|
||||||
8
util.h
8
util.h
|
|
@ -127,15 +127,15 @@ void* malloc_nofail(size_t size);
|
||||||
void memxor(unsigned char* xor, const unsigned char* block, unsigned 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
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue