PDA

View Full Version : MD5: how to compile win32 Console code?


5aLIVE
September 1st, 2006, 08:12
Hi, I have been trying to compile the C source files to test the MD5 Reference implementation as listed in RFC1321.

I wanted to compile mddriver.c so that I can step through the code to get a better idea of how it works. I'm using Visual C++ 6.0 and I'm not I'm getting the following error:

Compiling...
mddriver.c
c:\documents and settings\desktop\md5 reference implementation\mddriver.c(232) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.


To create a project, I Selected File->New->Projects->Win32 Console Application, enter a Project name.

Then create an empty project, and add the following source files:
md5.c and mddriver.c and the header files global.h and md5.h.

I've attached the files I have copied and pasted from the white paper.
I hope someone can give me directions on how to compile this please.

ZaiRoN
September 1st, 2006, 08:27
Uncheck *use precompiled header* somewhere in your project settings.

5aLIVE
September 1st, 2006, 08:49
Hi, I just tried as you suggest and I now get the following cryptic errors:

Code:
c:\mddriver.c(106) : error C2065: 'MD_CTX' : undeclared identifier
c:\mddriver.c(106) : error C2146: syntax error : missing ';' before identifier 'context'
c:\mddriver.c(106) : error C2065: 'context' : undeclared identifier
c:\mddriver.c(107) : error C2143: syntax error : missing ';' before 'type'
c:\mddriver.c(108) : error C2143: syntax error : missing ';' before 'type'
c:\mddriver.c(110) : warning C4013: 'MDInit' undefined; assuming extern returning int
c:\mddriver.c(111) : warning C4013: 'MDUpdate' undefined; assuming extern returning int
c:\mddriver.c(111) : error C2065: 'len' : undeclared identifier
c:\mddriver.c(112) : warning C4013: 'MDFinal' undefined; assuming extern returning int
c:\mddriver.c(112) : error C2065: 'digest' : undeclared identifier
c:\mddriver.c(114) : error C2065: 'MD5' : undeclared identifier
c:\mddriver.c(124) : error C2146: syntax error : missing ';' before identifier 'context'
c:\mddriver.c(125) : error C2275: 'time_t' : illegal use of this type as an expression
d:\program files\microsoft visual studio\vc98\include\time.h(79) : see declaration of 'time_t'
c:\mddriver.c(125) : error C2146: syntax error : missing ';' before identifier 'endTime'
c:\mddriver.c(125) : error C2065: 'endTime' : undeclared identifier
c:\mddriver.c(125) : error C2065: 'startTime' : undeclared identifier
c:\mddriver.c(126) : error C2143: syntax error : missing ';' before 'type'
c:\mddriver.c(127) : error C2143: syntax error : missing ';' before 'type'
c:\mddriver.c(134) : error C2065: 'i' : undeclared identifier
c:\mddriver.c(135) : error C2065: 'block' : undeclared identifier
c:\mddriver.c(135) : error C2109: subscript requires array or pointer type
c:\mddriver.c(135) : error C2106: '=' : left operand must be l-value
c:\mddriver.c(183) : error C2146: syntax error : missing ';' before identifier 'context'
c:\mddriver.c(184) : error C2143: syntax error : missing ';' before 'type'
c:\mddriver.c(185) : error C2143: syntax error : missing ';' before 'type'
c:\mddriver.c(192) : error C2065: 'buffer' : undeclared identifier
c:\mddriver.c(192) : warning C4022: 'fread' : pointer mismatch for actual parameter 1
c:\mddriver.c(208) : error C2146: syntax error : missing ';' before identifier 'context'
c:\mddriver.c(209) : error C2143: syntax error : missing ';' before 'type'
c:\mddriver.c(210) : error C2143: syntax error : missing ';' before 'type'
c:\mddriver.c(213) : warning C4022: 'fread' : pointer mismatch for actual parameter 1

Cthulhu
September 1st, 2006, 09:05
Here is the working project.

There was an error in the file mddriver.c

Code:

#ifndef MD
#define MD MD5
#endif


Where it should be

Code:

#ifndef MD
#define MD 5
#endif


My best regards

5aLIVE
September 1st, 2006, 09:20
Thankyou taking the time to look at this. It now compiles without error which is excellent.

If I run the mddrive.exe in a console window such as mddriver 5alive. It just carriage returns and appears to be waiting more input instead of displaying the hash.

Also I would expect the "test suite" strings to be hashed with no arguments?
Could there another bug in the listings? I'll take a closer look at the code although I am on a steep learning curve as it is.

UPDATE: Creating a text file and supplying this as a parameter displays the hash as expected.

UPDATE 2: Doh! I just noticed the switches -s, -t, and -x. I got it working now , although the -t (timetrial) caused a divide by zero exception at 0xC0000094 when digesting 1000 1000byte blocks.

Thanks,
5aLIVE.

ZaiRoN
September 1st, 2006, 09:40
Quote:
UPDATE: Creating a text file and supplying this as a parameter displays the hash as expected.
Do you understand why?
Hint: look at the code below:
Code:
if (argc > 1)
for (i = 1; i < argc; i++)
if (argv[I][0] == '-' && argv[I][1] == 's')
MDString (argv[I] + 2);
else if (strcmp (argv[I], "-t" == 0)
MDTimeTrial ();
else if (strcmp (argv[I], "-x" == 0)
MDTestSuite ();
else
MDFile (argv[I]);
else
MDFilter ();

5aLIVE
September 1st, 2006, 09:46
Hi Zairon.

Yes! I spotted these switches after looking at the code again (see post update 2 above). What ever happened to good old program documentation? Easy when you know how huh?

Now I need to try and to step through this code in the VC6 debugger to see what goes on under the hood.

Thanks fellas.

evlncrn8
September 1st, 2006, 09:49
include the .h file maybe if there is one?

5aLIVE
September 1st, 2006, 10:11
Right, how would I go about debugging a console program in the VC6 IDE when it expects command line arguments? Without arguments I just get see an console window as you would expect.

I expect I could do it by hardcoding a test string into the driver code and remove the command line arguments. I would prefer to be able to debug the program as it is though.

Can it be done?

UPDATE: Of course it can! Select Project Settings->Debug and then enter the desired program arguments in the Program arguments dialogue.