Chinese National Cryptography (SM2/SM3/SM4/SM9/ZUC): A Developer's Introduction
What "Guomi" (国密) is
Chinese national cryptography (商用密码, "SM" = commercial secrets) is the set of algorithm standards published by the Chinese Cryptography Administration. It is not a new branch of cryptography — the algorithms rest on the same foundations as their international counterparts (elliptic curves, hashes, block ciphers) but are China-designed standards used for cryptographic self-sufficiency and compliance.
What each algorithm does
| Algorithm | Type | International analog | Use | |---|---|---|---| | SM2 | ECC public-key | RSA / ECDSA | signatures, key exchange, public-key encryption | | SM3 | hash | SHA-256 | digests, integrity | | SM4 | block cipher | AES-128 | symmetric encryption | | SM9 | identity-based | IBE | use an identity (email/phone) directly as a public key | | ZUC | stream cipher | Snow 3G / AES-CTR | 4G/5G traffic encryption |
Developers mostly meet the first three (the "SM trio"); SM9 and ZUC serve niches (identity crypto, telecom).
Mapping to international algorithms
signing/encryption: RSA, ECDSA <-> SM2 (256-bit ECC)
digest: SHA-256 <-> SM3 (256-bit output)
symmetric: AES-128 <-> SM4 (128-bit block/key)
protocol suite: TLS-RSA/AES <-> TLCP (ECC-SM4-SM3 ciphersuite)
Strength equivalences (for intuition):
- SM2 256-bit ≈ RSA 3072-bit
- SM3 ≈ SHA-256
- SM4 ≈ AES-128
Who uses it
- Government: e-seals, e-licenses, government cloud (a web of GB/T standards assumes GM)
- Finance: banking core migration, UnionPay standards, digital-currency work
- 等保 2.0 (classified protection) level 3+: the most common driver — commercial cryptography becomes mandatory
- SOEs / critical infrastructure: energy, transport, water
- 密评 (crypto application security assessment): passing requires algorithm compliance
How developers implement it, by layer
Application layer (Java/Go/Node/frontend)
- Java: BouncyCastle (
org.bouncycastle.crypto.engines) or hutool's SmUtil - JS/Node: sm-crypto (pure JS, encrypt/decrypt/sign)
- Go:
github.com/tjfoc/gmssl,github.com/emmansun/gmsm
Protocol layer (GM HTTPS)
Standard OpenSSL lacks GM TLS. Options:
- Tongsuo (formerly BabaSSL): Ant-open-sourced, OpenSSL-compatible syntax, GM TLS 1.3 and dual certificates
- GmSSL: Peking University's fork implementing TLCP (GB/T 38656)
- Dual-certificate mode: SM2 + RSA in parallel, negotiated per client — the transition-period default
Hardware layer
Production key management requires certified crypto products: PCIe crypto cards, UKeys, cloud HSMs (GM editions from cloud vendors). Software implementations are for development and debugging — production signing keys should never leave certified hardware, a hard requirement of the assessment.
Learn by doing with online tools
One round-trip beats ten documentation reads. This site hosts a full GM toolkit (browser-local, nothing uploaded):
- SM2 Encrypt/Sign: generate a keypair → encrypt → decrypt → sign → verify, the complete public-key flow; doubles as a verified counterparty during integration
- SM3 Hash Calculator: reproduce the standard vector (
SM3("abc") = 66c7f0f4...) to rule out encoding issues - SM4 Encrypt/Decrypt: compare ECB/CBC and see ECB's pattern leakage first-hand
Three FAQs
Q: Are GM algorithms actually secure, or "weakened domestic crypto"? SM2/SM3/SM4 designs passed open international review (SM4 is published as IETF RFC 8998); there are no practical attacks. Strength is on par with international equivalents. "GM = weak" is a misconception.
Q: Does my system have to adopt GM? Two signals: 等保 level (3+ almost always means yes) and industry regulator (government/finance/SOE). Consumer internet generally has no mandate.
Q: How big is a migration? Three tiers: algorithm-layer swaps (RSA→SM2 calls) are days; GM TLS (Tongsuo + GM certificates) are weeks; full assessment compliance (hardware + governance) is a months-long program.
Checklist
- Know the trio: SM2 signs/encrypts, SM3 digests, SM4 encrypts symmetrically
- Compliance test: 等保 level 3+ or government/finance → GM required
- Debug integration with online tools before touching the protocol layer
- Production private keys live in certified hardware; software is for development
- GM TLS via Tongsuo/GmSSL with dual certificates for the transition
Provided by ToolVault. Related tools: SM2 Encrypt/Sign, SM3 Hash, SM4 Encrypt/Decrypt. Related reading: SM2 vs RSA, SM3 vs SHA-256. See the homepage for more developer tools.
Related Tools
Related Articles
SM3 vs SHA-256: Comparing the Chinese and NIST Hash Algorithms
SM3 versus SHA-256: same 256-bit digest strength, structural similarities (Merkle-Damgård), the standard test vectors for integration debugging, hardware acceleration differences, when Chinese compliance mandates SM3, and HMAC's algorithm-agnostic construction.
SM2 vs RSA: How to Choose Between Chinese and International Public-Key Crypto
SM2 versus RSA compared: security strength (256-bit SM2 ≈ 3072-bit RSA), performance (signing vs verification tradeoffs), key sizes, the C1C3C2/C1C2C3 ciphertext format pitfall, Chinese compliance requirements, and how to verify with an online SM2 tool.
JWT Decoded Shows "signature invalid" / Verification Failed — Is That Normal?
JWT decoded but shows signature invalid or verification failed? Learn the difference between decode and verify, why it fails, and when you should just read the payload vs. actually verify.