Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SM2性能问题 #701

Open
taorui2017 opened this issue Feb 14, 2025 · 11 comments
Open

SM2性能问题 #701

taorui2017 opened this issue Feb 14, 2025 · 11 comments

Comments

@taorui2017
Copy link

1、实际测出来,当config不加enable-ec_sm2p_64_gcc_128时,SM2签名验签性能大概只有2000tps(openssl3.0.3\openssl1.0.1也都是这个数值);加上enable-ec_sm2p_64_gcc_128 签名性能大概翻一倍
2、我看网上相关的文档,不加enable-ec_sm2p_64_gcc_128时测出来有5000-6000,加了后签名性能破万了
请问是不是编译的时候还要打开什么参数?或者做什么优化吗?,以上都是单线程测试,32字节

@zzl360
Copy link

zzl360 commented Feb 14, 2025

debug是否关闭了?

@taorui2017
Copy link
Author

debug默认就是关闭的吧?没有加--debug打开

@taorui2017
Copy link
Author

贴一下详细的测试过程:
1、下载Tongsuo-8.4.0.zip,root用户,解压到/root/目录
2、./config & make
3、export LD_LIBRARY_PATH=/root/Tongsuo-8.4.0/:$LD_LIBRARY_PATH;cd apps;ldd ./openssl;确认已链接到当前Tongsuo的lib
4、./openssl speed sm2
Doing 256 bits sign CurveSM2's for 10s: 21266 256 bits CurveSM2 signs in 9.99s
Doing 256 bits verify CurveSM2's for 10s: 25124 256 bits CurveSM2 verify in 9.99s
version: 3.0.3
built on: Fri Feb 14 05:57:54 2025 UTC
options: bn(64,64)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
CPUINFO: OPENSSL_ia32cap=0xfffa32034f8bffff:0x18400704219c27ab
sign verify sign/s verify/s
256 bits SM2 (CurveSM2) 0.0005s 0.0004s 2128.7 2514.9

结果:SM2签名验签性能只有2000多tps

5、开启优化:第二步改成./config enable-ec_sm2p_64_gcc_128 & make,其他步骤不变
6、./openssl speed sm2
Doing 256 bits sign CurveSM2's for 10s: 52577 256 bits CurveSM2 signs in 9.97s
Doing 256 bits verify CurveSM2's for 10s: 24849 256 bits CurveSM2 verify in 10.00s
version: 3.0.3
built on: Fri Feb 14 06:17:36 2025 UTC
options: bn(64,64)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
CPUINFO: OPENSSL_ia32cap=0xfffa32034f8bffff:0x18400704219c27ab
sign verify sign/s verify/s
256 bits SM2 (CurveSM2) 0.0002s 0.0004s 5273.5 2484.9

结果:开启优化后,签名性能翻了一倍,但是总体上感觉还是太低了,是不是还有什么参数没打开?或者哪个配置不对?

PS:特意又编了一版打开debug的(./config --debug),性能更低了,只有1500左右,如下所示:
./openssl speed sm2
Doing 256 bits sign CurveSM2's for 10s: 13775 256 bits CurveSM2 signs in 9.98s
Doing 256 bits verify CurveSM2's for 10s: 15895 256 bits CurveSM2 verify in 9.99s
version: 3.0.3
built on: Fri Feb 14 06:31:25 2025 UTC
options: bn(64,64)
compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O0 -g -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL
CPUINFO: OPENSSL_ia32cap=0xfffa32034f8bffff:0x18400704219c27ab
sign verify sign/s verify/s
256 bits SM2 (CurveSM2) 0.0007s 0.0006s 1380.3 1591.1

@zzl360
Copy link

zzl360 commented Feb 14, 2025

你用的什么cpu?

@taorui2017
Copy link
Author

vmware 虚拟机,kali 操作系统,1个物理核,4个逻辑核,宿主机的CPU是:12th Gen Intel(R) Core(TM) i7-1260P 2.10 GHz

@zzl360
Copy link

zzl360 commented Feb 14, 2025

性能跟CPU主频有关系,这种性能测试最好在实体机上测试。如果必须得在虚拟机里,可以拿openssl做对比测试。

@taorui2017
Copy link
Author

嗯,对比过了,不开sm2p的时候,跟原生的openssl性能一样。
同时,我还找到一篇文章:https://www.yuque.com/tsdoc/misc/nkoyr4wlm5pptdqc ,这里的测试数据也是2000多,跟我的测试结果一致。
但是另一篇文章:https://zhuanlan.zhihu.com/p/644584577,里面提到原生的openssl、不开sm2p的签名验签数据都是5000多。
这里就搞不懂了,不知道官方有没有SM2签名验签的数据,正常的应该是多少

@zzl360
Copy link

zzl360 commented Feb 14, 2025

cpu不一样,性能绝对值没有参考意义

@taorui2017
Copy link
Author

请问还有什么配置或者参数可以提高SM2的性能的吗?在同样的虚拟机里,我用别人编好的openssl动态库,SM2签名性能是tongsuo的3倍,验签性能是tongsuo的2倍

@zzl360
Copy link

zzl360 commented Feb 14, 2025

可以用那个openssl看一下它的编译参数是什么,以及这个版本的openssl里是不是添加了sm2的其他的性能优化代码

@taorui2017
Copy link
Author

好的,我再研究研究,多谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants