Giter Site home page Giter Site logo

gm-crypto-test-suite's Introduction

国密测试套件(GM Crypto Test Suite)

这是基于Golang的国密测试套件,用于测试国密SM2实现库或KMS服务,并验证其与tjfoc-gm库v1.4.0的兼容性。

测试对象

测试对象分为2种:KMS、国密算法库中的SM2非对称密钥。

  1. KMS(Key Management Service)是密钥管理服务,由服务提供商提供密钥的计算、存储服务,开发者通过调用其api完成密钥的生成、删除、加解密、签名验签等操作。 一般情况下,对于非对称密钥(SM2),开发者无法获取私钥,使用服务商提供的KeyID作为密钥的标识;同时,开发者可以获取公钥,将公钥正确解析后,直接用于加密、验签。
  2. 国密算法库是对国密算法的实现,可以是源代码或链接库的形式,完全在本地运行。

简言之,二者差异在于:

  • KMS无法获取私钥,仅有KeyID;算法库可以直接使用私钥
  • KMS在密钥生成、签名、解密时是远程计算;算法库全部是本地计算

为什么要测试

  1. 密钥、签名的编码格式可能不同 比方说,对于公钥,有的库可能通用的编码规则,如ASN1编码;有的可能使用自己的编码方式或不进行任何编码,如把byte格式的X值和Y值直接拼接。这使得所需的公钥的解析方式不同。

  2. 存在使用公钥直接加密、验签的场景 在对现有系统进行国密化改造时,原有的加密方案可能依赖于可解析的公钥、私钥。一个改动较少的方案是,仅改造涉及私钥的部分,包括密钥生成、签名、解密的操作;而通过公钥就可进行的操作,包括验签、加密,在可以解析公钥的情况下就不需要额外的改造。

测试范围

KMS

测试库自洽

  • 密钥生成
  • 加密再解密
  • 签名再验签

兼容tjfoc库

  • 公钥pem互相读写
  • tjfoc加密,测试库再解密
  • 测试库签名,tjfoc再验签

并发测试

  • 测试框架
  • 测试示例

国密实现库

测试库自洽

  • 密钥生成
  • 加密再解密
  • 签名再验签

兼容tjfoc库

  • 公钥pem互相读写
  • 私钥pem互相读写
  • tjfoc加密,测试库再解密
  • 测试库加密,tjfoc解密
  • 测试库签名,tjfoc再验签
  • tjfoc签名,测试库再验签

如何使用

kms

  1. 包装需要测试的库,实现kms/sm2_test/sm2.go中的全部2个接口。可参考example_tjfoc_kms.go,该文件为tjfoc库模拟的kms。
  2. 替换sm2_test.go中的initKms函数,将CreateKeyAdapter替换为返回封装的待测试kms对Sm2KMS接口的实现。
  3. 运行sm2_test.go,查看测试结果。

国密实现库

  1. 包装需要测试的库,实现implement/sm2_test/sm2.go中的全部3个接口。可参考example_tjfoc_implement.go,该文件为对tjfoc库的包装。
  2. 替换sm2_test.go中的initImpl函数,将KeyCreator替换为封装的待测试库对Sm2Creator接口的实现。
  3. 运行sm2_test.go,查看测试结果。

Ideas

  1. 目前的兼容性测试是以tjfoc库为基准的,可改造为任意2库的测试,以适应更多场景。
  2. 目前的测试方法为clone本代码库后进行添加/更改,改造为在其他代码库import进去,再传递接口的实现。
  3. 在1的基础上,定期生成多个库两两之间的兼容测试结果,反馈社区和作者。

gm-crypto-test-suite's People

Contributors

culiutudousi avatar matrix-zhang avatar

Stargazers

mysticbinary avatar

Watchers

James Cloos avatar Shangqi Liu avatar Edison.Hsu avatar Weili avatar Yan Qian avatar Edward NoaLand avatar Arthas Zeng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.