cheaderstatic-librariesbenchmarkinglibtomcrypt

libtomcrypt usage benchmarking


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?


Solution

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

    gcc file.c -ltomcrypt