sending hexadecimal data to cryptographic hash functions

F

Fernando Barsoba

Hi all,

First of all, I'd like to thank you "Skarmander" and "Flash Gordon" for
the help they provided me: Skarmander's algorithm and Flash's
modifications helped me a lot.

Here's the problem I had and the question which I still have regarding
that problem:

I tried to send a hex string to a function that performed message
authentication using a particular cryptographic function. Concretely, I
used HMAC-SHA1. The string I sent to the integrity check computation
(ICV) was a string over which bit operations were performed.. so the
result was a lot of gibberish. The result from the ICV was a string of
20 or 16 bytes, depending on the algorithm used (sha1 or md5), with the
message digest.

The problem I had was that the result, the output, was always different
each time I executed the program. Most surprising, when executing the
same function but with the following values, as in RFC 2202, test #2:

char msgtest[]="what do ya want for nothing?";
char key[]="Jefe";

I obtained the expected digest, and always the same. I checked sizes,
data types, etc.. but I always got the correct result for this one, but
different values when I executed my program with 'real' values.

Further investigating, I saw that my program wasn't able to deal with
hexadecimal keys. When I tried to use as key an hexadecimal number, as
in RFC 2202 test case #2

char tmp_key[]="0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"; // hex
char msgtest[]="Hi There";

I didn't know how. Skarmander gave a hand and provided me with an
algorithm to convert the text string to an actual sequence of
hexadecimal text string representing the hexadecimal value. Thanks to
his code and some additions from Flash Gordon I could use hexadecimal
keys. *** And then, I realized that perhaps that could help me with my
problem, that I could do the same with my hexadecimal string, the one I
sent to the ICV function. I did so, and my problem was solved: I always
got the same output.

So, the problem solved but still w/o a clue about what happened..why did
I have those problems in the first place? Isn't a string stored always
in hexadecimal values? and shouldn't the functions that manipulate this
string produce the digest correctly (provided that the data type is
unsigned char)?

Thanks,

FBM
 
D

Daniel Fischer

Hi,
So, the problem solved but still w/o a clue about what happened..why did
I have those problems in the first place? Isn't a string stored always
in hexadecimal values?

no, but you can always display the data representing a string using hex
values. For example, the following definitions may be equivalent
(depending on the kind of machine you're on):

unsigned char h[] = "hello";
unsigned char h[] = {104,101,108,108,111,0};
unsigned char h[] = {0x68,0x65,0x6c,0x6c,0x6f,0x0};

As you can see, the single characters making up the string "hello" can be
written as hexadecimal numbers, or as decimal numbers, or as the string
"hello".

However

unsigned char h[] = "68656c6c6f00";

is not equal to "hello", even if it contains all the characters in
hexadecimal notation. It is a different string containing the character
sequence "68656c6c6f00" and its hexadecimal representation is different
from that of "hello".

So basically, the hexadecimal key you tried to use wasn't applied as a key
given in hex but as a key given as a string consisting of the individual
characters that make up the hex notation of the key.


Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top