0

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;
}
jww
  • 97,681
  • 90
  • 411
  • 885
Chris
  • 95
  • 9
  • [`fseek(inFile, 0, SEEK_END);`](https://port70.net/~nsz/c/c11/n1570.html#7.21.9.2) is [undefined behavior for a binary stream](https://port70.net/~nsz/c/c11/n1570.html#note268) in strictly-conforming C code. Why that gets taught as "how to get the size of a file" is beyond me. "Size of a file" requires implementation-specific methods to determine, and `ftell()` is limited to 2 GB on 32-bit machines in any case. – Andrew Henle Apr 10 '19 at 18:58

1 Answers1

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.