wolfssl-examples/crypto/sm
Aidan Keefe 23c020e186 sm2-ecdh revised 2026-07-29 13:00:17 -06:00
..
Makefile Add SM2/SM3/SM4 examples 2026-07-29 13:38:24 -04:00
README.md Add SM2/SM3/SM4 examples 2026-07-29 13:38:24 -04:00
sm2-ecdh.c sm2-ecdh revised 2026-07-29 13:00:17 -06:00
sm2-sign-verify.c Add SM2/SM3/SM4 examples 2026-07-29 13:38:24 -04:00
sm3-hash.c Add SM2/SM3/SM4 examples 2026-07-29 13:38:24 -04:00
sm4-gcm-encrypt.c Add SM2/SM3/SM4 examples 2026-07-29 13:38:24 -04:00

README.md

wolfSSL SM2/SM3/SM4 Examples

Demonstrates the Chinese national (ShangMi) cryptographic algorithms at the wolfCrypt level:

  • sm3-hash.c - SM3 hash (Chinese national standard GB/T 32905-2016), checked against the standard's "abc" test vector.
  • sm4-gcm-encrypt.c - SM4-GCM (GB/T 32907-2016) authenticated encryption with tamper detection.
  • sm2-sign-verify.c - SM2 (GB/T 32918) digital signatures, including the identity-based "ZA" digest step via wc_ecc_sm2_create_digest().
  • sm2-ecdh.c - ECDH shared-secret agreement on the SM2 curve.

Building wolfSSL

The SM algorithm implementations ship in the separate wolfSSL/wolfsm overlay, so install that into a wolfSSL source tree first:

git clone https://github.com/wolfSSL/wolfsm
git clone https://github.com/wolfSSL/wolfssl
cd wolfsm
./install.sh ../wolfssl
cd ../wolfssl
./autogen.sh
./configure --enable-sm2 --enable-sm3 --enable-sm4-gcm
make
sudo make install

Other SM4 modes are available with --enable-sm4-ecb, --enable-sm4-cbc, --enable-sm4-ctr and --enable-sm4-ccm.

Building and running the examples

make
./sm3-hash [message]
./sm4-gcm-encrypt
./sm2-sign-verify [message]
./sm2-ecdh