信息安全研究 ›› 2023, Vol. 9 ›› Issue (10): 1001-.

• 技术应用 • 上一篇    下一篇

国密算法Python工具包的性能优化方法

谢振杰1,2付伟1罗芳1   

  1. 1(海军工程大学信息安全系武汉430033)
    2(中国人民解放军78156部队重庆400039)
  • 出版日期:2023-10-17 发布日期:2023-10-28
  • 通讯作者: 付伟 博士,副教授,硕士生导师.主要研究方向为云计算、云安全、分布式计算、信息安全. lukeyoyo@tom.com
  • 作者简介:谢振杰 硕士.主要研究方向为云安全、密码学应用. jsonxie@126.com 付伟 博士,副教授,硕士生导师.主要研究方向为云计算、云安全、分布式计算、信息安全. lukeyoyo@tom.com 罗芳 硕士,讲师.主要研究方向为对称密码设计、密码安全性分析. lf_0215@sina.com

Performance Optimization Method of Python Toolkit for Domestic  Cryptographic Algorithm

Xie Zhenjie1,2, Fu Wei1, and Luo Fang1   

  1. 1(Department of Information Security, Naval University of Engineering, Wuhan 430033)
    2(Unit 78156 of the PLA, Chongqing 400039)
  • Online:2023-10-17 Published:2023-10-28

摘要: 针对现有国密算法Python库运行效率不高的问题,综合运用提前编译、调用成熟的密码运算链接库、预计算、并行执行、构造双字节S盒、减少函数调用、避免中间类型转换以及优化代码细节等性能优化方法,开发包含SM2,SM3,SM4,ZUC这4种国密算法的高效Python工具包.该工具包的所有算法均包含适合机器高效运行的加速版与适合教学的未加速版,填补了SM2密钥交换协议Python开源代码的空白.对比测试表明,相比现有开源国密算法Python库中性能最佳的实现,该工具包SM2性能为其10倍左右,而SM3,SM4,ZUC性能可达100倍以上,与成熟的国际密码算法Python库性能相当.

关键词: 国密算法, Python, 性能优化, 密码算法库, 软件实现

Abstract: The known Python libraries of domestic cryptographic algorithms are not working efficiently. By comprehensively using performance optimization methods such as precompilation, calling mature cryptographic algorithm library, precomputation, parallel execution, constructing doublebyte Sbox, reducing function calls, avoiding intermediate type conversion and optimizing code details, a highefficiency Python toolkit containing four domestic cryptographic algorithms SM2, SM3, SM4 and ZUC is developed. All algorithms in this toolkit contain the accelerated versions suitable for efficient machine operation and the nonaccelerated versions suitable for teaching. And the gap of open source Python code of SM2 key exchange protocol is filled. The comparative test shows that, comparing with the best performance in the existing open source domestic cryptographic algorithm Python libraries, the performance of SM2 in this toolkit is about 10 times, the performances of SM3, SM4 and ZUC can reach more than 100 times, which are equivalent to the performances of the mature international cryptographic algorithm Python library.

Key words: domestic cryptographic algorithm, Python, performance optimization, cryptographic algorithm library, software implementation

中图分类号: