答案1
您可以通过运行来验证 nginx 是否是使用 OpenSSL 构建的nginx -V
。
[root@saurok ~]# nginx -V
nginx version: nginx/1.8.0
built by gcc 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)
built with OpenSSL 1.0.1k-fips 8 Jan 2015
TLS SNI support enabled
...
您可以通过运行 OpenSSL 的内部基准测试来验证 OpenSSL 是否使用 Intel AES-NI。
openssl speed aes-128-cbc
将的输出与 进行比较openssl speed -evp aes-128-cbc
。前者即使存在硬件加速也会跳过它,而后者则使用加速(如果可用)。除了基准测试之外,如果存在,它将自动使用。
例如:
[root@saurok ~]# openssl speed aes-128-cbc
Doing aes-128 cbc for 3s on 16 size blocks: 32797518 aes-128 cbc's in 3.00s
Doing aes-128 cbc for 3s on 64 size blocks: 9030109 aes-128 cbc's in 3.00s
Doing aes-128 cbc for 3s on 256 size blocks: 2311493 aes-128 cbc's in 3.00s
Doing aes-128 cbc for 3s on 1024 size blocks: 582201 aes-128 cbc's in 3.00s
Doing aes-128 cbc for 3s on 8192 size blocks: 72836 aes-128 cbc's in 3.00s
OpenSSL 1.0.1k-fips 8 Jan 2015
built on: Thu Aug 13 12:19:54 2015
options:bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) aes(partial) idea(int) blowfish(idx)
compiler: -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -DTERMIO -Wall -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_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 174920.10k 192642.33k 197247.40k 198724.61k 198890.84k
相比于
[root@saurok ~]# openssl speed -evp aes-128-cbc
Doing aes-128-cbc for 3s on 16 size blocks: 169042680 aes-128-cbc's in 3.00s
Doing aes-128-cbc for 3s on 64 size blocks: 45311567 aes-128-cbc's in 3.00s
Doing aes-128-cbc for 3s on 256 size blocks: 11536773 aes-128-cbc's in 3.00s
Doing aes-128-cbc for 3s on 1024 size blocks: 2897474 aes-128-cbc's in 3.00s
Doing aes-128-cbc for 3s on 8192 size blocks: 362685 aes-128-cbc's in 3.00s
OpenSSL 1.0.1k-fips 8 Jan 2015
built on: Thu Aug 13 12:19:54 2015
options:bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) aes(partial) idea(int) blowfish(idx)
compiler: -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -DTERMIO -Wall -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_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 901560.96k 966646.76k 984471.30k 989004.46k 990371.84k
如您所见,后者速度更快,表明正在使用硬件加速。
答案2
Nginx 与硬件卸载无关;这取决于所使用的加密库。通常,您将使用 OpenSSL,如果它是合适的版本,并且经过适当配置,它将使用硬件卸载来执行现代 CPU 上硅片支持的加密操作。