I was going to reply that the third parameter of encode_hex is an unsigned char, and that '\x0' is an unsigned char literal. But C still astonishes me from time to time. After googling a bit, I found that 'x' expressions are in fact integer literals [1]. C always promotes them to int. So I have changed that to a plain 0 to make the code more homogeneous, as using 'x' notation does not make a difference. Same comment applies to your other similar comments.

[1] http://stackoverflow.com/questions/433895/why-are-c-character-literals-ints-instead-of-chars