0

I wanted to compare AES algorithm performance from libtomcrypt in Windows and Ubuntu by creating a benchmark-like file, but I have got errors while coding it. Please help me. Below is my file for comparing:

Compare.c:

`#include <time.h> `
#include <tomcrypt.h>
#define MIN_TIME 10.0
#define MIN_ITERS 20 `

double test_rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) {
    int iterations = 0;
    clock_t start;
    double elapsed=0.0;
    int out;
    start=clock();
    do{ 
out = rijndael_ecb_encrypt(pt, ct, skey);
        iterations++;
        elapsed=(clock()-start)/(double)CLOCKS_PER_SEC;
    } while(elapsed<MIN_TIME || iterations<MIN_ITERS);
    elapsed=1000.0*elapsed/iterations;
    printf("%s \n",pt);
    printf("%s \n",skey->data);
    printf("%s \n",ct);
    printf("iterations: %8d \n",iterations);
    printf("%8.2lf ms per iteration \n",elapsed);
    printf("out: %d \n",out);
    return elapsed;
}

int main() {
    unsigned char pt[22]="-K4)<i50~'APg2fa7DiV";
    unsigned char ct[22];
    unsigned char key[16]="EDB1C6D13FC72";
    symmetric_key *skey;
    int err;
    double tout1;
    printf("%x",sizeof(pt));
    printf("%l",sizeof(key));
    if((err=rijndael_setup(key,16,0,skey))!=CRYPT_OK) {
    printf("%s",error_to_string(err));
    return -1;
    }
    tout1=test_rijndael_ecb_encrypt(pt,ct,skey);
    printf("%s \n",ct);
    printf("%f",tout1);
    return 0;
}

But when I compile this it shows runtime errors as:

gcc  -o "TestC"  ./src/TestC.o   
./src/TestC.o: In function `test_rijndael_ecb_encrypt':
/home/anvesh/workspace/TestC/Debug/../src/TestC.c:27: undefined reference to `rijndael_ecb_encrypt'
./src/TestC.o: In function `test_rijndael_ecb_decrypt':
/home/anvesh/workspace/TestC/Debug/../src/TestC.c:53: undefined reference to `rijndael_ecb_decrypt'
./src/TestC.o: In function `main':
/home/anvesh/workspace/TestC/Debug/../src/TestC.c:82: undefined reference to `rijndael_setup'
/home/anvesh/workspace/TestC/Debug/../src/TestC.c:83: undefined reference to `error_to_string'
collect2: error: ld returned 1 exit status
make: *** [TestC] Error 1

Where did I go wrong?

jxh
  • 69,070
  • 8
  • 110
  • 193
annunarcist
  • 1,637
  • 3
  • 20
  • 42

1 Answers1

0

You forgot to link with tomcrypt library. Compile with -ltomcrypt to link the library:

gcc file.c -ltomcrypt
P.P
  • 117,907
  • 20
  • 175
  • 238
  • Now a new error arises as below: /usr/bin/ld: cannot find -ltomcrypt collect2: error: ld returned 1 exit status – annunarcist May 30 '13 at 19:58
  • The library name is libtomcrypt.a Is it that -ltomcrypt or -llibtomcrypt?? And FYI the library is in ../libtomcrypt folder while the header files are in ../libtomcrypt/src/headers. – annunarcist May 30 '13 at 20:09
  • I think I am getting closer to get binary file generated. Now when I executed this command: cc -L/../libtomcrypt-1.17 / -I/../libtomcrypt-1.17/src/headers Compare.c it throws the following error: /usr/bin/ld: cannot find -l/../libtomcrypt-1.17/libtomcrypt.a collect2: error: ld returned 1 exit status make: *** [Compare] Error 1 How can I solve this error? – annunarcist May 30 '13 at 20:30
  • I am using a 64-bit Ubuntu OS and x86_64-linux-gnu compiler (32-bit or 64-bit??). – annunarcist May 30 '13 at 21:12
  • 1
    You can install tom crypt library and link the library in the system path: `sudo apt-get install libtomcrypt-dev` – P.P May 31 '13 at 06:08
  • The error (in your 1st comment) is because you have your library located elsewhere other than the standard path. So linker couldn't find the lib. You can use `-L` to give a path to searh for: `gcc file.c -I/path/to/includes -L/path/to/lib -libtomcrypt` – P.P May 31 '13 at 11:55
  • Now I have given the correct library path and executed the following command: cc -L/home/xxx/Documents/libtomcrypt-1.17 / -I/home/xxx/Documents/libtomcrypt-1.17/src/headers Compare.c But it still throws error as: /usr/bin/ld: cannot find /: File format not recognized collect2: error: ld returned 1 exit status – annunarcist May 31 '13 at 15:06
  • If you have given the correct path, linker error shouldn't be seen. Can you try installing it so that you don't have to link yourself: `sudo apt-get install libtomcrypt-dev` and then `gcc file.c -ltomcrypt` ? – P.P May 31 '13 at 15:12
  • Have one more question.....now that it executes using linux terminal. But I cannot use it for debugging and developing a project on it. I am using eclipse IDE for c/c++ for my project. So I cannot give a command and needs to set the lib path for my program to execute, right? I tried setting the libpath in eclipse as /usr/bin and C:/path/to/libtomcrypt/ and both locations have the libtomcrypt.a library files. But still I receive the following error: /usr/bin/ld: cannot find -l/usr/lib/libtomcrypt.a collect2: error: ld returned 1 exit status Please help me solve this problem?? Thank you :) – annunarcist May 31 '13 at 16:32
  • And also how to install a library (say libtomcrypt only) in windows to use it?? – annunarcist May 31 '13 at 16:33
  • hmm..I never used eclipse for C. May be, you can google and find how to set the linker options. If you are mingw it's same as how you link using gcc. No idea about MSVS. – P.P Jun 01 '13 at 11:01