I am working on project which requires distribution of files on different servers. For the distribution scheme I chose to use SHA1 algorithm and take the last 64 bits (out of 160 bits hash) to identify the file.
I am not sure if it is my fault or not but I am not able to get as an int a stable value of the last 64 bit of the hash.
What I tried is this:
char *plaintext = "file";
size_t len = strlen(plaintext);
char hash[41];
/*hash contains the hash of the file as char* */
plaintext_to_sha1(hash, plaintext, len);
/*get last 64 bits of the hash*/
uint64_t value = (uint64_t)(hash + (24 * sizeof(char)));
printk(LOG_LEVEL "value: %llu\n", value);
The value contained by value
is sometimes different and I do not understand what I am doing wrong. I am taking the last 64 bits by casting to int the hash shifted 24 bytes to the right.
Any suggestions are appreciated.
Use following :
memcpy(&value,hash+12,8);