gpt4 book ai didi

c - libtomcrypt 使用基准测试

转载 作者:行者123 更新时间:2023-11-30 17:51:14 26 4
gpt4 key购买 nike

我想通过创建类似基准的文件来比较 Windows 和 Ubuntu 中 libtomcrypt 的 AES 算法性能,但我在编码时遇到了错误。请帮我。以下是我的比较文件:

比较.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;
}

但是当我编译它时,它显示运行时错误:

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

我哪里出错了?

最佳答案

您忘记链接 tomcrypt 库。使用 -ltomcrypt 编译以链接库:

gcc file.c -ltomcrypt

关于c - libtomcrypt 使用基准测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16825167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com