From 7ddf846d33b51f2dd1fd90c2958de2cc8a4c48a4 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Wed, 28 Nov 2018 16:46:22 +0800 Subject: [PATCH] update --- demos/cpk/Makefile | 23 ----- demos/cpk/cpk-keygen.c | 95 ------------------ demos/cpk/cpk-setup.c | 99 ------------------ demos/cpk/cpk-sign.c | 147 --------------------------- demos/cpk/cpk-verify.c | 195 ------------------------------------ demos/fpe/Makefile | 12 --- demos/fpe/fpe-decrypt.c | 110 -------------------- demos/fpe/fpe-encrypt.c | 110 -------------------- demos/otp/otp-setup.c | 37 ------- demos/otp/otp.c | 43 -------- demos/sdf/Makefile | 10 -- demos/sdf/README.md | 14 --- demos/sdf/sdf-dev.sh | 18 ---- demos/sdf/sdf-sm1.sh | 16 --- demos/sdf/sdf-sm2enc.sh | 21 ---- demos/sdf/sdf-sm2sign.sh | 20 ---- demos/sdf/sdf-sm3.sh | 3 - demos/sdf/sdf-sm4.sh | 14 --- demos/sdf/sdf-ssf33.sh | 16 --- demos/sdf/sdf-ssl-server.sh | 7 -- demos/sdf/sdf-zuc.sh | 16 --- demos/sdf/sdf.c | 87 ---------------- demos/sdf/sdf.cnf | 16 --- demos/skf/Makefile | 11 -- demos/skf/skf.c | 88 ---------------- demos/sm1/build.info | 2 - demos/sm1/e_sm1.c | 89 ---------------- demos/sm1/sm1.c | 78 --------------- demos/sm1/sm1.h | 66 ------------ demos/sm1/sm1_cbc.c | 72 ------------- demos/sm1/sm1_cfb.c | 68 ------------- demos/sm1/sm1_ecb.c | 68 ------------- demos/sm1/sm1_ofb.c | 68 ------------- demos/sm2/Makefile | 25 ----- demos/sm2/sm2-encrypt.c | 75 -------------- demos/sm2/sm2-keygen.c | 106 -------------------- demos/sm2/sm2-sign.c | 65 ------------ demos/sm3/Makefile | 14 --- demos/sm3/sm3.c | 92 ----------------- demos/sm3/sm3evp.c | 120 ---------------------- demos/sm3/sm3hmac.c | 126 ----------------------- demos/sm4/Makefile | 14 --- demos/sm4/sms4.c | 109 -------------------- demos/sm4/sms4evp.c | 155 ---------------------------- demos/sm9/Makefile | 31 ------ demos/sm9/sm9-decrypt.c | 119 ---------------------- demos/sm9/sm9-encrypt.c | 121 ---------------------- demos/sm9/sm9-keygen.c | 97 ------------------ demos/sm9/sm9-setup.c | 95 ------------------ demos/sm9/sm9-sign.c | 129 ------------------------ demos/sm9/sm9-verify.c | 138 ------------------------- demos/ssf33/build.info | 2 - demos/ssf33/e_ssf33.c | 89 ---------------- demos/ssf33/ssf33.c | 80 --------------- demos/ssf33/ssf33.h | 67 ------------- demos/ssf33/ssf33_cbc.c | 73 -------------- demos/ssf33/ssf33_cfb.c | 68 ------------- demos/ssf33/ssf33_ecb.c | 68 ------------- demos/ssf33/ssf33_ofb.c | 68 ------------- 59 files changed, 3885 deletions(-) delete mode 100644 demos/cpk/Makefile delete mode 100644 demos/cpk/cpk-keygen.c delete mode 100644 demos/cpk/cpk-setup.c delete mode 100644 demos/cpk/cpk-sign.c delete mode 100644 demos/cpk/cpk-verify.c delete mode 100644 demos/fpe/Makefile delete mode 100644 demos/fpe/fpe-decrypt.c delete mode 100644 demos/fpe/fpe-encrypt.c delete mode 100644 demos/otp/otp-setup.c delete mode 100644 demos/otp/otp.c delete mode 100644 demos/sdf/Makefile delete mode 100644 demos/sdf/README.md delete mode 100755 demos/sdf/sdf-dev.sh delete mode 100755 demos/sdf/sdf-sm1.sh delete mode 100755 demos/sdf/sdf-sm2enc.sh delete mode 100755 demos/sdf/sdf-sm2sign.sh delete mode 100755 demos/sdf/sdf-sm3.sh delete mode 100755 demos/sdf/sdf-sm4.sh delete mode 100755 demos/sdf/sdf-ssf33.sh delete mode 100755 demos/sdf/sdf-ssl-server.sh delete mode 100755 demos/sdf/sdf-zuc.sh delete mode 100644 demos/sdf/sdf.c delete mode 100644 demos/sdf/sdf.cnf delete mode 100644 demos/skf/Makefile delete mode 100644 demos/skf/skf.c delete mode 100644 demos/sm1/build.info delete mode 100644 demos/sm1/e_sm1.c delete mode 100644 demos/sm1/sm1.c delete mode 100644 demos/sm1/sm1.h delete mode 100644 demos/sm1/sm1_cbc.c delete mode 100644 demos/sm1/sm1_cfb.c delete mode 100644 demos/sm1/sm1_ecb.c delete mode 100644 demos/sm1/sm1_ofb.c delete mode 100644 demos/sm2/Makefile delete mode 100644 demos/sm2/sm2-encrypt.c delete mode 100644 demos/sm2/sm2-keygen.c delete mode 100644 demos/sm2/sm2-sign.c delete mode 100644 demos/sm3/Makefile delete mode 100755 demos/sm3/sm3.c delete mode 100755 demos/sm3/sm3evp.c delete mode 100755 demos/sm3/sm3hmac.c delete mode 100644 demos/sm4/Makefile delete mode 100755 demos/sm4/sms4.c delete mode 100755 demos/sm4/sms4evp.c delete mode 100644 demos/sm9/Makefile delete mode 100644 demos/sm9/sm9-decrypt.c delete mode 100644 demos/sm9/sm9-encrypt.c delete mode 100644 demos/sm9/sm9-keygen.c delete mode 100644 demos/sm9/sm9-setup.c delete mode 100644 demos/sm9/sm9-sign.c delete mode 100644 demos/sm9/sm9-verify.c delete mode 100644 demos/ssf33/build.info delete mode 100644 demos/ssf33/e_ssf33.c delete mode 100644 demos/ssf33/ssf33.c delete mode 100644 demos/ssf33/ssf33.h delete mode 100644 demos/ssf33/ssf33_cbc.c delete mode 100644 demos/ssf33/ssf33_cfb.c delete mode 100644 demos/ssf33/ssf33_ecb.c delete mode 100644 demos/ssf33/ssf33_ofb.c diff --git a/demos/cpk/Makefile b/demos/cpk/Makefile deleted file mode 100644 index 2b5cd3a9..00000000 --- a/demos/cpk/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -all: - gcc cpk-setup.c -L/usr/local/lib -lcrypto -o cpk-setup - gcc cpk-keygen.c -L/usr/local/lib -lcrypto -o cpk-keygen - gcc cpk-sign.c -L/usr/local/lib -lcrypto -o cpk-sign - gcc cpk-verify.c -L/usr/local/lib -lcrypto -o cpk-verify - -test: - ./cpk-setup sign.mpk sign.msk - ./cpk-keygen sign.msk alice alice.ssk - ./cpk-sign cpk-setup alice alice.ssk cpk-setup-signed - ./cpk-verify cpk-setup-signed sign.mpk - -clean: - rm -fr cpk-setup - rm -fr cpk-keygen - rm -fr cpk-sign - rm -fr cpk-verify - rm -fr *.mpk - rm -fr *.msk - rm -fr *.sk - rm -fr *.ssk - rm -fr cpk-setup-signed - diff --git a/demos/cpk/cpk-keygen.c b/demos/cpk/cpk-keygen.c deleted file mode 100644 index 2988b97b..00000000 --- a/demos/cpk/cpk-keygen.c +++ /dev/null @@ -1,95 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2018 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 -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - BIO *msk_bio = NULL; - BIO *sk_bio = NULL; - CPK_MASTER_SECRET *msk = NULL; - EVP_PKEY *sk = NULL; - - if (argc != 4) { - printf("usage: %s \n", prog); - return 0; - } - - if (!(msk_bio = BIO_new_file(argv[1], "r")) - || !(msk = d2i_CPK_MASTER_SECRET_bio(msk_bio, NULL))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(sk = CPK_MASTER_SECRET_extract_private_key(msk, argv[2]))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(sk_bio = BIO_new_file(argv[3], "w")) - || !PEM_write_bio_PrivateKey(sk_bio, sk, NULL, NULL, 0, NULL, NULL)) { - ERR_print_errors_fp(stderr); - goto end; - } - - ret = 0; - -end: - BIO_free(msk_bio); - BIO_free(sk_bio); - CPK_MASTER_SECRET_free(msk); - EVP_PKEY_free(sk); - return ret; -} diff --git a/demos/cpk/cpk-setup.c b/demos/cpk/cpk-setup.c deleted file mode 100644 index a0863127..00000000 --- a/demos/cpk/cpk-setup.c +++ /dev/null @@ -1,99 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2018 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 -#include -#include -#include -#include -#include - - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - X509_ALGOR *map = NULL; - EC_KEY *ec_key = NULL; - EVP_PKEY *pkey = NULL; - CPK_MASTER_SECRET *msk = NULL; - CPK_PUBLIC_PARAMS *mpk = NULL; - BIO *mpk_bio = NULL; - BIO *msk_bio = NULL; - - if (argc != 3) { - printf("usage: %s \n", prog); - return 0; - } - - if (!(msk = CPK_MASTER_SECRET_create("codesign", NID_sm2p256v1, NID_cpk_map_sha1)) - || !(mpk = CPK_MASTER_SECRET_extract_public_params(msk))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(mpk_bio = BIO_new_file(argv[1], "w")) - || !(msk_bio = BIO_new_file(argv[2], "w")) - || !i2d_CPK_MASTER_SECRET_bio(msk_bio, msk) - || !i2d_CPK_PUBLIC_PARAMS_bio(mpk_bio, mpk)) { - ERR_print_errors_fp(stderr); - goto end; - } - - ret = 0; - -end: - X509_ALGOR_free(map); - //EC_KEY_free(ec_key); - EVP_PKEY_free(pkey); - CPK_MASTER_SECRET_free(msk); - CPK_PUBLIC_PARAMS_free(mpk); - BIO_free(msk_bio); - BIO_free(mpk_bio); - return ret; -} diff --git a/demos/cpk/cpk-sign.c b/demos/cpk/cpk-sign.c deleted file mode 100644 index 0933155a..00000000 --- a/demos/cpk/cpk-sign.c +++ /dev/null @@ -1,147 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2018 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 -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - EVP_MD_CTX *md_ctx = NULL; - EVP_PKEY_CTX *pctx; - EVP_PKEY *sk = NULL; - unsigned char magic[] = "~CPK signature appended~"; - unsigned char sig[128] = {0}; - size_t sigsize = sizeof(sig); - unsigned int idlen, siglen, totallen; - BIO *in_bio = NULL; - BIO *sk_bio = NULL; - BIO *out_bio = NULL; - unsigned char buf[1024]; - int len; - - if (argc != 5) { - printf("usage: %s \n", prog); - return 0; - } - - if (strlen(argv[2]) > 64) { - fprintf(stderr, "%s: signer's id too long\n", prog); - goto end; - } - - if (!(in_bio = BIO_new_file(argv[1], "r")) - || !(sk_bio = BIO_new_file(argv[3], "r")) - || !(out_bio = BIO_new_file(argv[4], "w"))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(sk = PEM_read_bio_PrivateKey(sk_bio, NULL, NULL, NULL))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(md_ctx = EVP_MD_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!EVP_DigestSignInit(md_ctx, &pctx, EVP_sm3(), NULL, sk)) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!EVP_PKEY_CTX_set_ec_scheme(pctx, NID_sm_scheme)) { - ERR_print_errors_fp(stderr); - goto end; - } - while ((len = BIO_read(in_bio, buf, sizeof(buf))) > 0) { - if (!EVP_DigestSignUpdate(md_ctx, buf, len)) { - ERR_print_errors_fp(stderr); - goto end; - } - if (len != BIO_write(out_bio, buf, len)) { - ERR_print_errors_fp(stderr); - goto end; - } - } - if (!EVP_DigestSignFinal(md_ctx, sig, &sigsize)) { - ERR_print_errors_fp(stderr); - goto end; - } - - idlen = strlen(argv[2]); - siglen = (unsigned int)sigsize; - totallen = sizeof(idlen) + idlen + sizeof(siglen) + siglen; - - if (BIO_write(out_bio, &idlen, sizeof(idlen)) != sizeof(idlen) - || BIO_write(out_bio, argv[2], strlen(argv[2])) != strlen(argv[2]) - || BIO_write(out_bio, &siglen, sizeof(siglen)) != sizeof(siglen) - || BIO_write(out_bio, sig, siglen) != siglen - || BIO_write(out_bio, &totallen, sizeof(totallen)) != sizeof(totallen) - || BIO_write(out_bio, magic, sizeof(magic)) != sizeof(magic)) { - ERR_print_errors_fp(stderr); - goto end; - } - - ret = 0; - -end: - EVP_MD_CTX_free(md_ctx); - EVP_PKEY_free(sk); - BIO_free(in_bio); - BIO_free(sk_bio); - BIO_free(out_bio); - return ret; -} diff --git a/demos/cpk/cpk-verify.c b/demos/cpk/cpk-verify.c deleted file mode 100644 index 51bfe557..00000000 --- a/demos/cpk/cpk-verify.c +++ /dev/null @@ -1,195 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2018 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 -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - FILE *fp = NULL; - BIO *bio = NULL; - BIO *bio_mpk = NULL; - CPK_PUBLIC_PARAMS *mpk = NULL; - EVP_PKEY *pk = NULL; - EVP_MD_CTX *md_ctx = NULL; - EVP_PKEY_CTX *pctx; - unsigned char magicstr[] = "~CPK signature appended~"; - unsigned char magic[sizeof(magicstr)] = {0}; - unsigned char id[128] = {0}; - unsigned char sig[128]; - unsigned int idlen, siglen, totallen; - int datalen; - - if (argc != 3) { - printf("usage: %s \n", prog); - return 0; - } - - if (!(fp = fopen(argv[1], "r"))) { - fprintf(stderr, "%s: open file failed\n", prog); - goto end; - } - - if (fseek(fp, -(sizeof(magic) + sizeof(unsigned int)), SEEK_END) != 0) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - if ((datalen = ftell(fp)) <= 0) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - - if (fread(&totallen, sizeof(unsigned int), 1, fp) != sizeof(unsigned char)) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - datalen -= totallen; - - if (fread(magic, 1, sizeof(magic), fp) != sizeof(magic)) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - - if (memcmp(magic, magicstr, sizeof(magic)) != 0) { - fprintf(stderr, "%s: file is not signed\n", prog); - goto end; - } - - if (fseek(fp, datalen, SEEK_SET) != 0) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - - if (fread(&idlen, 1, 4, fp) != 4) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - - if (fread(id, 1, idlen, fp) != idlen) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - - if (fread(&siglen, 1, sizeof(unsigned int), fp) != sizeof(unsigned int)) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - if (fread(sig, 1, siglen, fp) != siglen) { - fprintf(stderr, "%s: parse file error\n", prog); - goto end; - } - - fclose(fp); - fp = NULL; - - if (!(bio = BIO_new_file(argv[1], "r")) - || !(bio_mpk = BIO_new_file(argv[2], "r"))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(mpk = d2i_CPK_PUBLIC_PARAMS_bio(bio_mpk, NULL))) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!(pk = CPK_PUBLIC_PARAMS_extract_public_key(mpk, (char *)id))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(md_ctx = EVP_MD_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!EVP_DigestVerifyInit(md_ctx, &pctx, EVP_sm3(), NULL, pk)) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!EVP_PKEY_CTX_set_ec_scheme(pctx, NID_sm_scheme)) { - ERR_print_errors_fp(stderr); - goto end; - } - - while (datalen > 0) { - unsigned char buf[1024]; - int len; - - len = sizeof(buf) < datalen ? sizeof(buf) : datalen; - - if (len != BIO_read(bio, buf, len)) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!EVP_DigestVerifyUpdate(md_ctx, buf, len)) { - ERR_print_errors_fp(stderr); - goto end; - } - - datalen -= len; - } - - if (1 != EVP_DigestVerifyFinal(md_ctx, sig, siglen)) { - ERR_print_errors_fp(stderr); - printf("%s: failed\n", argv[1]); - goto end; - } - printf("%s: success\n", argv[1]); - - ret = 0; -end: - return ret; -} diff --git a/demos/fpe/Makefile b/demos/fpe/Makefile deleted file mode 100644 index 17a147d1..00000000 --- a/demos/fpe/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -all: - gcc fpe-encrypt.c -L /usr/local/lib -lcrypto -o fpe-encrypt - gcc fpe-decrypt.c -L /usr/local/lib -lcrypto -o fpe-decrypt - -test: - ./fpe-encrypt 0123456789012345 secretkey tweak001 - ./fpe-decrypt 6492610187935136 secretkey tweak001 - -clean: - rm -fr a.out - rm -fr fpe-encrypt - rm -fr fpe-decrypt diff --git a/demos/fpe/fpe-decrypt.c b/demos/fpe/fpe-decrypt.c deleted file mode 100644 index 7357eb15..00000000 --- a/demos/fpe/fpe-decrypt.c +++ /dev/null @@ -1,110 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2018 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. - * ==================================================================== - */ -/* - * Alert: - * This is a only a demo of the FFX format-preserving encryption algorithm, - * the encryption key should not be read from command line argumnents, and - * the key and tweak should be binary (full 8-bit per char). - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - FFX_CTX *ctx = NULL; - unsigned char key[32] = {0}; - char out[FFX_MAX_DIGITS + 1] = {0}; - - if (argc != 4) { - printf("usage: %s \n", prog); - return -1; - } - if (strlen(argv[1]) < FFX_MIN_DIGITS || strlen(argv[1]) > FFX_MAX_DIGITS) { - fprintf(stderr, "%s: invalid digits length, should be %d to %d\n", - prog, FFX_MIN_DIGITS, FFX_MAX_DIGITS); - return -1; - } - if (strlen(argv[2]) < FFX_MIN_TWEAKLEN || strlen(argv[2]) > FFX_MAX_TWEAKLEN) { - fprintf(stderr, "%s: invalid tweak length, should be %d to %d\n", - prog, FFX_MIN_TWEAKLEN, FFX_MAX_TWEAKLEN); - return -1; - } - strncpy((char *)key, argv[2], sizeof(key)); - - if (!(ctx = FFX_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!FFX_init(ctx, EVP_sms4_ecb(), key, 0)) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!FFX_decrypt(ctx, argv[1], out, strlen(argv[1]), - (unsigned char *)argv[3], strlen(argv[3]))) { - ERR_print_errors_fp(stderr); - goto end; - } - printf("%s\n", out); - - ret = 0; - -end: - FFX_CTX_free(ctx); - return ret; -} diff --git a/demos/fpe/fpe-encrypt.c b/demos/fpe/fpe-encrypt.c deleted file mode 100644 index 44d8bdbd..00000000 --- a/demos/fpe/fpe-encrypt.c +++ /dev/null @@ -1,110 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2018 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. - * ==================================================================== - */ -/* - * Alert: - * This is a only a demo of the FFX format-preserving encryption algorithm, - * the encryption key should not be read from command line argumnents, and - * the key and tweak should be binary (full 8-bit per char). - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - FFX_CTX *ctx = NULL; - unsigned char key[32] = {0}; - char out[FFX_MAX_DIGITS + 1] = {0}; - - if (argc != 4) { - printf("usage: %s \n", prog); - return -1; - } - if (strlen(argv[1]) < FFX_MIN_DIGITS || strlen(argv[1]) > FFX_MAX_DIGITS) { - fprintf(stderr, "%s: invalid digits length, should be %d to %d\n", - prog, FFX_MIN_DIGITS, FFX_MAX_DIGITS); - return -1; - } - if (strlen(argv[2]) < FFX_MIN_TWEAKLEN || strlen(argv[2]) > FFX_MAX_TWEAKLEN) { - fprintf(stderr, "%s: invalid tweak length, should be %d to %d\n", - prog, FFX_MIN_TWEAKLEN, FFX_MAX_TWEAKLEN); - return -1; - } - strncpy((char *)key, argv[2], sizeof(key)); - - if (!(ctx = FFX_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!FFX_init(ctx, EVP_sms4_ecb(), key, 0)) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!FFX_encrypt(ctx, argv[1], out, strlen(argv[1]), - (unsigned char *)argv[3], strlen(argv[3]))) { - ERR_print_errors_fp(stderr); - goto end; - } - printf("%s\n", out); - - ret = 0; - -end: - FFX_CTX_free(ctx); - return ret; -} diff --git a/demos/otp/otp-setup.c b/demos/otp/otp-setup.c deleted file mode 100644 index 2e4db93b..00000000 --- a/demos/otp/otp-setup.c +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - BIO *bio = NULL; - unsigned char key[32]; - - if (!RAND_bytes(key, sizeof(key))) { - ERR_print_errors_fp(stderr); - return -1; - } - - if (!(bio = BIO_new_file(".otp_secret", "w"))) { - ERR_print_errors_fp(stderr); - return -1; - } - - if (BIO_write(bio, key, sizeof(key)) != sizeof(key)) { - ERR_print_errors_fp(stderr); - BIO_free(bio); - return -1; - } - - printf("generate OTP seed in '.otp_secret'\n"); - - BIO_free(bio); - OPENSSL_cleanse(key, sizeof(key)); - - return 0; -} diff --git a/demos/otp/otp.c b/demos/otp/otp.c deleted file mode 100644 index 9809d16f..00000000 --- a/demos/otp/otp.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - char *prog = basename(argv[0]); - BIO *bio = NULL; - OTP_PARAMS params; - unsigned char key[32] = {0}; - unsigned char event[] = "this is a fixed value"; - unsigned int otp; - - params.type = NID_sm3; - params.te = 1; - params.option = NULL; - params.option_size = 0; - params.otp_digits = 6; - - if (!(bio = BIO_new_file(".otp_secret", "r"))) { - ERR_print_errors_fp(stderr); - return -1; - } - if (BIO_read(bio, key, sizeof(key)) != sizeof(key)) { - ERR_print_errors_fp(stderr); - BIO_free(bio); - return -1; - } - BIO_free(bio); - - if (!OTP_generate(¶ms, event, sizeof(event), &otp, key, sizeof(key))) { - ERR_print_errors_fp(stderr); - return -1; - } - - printf("%06u\n", otp); - return 0; -} diff --git a/demos/sdf/Makefile b/demos/sdf/Makefile deleted file mode 100644 index 0a146124..00000000 --- a/demos/sdf/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -all: - gcc sdf.c libsdf.so -o sdf - gcc sdf.c -DUSE_GMAPI -L /usr/local/lib -lcrypto -o sdf-gmapi - -test: - ./sdf-gmapi - -clean: - rm -fr sdf - rm -fr sdf-gmaip diff --git a/demos/sdf/README.md b/demos/sdf/README.md deleted file mode 100644 index bdd199f5..00000000 --- a/demos/sdf/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# SDF Demos - - - sdf-dev.sh - open device - - sdf-sm1.sh - encrypt/decrypt with sm1 - - sdf-sm2enc.sh - encypt with sm2 - - sdf-sm2sign.sh - sm2 sign/verify - - sdf-sm3.sh - sm3 test - - sdf-sm4.sh - sm4 - - sdf-ssf33.sh - ssf33 - - sdf-ssl-server.sh - TLS 1.2 server - - sdf-zuc.sh - zuc - - sdf.c - sdf open device - - sdf.cnf - configuration file for sdf engine - diff --git a/demos/sdf/sdf-dev.sh b/demos/sdf/sdf-dev.sh deleted file mode 100755 index 4d368266..00000000 --- a/demos/sdf/sdf-dev.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -x - - -SO_PATH="./libsdf.so" - -echo "[Commands]" -gmssl engine sdf -vvvv -echo "[Capabilities]" -gmssl engine sdf -c - -echo "[Change Device Label and Auth key]" -gmssl engine sdf -pre SO_PATH:$SO_PATH -pre OPEN_DEV -#gmssl engine sdf -pre SO_PATH:$SO_PATH -pre OPEN_DEV -pre OPEN_CONTAINER:1 - -echo "[Import/Export File]" -gmssl engine sdf -pre SO_PATH:$SO_PATH -pre IMPORT_FILE:localhost-signcer.pem - - diff --git a/demos/sdf/sdf-sm1.sh b/demos/sdf/sdf-sm1.sh deleted file mode 100755 index 04a6305f..00000000 --- a/demos/sdf/sdf-sm1.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -x - -#key=00000000000000000000000000000000 -#iv=00000000000000000000000000000000 - -key=12345678123456781234567812345678 -iv=12345678123456781234567812345678 -plaintext="This is the plaintext message." - -# FIXME: sm1/ssf33 is unkonwn to enc command -ciphertext=`echo $plaintext | sudo gmssl enc -sm1 -engine sdf -K $key -iv $iv -a` -plaintext=`echo $ciphertext | sudo gmssl enc -sm1 -d -engine sdf -K $key -iv $iv -a` - -echo "Ciphertext: $ciphertext" -echo "Plaintext: $plaintext" - diff --git a/demos/sdf/sdf-sm2enc.sh b/demos/sdf/sdf-sm2enc.sh deleted file mode 100755 index ddb76249..00000000 --- a/demos/sdf/sdf-sm2enc.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -x - -echo "######################################################################" -echo "# #" -echo "# Default PIN: 11111111 #" -echo "# #" -echo "######################################################################" - -echo "secret" | \ - sudo gmssl pkeyutl -encrypt -engine sdf -keyform engine -inkey ecc_1.exch -out sm2ciphertext.der - -# export the public key of the default encrypt/keyexchagne SM2 private key -# the default ID of the key container is `ecc_1.exch` -sudo gmssl pkey -engine sdf -inform engine -in ecc_1.exch -pubout -out sm2enckey.pem - -echo "secret" | \ - gmssl pkeyutl -encrypt -pkeyopt ec_scheme:sm2 -pkeyopt ec_encrypt_param:sm3 -pubin -inkey sm2enckey.pem -out sm2ciphertext2.der - -sudo gmssl pkeyutl -decrypt -engine sdf -keyform engine -inkey ecc_1.exch -in sm2ciphertext.der -sudo gmssl pkeyutl -decrypt -engine sdf -keyform engine -inkey ecc_1.exch -in sm2ciphertext2.der - diff --git a/demos/sdf/sdf-sm2sign.sh b/demos/sdf/sdf-sm2sign.sh deleted file mode 100755 index 1c21dc77..00000000 --- a/demos/sdf/sdf-sm2sign.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -x -# -# FIXME: if App already exist, this script will fail. -# - - -VERBOSE=2 -SO_PATH="./libsdf.so" -LABEL="MySKF" -APPNAME="MyApp1" -APPNAME2="MyApp2" - -echo "[Sign/Verify with SM2 Container]" -echo "abc" | gmssl sm3 -binary | sudo gmssl pkeyutl -sign -pkeyopt ec_scheme:sm2 -engine sdf -keyform engine -inkey ecc_1.sign -out sm2.sig -echo "abc" | gmssl sm3 -binary | sudo gmssl pkeyutl -verify -pkeyopt ec_scheme:sm2 -engine sdf -keyform engine -inkey ecc_1.sign -sigfile sm2.sig - -echo "[Verify with exported SM2 Verification Public Key]" -sudo gmssl pkey -engine sdf -inform engine -in ecc_1.sign -pubout -out sm2vkey.pem -echo "abc" | gmssl sm3 -binary | gmssl pkeyutl -verify -pkeyopt ec_scheme:sm2 -pubin -inkey sm2vkey.pem -sigfile sm2.sig - diff --git a/demos/sdf/sdf-sm3.sh b/demos/sdf/sdf-sm3.sh deleted file mode 100755 index 503deccf..00000000 --- a/demos/sdf/sdf-sm3.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -x - -echo -n abc | sudo gmssl dgst -sm3 -engine sdf -engine_impl # -r diff --git a/demos/sdf/sdf-sm4.sh b/demos/sdf/sdf-sm4.sh deleted file mode 100755 index 146ed607..00000000 --- a/demos/sdf/sdf-sm4.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -x - -#key=00000000000000000000000000000000 -#iv=00000000000000000000000000000000 - -key=12345678123456781234567812345678 -iv=12345678123456781234567812345678 -plaintext="This is the plaintext message." - -ciphertext=`echo $plaintext | sudo gmssl sms4 -K $key -iv $iv -a` - -echo $ciphertext -echo $plaintext | sudo gmssl sms4 -engine sdf -K $key -iv $iv -a -echo $ciphertext | sudo gmssl sms4 -d -engine sdf -K $key -iv $iv -a diff --git a/demos/sdf/sdf-ssf33.sh b/demos/sdf/sdf-ssf33.sh deleted file mode 100755 index 04a6305f..00000000 --- a/demos/sdf/sdf-ssf33.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -x - -#key=00000000000000000000000000000000 -#iv=00000000000000000000000000000000 - -key=12345678123456781234567812345678 -iv=12345678123456781234567812345678 -plaintext="This is the plaintext message." - -# FIXME: sm1/ssf33 is unkonwn to enc command -ciphertext=`echo $plaintext | sudo gmssl enc -sm1 -engine sdf -K $key -iv $iv -a` -plaintext=`echo $ciphertext | sudo gmssl enc -sm1 -d -engine sdf -K $key -iv $iv -a` - -echo "Ciphertext: $ciphertext" -echo "Plaintext: $plaintext" - diff --git a/demos/sdf/sdf-ssl-server.sh b/demos/sdf/sdf-ssl-server.sh deleted file mode 100755 index 24550a24..00000000 --- a/demos/sdf/sdf-ssl-server.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# `-trace` option require `.config enable-ssl-trace` - -#trace="-trace" - -#sudo gmssl s_server -tls1_2 -unlink -port 443 -cipher SM2 -engine sdf -keyform ENGINE -key ecc_1.sign -cert localhost-signcer.pem -msg -rev -sudo gmssl s_server -rev $trace -tls1_2 -unlink -port 4433 -cipher SM2 -engine sdf -keyform ENGINE -cert localhost.pem -key ecc_1.sign diff --git a/demos/sdf/sdf-zuc.sh b/demos/sdf/sdf-zuc.sh deleted file mode 100755 index 04a6305f..00000000 --- a/demos/sdf/sdf-zuc.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -x - -#key=00000000000000000000000000000000 -#iv=00000000000000000000000000000000 - -key=12345678123456781234567812345678 -iv=12345678123456781234567812345678 -plaintext="This is the plaintext message." - -# FIXME: sm1/ssf33 is unkonwn to enc command -ciphertext=`echo $plaintext | sudo gmssl enc -sm1 -engine sdf -K $key -iv $iv -a` -plaintext=`echo $ciphertext | sudo gmssl enc -sm1 -d -engine sdf -K $key -iv $iv -a` - -echo "Ciphertext: $ciphertext" -echo "Plaintext: $plaintext" - diff --git a/demos/sdf/sdf.c b/demos/sdf/sdf.c deleted file mode 100644 index 33b86a0d..00000000 --- a/demos/sdf/sdf.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include -#ifdef USE_GMAPI -# include -# include -# include -#else -/* - * We need vendor's SDF dynamic library and headers, for example when using - * Sansec PCI-E SDF card, make the following link: - * `ln -s /path/to/sansec/lib/linux/x86_64/libswsds.so.4.6.2.0_x64 libsdf.so` - * `ln -s /path/to/sansec/include/swsds.h sdf.h` - */ -# include "sdf.h" -#endif - - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - int rv; - void *hDev = NULL; - void *hSession = NULL; - DEVICEINFO devInfo; - -#ifdef USE_GMAPI - if (argc != 2) { - printf("usage: %s \n", prog); - return -1; - } - - if ((rv = SDF_LoadLibrary(argv[1], NULL)) != SDR_OK) { - ERR_print_errors_fp(stderr); - return -1; - } -#endif - - if ((rv = SDF_OpenDevice(&hDev)) != SDR_OK) { - fprintf(stderr, "%s: SDF_OpenDevice() return %08X", prog, rv); - goto end; - } - - if ((rv = SDF_OpenSession(hDev, &hSession)) != SDR_OK) { - fprintf(stderr, "%s: SDF_OpenSession() return %08X", prog, rv); - goto end; - } - - if ((rv = SDF_GetDeviceInfo(hSession, &devInfo)) != SDR_OK) { - fprintf(stderr, "%s: SDF_GetDeviceInfo() return %08X", prog, rv); - goto end; - } - -#ifdef USE_GMAPI - if ((rv = SDF_PrintDeviceInfo(&devInfo)) != SDR_OK) { - ERR_print_errors_fp(stderr); - goto end; - } -#endif - - if ((rv = SDF_CloseSession(hSession)) != SDR_OK) { - fprintf(stderr, "%s: SDF_CloseSession() return %08X", prog, rv); - goto end; - } - - if ((rv = SDF_CloseDevice(hDev)) != SDR_OK) { - fprintf(stderr, "%s: SDF_CloseDevice() return %08X", prog, rv); - goto end; - } - - ret = 0; - -end: -#ifdef USE_GMAPI - if (rv != SDR_OK) { - char *errstr; - SDF_GetErrorString(rv, &errstr); - fprintf(stderr, "%s: %s\n", prog, errstr); - ERR_print_errors_fp(stderr); - } - - SDF_UnloadLibrary(); -#endif - return ret; -} diff --git a/demos/sdf/sdf.cnf b/demos/sdf/sdf.cnf deleted file mode 100644 index fbb17ac2..00000000 --- a/demos/sdf/sdf.cnf +++ /dev/null @@ -1,16 +0,0 @@ -# conf file for gmssl sdf engine -openssl_conf = openssl_init - -[openssl_init] -engines = engine_section - -[engine_section] -sdf = sdf_section - -[sdf_section] -engine_id = sdf -SO_PATH = ./libswsds.so -VENDOR = sansec -OPEN_DEV = -init = 1 - diff --git a/demos/skf/Makefile b/demos/skf/Makefile deleted file mode 100644 index 83be1dd9..00000000 --- a/demos/skf/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -all: - #gcc skf.c libskf.so -o skf - gcc skf.c -DUSE_GMAPI -lcrypto -o skf-gmapi - -test: - #./skf - ./skf-gmapi - -clean: - rm -fr skf - rm -fr skf-gmapi diff --git a/demos/skf/skf.c b/demos/skf/skf.c deleted file mode 100644 index ca4c903c..00000000 --- a/demos/skf/skf.c +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include -#include -/* - * When USE_GMAPI, the code need to load vendor's SKF dynamic library through - * the GmSSL SKF framework, and the error string can be printed through the ERR - * module. - */ -#ifdef USE_GMAPI -# include -# include -# include -#else -/* - * Else the code can be directly linked with vendor's static or dynamic SKF - * library, and the code also need the vendor's SKF header files. - */ -# include "skf.h" -#endif - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - ULONG rv; - LPSTR nameList = NULL; - ULONG ulSize; - DEVHANDLE hDev; - DEVINFO devInfo; - -#ifdef USE_GMAPI - if (argc != 2) { - printf("usage: %s \n", prog); - return -1; - } - - if ((rv = SKF_LoadLibrary((LPSTR)argv[1], NULL)) != SAR_OK) { - ERR_print_errors_fp(stderr); - return -1; - } -#endif - - if ((rv = SKF_EnumDev(TRUE, NULL, &ulSize)) != SAR_OK) { - fprintf(stderr, "%s: SKF_EnumDev() return %u\n", prog, rv); - goto end; - } - - if (!(nameList = malloc(ulSize))) { - goto end; - } - - if ((rv = SKF_EnumDev(TRUE, nameList, &ulSize)) != SAR_OK) { - fprintf(stderr, "%s: SKF_EnumDev() return %u\n", prog, rv); - goto end; - } - - if ((rv = SKF_ConnectDev(nameList, &hDev)) != SAR_OK) { - fprintf(stderr, "%s: SKF_EnumDev() return %u\n", prog, rv); - goto end; - } - - if ((rv = SKF_GetDevInfo(hDev, &devInfo)) != SAR_OK) { - fprintf(stderr, "%s: SKF_EnumDev() return %u\n", prog, rv); - goto end; - } - -#ifdef USE_GMAPI - if ((rv = SKF_PrintDevInfo(&devInfo)) != SAR_OK) { - ERR_print_errors_fp(stderr); - goto end; - } -#endif - - if ((rv = SKF_DisConnectDev(hDev)) != SAR_OK) { - fprintf(stderr, "%s: SKF_EnumDev() return %u\n", prog, rv); - goto end; - } - - ret = 0; - -end: -#ifdef USE_GMAPI - SKF_UnloadLibrary(); -#endif - free(nameList); - return ret; -} diff --git a/demos/sm1/build.info b/demos/sm1/build.info deleted file mode 100644 index 5dc848fa..00000000 --- a/demos/sm1/build.info +++ /dev/null @@ -1,2 +0,0 @@ -LIBS=../../libcrypto -SOURCE[../../libcrypto]=sm1.c sm1_ecb.c sm1_cbc.c sm1_cfb.c sm1_ofb.c diff --git a/demos/sm1/e_sm1.c b/demos/sm1/e_sm1.c deleted file mode 100644 index 738bf1d4..00000000 --- a/demos/sm1/e_sm1.c +++ /dev/null @@ -1,89 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ - /* - * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include - -#include -#include -#include -#include -#include "evp_locl.h" -# include "internal/evp_int.h" -#include "../modes/modes_lcl.h" - - -typedef struct { - SM1_KEY ks; -} EVP_SM1_KEY; - -static int sm1_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) -{ - if (enc) { - ret = SM1_set_encrypt_key( - &EVP_C_DATA(EVP_SM1_KEY, ctx)->ks, key); - } else { - ret = SM1_set_decrypt_key( - &EVP_C_DATA(EVP_SM1_KEY, ctx)->ks, key); - } - return ret; -} - -IMPLEMENT_BLOCK_CIPHER(sm1, ks, SM1, EVP_SM1_KEY, NID_sm1, - 16, 16, 16, 128, EVP_CIPH_FLAG_DEFAULT_ASN1, - sm1_init_key, 0, 0, 0, 0) - diff --git a/demos/sm1/sm1.c b/demos/sm1/sm1.c deleted file mode 100644 index e07c9deb..00000000 --- a/demos/sm1/sm1.c +++ /dev/null @@ -1,78 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ - -/* - * As currently we dont have implementations, all these functions will - * return error. Maybe in the future there will be some hardware based - * implementations. For example, some of the code is compiled and running - * inside a crypto device, then there might be implementation. - */ -/* - * we need to generate some runtime alerts when these functions are called. - */ - -int SM1_set_encrypt_key(SM1_KEY *key, const unsigned char *user_key) -{ - return 0; -} - -int SM1_set_decrypt_key(SM1_KEY *key, const unsigned char *user_key) -{ - return 0; -} - -int SM1_encrypt(const unsigned char *in, unsigned char *out, SM1_KEY *key) -{ - return 0; -} - -int SM1_decrypt(const unsigned char *in, unsigned char *out, SM1_KEY *key) -{ - return 0; -} diff --git a/demos/sm1/sm1.h b/demos/sm1/sm1.h deleted file mode 100644 index c3898895..00000000 --- a/demos/sm1/sm1.h +++ /dev/null @@ -1,66 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 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. - * ==================================================================== - */ - -#ifndef HEADER_SM1_H -#define HEADER_SM1_H - -#define SM1_KEY_LENGTH 16 -#define SM1_BLOCK_SIZE 16 -#define SM1_IV_LENGTH (SM1_BLOCK_SIZE) - -typedef struct sm1_key_st { - unsigned int rk[64]; -} SM1_KEY; - -int SM1_set_encrypt_key(SM1_KEY *key, const unsigned char *user_key); -int SM1_set_decrypt_key(SM1_KEY *key, const unsigned char *user_key); -int SM1_encrypt(const unsigned char *in, unsigned char *out, SM1_KEY *key); -int SM1_decrypt(const unsigned char *in, unsigned char *out, SM1_KEY *key); - -#endif diff --git a/demos/sm1/sm1_cbc.c b/demos/sm1/sm1_cbc.c deleted file mode 100644 index fb89964d..00000000 --- a/demos/sm1/sm1_cbc.c +++ /dev/null @@ -1,72 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ -/* - * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include - -void SM1_cbc_encrypt(const unsigned char *in, unsigned char *out, - size_t inlen, const SM1_KEY *key, - unsigned char ivec[SM1_BLOCK_SIZE], int enc) -{ - if (enc) { - CRYPTO_cbc128_encrypt(in, out, inlen, key, ivec, - (block128_f)SM1_encrypt); - } else { - CRYPTO_cbc128_decrypt(in, out, inlen, key, ivec, - (block128_f)SM1_decrypt); - } -} diff --git a/demos/sm1/sm1_cfb.c b/demos/sm1/sm1_cfb.c deleted file mode 100644 index ceef0143..00000000 --- a/demos/sm1/sm1_cfb.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ -/* - * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include - -void SM1_cfb128_encrypt(const unsigned char *in, unsigned char *out, - size_t inlen, const SM1_KEY *key, - unsigned char ivec[SM1_BLOCK_SIZE], int *num, int enc) -{ - CRYPTO_cfb128_encrypt(in, out, inlen, key, ivec, num, enc, - (block128_f)SM1_encrypt); -} - diff --git a/demos/sm1/sm1_ecb.c b/demos/sm1/sm1_ecb.c deleted file mode 100644 index 38fb1a3a..00000000 --- a/demos/sm1/sm1_ecb.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ -/* - * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include - -void SM1_ecb_encrypt(const unsigned char *in, unsigned char *out, - const SM1_KEY *key, int enc) -{ - if (enc) { - SM1_encrypt(in, out, key); - } else { - SM1_decrypt(in, out, key); - } -} diff --git a/demos/sm1/sm1_ofb.c b/demos/sm1/sm1_ofb.c deleted file mode 100644 index 778741d4..00000000 --- a/demos/sm1/sm1_ofb.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ -/* - * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include - -void SM1_ofb128_encrypt(const unsigned char *in, unsigned char *out, - size_t inlen, const SM1_KEY *key, - unsigned char ivec[SM1_BLOCK_SIZE], int *num) -{ - CRYPTO_ofb128_encrypt(in, out, inlen, key, ivec, num, - (block128_f)SM1_encrypt); -} - diff --git a/demos/sm2/Makefile b/demos/sm2/Makefile deleted file mode 100644 index 53677a6b..00000000 --- a/demos/sm2/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -all: - gcc sm2-keygen.c -L /usr/local/lib -lcrypto -o sm2-keygen - gcc sm2-keygen.c -DENCRYPT_KEY -DNO_PROMPT -L /usr/local/lib -lcrypto -o sm2-keygen-enc - gcc sm2-keygen.c -DENCRYPT_KEY -L /usr/local/lib -lcrypto -o sm2-keygen-enc-prompt - gcc sm2-sign.c -L /usr/local/lib -lcrypto -o sm2-sign - gcc sm2-encrypt.c -L /usr/local/lib -lcrypto -o sm2-encrypt - -test: - ./sm2-keygen - echo - ./sm2-keygen-enc - echo - #./sm2-keygen-enc-prompt - ./sm2-sign - echo - ./sm2-encrypt - echo - -clean: - rm -fr a.out - rm -fr sm2-keygen - rm -fr sm2-keygen-enc - rm -fr sm2-keygen-enc-prompt - rm -fr sm2-sign - rm -fr sm2-encrypt diff --git a/demos/sm2/sm2-encrypt.c b/demos/sm2/sm2-encrypt.c deleted file mode 100644 index d1e06b62..00000000 --- a/demos/sm2/sm2-encrypt.c +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -int main(int argc, char **argv) -{ - int ret = -1; - EC_KEY *ec_key = NULL; - unsigned char key[64]; - unsigned char cbuf[1024]; - unsigned char pbuf[1024] = {0}; - size_t clen = sizeof(cbuf); - size_t plen = sizeof(pbuf); - int i; - - /* generate sm2 key pair */ - if (!(ec_key = EC_KEY_new_by_curve_name(NID_sm2p256v1)) - || !EC_KEY_generate_key(ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* generate to be encrypted symmetric key - * Notice: sm2 encrypt should only be used to encrypt short data - */ - if (!RAND_bytes(key, sizeof(key))) { - ERR_print_errors_fp(stderr); - goto end; - } - - printf("M = "); - for (i = 0; i < sizeof(key); i++) { - printf("%02X", key[i]); - } - printf("\n"); - - /* sm2 encrypt, hash algorithm is required for KDF */ - if (!SM2_encrypt(NID_sm3, key, sizeof(key), cbuf, &clen, ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - - printf("C = "); - for (i = 0; i < clen; i++) { - printf("%02X", cbuf[i]); - } - printf("\n"); - - /* sm2 decrypt */ - if (!SM2_decrypt(NID_sm3, cbuf, clen, pbuf, &plen, ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - - printf("M' = "); - for (i = 0; i < plen; i++) { - printf("%02X", pbuf[i]); - } - printf("\n"); - - ret = 0; - -end: - EC_KEY_free(ec_key); - return ret; -} diff --git a/demos/sm2/sm2-keygen.c b/demos/sm2/sm2-keygen.c deleted file mode 100644 index 3d78af81..00000000 --- a/demos/sm2/sm2-keygen.c +++ /dev/null @@ -1,106 +0,0 @@ - -/* - * This demo shows how to: - * - generate SM2 private - * - encrypt SM2 private key with SM4 - * - output public/private key in PEM format - * - generate the SM2 Z value from public key - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - EC_KEY *ec_key = NULL; - EVP_PKEY *pkey = NULL; - const EVP_CIPHER *cipher = NULL; - char *pass = NULL; - char *id = "12345678"; - unsigned char z[64]; - size_t zlen = sizeof(z); - int i; - - if (argc > 2) { - printf("usage: %s \n", prog); - return -1; - } - if (argc == 2) { - id = argv[1]; - } - - /* generate sm2 private key using EC_KEY API */ - if (!(ec_key = EC_KEY_new_by_curve_name(NID_sm2p256v1))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!EC_KEY_generate_key(ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* assign EC_KEY to EVP_PKEY */ - if (!(pkey = EVP_PKEY_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!EVP_PKEY_assign_EC_KEY(pkey, ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - ec_key = NULL; /* free-ed by EVP_PKEY */ - -#ifdef ENCRYPT_KEY - /* generate PKCS #8 EncryptedPrivateKeyInfo with SM4 - * else unencrypted PKCS #8 PrivateKeyInfo is generated. - */ - cipher = EVP_sms4_cbc(); -# ifdef NO_PROMPT - /* else user need to input password from prompt */ - pass = "P@ssw0rd"; -# endif -#endif - /* generate PKCS #8 in PEM format */ - if (!PEM_write_PKCS8PrivateKey(stdout, pkey, cipher, NULL, 0, 0, pass)) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* generate public key in pem format */ - if (!PEM_write_EC_PUBKEY(stdout, EVP_PKEY_get0_EC_KEY(pkey))) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* generate Z value in HEX */ - if (!SM2_compute_id_digest(EVP_sm3(), id, strlen(id), z, &zlen, - EVP_PKEY_get0_EC_KEY(pkey))) { - ERR_print_errors_fp(stderr); - goto end; - } - printf("Z = "); - for (i = 0; i < zlen; i++) { - printf("%02X", z[i]); - } - printf("\n"); - - ret = 0; - -end: - EC_KEY_free(ec_key); - EVP_PKEY_free(pkey); - return ret; -} diff --git a/demos/sm2/sm2-sign.c b/demos/sm2/sm2-sign.c deleted file mode 100644 index 3b2dfb0a..00000000 --- a/demos/sm2/sm2-sign.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -int main(int argc, char **argv) -{ - int ret = -1; - EC_KEY *ec_key = NULL; - char *id = "Alice"; - unsigned char msg[] = "This is the message to be signed"; - unsigned char dgst[EVP_MAX_MD_SIZE]; - size_t dgstlen = sizeof(dgst); - unsigned char sig[256]; - unsigned int siglen = sizeof(sig); - int i; - - if (!(ec_key = EC_KEY_new_by_curve_name(NID_sm2p256v1)) - || !EC_KEY_generate_key(ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - - printf("M = %s\n", (char *)msg); - printf("ID = %s\n", id); - - if (!SM2_compute_message_digest(EVP_sm3(), EVP_sm3(), msg, sizeof(msg), - id, strlen(id), dgst, &dgstlen, ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - printf("H(Z||M) = "); - for (i = 0; i < dgstlen; i++) { - printf("%02X", dgst[i]); - } - printf("\n"); - - if (!SM2_sign(NID_undef, dgst, dgstlen, sig, &siglen, ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - printf("Signature = "); - for (i = 0; i < siglen; i++) { - printf("%02X", sig[i]); - } - printf("\n"); - - if (1 != SM2_verify(NID_undef, dgst, dgstlen, sig, siglen, ec_key)) { - ERR_print_errors_fp(stderr); - goto end; - } - printf("Verification Success!\n"); - - ret = 0; - -end: - EC_KEY_free(ec_key); - return ret; -} diff --git a/demos/sm3/Makefile b/demos/sm3/Makefile deleted file mode 100644 index 0ddf5a8b..00000000 --- a/demos/sm3/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -all: - gcc sm3.c -L /usr/local/lib -lcrypto -o sm3 - gcc sm3evp.c -L /usr/local/lib -lcrypto -o sm3evp - gcc sm3hmac.c -L /usr/local/lib -lcrypto -o sm3hmac - -test: - echo "hello" | ./sm3 - echo "hello" | ./sm3evp - echo "hello" | ./sm3hmac - -clean: - rm -fr sm3 - rm -fr sm3evp - rm -fr sm3hmac diff --git a/demos/sm3/sm3.c b/demos/sm3/sm3.c deleted file mode 100755 index c1489216..00000000 --- a/demos/sm3/sm3.c +++ /dev/null @@ -1,92 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2018 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. - * ==================================================================== - */ -/* - * This SM3 demo use the native sm3_init/update/final APIs - */ - -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - sm3_ctx_t ctx; - unsigned char dgst[SM3_DIGEST_LENGTH]; - unsigned char buf[4096]; - ssize_t len; - int i; - - if (argc > 1) { - printf("usage: %s < file\n", basename(argv[0])); - return -1; - } - - /* init sm3 context */ - sm3_init(&ctx); - - /* increamental update data to be hashed */ - while ((len = read(STDIN_FILENO, buf, sizeof(buf))) > 0) { - sm3_update(&ctx, buf, len); - } - - /* get hash value */ - sm3_final(&ctx, dgst); - - /* print hash in hex */ - for (i = 0; i < sizeof(dgst); i++) { - printf("%02X", dgst[i]); - } - printf("\n"); - - return 0; -} diff --git a/demos/sm3/sm3evp.c b/demos/sm3/sm3evp.c deleted file mode 100755 index c0fe8dc4..00000000 --- a/demos/sm3/sm3evp.c +++ /dev/null @@ -1,120 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2018 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. - * ==================================================================== - */ -/* - * This SM3 demo use the abstract EVP API - */ - -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - FILE *fp = stdin; - unsigned char buf[1024]; - size_t len; - const EVP_MD *md = EVP_sm3(); - EVP_MD_CTX *mdctx = NULL; - unsigned char dgst[EVP_MAX_MD_SIZE]; - unsigned int dgstlen, i; - - /* hash a file when argv[1] exist, or from stdin */ - if (argc == 2) { - if (!(fp = fopen(argv[1], "r"))) { - fprintf(stderr, "open file %s failed\n", argv[1]); - return -1; - } - } - - /* get the SM3 EVP_MD object by name */ - if (!(md = EVP_get_digestbyname("sm3"))) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* create message digest (MD) context */ - if (!(mdctx = EVP_MD_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* set digest method, i.e. sm3 */ - if (!EVP_DigestInit(mdctx, md)) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* update data to be digested */ - while ((len = fread(buf, 1, sizeof(buf), fp))) { - if (!EVP_DigestUpdate(mdctx, buf, len)) { - ERR_print_errors_fp(stderr); - goto end; - } - } - - /* get the digest/hash value */ - if (!EVP_DigestFinal(mdctx, dgst, &dgstlen)) { - ERR_print_errors_fp(stderr); - goto end; - } - - for (i = 0; i < dgstlen; i++) { - printf("%02X", dgst[i]); - } - printf("\n"); - ret = 0; - -end: - fclose(fp); - EVP_MD_CTX_free(mdctx); - return ret; -} diff --git a/demos/sm3/sm3hmac.c b/demos/sm3/sm3hmac.c deleted file mode 100755 index f6558265..00000000 --- a/demos/sm3/sm3hmac.c +++ /dev/null @@ -1,126 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2018 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 -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - FILE *fp = stdin; - unsigned char key[32]; - unsigned char buf[1024]; - int len; - const EVP_MD *md; - HMAC_CTX *hmctx; - unsigned char mac[EVP_MAX_MD_SIZE]; - unsigned int maclen, i; - - if (argc == 2) { - if (!(fp = fopen(argv[1], "r"))) { - fprintf(stderr, "open file %s failed\n", argv[1]); - return -1; - } - } - - /* random generate HMAC key */ - if (!RAND_bytes(key, sizeof(key))) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* create HMAC context */ - if (!(hmctx = HMAC_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* get the sm3 EVP object */ - if (!(md = EVP_get_digestbyname("sm3"))) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* init HMAC hash algorithm (sm3) and key */ - if (!HMAC_Init_ex(hmctx, key, sizeof(key), md, NULL)) { - ERR_print_errors_fp(stderr); - goto end; - } - - /* update data to be MACed */ - while ((len = fread(buf, 1, sizeof(buf), fp))) { - if (!HMAC_Update(hmctx, buf, len)) { - ERR_print_errors_fp(stderr); - goto end; - } - } - - /* get the final HMAC tag */ - if (!HMAC_Final(hmctx, mac, &maclen)) { - ERR_print_errors_fp(stderr); - goto end; - } - - for (i = 0; i < maclen; i++) { - printf("%02x", mac[i]); - } - printf("\n"); - ret = 0; - -end: - fclose(fp); - HMAC_CTX_free(hmctx); - return ret; -} - diff --git a/demos/sm4/Makefile b/demos/sm4/Makefile deleted file mode 100644 index 898aed20..00000000 --- a/demos/sm4/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -all: - gcc sms4.c -L /usr/local/lib -lcrypto -o sms4 - gcc sms4.c -DUSE_RANDOM -L /usr/local/lib -lcrypto -o sms4rnd - gcc sms4evp.c -DMSG_LEN=20 -L /usr/local/lib -lcrypto -o sms4evp - -test: - ./sms4 - ./sms4rnd - ./sms4evp - -clean: - rm -fr sms4 - rm -fr sms4rnd - rm -fr sms4evp diff --git a/demos/sm4/sms4.c b/demos/sm4/sms4.c deleted file mode 100755 index dbd6d586..00000000 --- a/demos/sm4/sms4.c +++ /dev/null @@ -1,109 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2018 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. - * ==================================================================== - */ -/* - * This sm4 demo use the native sm3_init/update/final APIs - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -static void print_buf(const char *s, const unsigned char *buf, size_t buflen) -{ - int i; - printf("%s = ", s); - for (i = 0; i < buflen; i++) { - printf("%02X", buf[i]); - } - printf("\n"); -} - -int main(int argc, char **argv) -{ - sms4_key_t sms4; - unsigned char key[SMS4_KEY_LENGTH] = {0}; - unsigned char block[SMS4_BLOCK_SIZE] = {0}; - int i; - -#if USE_RANDOM - if (!RAND_bytes(key, sizeof(key)) - || !RAND_bytes(block, sizeof(block))) { - ERR_print_errors_fp(stderr); - return -1; - } -#endif - - print_buf("key", key, sizeof(key)); - print_buf("plaintext block", block, sizeof(block)); - - /* expand key for encryption */ - sms4_set_encrypt_key(&sms4, key); - - /* encrypt a block */ - sms4_encrypt(block, block, &sms4); - - print_buf("ciphertext block", block, sizeof(block)); - - /* expand key for decryption */ - sms4_set_decrypt_key(&sms4, key); - - /* decrypt a block */ - sms4_decrypt(block, block, &sms4); - - print_buf("decrypted block", block, sizeof(block)); - - return 0; -} diff --git a/demos/sm4/sms4evp.c b/demos/sm4/sms4evp.c deleted file mode 100755 index 9463fb4f..00000000 --- a/demos/sm4/sms4evp.c +++ /dev/null @@ -1,155 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2018 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. - * ==================================================================== - */ -/* - * This sm4 demo use the EVP API. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void print_buf(const char *s, const unsigned char *buf, size_t buflen) -{ - int i; - printf("%s = ", s); - for (i = 0; i < buflen; i++) { - printf("%02X", buf[i]); - } - printf("\n"); -} - -int main(int argc, char **argv) -{ - int ret = -1; - EVP_CIPHER_CTX *ctx = NULL; - const EVP_CIPHER *cipher = EVP_sms4_cbc(); - unsigned char key[SMS4_KEY_LENGTH] = {0}; - unsigned char iv[SMS4_IV_LENGTH] = {0}; - unsigned char msg[MSG_LEN]; - unsigned char cbuf[sizeof(msg) + SMS4_BLOCK_SIZE]; - unsigned char pbuf[sizeof(cbuf)]; - unsigned int clen, plen; - int len; - - /* generate random key/iv/msg */ - if (!RAND_bytes(key, sizeof(key)) - || !RAND_bytes(iv, sizeof(iv)) - || !RAND_bytes(msg, sizeof(msg))) { - ERR_print_errors_fp(stderr); - return -1; - } - - print_buf("key", key, sizeof(key)); - print_buf("iv", iv, sizeof(iv)); - print_buf("msg", msg, sizeof(msg)); - - /* create encrypt/decrypt context */ - if (!(ctx = EVP_CIPHER_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - - - /* encrypt */ - if (!EVP_EncryptInit(ctx, cipher, key, iv)) { - ERR_print_errors_fp(stderr); - goto end; - } - - clen = 0; - - if (!EVP_EncryptUpdate(ctx, cbuf, &len, msg, sizeof(msg))) { - ERR_print_errors_fp(stderr); - goto end; - } - clen += len; - - if (!EVP_EncryptFinal(ctx, cbuf + len, &len)) { - ERR_print_errors_fp(stderr); - goto end; - } - clen += len; - - print_buf("ciphertext", cbuf, clen); - - /* decrypt */ - if (!EVP_DecryptInit(ctx, cipher, key, iv)) { - ERR_print_errors_fp(stderr); - goto end; - } - - plen = 0; - - if (!EVP_DecryptUpdate(ctx, pbuf, &len, cbuf, clen)) { - ERR_print_errors_fp(stderr); - goto end; - } - plen += len; - - if (!EVP_DecryptFinal(ctx, pbuf + len, &len)) { - ERR_print_errors_fp(stderr); - goto end; - } - plen += len; - - print_buf("decrypted", pbuf, plen); - - ret = 0; - -end: - EVP_CIPHER_CTX_free(ctx); - return ret; -} diff --git a/demos/sm9/Makefile b/demos/sm9/Makefile deleted file mode 100644 index b2ed9918..00000000 --- a/demos/sm9/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -all: - gcc sm9-setup.c ../../libcrypto.a -o sm9-setup - gcc sm9-keygen.c ../../libcrypto.a -o sm9-keygen - gcc sm9-sign.c ../../libcrypto.a -o sm9-sign - gcc sm9-verify.c ../../libcrypto.a -o sm9-verify - gcc sm9-encrypt.c ../../libcrypto.a -o sm9-encrypt - gcc sm9-decrypt.c ../../libcrypto.a -o sm9-decrypt - -test: - echo "hello world" > hello.txt - ./sm9-setup sm9sign sm9sign.mpk sm9sign.msk - ./sm9-keygen sm9sign.msk alice alice.ssk - ./sm9-setup sm9encrypt sm9enc.mpk sm9enc.msk - ./sm9-keygen sm9enc.msk bob bob.esk - ./sm9-sign hello.txt alice.ssk hello.sig - ./sm9-verify hello.txt hello.sig sm9sign.mpk alice - ./sm9-encrypt hello.txt hello.sm9 sm9enc.mpk bob - ./sm9-decrypt hello.sm9 hello.dec bob.esk - -clean: - rm -fr sm9-setup - rm -fr sm9-keygen - rm -fr sm9-sign - rm -fr sm9-verify - rm -fr sm9-encrypt - rm -fr sm9-decrypt - rm -fr *.mpk - rm -fr *.msk - rm -fr *.ssk - rm -fr *.esk - rm -fr hello.* diff --git a/demos/sm9/sm9-decrypt.c b/demos/sm9/sm9-decrypt.c deleted file mode 100644 index f22f446e..00000000 --- a/demos/sm9/sm9-decrypt.c +++ /dev/null @@ -1,119 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2018 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 -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - FILE *sk_fp = NULL; - FILE *in_fp = NULL; - FILE *out_fp = NULL; - SM9PrivateKey *sk = NULL; - unsigned char in[1024]; - unsigned char out[1024]; - size_t inlen = sizeof(in); - size_t outlen = sizeof(out); - - if (argc != 4) { - printf("usage: %s \n", prog); - return 0; - } - - if (!(in_fp = fopen(argv[1], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[1]); - goto end; - } - inlen = fread(in, 1, sizeof(in), in_fp); - if (inlen >= sizeof(in)) { - fprintf(stderr, "%s: data to long\n", prog); - goto end; - } - - if (!(sk_fp = fopen(argv[3], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[2]); - goto end; - } - if (!(sk = d2i_SM9PrivateKey_fp(sk_fp, NULL))) { - ERR_print_errors_fp(stderr); - fprintf(stderr, "%s: parse public parameters failed\n", prog); - goto end; - } - - if (!SM9_decrypt(NID_sm9encrypt_with_sm3_xor, - in, inlen, out, &outlen, - sk)) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(out_fp = fopen(argv[2], "w"))) { - fprintf(stderr, "%s: can not open file\n", prog); - goto end; - } - if (fwrite(out, 1, outlen, out_fp) < 0) { - fprintf(stderr, "%s: output failed\n", prog); - goto end; - } - - ret = 0; - -end: - SM9PrivateKey_free(sk); - fclose(sk_fp); - fclose(in_fp); - fclose(out_fp); - return ret; -} diff --git a/demos/sm9/sm9-encrypt.c b/demos/sm9/sm9-encrypt.c deleted file mode 100644 index 22550f05..00000000 --- a/demos/sm9/sm9-encrypt.c +++ /dev/null @@ -1,121 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2018 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 -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - FILE *mpk_fp = NULL; - FILE *in_fp = NULL; - FILE *out_fp = NULL; - SM9PublicParameters *mpk = NULL; - SM9Ciphertext *cipher = NULL; - unsigned char in[256]; - unsigned char out[1024]; - size_t inlen = sizeof(in); - size_t outlen = sizeof(out); - - if (argc != 5) { - printf("usage: %s \n", prog); - return 0; - } - - if (!(in_fp = fopen(argv[1], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[1]); - goto end; - } - inlen = fread(in, 1, sizeof(in), in_fp); - if (inlen >= sizeof(in)) { - fprintf(stderr, "%s: data to long\n", prog); - goto end; - } - - if (!(mpk_fp = fopen(argv[3], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[2]); - goto end; - } - if (!(mpk = d2i_SM9PublicParameters_fp(mpk_fp, NULL))) { - ERR_print_errors_fp(stderr); - fprintf(stderr, "%s: parse public parameters failed\n", prog); - goto end; - } - - if (!SM9_encrypt(NID_sm9encrypt_with_sm3_xor, - in, inlen, out, &outlen, - mpk, argv[4], strlen(argv[4]))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(out_fp = fopen(argv[2], "w"))) { - fprintf(stderr, "%s: can not open file\n", prog); - goto end; - } - if (fwrite(out, 1, outlen, out_fp) < 0) { - fprintf(stderr, "%s: output failed\n", prog); - goto end; - } - - ret = 0; - -end: - SM9PublicParameters_free(mpk); - SM9Ciphertext_free(cipher); - fclose(mpk_fp); - fclose(in_fp); - fclose(out_fp); - return ret; -} diff --git a/demos/sm9/sm9-keygen.c b/demos/sm9/sm9-keygen.c deleted file mode 100644 index 9dc49502..00000000 --- a/demos/sm9/sm9-keygen.c +++ /dev/null @@ -1,97 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2018 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 -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - SM9MasterSecret *msk = NULL; - SM9PrivateKey *sk = NULL; - FILE *msk_fp = NULL; - FILE *sk_fp = NULL; - - if (argc != 4) { - printf("usage: %s \n", prog); - return -1; - } - - if (!(msk_fp = fopen(argv[1], "r")) - || !(msk = d2i_SM9MasterSecret_fp(msk_fp, NULL))) { - fprintf(stderr, "%s: read msk failed\n", prog); - goto end; - } - - if (!(sk = SM9_extract_private_key(msk, argv[2], strlen(argv[2])))) { - fprintf(stderr, "%s: generate private key failed\n", prog); - goto end; - } - - if (!(sk_fp = fopen(argv[3], "w")) - || !i2d_SM9PrivateKey_fp(sk_fp, sk)) { - fprintf(stderr, "%s: output sk file failed\n", prog); - goto end; - } - printf("generate private key file '%s'\n", argv[3]); - - ret = 0; - -end: - SM9MasterSecret_free(msk); - SM9PrivateKey_free(sk); - fclose(msk_fp); - fclose(sk_fp); - return ret; -} diff --git a/demos/sm9/sm9-setup.c b/demos/sm9/sm9-setup.c deleted file mode 100644 index 7fd979e9..00000000 --- a/demos/sm9/sm9-setup.c +++ /dev/null @@ -1,95 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2018 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 -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - char *msk_file; - char *mpk_file; - SM9MasterSecret *msk = NULL; - SM9PublicParameters *mpk = NULL; - FILE *msk_fp = NULL; - FILE *mpk_fp = NULL; - - if (argc != 4) { - printf("usage: %s \n", prog); - return -1; - } - - if (!SM9_setup(NID_sm9bn256v1, OBJ_txt2nid(argv[1]), NID_sm9hash1_with_sm3, &mpk, &msk)) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(msk_fp = fopen(argv[3], "w")) - || !(mpk_fp = fopen(argv[2], "w")) - || !i2d_SM9MasterSecret_fp(msk_fp, msk) - || !i2d_SM9PublicParameters_fp(mpk_fp, mpk)) { - fprintf(stderr, "%s: failed to output files\n", prog); - goto end; - } - printf("generate '%s'\n", argv[2]); - printf("generate '%s'\n", argv[3]); - - ret = 0; -end: - SM9MasterSecret_free(msk); - SM9PublicParameters_free(mpk); - fclose(msk_fp); - fclose(mpk_fp); - return ret; -} diff --git a/demos/sm9/sm9-sign.c b/demos/sm9/sm9-sign.c deleted file mode 100644 index 13b1814f..00000000 --- a/demos/sm9/sm9-sign.c +++ /dev/null @@ -1,129 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2018 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 -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - EVP_MD_CTX *ctx = NULL; - FILE *msg_fp = NULL; - FILE *sk_fp = NULL; - FILE *sig_fp = NULL; - SM9PrivateKey *sk = NULL; - SM9Signature *sig = NULL; - unsigned char buf[2048]; - int len; - - if (argc != 4) { - printf("usage: %s \n", prog); - return 0; - } - - if (!(ctx = EVP_MD_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!SM9_SignInit(ctx, EVP_sm3(), NULL)) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(msg_fp = fopen(argv[1], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[1]); - goto end; - } - while ((len = fread(buf, 1, sizeof(buf), msg_fp)) > 0) { - if (!SM9_SignUpdate(ctx, buf, len)) { - ERR_print_errors_fp(stderr); - goto end; - } - } - - if (!(sk_fp = fopen(argv[2], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[2]); - goto end; - } - if (!(sk = d2i_SM9PrivateKey_fp(sk_fp, NULL))) { - ERR_print_errors_fp(stderr); - fprintf(stderr, "%s: parse private key failed\n", prog); - goto end; - } - - if (!(sig = SM9_SignFinal(ctx, sk))) { - ERR_print_errors_fp(stderr); - fprintf(stderr, "%s: failed to generate siganture\n", prog); - goto end; - } - if (!(sig_fp = fopen(argv[3], "w"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[3]); - goto end; - } - if (!i2d_SM9Signature_fp(sig_fp, sig)) { - ERR_print_errors_fp(stderr); - goto end; - } - - ret = 0; - -end: - EVP_MD_CTX_free(ctx); - fclose(msg_fp); - fclose(sk_fp); - fclose(sig_fp); - SM9PrivateKey_free(sk); - SM9Signature_free(sig); - return ret; -} diff --git a/demos/sm9/sm9-verify.c b/demos/sm9/sm9-verify.c deleted file mode 100644 index 41d3db4c..00000000 --- a/demos/sm9/sm9-verify.c +++ /dev/null @@ -1,138 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2018 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 -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = basename(argv[0]); - EVP_MD_CTX *ctx = NULL; - FILE *msg_fp = NULL; - FILE *sig_fp = NULL; - FILE *mpk_fp = NULL; - SM9Signature *sig = NULL; - SM9PublicParameters *mpk = NULL; - SM9PublicKey *pk = NULL; - unsigned char buf[2048]; - int len; - - if (argc != 5) { - printf("usage: %s \n", prog); - return 0; - } - - if (!(ctx = EVP_MD_CTX_new())) { - ERR_print_errors_fp(stderr); - goto end; - } - if (!SM9_VerifyInit(ctx, EVP_sm3(), NULL)) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (!(msg_fp = fopen(argv[1], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[1]); - goto end; - } - while ((len = fread(buf, 1, sizeof(buf), msg_fp)) > 0) { - if (!SM9_VerifyUpdate(ctx, buf, len)) { - ERR_print_errors_fp(stderr); - goto end; - } - } - - if (!(sig_fp = fopen(argv[2], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[2]); - goto end; - } - if (!(sig = d2i_SM9Signature_fp(sig_fp, NULL))) { - ERR_print_errors_fp(stderr); - fprintf(stderr, "%s: parse signature failed\n", prog); - goto end; - } - - if (!(mpk_fp = fopen(argv[3], "r"))) { - fprintf(stderr, "%s: can not open file '%s'\n", prog, argv[2]); - goto end; - } - if (!(mpk = d2i_SM9PublicParameters_fp(mpk_fp, NULL))) { - ERR_print_errors_fp(stderr); - fprintf(stderr, "%s: parse public parameters failed\n", prog); - goto end; - } - if (!(pk = SM9_extract_public_key(mpk, argv[4], strlen(argv[4])))) { - ERR_print_errors_fp(stderr); - goto end; - } - - if (1 != SM9_VerifyFinal(ctx, sig, pk)) { - ERR_print_errors_fp(stderr); - printf("%s: verify failure\n", argv[2]); - goto end; - } - printf("%s: verify success\n", argv[2]); - - ret = 0; - -end: - EVP_MD_CTX_free(ctx); - fclose(msg_fp); - fclose(sig_fp); - fclose(mpk_fp); - SM9PublicParameters_free(mpk); - SM9PublicKey_free(pk); - SM9Signature_free(sig); - return ret; -} diff --git a/demos/ssf33/build.info b/demos/ssf33/build.info deleted file mode 100644 index cccfa69b..00000000 --- a/demos/ssf33/build.info +++ /dev/null @@ -1,2 +0,0 @@ -LIBS=../../libcrypto -SOURCE[../../libcrypto]=ssf33.c ssf33_ecb.c ssf33_cbc.c ssf33_cfb.c ssf33_ofb.c diff --git a/demos/ssf33/e_ssf33.c b/demos/ssf33/e_ssf33.c deleted file mode 100644 index ead75313..00000000 --- a/demos/ssf33/e_ssf33.c +++ /dev/null @@ -1,89 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ - /* - * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include - -#include -#include -#include -#include -#include "evp_locl.h" -# include "internal/evp_int.h" -#include "../modes/modes_lcl.h" - - -typedef struct { - SSF33_KEY ks; -} EVP_SSF33_KEY; - -static int ssf33_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) -{ - if (enc) { - ret = SSF33_set_encrypt_key( - &EVP_C_DATA(EVP_SSF33_KEY, ctx)->ks, key); - } else { - ret = SSF33_set_decrypt_key( - &EVP_C_DATA(EVP_SSF33_KEY, ctx)->ks, key); - } - return ret; -} - -IMPLEMENT_BLOCK_CIPHER(ssf33, ks, SSF33, EVP_SSF33_KEY, NID_ssf33, - 16, 16, 16, 128, EVP_CIPH_FLAG_DEFAULT_ASN1, - ssf33_init_key, 0, 0, 0, 0) - diff --git a/demos/ssf33/ssf33.c b/demos/ssf33/ssf33.c deleted file mode 100644 index b73061fd..00000000 --- a/demos/ssf33/ssf33.c +++ /dev/null @@ -1,80 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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 - -/* - * As currently we dont have implementations, all these functions will - * return error. Maybe in the future there will be some hardware based - * implementations. For example, some of the code is compiled and running - * inside a crypto device, then there might be implementation. - */ -/* - * we need to generate some runtime alerts when these functions are called. - */ - -int SSF33_set_encrypt_key(SSF33_KEY *key, const unsigned char *user_key) -{ - return 0; -} - -int SSF33_set_decrypt_key(SSF33_KEY *key, const unsigned char *user_key) -{ - return 0; -} - -int SSF33_encrypt(const unsigned char *in, unsigned char *out, SSF33_KEY *key) -{ - return 0; -} - -int SSF33_decrypt(const unsigned char *in, unsigned char *out, SSF33_KEY *key) -{ - return 0; -} diff --git a/demos/ssf33/ssf33.h b/demos/ssf33/ssf33.h deleted file mode 100644 index 6a107228..00000000 --- a/demos/ssf33/ssf33.h +++ /dev/null @@ -1,67 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 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. - * ==================================================================== - */ - -#ifndef HEADER_SSF33_H -#define HEADER_SSF33_H - -#define SSF33_KEY_LENGTH 16 -#define SSF33_BLOCK_SIZE 16 -#define SSF33_IV_LENGTH (SSF33_BLOCK_SIZE) - - -typedef struct ssf33_key_st { - unsigned int rk[64]; -} SSF33_KEY; - -int SSF33_set_encrypt_key(SSF33_KEY *key, const unsigned char *user_key); -int SSF33_set_decrypt_key(SSF33_KEY *key, const unsigned char *user_key); -int SSF33_encrypt(const unsigned char *in, unsigned char *out, SSF33_KEY *key); -int SSF33_decrypt(const unsigned char *in, unsigned char *out, SSF33_KEY *key); - -#endif diff --git a/demos/ssf33/ssf33_cbc.c b/demos/ssf33/ssf33_cbc.c deleted file mode 100644 index c9372d30..00000000 --- a/demos/ssf33/ssf33_cbc.c +++ /dev/null @@ -1,73 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ -/* - * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include - -void SSF33_cbc_encrypt(const unsigned char *in, unsigned char *out, - size_t inlen, const SSF33_KEY *key, - unsigned char ivec[SSF33_BLOCK_SIZE], int enc) -{ - if (enc) { - CRYPTO_cbc128_encrypt(in, out, inlen, key, ivec, - (block128_f)SSF33_encrypt); - } else { - CRYPTO_cbc128_decrypt(in, out, inlen, key, ivec, - (block128_f)SSF33_decrypt); - } -} - diff --git a/demos/ssf33/ssf33_cfb.c b/demos/ssf33/ssf33_cfb.c deleted file mode 100644 index e8146b2f..00000000 --- a/demos/ssf33/ssf33_cfb.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ -/* - * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include - -void SSF33_cfb128_encrypt(const unsigned char *in, unsigned char *out, - size_t inlen, const SSF33_KEY *key, - unsigned char ivec[SSF33_BLOCK_SIZE], int *num, int enc) -{ - CRYPTO_cfb128_encrypt(in, out, inlen, key, ivec, num, enc, - (block128_f)SSF33_encrypt); -} - diff --git a/demos/ssf33/ssf33_ecb.c b/demos/ssf33/ssf33_ecb.c deleted file mode 100644 index 12d45b5b..00000000 --- a/demos/ssf33/ssf33_ecb.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ -/* - * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include - -void SSF33_ecb_encrypt(const unsigned char *in, unsigned char *out, - const SSF33_KEY *key, int enc) -{ - if (enc) { - SSF33_encrypt(in, out, key); - } else { - SSF33_decrypt(in, out, key); - } -} diff --git a/demos/ssf33/ssf33_ofb.c b/demos/ssf33/ssf33_ofb.c deleted file mode 100644 index ead7fecd..00000000 --- a/demos/ssf33/ssf33_ofb.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ==================================================================== - * Copyright (c) 2016 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. - * ==================================================================== - */ -/* - * Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include - -void SSF33_ofb128_encrypt(const unsigned char *in, unsigned char *out, - size_t inlen, const SSF33_KEY *key, - unsigned char ivec[SSF33_BLOCK_SIZE], int *num) -{ - CRYPTO_ofb128_encrypt(in, out, inlen, key, ivec, num, - (block128_f)SSF33_encrypt); -} -