ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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...
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?
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.
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?
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) {
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 */
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....
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.
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.
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):
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.