如何在C中使用libtomcrypt API并对其执行基准测试

时间:2013-05-30 18:55:51

标签: c api aes static-libraries benchmarking

我已经下载了libtomcrypt API,并希望对AES算法进行基准测试。我所做的是创建一个源文件并包含tomcrypt.h头文件。然后我编写了用于测试加密功能的代码 - “rijndael_ecb_encrypt”。

    #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(){
//called the function
}

它编译正确,但有朗姆酒链接错误。它没有检测到函数“rijndael_ecb_encrypt”并将错误显示为:

gcc  -o "TestC"  ./src/TestC.o   
./src/TestC.o: In function `test_rijndael_ecb_encrypt':
/home/anvesh/workspace/TestC/Debug/../src/TestC.c:35: undefined reference to `rijndael_ecb_encrypt'
collect2: error: ld returned 1 exit status
make: *** [TestC] Error 1

我是否正确执行测试AES加密的执行时间?如果没有,是否有任何替代方案来实现?有什么建议?请帮帮我。

1 个答案:

答案 0 :(得分:2)

安装tom crypt库。

sudo apt-get install libtomcrypt-dev

然后在编译时包含库:

gcc file.c -ltomcrypt