I am working on adding a test program in C that implements openssl RC4 functions. The man page in Linux gives me the format for the functions and says to include the header file, which I did. However, when I try to compile, it keeps giving me errors.
/tmp/ccQwY6Sr.o: In function `main':
rc4.c:(.text+0xd5): undefined reference to `RC4_set_key'
rc4.c:(.text+0xef): undefined reference to `RC4'
collect2: error: ld returned 1 exit status
Surprisingly, I can not seem to find any info on this specific issue online. How is an undefined reference in I included the header file that's supposed to define them?
If anyone could point me in the right direction here, I would appreciate the help.
my compile line is:
gcc rc4.c -o rc4
my program is:
#include <openssl/rc4.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
FILE* inFile;
char * bufferIn;
char * bufferOut;
char data[] = "PASSword123";
RC4_KEY * key;
inFile = fopen("/home/chris/Desktop/testfile.txt", "rb+");
fseek(inFile, 0, SEEK_END);
int size = ftell(inFile);
rewind(inFile);
bufferIn = (char*)malloc(sizeof(char)*size);
bufferOut = (char*)malloc(sizeof(char)*size);
fread(bufferIn, 1, size, inFile);
rewind(inFile);
RC4_set_key(key, 11, data);
RC4(key, size, bufferIn, bufferOut);
free(bufferIn);
free(bufferOut);
return 0;
}
my compile line is: gcc rc4.c -o rc4
The <openssl/rc4.h>
header only includes declarations of the RC4 functions, not their definitions. These functions are defined in the libcrypto library, which is part of OpenSSL. Add -lcrypto
to your command line to link against this library.
As an aside, RC4 is not considered secure. Avoid using it.