yosi izaq
  • yosi izaq
    yosi izaq

    Hello , I am trying to use your lib to acivate HMAC-MD5 . I do a
        hmacmd5Reset(&param) ;
        hmacmd5Update(&param,(const unsigned char*) "abcdefg",8) ;
    code sequence and I get strange results (data vactor is included in the digest ) .
    I use this key :
    uint32 key[8] ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xef} ;

    Could anyone please tell me what I'm doing wrong ?
    An alternative would be an example of HMAC_MD5 test.


    • Bob Deblier
      Bob Deblier


      You must pass the key as an array of real 32-bit values, not as an array of 32-bit values containing only 8-bit values; what's more: in the code sample above you don't use the key at all!

      Try something like this instead:

      uint32 key[2] = { 0x12345678, 0x9abcdef }; /* 64 bits */
      uint32 digest[4]; /* 128 bits */

      hmacParam param;

      hmacmd5Setup(&param, key, 64);
      /* you don't need to reset after a setup */
      hmacmd5Update(&param, (const unsigned char*) "abcdefg", 8);
      hmacmd5Digest(&param, &digest);

      This should produce the result you desire.

    • Hi,

      As yo-yo was doing, I am also trying to write something using hmac-md5.

      I coded my project successfully in Perl using some hmac-md5 Perl modules, but Perl runs too slowly and I want to recode it in C.

      I have experience with very basic C/C++ programming, and even so, it's been a while. So I'm a little confused as to what to use.

      Basically I'm looking to follow this procedure:

      Read a binary file upon which a key will be used to create an hmac-md5 digest. File is small so it can fit into an array.

      Read a an ASCII text file containing a key or phrase to use as the hmac-md5 key.

      Output should be a 32-character hex text ASCII hash code.

      What functions would I use from hmac-md5 and how would I send the data to them and get the hash to print out?

      I tried using the suggested code in the previous reply to yo-yo but I'm at a loss at this point.

      Any help is appreciated!

      • Bob Deblier
        Bob Deblier

        See the previous example code to digest your data, once you've read it (in binary format).

        After computing the digest with the md5Digest function, you can print the 32-byte hexdump of the digest with:

        mp32println(4, digest);

    • Hi,

      Thanks for the info. However, I tried compiling a small program based on exactly the above code example.

      I used the following compiler lines:

      gcc -DHAVE_CONFIG_H -I. -I. -I.. -I..  -DOPTIMIZE_I586  -O3 -mpentium -march=pentium -fomit-frame-pointer -c cryptest.c


      /bin/sh ../libtool --mode=link gcc  -O3 -mpentium -march=pentium -fomit-frame-pointer  -o cryptest  cryptest.o ../ -lrt -lpthread

      and I get the following warnings:

      cryptest.c: In function `main':
      cryptest.c:31: warning: passing arg 1 of `hmacmd5Setup' from incompatible pointer type
      cryptest.c:33: warning: passing arg 1 of `hmacmd5Update' from incompatible pointer type
      cryptest.c:34: warning: passing arg 1 of `hmacmd5Digest' from incompatible pointer type
      cryptest.c:34: warning: passing arg 2 of `hmacmd5Digest' from incompatible pointer type

      The program compiles and links properly, but when I run it, I get a segfault:

      [root@thorne tests]# ./cryptest
      Segmentation fault

      Promising, but still not as I like it :)

      Any ideas what I should do to fix?


      • Ok I think I figured it out.

        The declaration needs to be hmacmd5Param param
        not just hmacParam, since we're doing it for md5.

        Also, hmacmd5Digest(&param, &digest) caused one remaining pointer warning. Changing it to hmacmd5Digest(&param, digest) fixed that.

        Now I get a hash with no segfaults.