mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-05 14:20:05 -05:00
Adds a random hash seed.
This commit is contained in:
parent
548e90c30f
commit
4455ba7e4f
14 changed files with 120 additions and 29 deletions
11
rehash.c
11
rehash.c
|
|
@ -41,6 +41,7 @@ static int state_rehash_process(struct snapraid_state* state, block_off_t blocks
|
|||
block_off_t countpos;
|
||||
block_off_t countmax;
|
||||
unsigned error;
|
||||
unsigned char seed[HASH_SIZE];
|
||||
|
||||
handle = handle_map(state, &diskmax);
|
||||
|
||||
|
|
@ -48,6 +49,9 @@ static int state_rehash_process(struct snapraid_state* state, block_off_t blocks
|
|||
|
||||
error = 0;
|
||||
|
||||
/* set a random seed */
|
||||
randomize(seed, HASH_SIZE);
|
||||
|
||||
/* check that we are in a sync complete state */
|
||||
for(i=blockstart;i<blockmax;++i) {
|
||||
/* for each disk, process the block */
|
||||
|
|
@ -141,12 +145,12 @@ static int state_rehash_process(struct snapraid_state* state, block_off_t blocks
|
|||
countsize += read_size;
|
||||
|
||||
/* compute the new hash */
|
||||
memhash(state->besthash, hash_new, buffer_aligned, read_size);
|
||||
memhash(state->besthash, seed, hash_new, buffer_aligned, read_size);
|
||||
|
||||
/* compute the old hash */
|
||||
/* note that we intentionally compute the new one before the old */
|
||||
/* to ensure to detect any random bit flip in the memory */
|
||||
memhash(state->hash, hash, buffer_aligned, read_size);
|
||||
memhash(state->hash, state->hashseed, hash, buffer_aligned, read_size);
|
||||
|
||||
/* compare the hash */
|
||||
if (memcmp(hash, block->hash, HASH_SIZE) != 0) {
|
||||
|
|
@ -170,8 +174,9 @@ static int state_rehash_process(struct snapraid_state* state, block_off_t blocks
|
|||
|
||||
state_progress_end(state, countpos, countmax, countsize);
|
||||
|
||||
/* set the new hash */
|
||||
/* set the new hash and seed */
|
||||
state->hash = state->besthash;
|
||||
memcpy(state->hashseed, seed, HASH_SIZE);
|
||||
|
||||
/* mark the state as needing write */
|
||||
state->need_write = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue