This commit is contained in:
Zhi Guan
2018-11-28 16:46:22 +08:00
parent 1fc95d13a7
commit 7ddf846d33
59 changed files with 0 additions and 3885 deletions

View File

@@ -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

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/cpk.h>
#include <openssl/pem.h>
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 <msk-file> <id> <sk-file>\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;
}

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/cpk.h>
#include <openssl/err.h>
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 <mpk-file> <msk-file>\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;
}

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/cpk.h>
#include <openssl/pem.h>
#include <openssl/sm2.h>
#include <openssl/is_gmssl.h>
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 <file> <id> <sk-file> <signed-file>\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;
}

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/cpk.h>
#include <openssl/pem.h>
#include <openssl/sm2.h>
#include <openssl/is_gmssl.h>
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 <signed-file> <mpk-file>\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;
}

View File

@@ -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

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/ffx.h>
#include <openssl/is_gmssl.h>
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 <digits> <key> <tweak>\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;
}

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/ffx.h>
#include <openssl/is_gmssl.h>
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 <digits> <key> <tweak>\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;
}

View File

@@ -1,37 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/is_gmssl.h>
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;
}

View File

@@ -1,43 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <openssl/err.h>
#include <openssl/otp.h>
#include <openssl/objects.h>
#include <openssl/is_gmssl.h>
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(&params, event, sizeof(event), &otp, key, sizeof(key))) {
ERR_print_errors_fp(stderr);
return -1;
}
printf("%06u\n", otp);
return 0;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -1,3 +0,0 @@
#!/bin/bash -x
echo -n abc | sudo gmssl dgst -sm3 -engine sdf -engine_impl # -r

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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"

View File

@@ -1,87 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#ifdef USE_GMAPI
# include <openssl/err.h>
# include <openssl/gmsdf.h>
# include <openssl/is_gmssl.h>
#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 <libsdf.so>\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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -1,88 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
/*
* 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 <openssl/err.h>
# include <openssl/gmskf.h>
# include <openssl/is_gmssl.h>
#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 <libskf.so>\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;
}

View File

@@ -1,2 +0,0 @@
LIBS=../../libcrypto
SOURCE[../../libcrypto]=sm1.c sm1_ecb.c sm1_cbc.c sm1_cfb.c sm1_ofb.c

View File

@@ -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 <stdio.h>
#include <openssl/evp.h>
#include <openssl/sm1.h>
#include <openssl/crypto.h>
#include <openssl/objects.h>
#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)

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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 <openssl/sm1.h>
#include <openssl/modes.h>
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);
}
}

View File

@@ -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 <openssl/sm1.h>
#include <openssl/modes.h>
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);
}

View File

@@ -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 <openssl/sm1.h>
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);
}
}

View File

@@ -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 <openssl/sm1.h>
#include <openssl/modes.h>
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);
}

View File

@@ -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

View File

@@ -1,75 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/ec.h>
#include <openssl/sm2.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/objects.h>
#include <openssl/is_gmssl.h>
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;
}

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/ec.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/sm2.h>
#include <openssl/objects.h>
#include <openssl/is_gmssl.h>
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 <id>\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;
}

View File

@@ -1,65 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <openssl/ec.h>
#include <openssl/sm2.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/is_gmssl.h>
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;
}

View File

@@ -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

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <openssl/sm3.h>
#include <openssl/is_gmssl.h>
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;
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/is_gmssl.h>
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;
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/hmac.h>
#include <openssl/rand.h>
#include <openssl/is_gmssl.h>
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;
}

View File

@@ -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

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/sms4.h>
#include <openssl/is_gmssl.h>
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;
}

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/sms4.h>
#include <openssl/is_gmssl.h>
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;
}

View File

@@ -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.*

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <openssl/sm9.h>
#include <openssl/err.h>
#include <openssl/objects.h>
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 <in-file> <out-file> <sk-file>\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;
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <openssl/sm9.h>
#include <openssl/err.h>
#include <openssl/objects.h>
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 <in-file> <out-file> <mpk-file> <id>\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;
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <openssl/sm9.h>
#include <openssl/err.h>
#include <openssl/objects.h>
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 <msk-file> <id> <sk-file>\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;
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <openssl/sm9.h>
#include <openssl/err.h>
#include <openssl/objects.h>
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 <sm9sign|sm9encrypt> <mpk-file> <msk-file>\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;
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <openssl/sm9.h>
#include <openssl/err.h>
#include <openssl/objects.h>
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 <msg-file> <sk-file> <sig-file>\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;
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <openssl/sm9.h>
#include <openssl/err.h>
#include <openssl/objects.h>
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 <msg-file> <sig-file> <mpk-file> <id>\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;
}

View File

@@ -1,2 +0,0 @@
LIBS=../../libcrypto
SOURCE[../../libcrypto]=ssf33.c ssf33_ecb.c ssf33_cbc.c ssf33_cfb.c ssf33_ofb.c

View File

@@ -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 <stdio.h>
#include <openssl/evp.h>
#include <openssl/ssf33.h>
#include <openssl/crypto.h>
#include <openssl/objects.h>
#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)

View File

@@ -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 <openssl/ssf33.h>
/*
* 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;
}

View File

@@ -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

View File

@@ -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 <openssl/ssf33.h>
#include <openssl/modes.h>
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);
}
}

View File

@@ -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 <openssl/ssf33.h>
#include <openssl/modes.h>
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);
}

View File

@@ -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 <openssl/ssf33.h>
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);
}
}

View File

@@ -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 <openssl/ssf33.h>
#include <openssl/modes.h>
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);
}