{"id":970,"date":"2023-12-09T10:38:09","date_gmt":"2023-12-09T05:08:09","guid":{"rendered":"https:\/\/nocturnalknight.co\/?p=970"},"modified":"2023-12-09T10:38:09","modified_gmt":"2023-12-09T05:08:09","slug":"what-makes-sm2-encryption-special-chinas-recommended-algorithm","status":"publish","type":"post","link":"http:\/\/3.10.118.248\/?p=970","title":{"rendered":"What Makes SM2 Encryption Special? China&#8217;s Recommended Algorithm"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><em>This article is intended for security enthusiast<\/em>s<em> or otherwise for people with an advanced understanding of Cryptography<\/em> <em>and some Programming.<\/em> <em>I have tried to give in some background theory a very basic implementation.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Are there backdoors in AES and what is China&#8217;s response to it?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The US NIST has been pushing AES as the standard for <strong>symmetric key encryption<\/strong>. However, many luminaries in cryptographic research and industry observers suspect that as possibly pushing a cipher with an <a href=\"https:\/\/en.wikipedia.org\/wiki\/National_Security_Agency\" target=\"_blank\" rel=\"noopener\" title=\"\">NSA<\/a>\/ <a href=\"https:\/\/en.wikipedia.org\/wiki\/GCHQ\" target=\"_blank\" rel=\"noopener\" title=\"\">GCHQ<\/a> backdoor. For Chinese entities (Government or commercial), the Sh\u0101ngM\u00ec (SM) series of ciphers provide alternatives. The SM9 standards provide a family of algorithms which will perform the entire gamut of things that RSA or AES is expected to do. They include the following.  <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/draft-shen-sm2-ecdsa-02\" target=\"_blank\" rel=\"noreferrer noopener\">SM2<\/a>\u00a0provides signature and verification based on\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Elliptic-curve_cryptography\" target=\"_blank\" rel=\"noreferrer noopener\">Elliptic Curve Cryptography (ECC)<\/a>\u00a0<\/li>\n\n\n\n<li><a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/draft-oscca-cfrg-sm3-02\" target=\"_blank\" rel=\"noreferrer noopener\">SM3<\/a>\u00a0is a hashing algorithm (Alternative to <a href=\"https:\/\/csrc.nist.rip\/groups\/ST\/toolkit\/BCM\/documents\/proposedmodes\/aes-hash\/aeshash.pdf\" target=\"_blank\" rel=\"noopener\" title=\"\">AES Hash<\/a>)<\/li>\n\n\n\n<li><a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/draft-ribose-cfrg-sm4-10\" target=\"_blank\" rel=\"noreferrer noopener\">SM4<\/a>&nbsp;is a set of encryption\/decryption block-cipher algorithms<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><em> SM4 was developed by L\u00fc Shuwang in 2007 and became a national standard (GB\/T 32907\u20132016) in 2016 [<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc8998\" target=\"_blank\" rel=\"noopener\" title=\"\">RFC 8998<\/a>].<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"elliptic-curve-cryptography\">Elliptic Curve Cryptography (ECC)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">ECC is one of the most prevalent approaches to\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Public-key_cryptography\" target=\"_blank\" rel=\"noreferrer noopener\">public-key cryptography<\/a>, along with <a href=\"https:\/\/en.wikipedia.org\/wiki\/Diffie%E2%80%93Hellman_key_exchange\" target=\"_blank\" rel=\"noopener\" title=\"\">Diffie\u2013Hellman<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/RSA_(cryptosystem)\" target=\"_blank\" rel=\"noopener\" title=\"\">RSA<\/a> &amp; <a href=\"https:\/\/en.wikipedia.org\/wiki\/YAK_(cryptography)\" target=\"_blank\" rel=\"noopener\" title=\"\">YAK<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"public-key-cryptography\">Public-key Cryptography<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Public-key cryptography relies on the generation of two keys:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>one private key which&nbsp;<strong>must remain private<\/strong><\/li>\n\n\n\n<li>one public key which can be shared with the world<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">It is impossible to know a private key from a public key (it takes more than centuries to compute &#8211; assuming a workable quantum computer is infeasible using existing material science). It is possible to prove the possession of a private key without disclosing it. This proof can be verified by using its corresponding public key. <strong>This proof is called a digital signature.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"high-level-functions\">High-level Functions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">ECC can perform signature and verification of messages (authenticity). ECC can also perform encryption and decryption (confidentiality), however, not directly. For encryption\/decryption, it needs the help of a shared secret aka Key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It achieves the same level of security as RSA (Rivest-Shamir-Adleman), the traditional public-key algorithm, using substantially shorter key sizes. This reduction translates into lower processing requirements and reduced storage demands. For instance, an ECC 256-bit key provides comparable security to an RSA 3072-bit key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For brevity&#8217;s sake, I&#8217;d refer you to <a href=\"https:\/\/hackernoon.com\/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3\" target=\"_blank\" rel=\"noreferrer noopener\">Hans Knutson&#8217;s very well-explained article on Hacker Noon<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Theory Summary: A Look Inside SM2 Key Generation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This section aims to offer a simplified understanding of different parameters found in SM2 libraries and their corresponding meanings, drawing inspiration from the insightful guides by Hans Knutson on Hacker Noon and Svetlin Nakov&#8217;s CryptoBook. (links in the reference section)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Comparing RSA and ECC Key Generation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>RSA:<\/strong>\u00a0Based on prime number factorization.\n<ul class=\"wp-block-list\">\n<li>Private key:&nbsp;Composed of two large prime numbers (p and q).<\/li>\n\n\n\n<li>Public key:&nbsp;Modulus (m) obtained by multiplying p and q (m = p * q).<\/li>\n\n\n\n<li>Key size:&nbsp;Determined by the number of bits in modulus (m).<\/li>\n\n\n\n<li>Difficulty:&nbsp;Decomposing m back into p and q is computationally intensive.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>ECC:<\/strong>\u00a0Leverages the discrete logarithm of elliptic curve elements.\n<ul class=\"wp-block-list\">\n<li>Elliptic curve:&nbsp;Defined as the set of points (x,&nbsp;y) satisfying the equation y^2 = x^3 + ax + b.<\/li>\n\n\n\n<li>Example:&nbsp;Bitcoin uses the curve secp256k1 with the equation y^2 = x^3 + 7.<\/li>\n\n\n\n<li>Point addition:&nbsp;Defined operation on points of the curve.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Key Generation in SM2:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Domain parameters:<\/strong>\n<ul class=\"wp-block-list\">\n<li>A prime field p of 256 bits.<\/li>\n\n\n\n<li>An elliptic curve E defined within the field p.<\/li>\n\n\n\n<li>A base point G on the curve E.<\/li>\n\n\n\n<li>Order n of G,&nbsp;representing the number of points in the subgroup generated by G.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Private key:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Randomly chosen integer d (1 &lt; d &lt; n).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Public key:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Point Q = d * G.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Understanding Parameters:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Prime field p:<\/strong>&nbsp;Defines the mathematical space where the curve operates.<\/li>\n\n\n\n<li><strong>Elliptic curve E:<\/strong>&nbsp;Provides a structure for performing cryptographic operations.<\/li>\n\n\n\n<li><strong>Base point G:<\/strong>&nbsp;Serves as a starting point for generating other points on the curve.<\/li>\n\n\n\n<li><strong>Order n:<\/strong>&nbsp;Represents the number of points in the subgroup generated by G,&nbsp;which dictates the security level of the scheme.<\/li>\n\n\n\n<li><strong>Private key d:<\/strong>&nbsp;Secret integer randomly chosen within a specific range.<\/li>\n\n\n\n<li><strong>Public key Q:<\/strong>&nbsp;Point obtained by multiplying the private key d with the base point G.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Visualization:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine a garden with flowers planted on specific points (x, y) satisfying a unique equation. This garden represents the elliptic curve E. You have a special key (d) that allows you to move around the garden and reach a specific flower (Q) using a defined path. Each step on this path is determined by the base point G. While anyone can see the flower (Q), only you have the knowledge of the path (d) leading to it, thus maintaining confidentiality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This analogy provides a simplified picture of key generation in SM2, illustrating the interplay between different parameters and their cryptographic significance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Diving Deeper into SM2\/SM3\/SM4 Integration with Golang<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This section focuses on the integration of the Chinese cryptographic standards SM2, SM3, and SM4 into Golang applications. It details the process of porting Java code to Golang and the specific challenges encountered.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Open-Source Implementations:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>GmSSL:<\/strong>&nbsp;Main open-source implementation of SM2\/SM3\/SM4,&nbsp;stands for &#8220;Guomi.&#8221;<\/li>\n\n\n\n<li><strong>Other implementations:<\/strong>&nbsp;gmsm (Golang),&nbsp;gmssl (Python),&nbsp;CFCA SADK (Java).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Porting Java Code to Golang:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Goal:<\/strong>&nbsp;Reverse-engineer the usage of CFCA SADK in Java code and adapt the corresponding functionality in Golang using gmsm.<\/li>\n\n\n\n<li><strong>Approach:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Hashing (SM3) and encryption (SM4) algorithms were directly ported using equivalent functions across languages.<\/li>\n\n\n\n<li>Security operations added to a classic REST API POST required specific attention.<\/li>\n\n\n\n<li><strong>Step 1:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Original parameters are concatenated in alphabetical order.<\/li>\n\n\n\n<li>API key is appended.<\/li>\n\n\n\n<li>The combined string is hashed using SM3.<\/li>\n\n\n\n<li>The resulting hash is added as an additional POST parameter.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Step 2:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Original parameters are concatenated in alphabetical order.<\/li>\n\n\n\n<li>The signature is generated using SM2.<\/li>\n\n\n\n<li><strong>Challenge:<\/strong>&nbsp;Golang library lacked PKCS7 formatting support for signatures,&nbsp;only supporting American standards.<\/li>\n\n\n\n<li><strong>Solution:<\/strong>&nbsp;Modification of the Golang library to support PKCS7 formatting for SM2 signatures.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Response Processing:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Response body is encrypted using SM4 with a key derived from the API key.<\/li>\n\n\n\n<li>Response body includes both an SM3 hash and SM2 signature for verification.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Key Takeaways:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Porting cryptographic algorithms across languages requires careful consideration of specific functionalities.<\/li>\n\n\n\n<li>Lack of standard support for specific formats (PKCS7 in this case) might necessitate library modification.<\/li>\n\n\n\n<li>Integrating SM2\/SM3\/SM4 in Golang requires utilizing libraries like gmsm and potentially adapting them for specific needs.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Getting your Hands Dirty<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go to <a href=\"https:\/\/github.com\/guanzhi\/GmSSL\/releases\" target=\"_blank\" rel=\"noopener\" title=\"\">https:\/\/github.com\/guanzhi\/GmSSL\/releases<\/a> download the version for your OS and move to your working directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1 - $ unzip or tar -xvf GmSSL-master.zip\/tar\n2 - $ mkdir build\n    $ cd build\n    $ cmake ..\n    $ make\n    $ make test\n    $ sudo make install\n3 - $ gmssl version\n    $ GmSSL 3.1.0 Dev\n4 -\n$ KEY=11223344556677881122334455667788\n$ IV=11223344556677881122334455667788\n\n$ echo hello | gmssl sm4 -cbc -encrypt -key $KEY -iv $IV -out sm4.cbc\n$ gmssl sm4 -cbc -decrypt -key $KEY -iv $IV -in sm4.cbc\n\n$ echo hello | gmssl sm4 -ctr -encrypt -key $KEY -iv $IV -out sm4.ctr\n$ gmssl sm4 -ctr -decrypt -key $KEY -iv $IV -in sm4.ctr\n\n$ echo -n abc | gmssl sm3\n$ gmssl sm2keygen -pass 1234 -out sm2.pem -pubout sm2pub.pem\n$ echo -n abc | gmssl sm3 -pubkey sm2pub.pem -id 1234567812345678\n$ echo -n abc | gmssl sm3hmac -key 11223344556677881122334455667788\n\n$ gmssl sm2keygen -pass 1234 -out sm2.pem -pubout sm2pub.pem\n\n$ echo hello | gmssl sm2sign -key sm2.pem -pass 1234 -out sm2.sig #-id 1234567812345678\n$ echo hello | gmssl sm2verify -pubkey sm2pub.pem -sig sm2.sig -id 1234567812345678\n\n$ echo hello | gmssl sm2encrypt -pubkey sm2pub.pem -out sm2.der\n$ gmssl sm2decrypt -key sm2.pem -pass 1234 -in sm2.der\n\n$ gmssl sm2keygen -pass 1234 -out sm2.pem -pubout sm2pub.pem\n\n$ echo hello | gmssl sm2encrypt -pubkey sm2pub.pem -out sm2.der\n$ gmssl sm2decrypt -key sm2.pem -pass 1234 -in sm2.der\n\n$ gmssl sm2keygen -pass 1234 -out rootcakey.pem\n$ gmssl certgen -C CN -ST Beijing -L Haidian -O PKU -OU CS -CN ROOTCA -days 3650 -key rootcakey.pem -pass 1234 -out rootcacert.pem -key_usage keyCertSign -key_usage cRLSign\n$ gmssl certparse -in rootcacert.pem\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-get-keys\">How to Get Keys<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The private key used for SM2 signing was provided to us, along with a passphrase for testing purposes. Of course, in production systems, the private key is generated and kept private. The file extension is .sm2; the first step was to make use of it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It can be parsed with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ openssl asn1parse -in file.sm2\n\n    0:d=0  hl=4 l= 802 cons: SEQUENCE\n    4:d=1  hl=2 l=   1 prim: INTEGER           :01\n    7:d=1  hl=2 l=  71 cons: SEQUENCE\n    9:d=2  hl=2 l=  10 prim: OBJECT            :1.2.156.10197.6.1.4.2.1\n   21:d=2  hl=2 l=   7 prim: OBJECT            :1.2.156.10197.1.104\n   30:d=2  hl=2 l=  48 prim: OCTET STRING      &#91;HEX DUMP]:8&#91;redacted]7\n   80:d=1  hl=4 l= 722 cons: SEQUENCE\n   84:d=2  hl=2 l=  10 prim: OBJECT            :1.2.156.10197.6.1.4.2.1\n   96:d=2  hl=4 l= 706 prim: OCTET STRING      &#91;HEX DUMP]:308&#91;redacted]249<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The OID 1.2.156.10197.1.104 means&nbsp;<a href=\"http:\/\/gmssl.org\/docs\/oid.html\" target=\"_blank\" rel=\"noreferrer noopener\">SM4 Block Cipher<\/a>. The OID 1.2.156.10197.6.1.4.2.1 simply means&nbsp;<a href=\"https:\/\/blog.csdn.net\/u012107052\/article\/details\/53082530\" target=\"_blank\" rel=\"noreferrer noopener\">data<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">.sm2 files are an ASN.1 structure encoded in DER and&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Base64\" target=\"_blank\" rel=\"noreferrer noopener\">base64<\/a>-ed. The ASN.1 structure contains (int, seq1, seq2). Seq1 contains the SM4-encrypted SM2 private key x. Seq2 contains the x509 cert of the corresponding SM2 public key (ECC coordinates (x,y) of the point X). From the private key x, it is also possible to get X=x\u2022P.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The x509 certificate is\u00a0<a href=\"https:\/\/www.cfca.com.cn\/upload\/CFCACPS20171117.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">signed by CFCA<\/a>, and the signature algorithm 1.2.156.10197.1.501 means\u00a0<a href=\"http:\/\/gmssl.org\/docs\/oid.html\" target=\"_blank\" rel=\"noreferrer noopener\">SM2 Signing with SM3<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-to-sign\">How to Sign with SM2<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now that the private key x is known, it is possible to use it to sign the concatenation of parameters and return the PKCS7 format expected.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a reminder, ECC Digital Signature Algorithm takes a random number k. This is why it is important to add a random generator to the signing function. It is also difficult to troubleshoot: signing the same message twice will provide different outputs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The signature will return two integers, r and s, as defined previously.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The format returned is PKCS7, which is structured with ASN.1. The&nbsp;<a href=\"https:\/\/github.com\/lapo-luchini\/asn1js\" target=\"_blank\" rel=\"noreferrer noopener\">asn1js<\/a>&nbsp;tool is perfect for reading and comparing ASN.1 structures. For maximum privacy, it should be cloned and used locally.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The ASN.1 structure of the signature will follow:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The algorithm used as hash, namely 1.2.156.10197.1.401 (sm3Hash)<\/li>\n\n\n\n<li>The data that is signed, with OID 1.2.156.10197.6.1.4.2.1 (data)<\/li>\n\n\n\n<li>A sequence of the x509 certificates corresponding to the private keys used to sign (we can sign with multiple keys)<\/li>\n\n\n\n<li>A set of the digital signatures for all the keys\/certificates signing. Each signature is a sequence of the corresponding certificate information (countryName, organizationName, commonName) and finally the two integer r and s, in hexadecimal representation <\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To generate such signature, the Golang equivalent is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import (\n\t\"math\/big\"\n\t\"encoding\/hex\"\n\t\"encoding\/base64\"\n\t\"crypto\/rand\"\n\t\"github.com\/tjfoc\/gmsm\/sm2\"\n\t\"github.com\/pgaulon\/gmsm\/x509\" \/\/ modified PKCS7\n)\n\n&#91;...]\n\n\tPRIVATE, _ := hex.DecodeString(\"somehexhere\")\n\tPUBLICX, _ := hex.DecodeString(\"6de24a97f67c0c8424d993f42854f9003bde6997ed8726335f8d300c34be8321\")\n\tPUBLICY, _ := hex.DecodeString(\"b177aeb12930141f02aed9f97b70b5a7c82a63d294787a15a6944b591ae74469\")\n\n\tpriv := new(sm2.PrivateKey)\n\tpriv.D = new(big.Int).SetBytes(PRIVATE)\n\tpriv.PublicKey.X = new(big.Int).SetBytes(PUBLICX)\n\tpriv.PublicKey.Y = new(big.Int).SetBytes(PUBLICY)\n\tpriv.PublicKey.Curve = sm2.P256Sm2()\n\n\tcert := getCertFromSM2(sm2CertPath) \/\/ utility to provision a x509 object from the .sm2 file data\n\tsign, _ := priv.Sign(rand.Reader, &#91;]byte(toSign), nil)\n\tsignedData, _ := x509.NewSignedData(&#91;]byte(toSign))\n\tsignerInfoConf := x509.SignerInfoConfig{}\n\tsignedData.AddSigner(cert, priv, signerInfoConf, sign)\n\tpkcs7SignedBytes, _ := signedData.Finish()\n\treturn base64.StdEncoding.EncodeToString(pkcs7SignedBytes)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Key Takeaways: Demystifying SM2 Cryptography<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>SM2 relies on Elliptic Curve Cryptography (ECC):<\/strong>&nbsp;This advanced mathematical method provides superior security compared to traditional RSA algorithms.<\/li>\n\n\n\n<li><strong>ECC keys are unique:<\/strong>&nbsp;The public key is a point reached by repeatedly adding the base point to itself a specific number of times.&nbsp;This number acts as the private key and remains secret.<\/li>\n\n\n\n<li><strong>ECC signatures are dynamic:<\/strong>&nbsp;Unlike static signatures,&nbsp;ECC signatures use a random element,&nbsp;ensuring they vary even for the same message.&nbsp;Each signature consists of two unique values (r and s).<\/li>\n\n\n\n<li><strong>Troubleshooting tools:<\/strong>&nbsp;ASN.1 issues can be tackled with asn1js,&nbsp;while Java problems can be identified using jdb and jd-gui.<\/li>\n\n\n\n<li><strong>Cryptography requires expertise:<\/strong>\u00a0Understanding and implementing cryptographic algorithms like SM2 demands specialized knowledge and careful attention.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">References &amp; Further Reading:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/cryptobook.nakov.com\/asymmetric-key-ciphers\/elliptic-curve-cryptography-ecc\">Elliptic Curve Cryptography (ECC)<\/a>&nbsp;<\/li>\n\n\n\n<li><a href=\"https:\/\/hackernoon.com\/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3\">What is the math behind elliptic curve cryptography? | HackerNoon<\/a>&nbsp;<\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/guanzhi\/GmSSL\/releases\">Releases \u00b7 guanzhi\/GmSSL<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China&#8217;s response to it? The US NIST has been pushing AES as the standard &hellip; <\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"http:\/\/3.10.118.248\/?p=970\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[25,186,62,65,81],"tags":[],"class_list":["post-970","post","type-post","status-publish","format-standard","hentry","category-china","category-cryptography","category-geopolitics","category-golang","category-information-security"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China&#039;s response to it? The US NIST has been pushing AES as the standard\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Ramkumar Sundarakalatharan\"\/>\n\t<link rel=\"canonical\" href=\"http:\/\/3.10.118.248\/?p=970\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_GB\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Nocturnalknight&#039;s Lair - Observations of a Random Wanderer!\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"What Makes SM2 Encryption Special? China\u2019s Recommended Algorithm - Nocturnalknight&#039;s Lair\" \/>\n\t\t<meta property=\"og:description\" content=\"This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China&#039;s response to it? The US NIST has been pushing AES as the standard\" \/>\n\t\t<meta property=\"og:url\" content=\"http:\/\/3.10.118.248\/?p=970\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2023-12-09T05:08:09+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2023-12-09T05:08:09+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@nocturnalknight\" \/>\n\t\t<meta name=\"twitter:title\" content=\"What Makes SM2 Encryption Special? China\u2019s Recommended Algorithm - Nocturnalknight&#039;s Lair\" \/>\n\t\t<meta name=\"twitter:description\" content=\"This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China&#039;s response to it? The US NIST has been pushing AES as the standard\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@nocturnalknight\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#blogposting\",\"name\":\"What Makes SM2 Encryption Special? China\\u2019s Recommended Algorithm - Nocturnalknight's Lair\",\"headline\":\"What Makes SM2 Encryption Special? China&#8217;s Recommended Algorithm\",\"author\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?author=2#author\"},\"publisher\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"http:\\\/\\\/3.10.118.248\\\/wp-content\\\/uploads\\\/2026\\\/08\\\/cropped-Ram-Profile.avif\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/#articleImage\"},\"datePublished\":\"2023-12-09T10:38:09+00:00\",\"dateModified\":\"2023-12-09T10:38:09+00:00\",\"inLanguage\":\"en-GB\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#webpage\"},\"isPartOf\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#webpage\"},\"articleSection\":\"china, cryptography, geopolitics, golang, Information Security\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/3.10.118.248\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?cat=81#listItem\",\"name\":\"Information Security\"}},{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?cat=81#listItem\",\"position\":2,\"name\":\"Information Security\",\"item\":\"http:\\\/\\\/3.10.118.248\\\/?cat=81\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?cat=186#listItem\",\"name\":\"cryptography\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?cat=186#listItem\",\"position\":3,\"name\":\"cryptography\",\"item\":\"http:\\\/\\\/3.10.118.248\\\/?cat=186\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#listItem\",\"name\":\"What Makes SM2 Encryption Special? China&#8217;s Recommended Algorithm\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?cat=81#listItem\",\"name\":\"Information Security\"}},{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#listItem\",\"position\":4,\"name\":\"What Makes SM2 Encryption Special? China&#8217;s Recommended Algorithm\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?cat=186#listItem\",\"name\":\"cryptography\"}}]},{\"@type\":\"Organization\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/#organization\",\"name\":\"Nocturnalknight's Lair\",\"description\":\"Observations of a Random Wanderer!\",\"url\":\"http:\\\/\\\/3.10.118.248\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"http:\\\/\\\/3.10.118.248\\\/wp-content\\\/uploads\\\/2026\\\/08\\\/cropped-Ram-Profile.avif\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970\\\/#organizationLogo\"},\"image\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970\\\/#organizationLogo\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/nocturnalknight\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/nocturnalknight\\\/\"]},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?author=2#author\",\"url\":\"http:\\\/\\\/3.10.118.248\\\/?author=2\",\"name\":\"Ramkumar Sundarakalatharan\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/818bc4a4d5681de6957f83aca2601d598459bf37a0a8b17d5abb1a889e2b9298?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Ramkumar Sundarakalatharan\"}},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#webpage\",\"url\":\"http:\\\/\\\/3.10.118.248\\\/?p=970\",\"name\":\"What Makes SM2 Encryption Special? China\\u2019s Recommended Algorithm - Nocturnalknight's Lair\",\"description\":\"This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China's response to it? The US NIST has been pushing AES as the standard\",\"inLanguage\":\"en-GB\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/#website\"},\"breadcrumb\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?p=970#breadcrumblist\"},\"author\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?author=2#author\"},\"creator\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/?author=2#author\"},\"datePublished\":\"2023-12-09T10:38:09+00:00\",\"dateModified\":\"2023-12-09T10:38:09+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/3.10.118.248\\\/#website\",\"url\":\"http:\\\/\\\/3.10.118.248\\\/\",\"name\":\"Nocturnalknight's Lair\",\"description\":\"Observations of a Random Wanderer!\",\"inLanguage\":\"en-GB\",\"publisher\":{\"@id\":\"http:\\\/\\\/3.10.118.248\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"What Makes SM2 Encryption Special? China\u2019s Recommended Algorithm - Nocturnalknight's Lair","description":"This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China's response to it? The US NIST has been pushing AES as the standard","canonical_url":"http:\/\/3.10.118.248\/?p=970","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"http:\/\/3.10.118.248\/?p=970#blogposting","name":"What Makes SM2 Encryption Special? China\u2019s Recommended Algorithm - Nocturnalknight's Lair","headline":"What Makes SM2 Encryption Special? China&#8217;s Recommended Algorithm","author":{"@id":"http:\/\/3.10.118.248\/?author=2#author"},"publisher":{"@id":"http:\/\/3.10.118.248\/#organization"},"image":{"@type":"ImageObject","url":"http:\/\/3.10.118.248\/wp-content\/uploads\/2026\/08\/cropped-Ram-Profile.avif","@id":"http:\/\/3.10.118.248\/#articleImage"},"datePublished":"2023-12-09T10:38:09+00:00","dateModified":"2023-12-09T10:38:09+00:00","inLanguage":"en-GB","mainEntityOfPage":{"@id":"http:\/\/3.10.118.248\/?p=970#webpage"},"isPartOf":{"@id":"http:\/\/3.10.118.248\/?p=970#webpage"},"articleSection":"china, cryptography, geopolitics, golang, Information Security"},{"@type":"BreadcrumbList","@id":"http:\/\/3.10.118.248\/?p=970#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"http:\/\/3.10.118.248#listItem","position":1,"name":"Home","item":"http:\/\/3.10.118.248","nextItem":{"@type":"ListItem","@id":"http:\/\/3.10.118.248\/?cat=81#listItem","name":"Information Security"}},{"@type":"ListItem","@id":"http:\/\/3.10.118.248\/?cat=81#listItem","position":2,"name":"Information Security","item":"http:\/\/3.10.118.248\/?cat=81","nextItem":{"@type":"ListItem","@id":"http:\/\/3.10.118.248\/?cat=186#listItem","name":"cryptography"},"previousItem":{"@type":"ListItem","@id":"http:\/\/3.10.118.248#listItem","name":"Home"}},{"@type":"ListItem","@id":"http:\/\/3.10.118.248\/?cat=186#listItem","position":3,"name":"cryptography","item":"http:\/\/3.10.118.248\/?cat=186","nextItem":{"@type":"ListItem","@id":"http:\/\/3.10.118.248\/?p=970#listItem","name":"What Makes SM2 Encryption Special? China&#8217;s Recommended Algorithm"},"previousItem":{"@type":"ListItem","@id":"http:\/\/3.10.118.248\/?cat=81#listItem","name":"Information Security"}},{"@type":"ListItem","@id":"http:\/\/3.10.118.248\/?p=970#listItem","position":4,"name":"What Makes SM2 Encryption Special? China&#8217;s Recommended Algorithm","previousItem":{"@type":"ListItem","@id":"http:\/\/3.10.118.248\/?cat=186#listItem","name":"cryptography"}}]},{"@type":"Organization","@id":"http:\/\/3.10.118.248\/#organization","name":"Nocturnalknight's Lair","description":"Observations of a Random Wanderer!","url":"http:\/\/3.10.118.248\/","logo":{"@type":"ImageObject","url":"http:\/\/3.10.118.248\/wp-content\/uploads\/2026\/08\/cropped-Ram-Profile.avif","@id":"http:\/\/3.10.118.248\/?p=970\/#organizationLogo"},"image":{"@id":"http:\/\/3.10.118.248\/?p=970\/#organizationLogo"},"sameAs":["https:\/\/x.com\/nocturnalknight","https:\/\/www.linkedin.com\/in\/nocturnalknight\/"]},{"@type":"Person","@id":"http:\/\/3.10.118.248\/?author=2#author","url":"http:\/\/3.10.118.248\/?author=2","name":"Ramkumar Sundarakalatharan","image":{"@type":"ImageObject","@id":"http:\/\/3.10.118.248\/?p=970#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/818bc4a4d5681de6957f83aca2601d598459bf37a0a8b17d5abb1a889e2b9298?s=96&d=mm&r=g","width":96,"height":96,"caption":"Ramkumar Sundarakalatharan"}},{"@type":"WebPage","@id":"http:\/\/3.10.118.248\/?p=970#webpage","url":"http:\/\/3.10.118.248\/?p=970","name":"What Makes SM2 Encryption Special? China\u2019s Recommended Algorithm - Nocturnalknight's Lair","description":"This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China's response to it? The US NIST has been pushing AES as the standard","inLanguage":"en-GB","isPartOf":{"@id":"http:\/\/3.10.118.248\/#website"},"breadcrumb":{"@id":"http:\/\/3.10.118.248\/?p=970#breadcrumblist"},"author":{"@id":"http:\/\/3.10.118.248\/?author=2#author"},"creator":{"@id":"http:\/\/3.10.118.248\/?author=2#author"},"datePublished":"2023-12-09T10:38:09+00:00","dateModified":"2023-12-09T10:38:09+00:00"},{"@type":"WebSite","@id":"http:\/\/3.10.118.248\/#website","url":"http:\/\/3.10.118.248\/","name":"Nocturnalknight's Lair","description":"Observations of a Random Wanderer!","inLanguage":"en-GB","publisher":{"@id":"http:\/\/3.10.118.248\/#organization"}}]},"og:locale":"en_GB","og:site_name":"Nocturnalknight's Lair - Observations of a Random Wanderer!","og:type":"article","og:title":"What Makes SM2 Encryption Special? China\u2019s Recommended Algorithm - Nocturnalknight's Lair","og:description":"This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China's response to it? The US NIST has been pushing AES as the standard","og:url":"http:\/\/3.10.118.248\/?p=970","article:published_time":"2023-12-09T05:08:09+00:00","article:modified_time":"2023-12-09T05:08:09+00:00","twitter:card":"summary_large_image","twitter:site":"@nocturnalknight","twitter:title":"What Makes SM2 Encryption Special? China\u2019s Recommended Algorithm - Nocturnalknight's Lair","twitter:description":"This article is intended for security enthusiasts or otherwise for people with an advanced understanding of Cryptography and some Programming. I have tried to give in some background theory a very basic implementation. Are there backdoors in AES and what is China's response to it? The US NIST has been pushing AES as the standard","twitter:creator":"@nocturnalknight"},"aioseo_meta_data":{"post_id":"970","title":null,"description":null,"keywords":null,"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-08-19 11:53:11","updated":"2026-08-19 11:53:11"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"http:\/\/3.10.118.248\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"http:\/\/3.10.118.248\/?cat=81\" title=\"Information Security\">Information Security<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"http:\/\/3.10.118.248\/?cat=186\" title=\"cryptography\">cryptography<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tWhat Makes SM2 Encryption Special? China\u2019s Recommended Algorithm\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"http:\/\/3.10.118.248"},{"label":"Information Security","link":"http:\/\/3.10.118.248\/?cat=81"},{"label":"cryptography","link":"http:\/\/3.10.118.248\/?cat=186"},{"label":"What Makes SM2 Encryption Special? China&#8217;s Recommended Algorithm","link":"http:\/\/3.10.118.248\/?p=970"}],"amp_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/3.10.118.248\/index.php?rest_route=\/wp\/v2\/posts\/970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/3.10.118.248\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/3.10.118.248\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/3.10.118.248\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/3.10.118.248\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=970"}],"version-history":[{"count":0,"href":"http:\/\/3.10.118.248\/index.php?rest_route=\/wp\/v2\/posts\/970\/revisions"}],"wp:attachment":[{"href":"http:\/\/3.10.118.248\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/3.10.118.248\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=970"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/3.10.118.248\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}