So What Is SM2?

Prof Bill Buchanan OBE
2 min readDec 4, 2023


And, so, NIST has defined AES as the standard for symmetric key encryption. But, NIST was pinpointed as possibly pushing a cipher with an NSA backdoor. For companies in China, the ShāngMì (SM) series of ciphers provide one alternative for TLS 1.3 integration and Wireless authentication. With this SM2 defines public key encryption, SM3 defines a hashing function, and SM4 for encryption. Overall, SM4 was developed by Lü Shuwang in 2007 and became a national standard (GB/T 32907–2016) in 2016 [RFC 8998].

In normal elliptic curve signing, we use secp256k1 (as used in Bitcoin and Ethereum) and NIST P-256. So what’s the equivalent for Chinese ciphers? Well, SM2 is a public key method that is defined by the Chinese Commercial Cryptography Administration Office.


With elliptic curve cryptography, we start with a definition for the curve, such as:

y²=x³+ax+b (mod p)

This defines values for a, b and p. Next, we select a base point on the curve (G and generates a random scalar value (D). This is the private key, and where the public key is generated from a point multiplication of


This results in an (x,y) point on the curve.


First we create a folder named “bc_sm02”, and then go into that folder.We can create a Dotnet console project for .NET 8.0 with:

dotnet new console --framework net8.0

Next we can install the Bouncy Castle library with:

dotnet add package BouncyCastle.Crypto.dll --version 1.8.1

We first need to use the “sm2p256v1” curve type:

X9ECParameters x9ECParameters = GMNamedCurves.GetByName("sm2p256v1");

And then generate the key pair with:

ECDomainParameters sm2Parameters = new ECDomainParameters(x9ECParameters.Curve, x9ECParameters.G, x9ECParameters.N);
Org.BouncyCastle.Crypto.Parameters.ECKeyGenerationParameters keygenParams = new Org.BouncyCastle.Crypto.Parameters.ECKeyGenerationParameters (sm2Parameters, new SecureRandom());
Org.BouncyCastle.Crypto.Generators.ECKeyPairGenerator generator = new Org.BouncyCastle.Crypto.Generators.ECKeyPairGenerator();




Prof Bill Buchanan OBE

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.