I am trying to print the results of an MD5 hash to the console and it is working for the most part. To ensure correctness, I used an online MD5 calculator to compare results. Most of the characters are the same, but a few are missing in mine and they are are all leading zeroes.
Let me explain. The result is a 16 byte unsigned char *. I print each of these bytes one by one. Each byte prints TWO characters to the screen. However, if the first character out of the two is a zero, it does not print the zero.
printk("%x", result);
Result is of type unsigned char*. Am I formatting it properly or am I missing something?
Use "%02x"
.
The two means you always want the output to be (at least) two characters wide.
The zero means if padding is necessary, to use zeros instead of spaces.
result
is a pointer, use a loop to print all the digits:
int i; for (i = 0; i < 16; i++) { printf("%02x", result[i]); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With