1

我已经下载了 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
}

它编译正确,但存在 rumtime 链接错误。它没有检测到函数“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 加密的执行时间?如果没有,还有其他方法可以实现吗?有什么建议么?请帮我。

4

1 回答 1

2

安装 tom crypt 库。

sudo apt-get install libtomcrypt-dev

然后在编译时包含该库:

gcc file.c -ltomcrypt
于 2013-05-31T06:09:34.577 回答