Operating System - HP-UX
1845948 Members
3164 Online
110250 Solutions
New Discussion

Re: Problem running c program calling md5_string function

 
SOLVED
Go to solution
JESUS GARCIA
New Member

Problem running c program calling md5_string function

This program compile correctly but md5_string function doesn't return nothing:

desar# cc md.c -o md -lcryptx
desar# ./md hola
Error: Cannot hash string hola
desar#



1 #include
2 #include
3 #include
4
5 off_t md5_string(unsigned char *bufp, off_t len, unsigned char digest[])
;
6
7 void obtener_md5 (unsigned char *my_string, off_t my_len)
8 {
9 unsigned char my_digest[MD5_HSIZE];
10 int i = 0;
11
12 if ((md5_string(my_string, my_len, my_digest)) < 0) {
13 printf ("Error: Cannot hash string %s\n",my_string );
14 return;
15 }
16
17 for (i = 0; i < MD5_HSIZE; i++) printf("%02x", my_digest[i] );
18 }
19
20
21 int main(int argc, unsigned char **argv)
22 {
23 unsigned char *my_string;
24 unsigned char my_digest[MD5_HSIZE];
25 off_t my_len;
26 int i = 0;
27
28 if (argc != 2)
29 {
30 fprintf(stderr, "Uso: md cadena\n");
31 exit(2);
32 }
33
34 my_string = argv[1];
35
36 if ((md5_string(my_string, my_len, my_digest)) < 0) {
37 printf ("Error: Cannot hash string %s\n",my_string );
38 exit(1);
39 }
40
41 printf ("Hash md5 de la cadena %s de longitud %i :\n",my_string, my_le
n);
42 for (i = 0; i < MD5_HSIZE; i++) printf("%02x", my_digest[i] );
43 printf ("\n");
44 exit(0);
45 }

8 REPLIES 8
JESUS GARCIA
New Member

Re: Problem running c program calling md5_string function

The bundle "HP-UX MD5 Secure Checksum" was installed without problems:

desar:/# uname -a
HP-UX desar B.11.11 U 9000/800 4221864724 unlimited-user license
desar:/# swlist -l product | grep MD5
LibCryptX A.01.00.00 HP-UX LibCryptX (MD5 APIs)
MD5sum A.01.00.00 HP-UX MD5sum (md5sum Command)

Sample runnning "md5sum" command:

desar:/# echo "hola\c" | md5sum -k
4d186321c1a7f0f354b297e8914ab240 4
desar:/#
Stephen Keane
Honored Contributor

Re: Problem running c program calling md5_string function

Hola,

34 my_string = argv[1];
35 my_len = strlen(my_string);
36 if ((md5_string(my_string, my_len, my_digest)) < 0) {
37 printf ("Error: Cannot hash string %s\n",my_string );
38 exit(1);

Would that help? I don't have the man page for md5_string, so I'm guessing.
JESUS GARCIA
New Member

Re: Problem running c program calling md5_string function

Thanks, but some result.

Man page says "my_len" is an output parameter:

The md5_string() function hashes an arbitrary finite stream of data (similar to the example in the preceding paragraph). It returns the digest in the output parameter and the string size as a return argument.

I attach Md5 man pages.
Stephen Keane
Honored Contributor

Re: Problem running c program calling md5_string function

Can you see if errno is being set when md5_string() is called, and if so, what value it contains. Might give us a clue.
Sandman!
Honored Contributor
Solution

Re: Problem running c program calling md5_string function

Hi,

After including Stephen's suggestion in your code i.e.

>> my_len = strlen(my_string); <<

compile your program in 64-bit mode by supplying the +DD64 switch...

# cc +DD64 md.c -o md -lcryptx

For 32-bit compilation replace md5_string() routine with the 32-bit primitives i.e.

md5_init()
md5_update()
md5_final()

cheers!
Sandman!
Honored Contributor

Re: Problem running c program calling md5_string function

Hi,

Attached is the code for the "md" program that uses the core 32-bit APIs i.e.

md5_init()
md5_update()
md5_final()

It'll run on both 32 and 64-bit machines. However the md5-string() function needs to be compiled in 64-bit mode.

Hope it helps...Enjoy!!!
JESUS GARCIA
New Member

Re: Problem running c program calling md5_string function

Thank you very much Sandman.
Both solutions work fine.
JESUS GARCIA
New Member

Re: Problem running c program calling md5_string function

.