Skip to content

Commit 99335c8

Browse files
Add Appendix I for wolfSM (ShangMi) documentation
Co-Authored-By: [email protected] <[email protected]>
1 parent 7290234 commit 99335c8

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

wolfSSL/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ APPENDIX= appendix01.md \
2727
appendix05.md \
2828
appendix06.md \
2929
appendix07.md \
30-
appendix08.md
30+
appendix08.md \
31+
appendix09.md
3132

3233
ifeq ($(DOC_LANG),JA)
3334
PDF = wolfSSL-Manual-jp.pdf

wolfSSL/mkdocs-ja.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ nav:
143143
- "F. エラーコード": appendix06.md
144144
- "G. ポスト量子暗号の実験": appendix07.md
145145
- "H. wolfSSL 移植ガイド": appendix08.md
146+
- "I. wolfSM (ShangMi)": appendix09.md
146147
theme:
147148
name: null
148149
custom_dir: ../mkdocs-material/material

wolfSSL/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ nav:
143143
- "F. Error Codes": appendix06.md
144144
- "G. Experimenting with Post-Quantum Cryptography": appendix07.md
145145
- "H. wolfSSL Porting Guide": appendix08.md
146+
- "I. wolfSM (ShangMi)": appendix09.md
146147
theme:
147148
name: null
148149
custom_dir: ../mkdocs-material/material

wolfSSL/src/appendix09.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# wolfSM (ShangMi)
2+
3+
This appendix provides information about the Chinese National Standard's cryptographic algorithms known as ShangMi (SM) in wolfSSL.
4+
5+
wolfSM support includes:
6+
* SM3 - Hash Function
7+
* SM4 - Cipher
8+
* SM2 - ECDH key agreement and a signature scheme using the specified 256-bit elliptic curve.
9+
10+
The code must be installed into wolfSSL in order to be used.
11+
12+
Note that the test and build configuration code is already in wolfSSL.
13+
14+
## Building wolfSM
15+
16+
Once the wolfSM files have been installed into wolfSSL, you can build SM algorithms into wolfSSL.
17+
18+
Choose which algorithms you require on the configure line:
19+
* `--enable-sm3`
20+
* `--enable-sm4-ecb`
21+
* `--enable-sm4-cbc`
22+
* `--enable-sm4-ctr`
23+
* `--enable-sm4-gcm`
24+
* `--enable-sm4-ccm`
25+
* `--enable-sm2`
26+
27+
For example, to include SM3, SM4-GCM and SM2:
28+
29+
```sh
30+
./autogen.sh
31+
./configure --enable-sm3 --enable-sm4-gcm --enable-sm2
32+
make
33+
sudo make install
34+
```
35+
36+
### Optimized SM2
37+
38+
To use optimized implementations of SM2 you can either use C only code or C code with the faster assembly code.
39+
40+
For C code only: `--enable-sp`
41+
For C and assembly code: `--enable-sp --enable-sp-asm`
42+
43+
Optimized C code is available for 32 and 64 bit CPUs.
44+
45+
Assembly code is available for the following platforms:
46+
* Intel x64
47+
* Aarch64
48+
* ARM 32-bit
49+
* ARM Thumb2
50+
* ARM Thumb
51+
52+
## Testing wolfSM
53+
54+
To test that the SM ciphers are working use the following command:
55+
56+
```sh
57+
make test
58+
```
59+
60+
To benchmark the algorithms enabled:
61+
62+
```sh
63+
./wolfcrypt/benchmark/benchmark
64+
```
65+
66+
To benchmark specific algorithms, add to the command line the option/s matching the algorithm/s:
67+
* SM2: `-sm2`
68+
* SM3: `-sm3`
69+
* SM4: `-sm4` or
70+
* SM4-CBC: `-sm4-cbc`
71+
* SM4-GCM: `-sm4-gcm`
72+
* SM4-CCM: `-sm4-ccm`
73+
74+
### Testing TLS
75+
76+
SM ciphers are able to be used with TLSv1.2 and TLSv1.3.
77+
78+
Note: SM2, SM3 and at least one SM4 cipher must be built in order for SM ciphers suite to work. All algorithms must be SM.
79+
80+
The cipher suites added are:
81+
- ECDHE-ECDSA-SM4-CBC-SM3 (TLSv1.2, `--enable-sm2 --enable-sm3 --enable-sm4-cbc`)
82+
- ECDHE-ECDSA-SM4-GCM-SM3 (TLSv1.2, `--enable-sm2 --enable-sm3 --enable-sm4-gcm`)
83+
- ECDHE-ECDSA-SM4-CCM-SM3 (TLSv1.2, `--enable-sm2 --enable-sm3 --enable-sm4-ccm`)
84+
- TLS13-SM4-GCM-SM3 (TLSv1.3, `--enable-sm2 --enable-sm3 --enable-sm4-gcm`)
85+
- TLS13-SM4-CCM-SM3 (TLSv1.3, `--enable-sm2 --enable-sm3 --enable-sm4-ccm`)
86+
87+
#### Example of using SM cipher suites with TLSv1.2
88+
89+
An example of testing TLSv1.2 with "ECDHE-ECDSA-SM4-CBC-SM3" cipher suite:
90+
91+
```sh
92+
./examples/server/server -v 3 -l ECDHE-ECDSA-SM4-CBC-SM3 \
93+
-c ./certs/sm2/server-sm2.pem -k ./certs/sm2/server-sm2-priv.pem \
94+
-A ./certs/sm2/client-sm2.pem -V &
95+
./examples/client/client -v 3 -l ECDHE-ECDSA-SM4-CBC-SM3 \
96+
-c ./certs/sm2/client-sm2.pem -k ./certs/sm2/client-sm2-priv.pem \
97+
-A ./certs/sm2/root-sm2.pem -C
98+
```
99+
100+
The output using the commands above will be:
101+
102+
```
103+
SSL version is TLSv1.2
104+
SSL cipher suite is TLS_ECDHE_ECDSA_WITH_SM4_CBC_SM3
105+
SSL curve name is SM2P256V1
106+
SSL version is TLSv1.2
107+
SSL cipher suite is TLS_ECDHE_ECDSA_WITH_SM4_CBC_SM3
108+
SSL curve name is SM2P256V1
109+
Client message: hello wolfssl!
110+
I hear you fa shizzle!
111+
```
112+
113+
#### Example of using SM cipher suites with TLSv1.3
114+
115+
An example of testing TLSv1.3 with "TLS13-SM4-GCM-SM3" cipher suite:
116+
117+
```sh
118+
./examples/server/server -v 4 -l TLS13-SM4-GCM-SM3 \
119+
-c ./certs/sm2/server-sm2.pem -k ./certs/sm2/server-sm2-priv.pem \
120+
-A ./certs/sm2/client-sm2.pem -V &
121+
./examples/client/client -v 4 -l TLS13-SM4-GCM-SM3 \
122+
-c ./certs/sm2/client-sm2.pem -k ./certs/sm2/client-sm2-priv.pem \
123+
-A ./certs/sm2/root-sm2.pem -C
124+
```
125+
126+
The output using the commands above will be:
127+
128+
```
129+
SSL version is TLSv1.3
130+
SSL cipher suite is TLS_SM4_GCM_SM3
131+
SSL curve name is SM2P256V1
132+
SSL version is TLSv1.3
133+
SSL cipher suite is TLS_SM4_GCM_SM3
134+
SSL curve name is SM2P256V1
135+
Client message: hello wolfssl!
136+
I hear you fa shizzle!
137+
```

0 commit comments

Comments
 (0)