Skip to content

Commit a77feb2

Browse files
committed
Update tools help
1 parent e43f9e3 commit a77feb2

25 files changed

Lines changed: 256 additions & 217 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ endif()
10261026
#
10271027
set(CPACK_PACKAGE_NAME "GmSSL")
10281028
set(CPACK_PACKAGE_VENDOR "GmSSL develop team")
1029-
set(CPACK_PACKAGE_VERSION "3.3.0-dev.1173")
1029+
set(CPACK_PACKAGE_VERSION "3.3.0-dev.1174")
10301030
set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/README.md)
10311031
set(CPACK_NSIS_MODIFY_PATH ON)
10321032
include(CPack)

cmake/tool_helpers.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ function(gmssl_run_capture out_var)
2525
set(${out_var} "${TEST_STDOUT}" PARENT_SCOPE)
2626
endfunction()
2727

28+
function(gmssl_expect_fail)
29+
execute_process(
30+
COMMAND ${GMSSL_BIN} ${ARGN}
31+
RESULT_VARIABLE TEST_RESULT
32+
ERROR_VARIABLE TEST_STDERR
33+
OUTPUT_VARIABLE TEST_STDOUT
34+
)
35+
if(TEST_RESULT EQUAL 0)
36+
message(FATAL_ERROR "command unexpectedly succeeded: ${GMSSL_BIN} ${ARGN}\nstderr: ${TEST_STDERR}\nstdout: ${TEST_STDOUT}")
37+
endif()
38+
endfunction()
39+
2840
function(gmssl_expect_stdout expected)
2941
gmssl_run_capture(TEST_STDOUT ${ARGN})
3042
if(NOT TEST_STDOUT STREQUAL "${expected}")

cmake/tool_sm4.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,29 @@ file(WRITE tool_sm4_cbc_kat.plain "0123456789abcdef")
1717
gmssl_run(sm4_cbc -encrypt -key ${SM4_KEY} -iv ${SM4_IV}
1818
-in tool_sm4_cbc_kat.plain -out tool_sm4_cbc_kat.cipher)
1919
gmssl_expect_file_hex(tool_sm4_cbc_kat.cipher
20-
"e6887b77dbabb572ffa07fed7548b192ceaace11f2b90b94c2b7a4d9382e471e")
20+
"e6887b77dbabb572ffa07fed7548b192")
2121
gmssl_run(sm4_cbc -decrypt -key ${SM4_KEY} -iv ${SM4_IV}
2222
-in tool_sm4_cbc_kat.cipher -out tool_sm4_cbc_kat.decrypt)
2323
gmssl_files_equal(tool_sm4_cbc_kat.plain tool_sm4_cbc_kat.decrypt)
2424

25+
file(WRITE tool_sm4_cbc_short.plain "abc")
26+
gmssl_expect_fail(sm4_cbc -encrypt -key ${SM4_KEY} -iv ${SM4_IV}
27+
-in tool_sm4_cbc_short.plain -out tool_sm4_cbc_short.cipher)
28+
gmssl_run(sm4_cbc -encrypt -pkcs7_padding -key ${SM4_KEY} -iv ${SM4_IV}
29+
-in tool_sm4_cbc_short.plain -out tool_sm4_cbc_short_pkcs7.cipher)
30+
gmssl_run(sm4_cbc -decrypt -pkcs7_padding -key ${SM4_KEY} -iv ${SM4_IV}
31+
-in tool_sm4_cbc_short_pkcs7.cipher -out tool_sm4_cbc_short_pkcs7.decrypt)
32+
gmssl_files_equal(tool_sm4_cbc_short.plain tool_sm4_cbc_short_pkcs7.decrypt)
33+
34+
file(WRITE tool_sm4_cbc_pkcs7_kat.plain "0123456789abcdef")
35+
gmssl_run(sm4_cbc -encrypt -pkcs7_padding -key ${SM4_KEY} -iv ${SM4_IV}
36+
-in tool_sm4_cbc_pkcs7_kat.plain -out tool_sm4_cbc_pkcs7_kat.cipher)
37+
gmssl_expect_file_hex(tool_sm4_cbc_pkcs7_kat.cipher
38+
"e6887b77dbabb572ffa07fed7548b192ceaace11f2b90b94c2b7a4d9382e471e")
39+
gmssl_run(sm4_cbc -decrypt -pkcs7_padding -key ${SM4_KEY} -iv ${SM4_IV}
40+
-in tool_sm4_cbc_pkcs7_kat.cipher -out tool_sm4_cbc_pkcs7_kat.decrypt)
41+
gmssl_files_equal(tool_sm4_cbc_pkcs7_kat.plain tool_sm4_cbc_pkcs7_kat.decrypt)
42+
2543
file(WRITE tool_sm4_unified_cbc_kat.plain "0123456789abcdef")
2644
gmssl_run(sm4 -cbc -encrypt -key ${SM4_KEY} -iv ${SM4_IV}
2745
-in tool_sm4_unified_cbc_kat.plain -out tool_sm4_unified_cbc_kat.cipher)
@@ -32,6 +50,7 @@ gmssl_run(sm4 -cbc -decrypt -key ${SM4_KEY} -iv ${SM4_IV}
3250
gmssl_files_equal(tool_sm4_unified_cbc_kat.plain tool_sm4_unified_cbc_kat.decrypt)
3351

3452
gmssl_symmetric_roundtrip(tool_sm4_cbc sm4_cbc -key ${SM4_KEY} -iv ${SM4_IV})
53+
gmssl_symmetric_roundtrip(tool_sm4_cbc_pkcs7 sm4_cbc -pkcs7_padding -key ${SM4_KEY} -iv ${SM4_IV})
3554
gmssl_symmetric_roundtrip(tool_sm4_ctr sm4_ctr -key ${SM4_KEY} -iv ${SM4_IV})
3655
gmssl_symmetric_roundtrip(tool_sm4_gcm sm4_gcm -key ${SM4_KEY} -iv 000000000000000000000000 -aad_hex 001122 -taglen 16)
3756

cmake/tool_zuc.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ gmssl_files_equal(tool_zuc.plain tool_zuc.decrypt)
1212
gmssl_run(zuc_128_eea3
1313
-key 173d14ba5003731d7a60049470f00a29
1414
-count 0x66035492 -bearer 15 -direction 0
15-
-in_hex 6cf65340735552ab0c9752fa6f9025fe0bd675d9005875b2
15+
-in tool_zuc.plain
1616
-out tool_zuc_128_eea3.cipher)
1717
gmssl_expect_file_hex(tool_zuc_128_eea3.cipher
18-
"a6c85fc66afb8533aafc2518dfe784940ee1e4b030238cc8")
19-
gmssl_expect_stdout("390a91b7\n" zuc_128_eia3
18+
"fa0f3eb52d9be1af9e521680d313c40c")
19+
gmssl_expect_stdout("b0361765\n" zuc_128_eia3
2020
-key 00000000000000000000000000000000
21-
-count 0 -bearer 0 -direction 0 -in_hex 00)
21+
-count 0 -bearer 0 -direction 0 -in tool_zuc.plain)
2222

2323
gmssl_run(zuc256
2424
-key 0000000000000000000000000000000000000000000000000000000000000000

include/gmssl/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" {
1818

1919

2020
#define GMSSL_VERSION_NUM 30300
21-
#define GMSSL_VERSION_STR "GmSSL 3.3.0-dev.1173"
21+
#define GMSSL_VERSION_STR "GmSSL 3.3.0-dev.1174"
2222

2323
int gmssl_version_num(void);
2424
const char *gmssl_version_str(void);

tools/certgen.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ static char *usage =
111111
" gmssl sm2keygen -pass P@ssw0rd -out rootcakey.pem\n"
112112
"\n"
113113
" gmssl certgen -C CN -ST Beijing -L Haidian -O PKU -OU CS -CN ROOTCA -days 3650 \\\n"
114-
" -key rootcakey.pem -pass P@ssw0rd \\\n"
115-
" -ca -path_len_constraint 6 \\\n"
116-
" -key_usage keyCertSign -key_usage cRLSign \\\n"
117-
" -crl_http_uri http://pku.edu.cn/ca.crl \\\n"
118-
" -ca_issuers_uri http://pku.edu.cn/ca.crt -ocsp_uri http://ocsp.pku.edu.cn \\\n"
119-
" -out rootcacert.pem\n"
114+
" -key rootcakey.pem -pass P@ssw0rd \\\n"
115+
" -ca -path_len_constraint 6 \\\n"
116+
" -key_usage keyCertSign -key_usage cRLSign \\\n"
117+
" -crl_http_uri http://pku.edu.cn/ca.crl \\\n"
118+
" -ca_issuers_uri http://pku.edu.cn/ca.crt -ocsp_uri http://ocsp.pku.edu.cn \\\n"
119+
" -out rootcacert.pem\n"
120120
"\n";
121121

122122

tools/gmssl.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,18 @@ static const char *options =
160160
" sm3 Generate SM3 hash\n"
161161
" sm3hmac Generate SM3 HMAC tag\n"
162162
" sm3_pbkdf2 Hash password into key using PBKDF2 algoritm\n"
163-
" sm4 Encrypt or decrypt with SM4\n"
164-
" sm4_gcm Encrypt or decrypt with SM4 GCM\n"
163+
#ifdef ENABLE_SM4_ECB
164+
" sm4_ecb Encrypt or decrypt with SM4 ECB\n"
165+
#endif
165166
" sm4_cbc Encrypt or decrypt with SM4 CBC\n"
167+
#ifdef ENABLE_SM4_CFB
168+
" sm4_cfb Encrypt or decrypt with SM4 CFB\n"
169+
#endif
170+
#ifdef ENABLE_SM4_OFB
171+
" sm4_ofb Encrypt or decrypt with SM4 OFB\n"
172+
#endif
166173
" sm4_ctr Encrypt or decrypt with SM4 CTR\n"
174+
" sm4_gcm Encrypt or decrypt with SM4 GCM\n"
167175
#ifdef ENABLE_SM4_CCM
168176
" sm4_ccm Encrypt or decrypt with SM4 CCM\n"
169177
#endif
@@ -173,15 +181,6 @@ static const char *options =
173181
#ifdef ENABLE_SM4_FF1
174182
" sm4_ff1 Encrypt or decrypt digits with SM4 FF1\n"
175183
#endif
176-
#ifdef ENABLE_SM4_ECB
177-
" sm4_ecb Encrypt or decrypt with SM4 ECB\n"
178-
#endif
179-
#ifdef ENABLE_SM4_CFB
180-
" sm4_cfb Encrypt or decrypt with SM4 CFB\n"
181-
#endif
182-
#ifdef ENABLE_SM4_OFB
183-
" sm4_ofb Encrypt or decrypt with SM4 OFB\n"
184-
#endif
185184
#ifdef ENABLE_SM4_CBC_MAC
186185
" sm4_cbc_mac Generate SM4 CBC-MAC\n"
187186
#endif

tools/reqsign.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ static char *usage =
112112
"\n"
113113
" gmssl sm2keygen -pass P@ssw0rd -out rootcakey.pem\n"
114114
" gmssl certgen -C CN -ST Beijing -L Haidian -O PKU -OU CS -CN ROOTCA -days 3650 \\\n"
115-
" -key rootcakey.pem -pass P@ssw0rd \\\n"
116-
" -ca -path_len_constraint 6 \\\n"
117-
" -key_usage keyCertSign -key_usage cRLSign \\\n"
118-
" -crl_http_uri http://pku.edu.cn/ca.crl \\\n"
119-
" -ca_issuers_uri http://pku.edu.cn/ca.crt -ocsp_uri http://ocsp.pku.edu.cn \\\n"
120-
" -out rootcacert.pem\n"
115+
" -key rootcakey.pem -pass P@ssw0rd \\\n"
116+
" -ca -path_len_constraint 6 \\\n"
117+
" -key_usage keyCertSign -key_usage cRLSign \\\n"
118+
" -crl_http_uri http://pku.edu.cn/ca.crl \\\n"
119+
" -ca_issuers_uri http://pku.edu.cn/ca.crt -ocsp_uri http://ocsp.pku.edu.cn \\\n"
120+
" -out rootcacert.pem\n"
121121
"\n"
122122
" # Generate sub-CA certificate request\n"
123123
"\n"
@@ -127,12 +127,12 @@ static char *usage =
127127
" # Sign certificate request to generate sub-CA certificate\n"
128128
"\n"
129129
" gmssl reqsign -in careq.pem -serial_len 12 -days 365 \\\n"
130-
" -cacert rootcacert.pem -key rootcakey.pem -pass P@ssw0rd \\\n"
131-
" -ca -path_len_constraint 0 \\\n"
132-
" -key_usage keyCertSign -key_usage cRLSign \\\n"
133-
" -crl_http_uri http://pku.edu.cn/ca.crl \\\n"
134-
" -ca_issuers_uri http://pku.edu.cn/ca.crt -ocsp_uri http://ocsp.pku.edu.cn \\\n"
135-
" -out cacert.pem\n"
130+
" -cacert rootcacert.pem -key rootcakey.pem -pass P@ssw0rd \\\n"
131+
" -ca -path_len_constraint 0 \\\n"
132+
" -key_usage keyCertSign -key_usage cRLSign \\\n"
133+
" -crl_http_uri http://pku.edu.cn/ca.crl \\\n"
134+
" -ca_issuers_uri http://pku.edu.cn/ca.crt -ocsp_uri http://ocsp.pku.edu.cn \\\n"
135+
" -out cacert.pem\n"
136136
"\n";
137137

138138
static int ext_key_usage_set(int *usages, const char *usage_name)

tools/sm2exch.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,36 +80,36 @@ static const char *options =
8080
" gmssl sm2keygen -pass P@ssw0rd -out alice.pem -pubout alicepub.pem\n"
8181
" gmssl sm2keygen -pass P@ssw0rd -out bob.pem -pubout bobpub.pem\n"
8282
" gmssl sm2exch -stage init \\\n"
83-
" -exch_keyout alice_ra.pem -exch_pass P@ssw0rd -out ra.hex\n"
83+
" -exch_keyout alice_ra.pem -exch_pass P@ssw0rd -out ra.hex\n"
8484
" gmssl sm2exch -stage respond \\\n"
85-
" -key bob.pem -pass P@ssw0rd -id Bob \\\n"
86-
" -peer_pubkey alicepub.pem -peer_id Alice -in ra.hex \\\n"
87-
" -exch_keyout bob_rb.pem -exch_pass P@ssw0rd \\\n"
88-
" -secret_state_out bob_secret_state.hex -out rb_sb.hex\n"
85+
" -key bob.pem -pass P@ssw0rd -id Bob \\\n"
86+
" -peer_pubkey alicepub.pem -peer_id Alice -in ra.hex \\\n"
87+
" -exch_keyout bob_rb.pem -exch_pass P@ssw0rd \\\n"
88+
" -secret_state_out bob_secret_state.hex -out rb_sb.hex\n"
8989
" gmssl sm2exch -stage confirm \\\n"
90-
" -key alice.pem -pass P@ssw0rd -id Alice \\\n"
91-
" -peer_pubkey bobpub.pem -peer_id Bob \\\n"
92-
" -exch_key alice_ra.pem -exch_pass P@ssw0rd -in rb_sb.hex \\\n"
93-
" -keylen 48 -keyout alice_shared_key.hex -out sa.hex\n"
90+
" -key alice.pem -pass P@ssw0rd -id Alice \\\n"
91+
" -peer_pubkey bobpub.pem -peer_id Bob \\\n"
92+
" -exch_key alice_ra.pem -exch_pass P@ssw0rd -in rb_sb.hex \\\n"
93+
" -keylen 48 -keyout alice_shared_key.hex -out sa.hex\n"
9494
" gmssl sm2exch -stage finish \\\n"
95-
" -key bob.pem -pass P@ssw0rd -id Bob \\\n"
96-
" -peer_pubkey alicepub.pem -peer_id Alice \\\n"
97-
" -exch_key bob_rb.pem -exch_pass P@ssw0rd \\\n"
98-
" -secret_state bob_secret_state.hex -in sa.hex \\\n"
99-
" -keylen 48 -keyout bob_shared_key.hex\n"
95+
" -key bob.pem -pass P@ssw0rd -id Bob \\\n"
96+
" -peer_pubkey alicepub.pem -peer_id Alice \\\n"
97+
" -exch_key bob_rb.pem -exch_pass P@ssw0rd \\\n"
98+
" -secret_state bob_secret_state.hex -in sa.hex \\\n"
99+
" -keylen 48 -keyout bob_shared_key.hex\n"
100100
"\n"
101101
"Certificate workflow:\n"
102102
"\n"
103103
" gmssl sm2exch -stage respond \\\n"
104-
" -key bob_enc_key.pem -pass P@ssw0rd -id Bob \\\n"
105-
" -peer_cert alice_enc_cert.pem -peer_id Alice -in ra.hex \\\n"
106-
" -exch_keyout bob_rb.pem -exch_pass P@ssw0rd \\\n"
107-
" -secret_state_out bob_secret_state.hex -out rb_sb.hex\n"
104+
" -key bob_enc_key.pem -pass P@ssw0rd -id Bob \\\n"
105+
" -peer_cert alice_enc_cert.pem -peer_id Alice -in ra.hex \\\n"
106+
" -exch_keyout bob_rb.pem -exch_pass P@ssw0rd \\\n"
107+
" -secret_state_out bob_secret_state.hex -out rb_sb.hex\n"
108108
" gmssl sm2exch -stage confirm \\\n"
109-
" -key alice_enc_key.pem -pass P@ssw0rd -id Alice \\\n"
110-
" -peer_cert bob_enc_cert.pem -peer_id Bob \\\n"
111-
" -exch_key alice_ra.pem -exch_pass P@ssw0rd -in rb_sb.hex \\\n"
112-
" -keyout alice_shared_key.hex -out sa.hex\n"
109+
" -key alice_enc_key.pem -pass P@ssw0rd -id Alice \\\n"
110+
" -peer_cert bob_enc_cert.pem -peer_id Bob \\\n"
111+
" -exch_key alice_ra.pem -exch_pass P@ssw0rd -in rb_sb.hex \\\n"
112+
" -keyout alice_shared_key.hex -out sa.hex\n"
113113
"\n"
114114
"Notes\n"
115115
"\n"

0 commit comments

Comments
 (0)