| English | 简体中文 |
Go ShangMi (Commercial Cryptography) Library, abbreviated as GMSM, is a secure, high-performance, and easy-to-use Go cryptographic library that covers the Chinese commercial cryptographic public algorithms SM2/SM3/SM4/SM9/ZUC.
If you want to raise an issue, we recommend reading How To Ask Questions The Smart Way.
The core implementation of SM2 elliptic curve public key cryptography algorithm is located in the internal/sm2ec package. This implementation achieves performance comparable to the native NIST P-256 curve implementation in the Go standard library (non-BoringCrypto) and includes assembly optimizations for amd64, arm64, s390x, ppc64le, riscv64, and loong64 architectures.
Features:
For detailed performance optimization analysis and implementation details, please refer to the SM2 Performance Optimization Wiki.
The underlying mathematical operations (prime fields, extension fields, elliptic curves, and bilinear pairings) of SM9 identity-based cryptography algorithm are implemented in the bn256 package, with optimizations for amd64, arm64, ppc64x, riscv64, and loong64 architectures.
Features:
For implementation details and optimization strategies, please refer to the SM9 Implementation and Optimization Wiki.
SM3 cryptographic hash algorithm (GM/T 0004-2012) implements efficient SIMD optimizations:
Architecture Optimizations:
For detailed implementation analysis, please refer to the SM3 Performance Optimization Wiki.
SM4 block cipher algorithm (GM/T 0002-2012) implements multi-architecture assembly optimizations with fused optimizations for common operation modes:
Architecture Optimizations:
Operation Mode Optimizations:
For detailed implementation analysis, please refer to the SM4 Performance Optimization Wiki.
The Zu Chongzhi stream cipher algorithm (GM/T 0001-2012) implements optimizations based on SIMD, AES instructions, and carry-less multiplication instructions, supporting amd64, arm64, and ppc64x architectures.
Features:
For detailed implementation analysis, please refer to the Efficient Software Implementations of ZUC Wiki.
Compliant with the standard “GB/T 15852.1-2020 Information Security Technology - Message Authentication Code Algorithm Part 1: Mechanism using a Block Cipher”, implementing various MAC algorithms:
Supported MAC Modes:
Implements various operation modes defined in the standard “GB/T 17964-2021 Information Security Technology - Modes of Operation for Block Ciphers”:
Supported Operation Modes:
Notes:
cipher.BlockMode interface and contains internal tweak state, does NOT support concurrent useImplements various standards-compliant padding schemes with constant-time unpadding to defend against Padding Oracle attacks:
| Padding Scheme | Corresponding Standard |
|---|---|
| PKCS#7 | GB/T 17964-2021 Appendix C.2 Padding Method 1 / RFC 5652 |
| ISO/IEC 9797-1 Method 2 | GB/T 17964-2021 Appendix C.3 Padding Method 2 |
| ANSI X.923 | ANSI X9.23 Standard |
| ISO/IEC 9797-1 Method 3 | GB/T 17964-2021 Appendix C.4 Padding Method 3 |
| Zero Padding | Non-standard (legacy compatibility) |
Secure Implementation:
ConstantTimeUnpad() and Unpad() methodsConstantTimeUnpad() to defend against timing attacksUnpad() is only for performance optimization with non-sensitive dataExtended from the Go standard library crypto/x509 package with added support for Chinese commercial cryptography algorithms, compliant with “GM/T 0015-2012 Digital Certificate Format Specification Based on SM2 Cryptographic Algorithm”.
Extended from the mozilla-services/pkcs7 project (archived in February 2024) with added support for Chinese commercial cryptography algorithms, compliant with RFC 2315 standard.
Extended from the youmark/pkcs8 project with added support for Chinese commercial cryptography algorithms, compliant with RFC 5208 / RFC 5958 standards.
Provides an interface design similar to the Go standard library crypto/ecdh, supporting SM2 curve key agreement protocols:
Supported Protocols:
Features:
big.Int dependency for better performancesm2 package key exchange protocolCompliant with “GM/T 0105-2021 Software Random Number Generator Design Guide” and compatible with NIST SP 800-90A partial requirements.
Features:
Provides interoperability support with CFCA SADK:
Features:
Compliant with NIST FIPS 203 standard, based on the Go standard library implementation.
Supported Parameter Sets:
Compliant with NIST FIPS 204 standard.
Compliant with NIST FIPS 205 standard.
This software is licensed under the MIT License. For details, please refer to the LICENSE file. If you are unfamiliar with the terms of the MIT License, please refer to MIT License. Please be aware of and comply with the licensee obligations!
The basic architecture, design, and some code of this project are derived from golang crypto.
The SM4 block cipher algorithm amd64 SIMD AES-NI implementation (SSE part) algorithm is derived from mjosaarinen/sm4ni.
The initial version of SM9/BN256 code was copied from the cloudflare/bn256 project, and later the basic prime field, extension field, elliptic curve operations, etc. were rewritten.
The Zu Chongzhi stream cipher algorithm implementation amd64 SIMD AES-NI, CLMUL implementation algorithm is derived from the Intel(R) Multi-Buffer Crypto for IPsec Library project.
The PKCS7 package code is a fork of the mozilla-services/pkcs7 project (which was archived on February 10, 2024) with commercial cryptography extensions.
The PKCS8 package code is a fork of the youmark/pkcs8 project with commercial cryptography extensions.
Before using this project, please be sure to carefully read the GMSM Software Disclaimer!
If this project is useful to you, please consider giving it a Star.