Reputation: 8080
I need to implement a hash function that produces a 32 bit (sufficiently unique) value to be used a message identifier when sending a message. I maintain a sequence number and keep incrementing it along with some other variables and sum them up and want to get a hash of the total (I am planning to use MD5 for this and then pick the first 32 bits of the output). However I see that the MD5 function in Linux only takes string input,
MD5((unsigned char*)data, strlen(data), result);
I have thought of sprintf'ing the 'total' and then calculating the hash, but would like to know if there is some function to directly compute the MD5 of the numeric value of 'total'?
Upvotes: 0
Views: 425
Reputation:
unsigned char *
does not imply a string, or a null-terminated string. At least not in this context. It is just a pointer to N number of 8-bit words with no value restrictions whatsoever. And so, you don't have to have any snprintf
or anything like that in order to convert your data into ASCII strings. If it helps, here is the source of md5sum
tool.
Upvotes: 2