mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
add tools
This commit is contained in:
119
tools/gmssl.c
119
tools/gmssl.c
@@ -49,15 +49,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gmssl/pem.h>
|
|
||||||
#include <gmssl/x509.h>
|
|
||||||
#include <gmssl/x509_ext.h>
|
|
||||||
#include <gmssl/pkcs8.h>
|
|
||||||
#include <gmssl/rand.h>
|
|
||||||
#include <gmssl/version.h>
|
|
||||||
#include <gmssl/error.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
extern int version_main(int argc, char **argv);
|
||||||
extern int rand_main(int argc, char **argv);
|
extern int rand_main(int argc, char **argv);
|
||||||
extern int certgen_main(int argc, char **argv);
|
extern int certgen_main(int argc, char **argv);
|
||||||
extern int certparse_main(int argc, char **argv);
|
extern int certparse_main(int argc, char **argv);
|
||||||
@@ -67,14 +61,21 @@ extern int pbkdf2_main(int argc, char **argv);
|
|||||||
extern int reqgen_main(int argc, char **argv);
|
extern int reqgen_main(int argc, char **argv);
|
||||||
extern int reqparse_main(int argc, char **argv);
|
extern int reqparse_main(int argc, char **argv);
|
||||||
extern int reqsign_main(int argc, char **argv);
|
extern int reqsign_main(int argc, char **argv);
|
||||||
extern int sm2decrypt_main(int argc, char **argv);
|
|
||||||
extern int sm2encrypt_main(int argc, char **argv);
|
|
||||||
extern int sm2keygen_main(int argc, char **argv);
|
extern int sm2keygen_main(int argc, char **argv);
|
||||||
extern int sm2sign_main(int argc, char **argv);
|
extern int sm2sign_main(int argc, char **argv);
|
||||||
extern int sm2verify_main(int argc, char **argv);
|
extern int sm2verify_main(int argc, char **argv);
|
||||||
|
extern int sm2encrypt_main(int argc, char **argv);
|
||||||
|
extern int sm2decrypt_main(int argc, char **argv);
|
||||||
extern int sm3_main(int argc, char **argv);
|
extern int sm3_main(int argc, char **argv);
|
||||||
extern int sm3hmac_main(int argc, char **argv);
|
extern int sm3hmac_main(int argc, char **argv);
|
||||||
extern int sm4_main(int argc, char **argv);
|
extern int sm4_main(int argc, char **argv);
|
||||||
|
extern int zuc_main(int argc, char **argv);
|
||||||
|
extern int sm9setup_main(int argc, char **argv);
|
||||||
|
extern int sm9keygen_main(int argc, char **argv);
|
||||||
|
extern int sm9sign_main(int argc, char **argv);
|
||||||
|
extern int sm9verify_main(int argc, char **argv);
|
||||||
|
extern int sm9encrypt_main(int argc, char **argv);
|
||||||
|
extern int sm9decrypt_main(int argc, char **argv);
|
||||||
extern int tlcp_client_main(int argc, char **argv);
|
extern int tlcp_client_main(int argc, char **argv);
|
||||||
extern int tlcp_server_main(int argc, char **argv);
|
extern int tlcp_server_main(int argc, char **argv);
|
||||||
extern int tls12_client_main(int argc, char **argv);
|
extern int tls12_client_main(int argc, char **argv);
|
||||||
@@ -84,59 +85,60 @@ extern int tls13_server_main(int argc, char **argv);
|
|||||||
|
|
||||||
|
|
||||||
static const char *options =
|
static const char *options =
|
||||||
" commands:\n"
|
"command [options]\n"
|
||||||
" help\n"
|
"\n"
|
||||||
" version\n"
|
"Commands:\n"
|
||||||
" rand\n"
|
" help Print commands list or help for one command\n"
|
||||||
" sm2keygen\n"
|
" version Print version\n"
|
||||||
" sm2sign\n"
|
" rand Generate random bytes\n"
|
||||||
" sm2verify\n"
|
" sm2keygen Generate SM2 keypair\n"
|
||||||
" sm2encrypt\n"
|
" sm2sign Generate SM2 signature\n"
|
||||||
" sm2decrypt\n"
|
" sm2verify Verify SM2 signature\n"
|
||||||
" sm3\n"
|
" sm2encrypt SM2 public key encryption\n"
|
||||||
" sm3hmac\n"
|
" sm2decrypt SM2 decryption\n"
|
||||||
" sm4\n"
|
" sm3 Generate SM3 hash\n"
|
||||||
" pbkdf2\n"
|
" sm3hmac Generate HMAC-SM3 MAC tag\n"
|
||||||
" reqgen\n"
|
" sm4 Encrypt or decrypt data with SM4\n"
|
||||||
" reqsign\n"
|
" zuc Encrypt or decrypt data with ZUC\n"
|
||||||
" reqparse\n"
|
" sm9setup Generate SM9 master secret\n"
|
||||||
" crlparse\n"
|
" sm9keygen Generate SM9 private key\n"
|
||||||
" certgen\n"
|
" sm9sign Generate SM9 signature\n"
|
||||||
" certparse\n"
|
" sm9verify Verify SM9 signature\n"
|
||||||
" certverify\n"
|
" sm9encrypt SM9 public key encryption\n"
|
||||||
" tlcp_client\n"
|
" sm9decrypt SM9 decryption\n"
|
||||||
" tlcp_server\n"
|
" pbkdf2 Generate key from password\n"
|
||||||
" tls12_client\n"
|
" reqgen Generate PKCS #10 certificate signing request (CSR)\n"
|
||||||
" tls12_server\n"
|
" reqsign Generate a certificate from PKCS #10 CSR\n"
|
||||||
" tls13_client\n"
|
" reqparse Parse and print a PKCS #10 CSR\n"
|
||||||
" tls13_server\n";
|
" crlparse Parse and print CRL\n"
|
||||||
|
" certgen Generate a self-signed X.509 certificate in PEM format\n"
|
||||||
|
" certparse Parse and print certificates in a PEM file\n"
|
||||||
|
" certverify Verify certificate chain in a PEM file\n"
|
||||||
|
" tlcp_client TLCP client\n"
|
||||||
|
" tlcp_server TLCP server\n"
|
||||||
|
" tls12_client TLS 1.2 client\n"
|
||||||
|
" tls12_server TLS 1.2 server\n"
|
||||||
|
" tls13_client TLS 1.3 client\n"
|
||||||
|
" tls13_server TLS 1.3 server\n";
|
||||||
|
|
||||||
|
|
||||||
int version_main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
printf("%s\n", gmssl_version_str());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
char *prog = argv[0];
|
char *prog = argv[0];
|
||||||
|
|
||||||
|
|
||||||
if (argc < 2) {
|
|
||||||
printf("usage: %s\n %s\n", prog, options);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
|
if (argc < 1) {
|
||||||
|
printf("Usage: %s %s\n", prog, options);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
while (argc > 0) {
|
while (argc > 0) {
|
||||||
if (!strcmp(*argv, "help")) {
|
if (!strcmp(*argv, "help")) {
|
||||||
help:
|
printf("usage: %s %s\n", prog, options);
|
||||||
printf("usage: %s\n %s\n", prog, options);
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (!strcmp(*argv, "version")) {
|
} else if (!strcmp(*argv, "version")) {
|
||||||
return version_main(argc, argv);
|
return version_main(argc, argv);
|
||||||
@@ -156,6 +158,8 @@ help:
|
|||||||
return reqsign_main(argc, argv);
|
return reqsign_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "pbkdf2")) {
|
} else if (!strcmp(*argv, "pbkdf2")) {
|
||||||
return pbkdf2_main(argc, argv);
|
return pbkdf2_main(argc, argv);
|
||||||
|
} else if (!strcmp(*argv, "sm2keygen")) {
|
||||||
|
return sm2keygen_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "sm2sign")) {
|
} else if (!strcmp(*argv, "sm2sign")) {
|
||||||
return sm2sign_main(argc, argv);
|
return sm2sign_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "sm2verify")) {
|
} else if (!strcmp(*argv, "sm2verify")) {
|
||||||
@@ -164,14 +168,26 @@ help:
|
|||||||
return sm2encrypt_main(argc, argv);
|
return sm2encrypt_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "sm2decrypt")) {
|
} else if (!strcmp(*argv, "sm2decrypt")) {
|
||||||
return sm2decrypt_main(argc, argv);
|
return sm2decrypt_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "sm2keygen")) {
|
|
||||||
return sm2keygen_main(argc, argv);
|
|
||||||
} else if (!strcmp(*argv, "sm3")) {
|
} else if (!strcmp(*argv, "sm3")) {
|
||||||
return sm3_main(argc, argv);
|
return sm3_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "sm3hmac")) {
|
} else if (!strcmp(*argv, "sm3hmac")) {
|
||||||
return sm3hmac_main(argc, argv);
|
return sm3hmac_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "sm4")) {
|
} else if (!strcmp(*argv, "sm4")) {
|
||||||
return sm4_main(argc, argv);
|
return sm4_main(argc, argv);
|
||||||
|
} else if (!strcmp(*argv, "zuc")) {
|
||||||
|
return zuc_main(argc, argv);
|
||||||
|
} else if (!strcmp(*argv, "sm9setup")) {
|
||||||
|
return sm9setup_main(argc, argv);
|
||||||
|
} else if (!strcmp(*argv, "sm9keygen")) {
|
||||||
|
return sm9keygen_main(argc, argv);
|
||||||
|
} else if (!strcmp(*argv, "sm9sign")) {
|
||||||
|
return sm9sign_main(argc, argv);
|
||||||
|
} else if (!strcmp(*argv, "sm9verify")) {
|
||||||
|
return sm9verify_main(argc, argv);
|
||||||
|
} else if (!strcmp(*argv, "sm9encrypt")) {
|
||||||
|
return sm9encrypt_main(argc, argv);
|
||||||
|
} else if (!strcmp(*argv, "sm9decrypt")) {
|
||||||
|
return sm9decrypt_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "tlcp_client")) {
|
} else if (!strcmp(*argv, "tlcp_client")) {
|
||||||
return tlcp_client_main(argc, argv);
|
return tlcp_client_main(argc, argv);
|
||||||
} else if (!strcmp(*argv, "tlcp_server")) {
|
} else if (!strcmp(*argv, "tlcp_server")) {
|
||||||
@@ -185,7 +201,6 @@ help:
|
|||||||
} else if (!strcmp(*argv, "tls13_server")) {
|
} else if (!strcmp(*argv, "tls13_server")) {
|
||||||
return tls13_server_main(argc, argv);
|
return tls13_server_main(argc, argv);
|
||||||
} else {
|
} else {
|
||||||
bad:
|
|
||||||
fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv);
|
fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv);
|
||||||
fprintf(stderr, "usage: %s %s\n", prog, options);
|
fprintf(stderr, "usage: %s %s\n", prog, options);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
61
tools/sm3.c
61
tools/sm3.c
@@ -49,19 +49,26 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gmssl/sm3.h>
|
|
||||||
#include <gmssl/sm2.h>
|
#include <gmssl/sm2.h>
|
||||||
|
#include <gmssl/sm3.h>
|
||||||
#include <gmssl/error.h>
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const char *options = "[-hex|-bin] [-pubkey pem [-id str]] [-in file]";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int sm3_main(int argc, char **argv)
|
int sm3_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
int ret = 1;
|
||||||
char *prog = argv[0];
|
char *prog = argv[0];
|
||||||
|
int bin = 0;
|
||||||
char *pubkeyfile = NULL;
|
char *pubkeyfile = NULL;
|
||||||
char *infile = NULL;
|
char *infile = NULL;
|
||||||
char *id = NULL;
|
char *id = NULL;
|
||||||
FILE *pubkeyfp = NULL;
|
FILE *pubkeyfp = NULL;
|
||||||
FILE *infp = stdin;
|
FILE *infp = stdin;
|
||||||
|
|
||||||
SM3_CTX sm3_ctx;
|
SM3_CTX sm3_ctx;
|
||||||
uint8_t dgst[32];
|
uint8_t dgst[32];
|
||||||
uint8_t buf[4096];
|
uint8_t buf[4096];
|
||||||
@@ -73,26 +80,32 @@ int sm3_main(int argc, char **argv)
|
|||||||
|
|
||||||
while (argc > 0) {
|
while (argc > 0) {
|
||||||
if (!strcmp(*argv, "-help")) {
|
if (!strcmp(*argv, "-help")) {
|
||||||
help:
|
fprintf(stderr, "usage: %s %s\n", prog, options);
|
||||||
fprintf(stderr, "usage: %s [-pubkey pem [-id str]] [-in file]\n", prog);
|
|
||||||
fprintf(stderr, "usage: echo -n \"abc\" | %s\n", prog);
|
fprintf(stderr, "usage: echo -n \"abc\" | %s\n", prog);
|
||||||
return -1;
|
return 0;
|
||||||
|
} else if (!strcmp(*argv, "-hex")) {
|
||||||
|
if (bin) {
|
||||||
|
error_print();
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
bin = 0;
|
||||||
|
} else if (!strcmp(*argv, "-bin")) {
|
||||||
|
bin = 1;
|
||||||
} else if (!strcmp(*argv, "-pubkey")) {
|
} else if (!strcmp(*argv, "-pubkey")) {
|
||||||
if (--argc < 1) goto bad;
|
if (--argc < 1) goto bad;
|
||||||
pubkeyfile = *(++argv);
|
pubkeyfile = *(++argv);
|
||||||
|
|
||||||
} else if (!strcmp(*argv, "-id")) {
|
} else if (!strcmp(*argv, "-id")) {
|
||||||
if (--argc < 1) goto bad;
|
if (--argc < 1) goto bad;
|
||||||
id = *(++argv);
|
id = *(++argv);
|
||||||
|
|
||||||
} else if (!strcmp(*argv, "-in")) {
|
} else if (!strcmp(*argv, "-in")) {
|
||||||
if (--argc < 1) goto bad;
|
if (--argc < 1) goto bad;
|
||||||
infile = *(++argv);
|
infile = *(++argv);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv);
|
fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv);
|
||||||
goto help;
|
goto end;
|
||||||
|
bad:
|
||||||
|
fprintf(stderr, "%s: '%s' option value required\n", prog, *argv);
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
@@ -107,11 +120,11 @@ help:
|
|||||||
|
|
||||||
if (!(pubkeyfp = fopen(pubkeyfile, "r"))) {
|
if (!(pubkeyfp = fopen(pubkeyfile, "r"))) {
|
||||||
error_print();
|
error_print();
|
||||||
return -1;
|
goto end;
|
||||||
}
|
}
|
||||||
if (sm2_public_key_info_from_pem(&sm2_key, pubkeyfp) != 1) {
|
if (sm2_public_key_info_from_pem(&sm2_key, pubkeyfp) != 1) {
|
||||||
error_print();
|
error_print();
|
||||||
return -1;
|
goto end;
|
||||||
}
|
}
|
||||||
if (!id) {
|
if (!id) {
|
||||||
id = SM2_DEFAULT_ID;
|
id = SM2_DEFAULT_ID;
|
||||||
@@ -123,14 +136,14 @@ help:
|
|||||||
} else {
|
} else {
|
||||||
if (id) {
|
if (id) {
|
||||||
fprintf(stderr, "%s: option '-id' must be with '-pubkey'\n", prog);
|
fprintf(stderr, "%s: option '-id' must be with '-pubkey'\n", prog);
|
||||||
goto help;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (infile) {
|
if (infile) {
|
||||||
if (!(infp = fopen(infile, "r"))) {
|
if (!(infp = fopen(infile, "r"))) {
|
||||||
error_print();
|
error_print();
|
||||||
return -1;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) {
|
while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) {
|
||||||
@@ -138,17 +151,19 @@ help:
|
|||||||
}
|
}
|
||||||
|
|
||||||
sm3_finish(&sm3_ctx, dgst);
|
sm3_finish(&sm3_ctx, dgst);
|
||||||
for (i = 0; i < sizeof(dgst); i++) {
|
|
||||||
printf("%02x", dgst[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
if (infile) {
|
if (bin) {
|
||||||
fclose(infp);
|
fwrite(dgst, 1, 32, stdout);
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < sizeof(dgst); i++) {
|
||||||
|
printf("%02x", dgst[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
|
||||||
bad:
|
ret = 0;
|
||||||
fprintf(stderr, "%s: '%s' option value required\n", prog, *argv);
|
|
||||||
return -1;
|
end:
|
||||||
|
if (infile) fclose(infp);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
60
tools/sm9decrypt.c
Normal file
60
tools/sm9decrypt.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this
|
||||||
|
* software must display the following acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project.
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||||
|
* products derived from this software without prior written
|
||||||
|
* permission. For written permission, please contact
|
||||||
|
* guanzhi1980@gmail.com.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "GmSSL"
|
||||||
|
* nor may "GmSSL" appear in their names without prior written
|
||||||
|
* permission of the GmSSL Project.
|
||||||
|
*
|
||||||
|
* 6. Redistributions of any form whatsoever must retain the following
|
||||||
|
* acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||||
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <gmssl/sm9.h>
|
||||||
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
|
|
||||||
|
int sm9decrypt_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: not implemented\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
60
tools/sm9encrypt.c
Normal file
60
tools/sm9encrypt.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this
|
||||||
|
* software must display the following acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project.
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||||
|
* products derived from this software without prior written
|
||||||
|
* permission. For written permission, please contact
|
||||||
|
* guanzhi1980@gmail.com.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "GmSSL"
|
||||||
|
* nor may "GmSSL" appear in their names without prior written
|
||||||
|
* permission of the GmSSL Project.
|
||||||
|
*
|
||||||
|
* 6. Redistributions of any form whatsoever must retain the following
|
||||||
|
* acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||||
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <gmssl/sm9.h>
|
||||||
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
|
|
||||||
|
int sm9encrypt_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: not implemented\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
60
tools/sm9keygen.c
Normal file
60
tools/sm9keygen.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this
|
||||||
|
* software must display the following acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project.
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||||
|
* products derived from this software without prior written
|
||||||
|
* permission. For written permission, please contact
|
||||||
|
* guanzhi1980@gmail.com.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "GmSSL"
|
||||||
|
* nor may "GmSSL" appear in their names without prior written
|
||||||
|
* permission of the GmSSL Project.
|
||||||
|
*
|
||||||
|
* 6. Redistributions of any form whatsoever must retain the following
|
||||||
|
* acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||||
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <gmssl/sm9.h>
|
||||||
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
|
|
||||||
|
int sm9keygen_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: not implemented\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
60
tools/sm9setup.c
Normal file
60
tools/sm9setup.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this
|
||||||
|
* software must display the following acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project.
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||||
|
* products derived from this software without prior written
|
||||||
|
* permission. For written permission, please contact
|
||||||
|
* guanzhi1980@gmail.com.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "GmSSL"
|
||||||
|
* nor may "GmSSL" appear in their names without prior written
|
||||||
|
* permission of the GmSSL Project.
|
||||||
|
*
|
||||||
|
* 6. Redistributions of any form whatsoever must retain the following
|
||||||
|
* acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||||
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <gmssl/sm9.h>
|
||||||
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
|
|
||||||
|
int sm9setup_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: not implemented\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
60
tools/sm9sign.c
Normal file
60
tools/sm9sign.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this
|
||||||
|
* software must display the following acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project.
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||||
|
* products derived from this software without prior written
|
||||||
|
* permission. For written permission, please contact
|
||||||
|
* guanzhi1980@gmail.com.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "GmSSL"
|
||||||
|
* nor may "GmSSL" appear in their names without prior written
|
||||||
|
* permission of the GmSSL Project.
|
||||||
|
*
|
||||||
|
* 6. Redistributions of any form whatsoever must retain the following
|
||||||
|
* acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||||
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <gmssl/sm9.h>
|
||||||
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
|
|
||||||
|
int sm9sign_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: not implemented\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
60
tools/sm9verify.c
Normal file
60
tools/sm9verify.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this
|
||||||
|
* software must display the following acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project.
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||||
|
* products derived from this software without prior written
|
||||||
|
* permission. For written permission, please contact
|
||||||
|
* guanzhi1980@gmail.com.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "GmSSL"
|
||||||
|
* nor may "GmSSL" appear in their names without prior written
|
||||||
|
* permission of the GmSSL Project.
|
||||||
|
*
|
||||||
|
* 6. Redistributions of any form whatsoever must retain the following
|
||||||
|
* acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||||
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <gmssl/sm9.h>
|
||||||
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
|
|
||||||
|
int sm9verify_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: not implemented\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
59
tools/version.c
Normal file
59
tools/version.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this
|
||||||
|
* software must display the following acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project.
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||||
|
* products derived from this software without prior written
|
||||||
|
* permission. For written permission, please contact
|
||||||
|
* guanzhi1980@gmail.com.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "GmSSL"
|
||||||
|
* nor may "GmSSL" appear in their names without prior written
|
||||||
|
* permission of the GmSSL Project.
|
||||||
|
*
|
||||||
|
* 6. Redistributions of any form whatsoever must retain the following
|
||||||
|
* acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||||
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <gmssl/version.h>
|
||||||
|
|
||||||
|
|
||||||
|
int version_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
printf("%s\n", gmssl_version_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
180
tools/zuc.c
Normal file
180
tools/zuc.c
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this
|
||||||
|
* software must display the following acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project.
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||||
|
* products derived from this software without prior written
|
||||||
|
* permission. For written permission, please contact
|
||||||
|
* guanzhi1980@gmail.com.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "GmSSL"
|
||||||
|
* nor may "GmSSL" appear in their names without prior written
|
||||||
|
* permission of the GmSSL Project.
|
||||||
|
*
|
||||||
|
* 6. Redistributions of any form whatsoever must retain the following
|
||||||
|
* acknowledgment:
|
||||||
|
* "This product includes software developed by the GmSSL Project
|
||||||
|
* (http://gmssl.org/)"
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||||
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <gmssl/zuc.h>
|
||||||
|
#include <gmssl/hex.h>
|
||||||
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const char *options = "-key hex -iv hex [-in file] [-out file]";
|
||||||
|
|
||||||
|
|
||||||
|
int zuc_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *prog = argv[0];
|
||||||
|
char *keystr = NULL;
|
||||||
|
char *ivstr = NULL;
|
||||||
|
char *infile = NULL;
|
||||||
|
char *outfile = NULL;
|
||||||
|
uint8_t key[16];
|
||||||
|
uint8_t iv[16];
|
||||||
|
size_t keylen = sizeof(key);
|
||||||
|
size_t ivlen = sizeof(iv);
|
||||||
|
FILE *infp = stdin;
|
||||||
|
FILE *outfp = stdout;
|
||||||
|
ZUC_CTX zuc_ctx;
|
||||||
|
uint8_t inbuf[4096];
|
||||||
|
size_t inlen;
|
||||||
|
uint8_t outbuf[4196];
|
||||||
|
size_t outlen;
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
fprintf(stderr, "usage: %s %s\n", prog, options);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
|
while (argc > 0) {
|
||||||
|
if (!strcmp(*argv, "-help")) {
|
||||||
|
fprintf(stderr, "usage: %s %s\n", prog, options);
|
||||||
|
return 0;
|
||||||
|
} else if (!strcmp(*argv, "-key")) {
|
||||||
|
if (--argc < 1) goto bad;
|
||||||
|
keystr = *(++argv);
|
||||||
|
} else if (!strcmp(*argv, "-iv")) {
|
||||||
|
if (--argc < 1) goto bad;
|
||||||
|
ivstr = *(++argv);
|
||||||
|
} else if (!strcmp(*argv, "-in")) {
|
||||||
|
if (--argc < 1) goto bad;
|
||||||
|
infile = *(++argv);
|
||||||
|
} else if (!strcmp(*argv, "-out")) {
|
||||||
|
if (--argc < 1) goto bad;
|
||||||
|
outfile = *(++argv);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv);
|
||||||
|
return 1;
|
||||||
|
bad:
|
||||||
|
fprintf(stderr, "%s: no option value\n", prog);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keystr) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (strlen(keystr) != 32) {
|
||||||
|
printf("keystr len = %d\n", strlen(keystr));
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (hex_to_bytes(keystr, strlen(keystr), key, &keylen) != 1) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ivstr) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (strlen(ivstr) != 32) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (hex_to_bytes(ivstr, strlen(ivstr), iv, &ivlen) != 1) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (infile) {
|
||||||
|
if (!(infp = fopen(infile, "r"))) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (outfile) {
|
||||||
|
if (!(outfp = fopen(outfile, "w"))) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zuc_encrypt_init(&zuc_ctx, key, iv) != 1) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
while ((inlen = fread(inbuf, 1, sizeof(inbuf), infp)) > 0) {
|
||||||
|
if (zuc_encrypt_update(&zuc_ctx, inbuf, inlen, outbuf, &outlen) != 1) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fwrite(outbuf, 1, outlen, outfp) != outlen) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (zuc_encrypt_finish(&zuc_ctx, outbuf, &outlen) != 1) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fwrite(outbuf, 1, outlen, outfp) != outlen) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user