Better MD5 support with test vectors, speed test and libcrypto fast implementation.

This commit is contained in:
Andrea Mazzoleni 2011-03-25 21:04:46 +01:00
parent 26c0e26a33
commit face268eb1
14 changed files with 182 additions and 53 deletions

18
check.c
View file

@ -93,8 +93,7 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
/* for each disk, process the block */
for(j=0;j<diskmax;++j) {
int read_size;
struct md5_t md5;
unsigned char hash[HASH_MAX];
unsigned char hash[MD5_SIZE];
struct snapraid_block* block;
block = disk_block_get(handle[j].disk, i);
@ -156,12 +155,10 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
}
/* now compute the hash */
md5_init(&md5);
md5_update(&md5, block_buffer, read_size);
md5_final(&md5, hash);
memmd5(hash, block_buffer, read_size);
/* compare the hash */
if (memcmp(hash, block->hash, HASH_MAX) != 0) {
if (memcmp(hash, block->hash, MD5_SIZE) != 0) {
/* save the failed block for the parity check */
++failed;
failed_block = block;
@ -222,8 +219,7 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
++recovered_error;
}
} else if (failed == 1) {
struct md5_t md5;
unsigned char hash[HASH_MAX];
unsigned char hash[MD5_SIZE];
unsigned failed_size;
int ret;
int fixable;
@ -243,12 +239,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 */
md5_init(&md5);
md5_update(&md5, block_buffer, failed_size);
md5_final(&md5, hash);
memmd5(hash, block_buffer, failed_size);
/* compare the hash */
if (memcmp(hash, failed_block->hash, HASH_MAX) != 0) {
if (memcmp(hash, failed_block->hash, MD5_SIZE) != 0) {
fprintf(stderr, "%u: Parity data error\n", i);
fprintf(stderr, "%u: UNRECOVERABLE erros for this block\n", i);
++unrecoverable_error;