LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-12-2005, 11:15 AM   #1
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Rep: Reputation: 15
Undefined reference error


i am getting the generic "undefinded reference error" in my function.can any1 tell me as to what this actually means?is it due to a missing header file?i have included all the necessary headers...


thanks
 
Old 11-12-2005, 11:21 AM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
Do you include all shared libraries as well?
 
Old 11-12-2005, 11:26 AM   #3
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
well i do not understand what do you mean by the term "shared libraries". i am implementing it on linux platform and have included the openSSL/md5.h and openSSL/hmac.h files. do you have any idea as to what else i need 2 include?
 
Old 11-12-2005, 11:30 AM   #4
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
what i mean is i am implementing IPSEC AH header functionality and am getting the "undefined reference error" for the MD5_Init(), which is a function in the MD5 message digest code.i have included the above files for the same.
 
Old 11-12-2005, 11:31 AM   #5
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
When you get an "undefinded reference error" it mean when the linker got out to find all the methods that you program is needs to run it can't find one. This can happen if you are using a shared library as Ygrex said. Shared Libraries are library files (a collection of methods that someone else wrote but you can use if you have the object files and the correct headers). So when the linker goes out to find the actual method (not just the definition which is in the header files) it can link to that object file. So it sounds like you are including a header, but do not have the library file that goes along with it.

Usually the linker will tell you what it can't find. What method can't it find when it tries to link the program?
 
Old 11-12-2005, 11:36 AM   #6
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
well, as i have already said, i am trying to invoke the functions MD5_Init(), MD5_Update() and MD5_Final() in this code. i get the undefined reference error for all these functions....

my code for the same is as follows....

#include <openssl/hmac.h>
#include <openssl/md5.h>
void
hmac_md5(text, text_len, key, key_len, digest)
const unsigned char text[20]; /* pointer to data stream */
int text_len; /* length of data stream */
const unsigned char key[20]; /* pointer to authentication key */
int key_len; /* length of authentication key */
caddr_t digest; /* caller digest to be filled in */

{
MD5_CTX context;
unsigned char k_ipad[65]="sdfa"; /* inner padding -
* key XORd with ipad
*/
unsigned char k_opad[65]="sadfas"; /* outer padding -
* key XORd with opad
*/
unsigned char tk[16];
int i;
/* if key is longer than 64 bytes reset it to key=MD5(key) */
/* if (key_len > 64) {

MD5_CTX tctx;
MD5_Init(&tctx);
MD5_Update(&tctx, key, key_len);
MD5_Final(tk, &tctx);

key = tk;
key_len = 16;
}
*/
/*
* the HMAC_MD5 transform looks like:
*
* MD5(K XOR opad, MD5(K XOR ipad, text))
*
* where K is an n byte key
* ipad is the byte 0x36 repeated 64 times

* opad is the byte 0x5c repeated 64 times
* and text is the data being protected
*/

/* start out by storing key in pads */
/* bzero( k_ipad, sizeof k_ipad);
bzero( k_opad, sizeof k_opad);
bcopy( key, k_ipad, key_len);
bcopy( key, k_opad, key_len);
*/
/* XOR key with ipad and opad values */
/* for (i=0; i<64; i++) {
k_ipad[i] = 0;
k_opad[i] = 0;
}*/
/*
* perform inner MD5
*/
MD5_Init(&context); /* init context for 1st
* pass */
MD5_Update(&context, k_ipad, 64); /* start with inner pad */
MD5_Update(&context, text, text_len); /* then text of datagram */
MD5_Final(digest, &context); /* finish up 1st pass */
/*
* perform outer MD5
*/
MD5_Init(&context); /* init context for 2nd
* pass */
MD5_Update(&context, k_opad, 64); /* start with outer pad */
MD5_Update(&context, digest, 16); /* then results of 1st
* hash */
MD5_Final(digest, &context); /* finish up 2nd pass */


}

int main()
{
caddr_t digest;
hmac_md5("text", 4, "ksdhf", 5, digest);
return 0;
}
 
Old 11-12-2005, 11:47 AM   #7
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
probably '-lopenssl' or '-lssl' options to the compiler ?
 
Old 11-12-2005, 11:50 AM   #8
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
well the program compiles with tht command '-lssl' but gives a SEGMENTATION FAULT when i try and run it
 
Old 11-12-2005, 11:54 AM   #9
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
Looks to me it is dieing on the call to MD5_Final(digest, &context);
 
Old 11-12-2005, 11:57 AM   #10
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
any idea as to how the problem can be fixed guys? i would really appreciate it no end....
 
Old 11-12-2005, 12:01 PM   #11
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
i tried commenting the MD5_Final() function and it does run...i mean the segmentation fault error doesnt appear now..i am wondering as to why this fault appears in the 1st place....
 
Old 11-12-2005, 12:14 PM   #12
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
I replace the line
MD5_Final(digest, &context); /* finish up 2nd pass */
where digest is a caddr_t with
MD5_Final(tk, &context); /* finish up 2nd pass */
where tk is a unsigned char tk[16].

In the header file the MD5_Fianl is defined as:
int MD5_Final(unsigned char *md, MD5_CTX *c);

And from the MD5_final man page it *md needs to be at least 16 chars long. When i made this replacement the seg fault went away. Wether it is doing what it should be i don't know, but the seg fault is now gone.

Is there a unsigned char* in the caddr_t struct?
 
Old 11-12-2005, 12:28 PM   #13
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
well i am sorry man, but i fail to find the struct details for caddr_t. it is a part of an internet draft and the implementation details of this struct dont seem to be made public.in that case, is there any clue as to what i should be doing next?the MD5_final() function returns the final calculated digest back,i printed the value at intermed points for the ' digest ' and it did return me a string.
 
Old 11-12-2005, 12:38 PM   #14
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
I found a definition for caddr_t in usr/include/bits/types.h
it is a unsigned char*
so I change this line
caddr_t digest ;

to this
caddr_t digest = (caddr_t)malloc(16);

and it works

and to create the memory space for the character array.
 
Old 11-12-2005, 12:47 PM   #15
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
i tried to run the following test vectors given in the rfc on our program, but i tend to get diff answers from what are needed.are you getting the answers conforming to the test cases given here?


Test Vectors (Trailing '\0' of a character string not included in test):

key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
key_len = 16 bytes
data = "Hi There"
data_len = 8 bytes
digest = 0x9294727a3638bb1c13f48ef8158bfc9d

key = "Jefe"
data = "what do ya want for nothing?"
data_len = 28 bytes
digest = 0x750c783e6ab0b503eaa86e310a5db738

key = 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

key_len 16 bytes
data = 0xDDDDDDDDDDDDDDDDDDDD...
..DDDDDDDDDDDDDDDDDDDD...
..DDDDDDDDDDDDDDDDDDDD...
..DDDDDDDDDDDDDDDDDDDD...
..DDDDDDDDDDDDDDDDDDDD
data_len = 50 bytes
digest = 0x56be34521d144c88dbb8c733f0e8b3f6
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting undefined reference to main error?? Mistro116@yahoo.com Programming 14 07-29-2011 08:28 AM
Undefined reference error in MD5_Init() jacques83 Linux - Networking 0 11-11-2005 09:44 PM
gcc ld error. Undefined reference redness Linux - Software 4 02-08-2005 02:01 AM
undefined reference error Quest101 Programming 3 01-01-2005 12:27 PM
Undefined reference to function error Quest101 Linux - Newbie 0 12-30-2004 05:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration