3
我想獲得我的硬件的加密性能測試,同時這樣做我使用openssl速度測試命令。openssl使用cryptodev引擎的速度測試與硬件加速器一起導致虛假的計時結果
第一測試I執行是不啓用硬件加速:
$ openssl speed -evp aes-128-cbc -engine cryptodev
Doing aes-128-cbc for 3s on 16 size blocks: 4437806 aes-128-cbc's in 3.00s
Doing aes-128-cbc for 3s on 64 size blocks: 1244528 aes-128-cbc's in 3.00s
Doing aes-128-cbc for 3s on 256 size blocks: 322780 aes-128-cbc's in 3.00s
Doing aes-128-cbc for 3s on 1024 size blocks: 81429 aes-128-cbc's in 3.00s
Doing aes-128-cbc for 3s on 8192 size blocks: 10215 aes-128-cbc's in 3.00s
OpenSSL 1.0.1j 15 Oct 2014
built on: Thu Jul 23 18:58:46 CDT 2015
options:bn(64,32) rc4(ptr,char) des(idx,cisc,16,long) aes(partial) idea(int) blowfish(ptr)
compiler: arm-poky-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard
-mfpu=neon -mtune=cortex-a9 --sysroot=... -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS
-D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -DTERMIO -O2 -pipe -g
-feliminate-unused-debug-types -Wall -Wa,--noexecstack -DHAVE_CRYPTODEV -DUSE_CRYPTODEV_DIGESTS
-DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM
-DAES_ASM -DGHASH_ASM
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
aes-128-cbc 23668.30k 26549.93k 27543.89k 27794.43k 27893.76k
然後啓用硬件加速,並得到下面的結果:
$ openssl speed -evp aes-128-cbc -engine cryptodev
engine "cryptodev" set.
Doing aes-128-cbc for 3s on 16 size blocks: 39552 aes-128-cbc's in ***0.08s***
Doing aes-128-cbc for 3s on 64 size blocks: 37060 aes-128-cbc's in ***0.05s***
Doing aes-128-cbc for 3s on 256 size blocks: 32674 aes-128-cbc's in ***0.07s***
Doing aes-128-cbc for 3s on 1024 size blocks: 26101 aes-128-cbc's in ***0.06s***
Doing aes-128-cbc for 3s on 8192 size blocks: 8286 aes-128-cbc's in ***0.02s***
OpenSSL 1.0.1j 15 Oct 2014
built on: Thu Jul 23 18:58:46 CDT 2015
options:bn(64,32) rc4(ptr,char) des(idx,cisc,16,long) aes(partial) idea(int) blowfish(ptr)
compiler: arm-poky-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard
-mfpu=neon -mtune=cortex-a9 --sysroot=.... -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS
-D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -DTERMIO -O2 -pipe -g
-feliminate-unused-debug-types -Wall -Wa,--noexecstack -DHAVE_CRYPTODEV -DUSE_CRYPTODEV_DIGESTS
-DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM
-DAES_ASM -DGHASH_ASM
The 'numbers' are in 1000s of bytes per second processed.
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
我的問題是,爲什麼在測試運行了10秒毫秒,當測試應該爲每個塊大小運行3秒。這是OpenSSL中的錯誤嗎?
我通過OpenSSL的版本1.0.1j代碼去了,以下是我發現:
#ifndef OPENSSL_NO_AES
if (doit[D_CBC_128_AES])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
AES_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&aes_ks1,
iv,AES_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_128_AES,j,count,d);
}
}
這裏Time_F定義如下:
static double Time_F(int s)
{
return app_tminterval(s,usertime);
}
#endif
app_tminterval定義如:
#else
#include <sys/time.h>
#include <sys/resource.h>
double app_tminterval(int stop,int usertime)
{
double ret = 0;
struct rusage rus;
struct timeval now;
static struct timeval tmstart;
if (usertime) getrusage(RUSAGE_SELF,&rus), now = rus.ru_utime;
else gettimeofday(&now,NULL);
if (stop==TM_START) tmstart = now;
else ret = ((now.tv_sec+now.tv_usec*1e-6)
- (tmstart.tv_sec+tmstart.tv_usec*1e-6));
return ret;
}
#endif
在這裏,我很困惑如何處理應用程序間隔小於10ms的時間,而沒有硬件加速器的實際測試運行3秒。
謝謝
可能相關:[我怎樣才能解釋openssl速度輸出?](http://stackoverflow.com/q/17410270) – jww
明顯的建議是,它只是比預期的更早敲擊循環終止條件。 「COND(c [D_CBC_128_AES] [j])'實際上是什麼意思? – Notlikethat