I am trying to trace how this open source program, mhash computes it's hashing
I can run the program successfully by using using the following commands:
gcc -o example example.c -lmhash
(also, mhash is currently installed, and I am running Ubuntu Linux)
Mhash can be found here: http://mhash.sourceforge.net/
and the example that I have tried is here:
#include <mhash.h>
#include <stdio.h>
int main()
{
char password[] = "Jefe";
int keylen = 4;
char data[] = "what do ya want for nothing?";
int datalen = 28;
MHASH td;
unsigned char *mac;
int j;
td = mhash_hmac_init(MHASH_MD5, password, keylen,
mhash_get_hash_pblock(MHASH_MD5));
mhash(td, data, datalen);
mac = mhash_hmac_end(td);
/*
* The output should be 0x750c783e6ab0b503eaa86e310a5db738
* according to RFC 2104.
*/
printf("0x");
for (j = 0; j < mhash_get_block_size(MHASH_MD5); j++) {
printf("%.2x", mac[j]);
}
printf("\n");
exit(0);
}
I have read the API's, it has very well documentations, but there are soo many files, I do not know from which areas it inherits it's algorithms from?
Thanks for your time and help in advance
Your question seems a little vague to me ... I'm not sure I fully understand it. I'll adventure myself into an answer though.
If you simply don't know what gets executed for crunching that
MD5hash the easiest way to get into it is probably to attach yourself with a debugger on this example program of yours. Make sure you have the debug flags enabled on yourmhashlibrary (which seem to be on by default), then step inmhashand see where that gets you. You cannot miss anything this way.In gdb it would look something like this (You'd probably want to use an IDE - eclipse perhaps, to make it a LOT prettier):
and so on ...
If by any chance you want to passively get some sort a call graph of your
exampleprogram execution you could do that with a profiler. Usinggprofon this program would issue something like this (this would require your library/program recompiled with -pg flag):showing you which functions got executed and how they were called.