Categorygithub.com/hxx258456/ccgo
module
0.0.4
Repository: https://github.com/hxx258456/ccgo.git
Documentation: pkg.go.dev

# README

ccgo 国密改造fabric 使用go加密模块

================ 基于go1.17.5实现的国密算法库,包括:

  • sm2 : 基于emmansun/gmsm的sm2部分实现部分扩展。
  • sm2soft : 基于tjfoc/gmsm的sm2部分的纯软实现,仅作验证与参考用。
  • sm3 : 基于emmansun/gmsm的sm3部分实现部分扩展。
  • sm3soft : 基于tjfoc/gmsm的sm3部分的纯软实现,仅作验证与参考用。
  • sm4 : 基于emmansun/gmsm的sm4部分实现部分扩展。
  • sm4soft : 基于tjfoc/gmsm的sm4部分的纯软实现,仅作验证与参考用。
  • x509 : 基于go1.17.5的x509包与本项目的sm2/sm3/sm4包实现国密改造。
  • gmtls : 基于go1.17.5的tls包与本项目的sm2/sm3/sm4包实现国密改造。
  • gmhttp : 基于go1.17.5net/http包做了对应的国密改造。
  • grpc : 基于google.golang.org/grpcv1.44.0版本做了对应的国密改造。

在x509与gmtls的实现中,国密算法采用的是基于emmansun/gmsm的国密实现,该开源项目已实现利用amd64与arm64架构CPU实现对应国密算法的硬件加速。sm2soft/sm3soft/sm4soft是对应国密算法的纯软实现,仅用作验证与参考。

gmgo的包路径

go package: github.com/hxx258456/ccgo

国密标准参考

本项目涉及到的国密有SM2、SM3和SM4,相关国密标准如下:

  • GB/T 33560-2017 密码应用标识规范
  • GB/T 32918.1-2016 SM2椭圆曲线公钥密码算法 第1部分:总则
  • GB/T 32918.2-2016 SM2椭圆曲线公钥密码算法 第2部分:数字签名算法
  • GB/T 32918.3-2016 SM2椭圆曲线公钥密码算法 第3部分:密钥交换协议
  • GB/T 32918.4-2016 SM2椭圆曲线公钥密码算法 第4部分:公钥加密算法
  • GB/T 32918.5-2017 SM2椭圆曲线公钥密码算法 第5部分:参数定义
  • GB/T 35275-2017 SM2密码算法加密签名消息语法规范
  • GB/T 35276-2017 SM2密码算法使用规范
  • GB/T 32905-2016 SM3密码杂凑算法
  • GB/T 32907-2016 SM4分组密码算法

测试案例

从测试案例入手快速了解gmgo的使用。

sm2

测试案例代码: sm2test/sm2_test.go

cd sm2test
go test

sm3

测试案例代码: sm3/sm3_test.go

cd sm3
go test

sm4

测试案例代码: sm4/sm4_test.gosm4/sm4_gcm_test.go

cd sm4
go test

x509

测试案例代码: x509/x509_test.go

cd x509
go test -v -run "^(TestX509|TestX509WithFile|TestCreateCertFromCA)$"

注意,x509_testTestCreateCertFromCA测试函数生成的sm2系列密钥文件与证书将会用于gmtlsgmgrpc的测试案例。

gmtls

测试案例代码: gmtls/tls_test/tls_test.go

cd gmtls/tls_test
go test

执行之前请确认certs目录下的sm2系列文件是否最新。可以在该目录下执行copyCerts.sh直接从x509的对应目录下拷贝。

gmgrpc

测试案例代码: grpc/grpc_test/grpc_test.go

cd grpc/grpc_test
go test

执行之前请确认testdata目录下的文件是否最新。可以在该目录下执行copyCerts.sh直接从x509的对应目录下拷贝。

本项目参考了以下开源项目,基于其代码做了部分二次开发,向对应的开源作者表示感谢!

  • https://github.com/emmansun/gmsm
  • https://github.com/tjfoc/gmsm
  • https://github.com/golang/go
  • https://github.com/grpc/grpc-go
  • https://github.com/envoyproxy/go-control-plane
  • https://github.com/golang/net
  • https://github.com/gorilla/mux
  • https://github.com/gorilla/handlers
  • https://github.com/felixge/httpsnoop
  • https://github.com/grpc-ecosystem/go-grpc-middleware
  • https://github.com/prometheus/client_golang

对应的版权声明参见目录thrid_licenses

# Packages

Package http provides HTTP client and server implementations.
Package tls partially implements TLS 1.2, as specified in RFC 5246, and TLS 1.3, as specified in RFC 8446.
No description provided by the author
`grpc_middleware` is a collection of gRPC middleware packages: interceptors, helpers and tools.
package grpc implements an RPC system called gRPC.
Package handlers is a collection of handlers (aka "HTTP middleware") for use with Go's net/http package (or any framework supporting http.Handler).
Package httpsnoop provides an easy way to capture http related metrics (i.e.
Package mux implements a request router and dispatcher.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package sm3 handle shangmi sm3 hash algorithm.
No description provided by the author
Package sm4 handle shangmi sm4 symmetric encryption algorithm.
No description provided by the author
No description provided by the author
Package x509 parses X.509-encoded keys and certificates.
No description provided by the author