Support VC-WIN32

This commit is contained in:
Zhi Guan
2016-07-04 13:03:03 +02:00
parent f881784b73
commit 09f054b2f2
109 changed files with 16877 additions and 200 deletions

165
crypto/sm2/Makefile.save Normal file
View File

@@ -0,0 +1,165 @@
#
# crypto/sm2/Makefile
#
DIR= sm2
TOP= ../..
CC= cc
INCLUDES= -I.. -I$(TOP) -I../../include
CFLAG=-g -Wall
MAKEFILE= Makefile
AR= ar r
CFLAGS= $(INCLUDES) $(CFLAG)
GENERAL=Makefile
TEST=sm2test.c
APPS=
LIB=$(TOP)/libcrypto.a
LIBSRC= sm2_lib.c sm2_asn1.c sm2_err.c sm2_sign.c sm2_enc.c sm2_kap.c
LIBOBJ= sm2_lib.o sm2_asn1.o sm2_err.o sm2_sign.o sm2_enc.o sm2_kap.o
SRC= $(LIBSRC)
EXHEADER= sm2.h
HEADER= $(EXHEADER)
ALL= $(GENERAL) $(SRC) $(HEADER)
top:
(cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
all: lib
lib: $(LIBOBJ)
$(AR) $(LIB) $(LIBOBJ)
$(RANLIB) $(LIB) || echo Never mind.
@touch lib
files:
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
links:
@$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
@$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
@$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
install:
@[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
@headerlist="$(EXHEADER)"; for i in $$headerlist; \
do \
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
done;
tags:
ctags $(SRC)
tests:
lint:
lint -DLINT $(INCLUDES) $(SRC)>fluff
update: depend
depend:
@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
dclean:
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
mv -f Makefile.new $(MAKEFILE)
clean:
rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
# DO NOT DELETE THIS LINE -- make depend depends on it.
sm2_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
sm2_asn1.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
sm2_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
sm2_asn1.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
sm2_asn1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
sm2_asn1.o: ../../include/openssl/evp.h ../../include/openssl/kdf.h
sm2_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
sm2_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
sm2_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
sm2_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
sm2_asn1.o: ../../include/openssl/sha.h ../../include/openssl/sm2.h
sm2_asn1.o: ../../include/openssl/sm3.h ../../include/openssl/stack.h
sm2_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
sm2_asn1.o: ../../include/openssl/x509_vfy.h sm2_asn1.c
sm2_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
sm2_enc.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
sm2_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
sm2_enc.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
sm2_enc.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
sm2_enc.o: ../../include/openssl/evp.h ../../include/openssl/kdf.h
sm2_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
sm2_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
sm2_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
sm2_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
sm2_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
sm2_enc.o: ../../include/openssl/sm2.h ../../include/openssl/sm3.h
sm2_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
sm2_enc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
sm2_enc.o: ../o_str.h sm2_enc.c
sm2_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
sm2_err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
sm2_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
sm2_err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
sm2_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
sm2_err.o: ../../include/openssl/kdf.h ../../include/openssl/lhash.h
sm2_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
sm2_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
sm2_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
sm2_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
sm2_err.o: ../../include/openssl/sm2.h ../../include/openssl/sm3.h
sm2_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
sm2_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
sm2_err.o: sm2_err.c
sm2_kap.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
sm2_kap.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
sm2_kap.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
sm2_kap.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
sm2_kap.o: ../../include/openssl/err.h ../../include/openssl/evp.h
sm2_kap.o: ../../include/openssl/kdf.h ../../include/openssl/lhash.h
sm2_kap.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
sm2_kap.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
sm2_kap.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
sm2_kap.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
sm2_kap.o: ../../include/openssl/sm2.h ../../include/openssl/sm3.h
sm2_kap.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
sm2_kap.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h sm2.h
sm2_kap.o: sm2_kap.c
sm2_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
sm2_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
sm2_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
sm2_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
sm2_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
sm2_lib.o: ../../include/openssl/evp.h ../../include/openssl/kdf.h
sm2_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
sm2_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
sm2_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
sm2_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
sm2_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
sm2_lib.o: ../../include/openssl/sm2.h ../../include/openssl/sm3.h
sm2_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
sm2_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
sm2_lib.o: sm2_lib.c
sm2_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
sm2_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
sm2_sign.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
sm2_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
sm2_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
sm2_sign.o: ../../include/openssl/evp.h ../../include/openssl/kdf.h
sm2_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
sm2_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
sm2_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
sm2_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
sm2_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
sm2_sign.o: ../../include/openssl/sm2.h ../../include/openssl/sm3.h
sm2_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
sm2_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
sm2_sign.o: sm2_sign.c

View File

@@ -53,7 +53,6 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <strings.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
@@ -105,7 +104,7 @@ SM2_CIPHERTEXT_VALUE *SM2_CIPHERTEXT_VALUE_new(const EC_GROUP *group)
return NULL;
}
bzero(cv, sizeof(*cv));
memset(cv, 0, sizeof(*cv));
if (!(cv->ephem_point = EC_POINT_new(group))) {
SM2err(SM2_F_SM2_CIPHERTEXT_VALUE_NEW, SM2_R_POINT_NEW_FAILED);
@@ -120,7 +119,7 @@ void SM2_CIPHERTEXT_VALUE_free(SM2_CIPHERTEXT_VALUE *cv)
{
if (cv->ephem_point) EC_POINT_free(cv->ephem_point);
if (cv->ciphertext) OPENSSL_free(cv->ciphertext);
bzero(cv, sizeof(SM2_CIPHERTEXT_VALUE));
memset(cv, 0, sizeof(*cv));
OPENSSL_free(cv);
}
@@ -352,7 +351,7 @@ SM2_CIPHERTEXT_VALUE *SM2_do_encrypt(const SM2_ENC_PARAMS *params,
SM2err(SM2_F_SM2_DO_ENCRYPT, SM2_R_MALLOC_FAILED);
goto end;
}
bzero(cv, sizeof(SM2_CIPHERTEXT_VALUE));
memset(cv, 0, sizeof(*cv));
cv->ephem_point = EC_POINT_new(ec_group);
cv->ciphertext = OPENSSL_malloc(inlen);
cv->ciphertext_size = inlen;

View File

@@ -1,119 +0,0 @@
/* crypto/sm2/sm2_err.c */
/* ====================================================================
* Copyright (c) 2015 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 <openssl/err.h>
#include "sm2.h"
#ifndef OPENSSL_NO_ERR
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECIES,func,0)
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECIES,0,reason)
static ERR_STRING_DATA SM2_str_functs[] = {
{ERR_FUNC(SM2_F_SM2_SET_ID), "SM2_SET_ID"},
{ERR_FUNC(SM2_F_SM2_GET_ID), "SM2_F_SM2_GET_ID"},
{ERR_FUNC(SM2_F_SM2_COMPUTE_ID_DIGEST), "SM2_compute_id_digest"},
{ERR_FUNC(SM2_F_SM2_CIPHERTEXT_VALUE_SIZE), "SM2_CIPHERTEXT_VALUE_size"},
{ERR_FUNC(SM2_F_SM2_CIPHERTEXT_VALUE_FREE), "SM2_CIPHERTEXT_VALUE_free"},
{ERR_FUNC(SM2_F_SM2_CIPHERTEXT_VALUE_ENCODE), "SM2_CIPHERTEXT_VALUE_encode"},
{ERR_FUNC(SM2_F_SM2_CIPHERTEXT_VALUE_DECODE), "SM2_CIPHERTEXT_VALUE_decode"},
{ERR_FUNC(SM2_F_SM2_CIPHERTEXT_VALUE_PRINT), "SM2_CIPHERTEXT_VALUE_print"},
{ERR_FUNC(SM2_F_SM2_DO_ENCRYPT), "SM2_do_encrypt"},
{ERR_FUNC(SM2_F_SM2_DO_DECRYPT), "SM2_do_decrypt"},
{ERR_FUNC(SM2_F_SM2_ENCRYPT), "SM2_encrypt"},
{ERR_FUNC(SM2_F_SM2_DECRYPT), "SM2_decrypt"},
{ERR_FUNC(SM2_F_SM2_SIGNATURE_SIZE), "SM2_signature_size"},
{ERR_FUNC(SM2_F_SM2_SIGN_SETUP), "SM2_sign_setup"},
{ERR_FUNC(SM2_F_SM2_DO_SIGN_EX), "SM2_do_sign_ex"},
{ERR_FUNC(SM2_F_SM2_DO_SIGN), "SM2_do_sign"},
{ERR_FUNC(SM2_F_SM2_DO_VERIFY), "SM2_do_verify"},
{ERR_FUNC(SM2_F_SM2_SIGN_EX), "SM2_sign_ex"},
{ERR_FUNC(SM2_F_SM2_SIGN), "SM2_sign"},
{ERR_FUNC(SM2_F_SM2_VERIFY), "SM2_verify"},
{ERR_FUNC(SM2_F_SM2_KAP_CTX_INIT), "SM2_KAP_CTX_init"},
{ERR_FUNC(SM2_F_SM2_KAP_CTX_CLEANUP), "SM2_KAP_CTX_cleanup"},
{ERR_FUNC(SM2_F_SM2_KAP_PREPARE), "SM2_KAP_prepare"},
{ERR_FUNC(SM2_F_SM2_KAP_COMPUTE_KEY), "SM2_KAP_compute_key"},
{ERR_FUNC(SM2_F_SM2_KAP_FINAL_CHECK), "SM2_KAP_final_check"},
{0,NULL}
};
static ERR_STRING_DATA SM2_str_reasons[] = {
{ERR_REASON(SM2_R_BAD_DATA), "bad data"},
{ERR_REASON(SM2_R_UNKNOWN_CIPHER_TYPE), "unknown cipher type"},
{ERR_REASON(SM2_R_ENCRYPT_FAILED), "encrypt failed"},
{ERR_REASON(SM2_R_DECRYPT_FAILED), "decrypt failed"},
{ERR_REASON(SM2_R_UNKNOWN_MAC_TYPE), "unknown MAC type"},
{ERR_REASON(SM2_R_GEN_MAC_FAILED), "MAC generation failed"},
{ERR_REASON(SM2_R_VERIFY_MAC_FAILED), "MAC verification failed"},
{ERR_REASON(SM2_R_ECDH_FAILED), "ECDH failed"},
{ERR_REASON(SM2_R_BUFFER_TOO_SMALL), "buffer too small"},
{ERR_REASON(SM2_R_SM2_KAP_NOT_INITED), "KAP not inited"},
{ERR_REASON(SM2_R_RANDOM_NUMBER_GENERATION_FAILED), "random number generation failed"},
{ERR_REASON(SM2_R_ERROR), "Error"},
{0,NULL}
};
#endif
void ERR_load_SM2_strings(void)
{
#ifndef OPENSSL_NO_ERR
if (ERR_func_error_string(SM2_str_functs[0].error) == NULL) {
ERR_load_strings(0,SM2_str_functs);
ERR_load_strings(0,SM2_str_reasons);
}
#endif
}

View File

@@ -54,7 +54,6 @@
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/err.h>
@@ -134,7 +133,7 @@ int sm2_get_public_key_data(unsigned char *buf, EC_KEY *ec_key)
return 0;
}
nbytes = (EC_GROUP_get_degree(EC_KEY_get0_group(ec_key)) + 7)/8;
bzero(buf, nbytes * 6);
memset(buf, 0, nbytes * 6);
bn_ctx = BN_CTX_new();
p = BN_new();

View File

@@ -1,6 +1,5 @@
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <openssl/ec.h>
#include <openssl/bn.h>
#include <openssl/evp.h>
@@ -26,7 +25,7 @@ int fbytes(unsigned char *buf, int num)
if (BN_num_bytes(bn) > num) {
goto end;
}
bzero(buf, num);
memset(buf, 0, num);
if (!BN_bn2bin(bn, buf + num - BN_num_bytes(bn))) {
goto end;
}
@@ -732,7 +731,7 @@ int test_evp_pkey_sign(EVP_PKEY *pkey, int do_sm2, int verbose)
}
dgstlen = 32;
bzero(sig, sizeof(sig));
memset(sig, 0, sizeof(sig));
siglen = sizeof(sig);
if (!EVP_PKEY_sign(pkctx, sig, &siglen, dgst, dgstlen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
@@ -829,7 +828,7 @@ int test_evp_pkey_encrypt(EVP_PKEY *pkey, int do_sm2, int verbose)
goto end;
}
bzero(mbuf, sizeof(mbuf));
memset(mbuf, 0, sizeof(mbuf));
mbuflen = sizeof(mbuf);
if (!EVP_PKEY_decrypt(pkctx, mbuf, &mbuflen, cbuf, cbuflen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
@@ -877,7 +876,7 @@ int test_evp_pkey_encrypt_old(EVP_PKEY *pkey, int verbose)
printf("\n");
}
bzero(mbuf, sizeof(mbuf));
memset(mbuf, 0, sizeof(mbuf));
if ((len = EVP_PKEY_decrypt_old(mbuf, cbuf, len, pkey)) <= 0) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
@@ -1119,7 +1118,7 @@ int test_evp_seal(int curve_id, const EVP_CIPHER *cipher, BIO *out, int verbose)
goto end;
}
bzero(mbuf, sizeof(mbuf));
memset(mbuf, 0, sizeof(mbuf));
p = mbuf;
len = sizeof(mbuf);