From 9dec172acb29d4aa16120784b1587edd7f46648c Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Wed, 16 Sep 2015 18:38:22 +0300 Subject: [PATCH] New (autoconf based) build system (install unfinished). Support for compilation with already-released openssl --- Makefile | 282 ------------------------------------------------- Makefile.am | 13 +++ config.h.in | 65 ++++++++++++ configure.ac | 22 ++++ gost_ameth.c | 118 +++++++++------------ gost_crypt.c | 6 +- gost_ec_keyx.c | 6 +- gost_eng.c | 109 +++++++++++-------- gost_md2012.c | 4 +- gost_obj.txt | 2 +- gost_params.c | 4 +- gost_pmeth.c | 92 +++++++--------- 12 files changed, 265 insertions(+), 458 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100644 config.h.in create mode 100644 configure.ac diff --git a/Makefile b/Makefile deleted file mode 100644 index 727f95a..0000000 --- a/Makefile +++ /dev/null @@ -1,282 +0,0 @@ -DIR=ccgost -TOP=../.. -CC=cc -INCLUDES= -I../../include -CFLAG=-g -MAKEFILE= Makefile -AR= ar r -CFLAGS= $(INCLUDES) $(CFLAG) -LIB=$(TOP)/libcrypto.a - -LIBSRC= gost_md2012.c gosthash2012.c gost_ec_sign.c gost_ec_keyx.c gost89.c gost_ameth.c gost_asn1.c gost_crypt.c gost_ctl.c gost_eng.c gosthash.c gost_keywrap.c gost_md.c gost_params.c gost_pmeth.c obj_create.c newnids.c - -LIBOBJ= gost_md2012.o gosthash2012.o e_gost_err.o gost_ec_keyx.o gost_ec_sign.o gost89.o gost_ameth.o gost_asn1.o gost_crypt.o gost_ctl.o gost_eng.o gosthash.o gost_keywrap.o gost_md.o gost_params.o gost_pmeth.o newnids.o - -SRC=$(LIBSRC) - -LIBNAME=gost - -top: - (cd $(TOP); $(MAKE) DIRS=engines sub_all) - -all: lib - -tags: - ctags $(SRC) - -errors: - $(PERL) ../../util/mkerr.pl -conf gost.ec -nostatic -write $(SRC) - -lib: $(LIBOBJ) - if [ -n "$(SHARED_LIBS)" ]; then \ - $(MAKE) -f $(TOP)/Makefile.shared -e \ - LIBNAME=$(LIBNAME) \ - LIBEXTRAS='$(LIBOBJ)' \ - LIBDEPS='-L$(TOP) -lcrypto' \ - link_o.$(SHLIB_TARGET); \ - else \ - $(AR) $(LIB) $(LIBOBJ); \ - fi - @touch lib - -install: - [ -n "$(INSTALLTOP)" ] # should be set by top Makefile... - if [ -n "$(SHARED_LIBS)" ]; then \ - set -e; \ - echo installing $(LIBNAME); \ - pfx=lib; \ - if expr "$(PLATFORM)" : "Cygwin" >/dev/null; then \ - sfx=".so"; \ - cp cyg$(LIBNAME).dll $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx.new; \ - else \ - case "$(CFLAGS)" in \ - *DSO_DLFCN*) sfx=`expr "$(SHLIB_EXT)" : '.*\(\.[a-z][a-z]*\)' \| ".so"`;; \ - *DSO_DL*) sfx=".sl";; \ - *DSO_WIN32*) sfx="eay32.dll"; pfx=;; \ - *) sfx=".bad";; \ - esac; \ - cp $${pfx}$(LIBNAME)$$sfx $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx.new; \ - fi; \ - chmod 555 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx.new; \ - mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx.new $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$${pfx}$(LIBNAME)$$sfx; \ - fi - -tests: - -update: local_depend - @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi - -depend: local_depend - @if [ -z "$(THIS)" ]; then $(MAKE) -f $(TOP)/Makefile reflect THIS=$@; fi -local_depend: - @[ -z "$(THIS)" ] || $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) - -files: - $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO - -lint: - lint -DLINT $(INCLUDES) $(SRC)>fluff - -dclean: - $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new - mv -f Makefile.new $(MAKEFILE) - -clean: - rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff *.so *.sl *.dll *.dylib - -newnids.c: mkobj.pl gost_objs.txt - $(PERL) mkobj.pl - -newnids.h: mkobj.pl gost_objs.txt - $(PERL) mkobj.pl - - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -gost89.o: gost89.c gost89.h -newnids.o: ../../include/openssl/objects.h -gost_ameth.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h -gost_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h -gost_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -gost_ameth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h -gost_ameth.o: ../../include/openssl/engine.h ../../include/openssl/err.h -gost_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -gost_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -gost_ameth.o: ../../include/openssl/opensslconf.h -gost_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -gost_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h -gost_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h -gost_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -gost_ameth.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h -gost_ameth.o: gost_ameth.c gost_lcl.h gosthash.h -gost_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_asn1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_asn1.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_asn1.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_asn1.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -gost_asn1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -gost_asn1.o: ../../include/openssl/opensslconf.h -gost_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -gost_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h -gost_asn1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h -gost_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -gost_asn1.o: ../../include/openssl/x509_vfy.h gost89.h gost_asn1.c gost_lcl.h -gost_asn1.o: gosthash.h -gost_crypt.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_crypt.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_crypt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_crypt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_crypt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_crypt.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_crypt.o: ../../include/openssl/err.h ../../include/openssl/evp.h -gost_crypt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -gost_crypt.o: ../../include/openssl/objects.h -gost_crypt.o: ../../include/openssl/opensslconf.h -gost_crypt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -gost_crypt.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h -gost_crypt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h -gost_crypt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -gost_crypt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h -gost_crypt.o: e_gost_err.h gost89.h gost_crypt.c gost_lcl.h gosthash.h -gost_ctl.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_ctl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_ctl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_ctl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_ctl.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_ctl.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_ctl.o: ../../include/openssl/err.h ../../include/openssl/evp.h -gost_ctl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -gost_ctl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h -gost_ctl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -gost_ctl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h -gost_ctl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h -gost_ctl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -gost_ctl.o: ../../include/openssl/x509_vfy.h gost89.h gost_ctl.c gost_lcl.h -gost_ctl.o: gosthash.h -gost_ec_keyx.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_ec_keyx.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_ec_keyx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_ec_keyx.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_ec_keyx.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_ec_keyx.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_ec_keyx.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -gost_ec_keyx.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -gost_ec_keyx.o: ../../include/openssl/opensslconf.h -gost_ec_keyx.o: ../../include/openssl/opensslv.h -gost_ec_keyx.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h -gost_ec_keyx.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h -gost_ec_keyx.o: ../../include/openssl/sha.h ../../include/openssl/stack.h -gost_ec_keyx.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -gost_ec_keyx.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h -gost_ec_keyx.o: gost_ec_keyx.c gost_keywrap.h gost_lcl.h gosthash.h -gost_ec_sign.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_ec_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_ec_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_ec_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_ec_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_ec_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_ec_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h -gost_ec_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -gost_ec_sign.o: ../../include/openssl/objects.h -gost_ec_sign.o: ../../include/openssl/opensslconf.h -gost_ec_sign.o: ../../include/openssl/opensslv.h -gost_ec_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h -gost_ec_sign.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h -gost_ec_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h -gost_ec_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -gost_ec_sign.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h -gost_ec_sign.o: gost_ec_sign.c gost_lcl.h gosthash.h -gost_eng.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_eng.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_eng.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_eng.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_eng.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_eng.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_eng.o: ../../include/openssl/err.h ../../include/openssl/evp.h -gost_eng.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -gost_eng.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h -gost_eng.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -gost_eng.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h -gost_eng.o: ../../include/openssl/sha.h ../../include/openssl/stack.h -gost_eng.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -gost_eng.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h gost_eng.c -gost_eng.o: gost_lcl.h gosthash.h -gost_keywrap.o: gost89.h gost_keywrap.c gost_keywrap.h -gost_md.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_md.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_md.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_md.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_md.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_md.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_md.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -gost_md.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -gost_md.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h -gost_md.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h -gost_md.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h -gost_md.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -gost_md.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h -gost_md.o: e_gost_err.h gost89.h gost_lcl.h gost_md.c gosthash.h -gost_md2012.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h -gost_md2012.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h -gost_md2012.o: ../../include/openssl/evp.h ../../include/openssl/obj_mac.h -gost_md2012.o: ../../include/openssl/objects.h -gost_md2012.o: ../../include/openssl/opensslconf.h -gost_md2012.o: ../../include/openssl/opensslv.h -gost_md2012.o: ../../include/openssl/ossl_typ.h -gost_md2012.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h -gost_md2012.o: ../../include/openssl/symhacks.h gost_md2012.c gosthash2012.h -gost_md2012.o: gosthash2012_const.h gosthash2012_precalc.h gosthash2012_sse2.h -gost_params.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_params.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_params.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_params.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_params.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_params.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_params.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -gost_params.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -gost_params.o: ../../include/openssl/opensslconf.h -gost_params.o: ../../include/openssl/opensslv.h -gost_params.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h -gost_params.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h -gost_params.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -gost_params.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h -gost_params.o: gost89.h gost_lcl.h gost_params.c gosthash.h -gost_pmeth.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_pmeth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_pmeth.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h -gost_pmeth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h -gost_pmeth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h -gost_pmeth.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h -gost_pmeth.o: ../../include/openssl/engine.h ../../include/openssl/err.h -gost_pmeth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h -gost_pmeth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h -gost_pmeth.o: ../../include/openssl/opensslconf.h -gost_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -gost_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h -gost_pmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h -gost_pmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h -gost_pmeth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h -gost_pmeth.o: e_gost_err.h gost89.h gost_lcl.h gost_pmeth.c gosthash.h -gost_sign.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h -gost_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h -gost_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -gost_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h -gost_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h -gost_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h -gost_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h -gost_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h -gost_sign.o: ../../include/openssl/objects.h -gost_sign.o: ../../include/openssl/opensslconf.h -gost_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -gost_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h -gost_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h -gost_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h -gost_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h -gost_sign.o: e_gost_err.h gost89.h gost_lcl.h gost_sign.c gosthash.h -gosthash.o: gost89.h gosthash.c gosthash.h -gosthash2012.o: gosthash2012.c gosthash2012.h gosthash2012_const.h -gosthash2012.o: gosthash2012_precalc.h gosthash2012_sse2.h diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..8e247b7 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,13 @@ +enginedir=@ENGINEDIR@ +srcdir=. +lib_LTLIBRARIES=libgost.la +libgost_enginedir=$(enginedir) +libgost_la_includedir=$(includedir)/openssl +libgost_la_include_HEADERS=e_gost_err.h gost89.h gosthash2012_const.h gosthash2012.h gosthash2012_precalc.h gosthash2012_ref.h gosthash2012_sse2.h gosthash.h gost_keywrap.h gost_lcl.h newnids.h +libgost_la_SOURCES=e_gost_err.c gost89.c gost_ameth.c gost_asn1.c gost_crypt.c gost_ctl.c gost_ec_keyx.c gost_ec_sign.c gost_eng.c gosthash2012.c gosthash.c gost_keywrap.c gost_md2012.c gost_md.c gost_params.c gost_pmeth.c newnids.c obj_create.c + +install-data-hook: + rm -f $(DESTDIR)$(enginedir)/*.a $(DESTDIR)$(enginedir)/*.la + +newnids.c newnids.h: mkobj.pl gost_obj.txt + $(PERL) mkobj.pl diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..a55451a --- /dev/null +++ b/config.h.in @@ -0,0 +1,65 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `crypto' library (-lcrypto). */ +#undef HAVE_LIBCRYPTO + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..35ceec5 --- /dev/null +++ b/configure.ac @@ -0,0 +1,22 @@ +AC_PREREQ(2.63) +AC_INIT([libgost],[1.0.2],[openssl-gost@lists.wagner.pp.ru]) +AC_CONFIG_SRCDIR([./gost_eng.c]) +AM_INIT_AUTOMAKE([foreign]) +AC_CONFIG_HEADERS([config.h]) +LT_INIT + +ENGINEDIR=$libdir/ssl/engines +AC_ARG_WITH([enginedir], + [AS_HELP_STRING([--with-enginedir],[specify location of OpenSSL engines])], + [ENGINEDIR="$withval"]) +AC_SUBST(ENGINEDIR) + +# Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_LIBTOOL +AC_CHECK_PROG([PERL],[perl],[perl],[AC_MSG_ERROR([*** perl not found])]) +# Checks for libraries. +AC_CHECK_LIB([crypto], [ENGINE_new], [], [AC_MSG_ERROR([*** libcrypto not found])]) +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/gost_ameth.c b/gost_ameth.c index c8d7e4f..fb88eb3 100644 --- a/gost_ameth.c +++ b/gost_ameth.c @@ -55,13 +55,11 @@ static int pkey_bits_gost(const EVP_PKEY *pk) if (!pk) return -1; - switch (EVP_PKEY_base_id(pk)) { - case NID_id_GostR3410_2001: - case NID_id_GostR3410_2012_256: + int id= (EVP_PKEY_base_id(pk)); + if ( id == NID_id_GostR3410_2001 ||id == NID_gost2012_256) return 256; - case NID_id_GostR3410_2012_512: + if (id == NID_gost2012_512) return 512; - } return -1; } @@ -71,6 +69,7 @@ static ASN1_STRING *encode_gost_algor_params(const EVP_PKEY *key) ASN1_STRING *params = ASN1_STRING_new(); GOST_KEY_PARAMS *gkp = GOST_KEY_PARAMS_new(); int pkey_param_nid = NID_undef; + int base_id = EVP_PKEY_base_id(key); void *key_ptr = EVP_PKEY_get0((EVP_PKEY *)key); int result = 0; @@ -78,19 +77,15 @@ static ASN1_STRING *encode_gost_algor_params(const EVP_PKEY *key) GOSTerr(GOST_F_ENCODE_GOST_ALGOR_PARAMS, ERR_R_MALLOC_FAILURE); goto err; } - switch (EVP_PKEY_base_id(key)) { - case NID_id_GostR3410_2012_256: + if (base_id == NID_gost2012_256) { pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(key_ptr)); - gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_2012_256); - break; - case NID_id_GostR3410_2012_512: + gkp->hash_params = OBJ_nid2obj(NID_md_gost12_256); + } else if (base_id == NID_gost2012_512) { pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(key_ptr)); - gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_2012_512); - break; - case NID_id_GostR3410_2001: + gkp->hash_params = OBJ_nid2obj(NID_md_gost12_512); + } else if (base_id == NID_id_GostR3410_2001) { pkey_param_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(key_ptr)); gkp->hash_params = OBJ_nid2obj(NID_id_GostR3411_94_CryptoProParamSet); - break; } if (pkey_param_nid == NID_undef) { @@ -124,15 +119,14 @@ static int gost_decode_nid_params(EVP_PKEY *pkey, int pkey_nid, int param_nid) { void *key_ptr = EVP_PKEY_get0(pkey); - switch (pkey_nid) { - case NID_id_GostR3410_2012_256: - case NID_id_GostR3410_2012_512: - case NID_id_GostR3410_2001: + if (pkey_nid == NID_gost2012_256 || + pkey_nid == NID_gost2012_512 || + pkey_nid == NID_id_GostR3410_2001) { if (!key_ptr) { key_ptr = EC_KEY_new(); if (!EVP_PKEY_assign(pkey, pkey_nid, key_ptr)) { EC_KEY_free(key_ptr); - break; + return 0; } } return fill_GOST_EC_params(key_ptr, param_nid); @@ -182,10 +176,11 @@ static int decode_gost_algor_params(EVP_PKEY *pkey, X509_ALGOR *palg) static int gost_set_priv_key(EVP_PKEY *pkey, BIGNUM *priv) { - switch (EVP_PKEY_base_id(pkey)) { - case NID_id_GostR3410_2012_512: - case NID_id_GostR3410_2012_256: - case NID_id_GostR3410_2001: + int id = EVP_PKEY_base_id(pkey); + + if (id == NID_gost2012_512 || + id == NID_gost2012_256 || + id == NID_id_GostR3410_2001) { EC_KEY *ec = EVP_PKEY_get0(pkey); if (!ec) { @@ -196,27 +191,23 @@ static int gost_set_priv_key(EVP_PKEY *pkey, BIGNUM *priv) return 0; if (!EVP_PKEY_missing_parameters(pkey)) gost_ec_compute_public(ec); - break; + return 1; } - default: - return 0; - } - return 1; + return 0; } BIGNUM *gost_get0_priv_key(const EVP_PKEY *pkey) { - switch (EVP_PKEY_base_id(pkey)) { - case NID_id_GostR3410_2012_512: - case NID_id_GostR3410_2012_256: - case NID_id_GostR3410_2001: - { - EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pkey); - if (ec) - return (BIGNUM *)EC_KEY_get0_private_key(ec); - break; - } - } + int id =EVP_PKEY_base_id(pkey); + + if (id == NID_gost2012_512 || + id == NID_gost2012_256|| + id == NID_id_GostR3410_2001) + { + EC_KEY *ec = EVP_PKEY_get0((EVP_PKEY *)pkey); + if (ec) + return (BIGNUM *)EC_KEY_get0_private_key(ec); + } return NULL; } @@ -228,18 +219,14 @@ static int pkey_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2) int nid = EVP_PKEY_base_id(pkey), md_nid = NID_undef; X509_ALGOR *alg1 = NULL, *alg2 = NULL; - switch (nid) { - case NID_id_GostR3410_2012_512: - md_nid = NID_id_GostR3411_2012_512; - break; - case NID_id_GostR3410_2012_256: - md_nid = NID_id_GostR3411_2012_256; - break; - case NID_id_GostR3410_2001: - case NID_id_GostR3410_94: + if (nid == NID_gost2012_512) { + md_nid = NID_md_gost12_512; + } else if (nid == NID_gost2012_256) { + md_nid = NID_md_gost12_256; + } else if (nid == NID_id_GostR3410_2001 || + nid == NID_id_GostR3410_94) { md_nid = NID_id_GostR3411_94; - break; - default: + } else { return -1; } @@ -803,17 +790,18 @@ static int pub_cmp_gost_ec(const EVP_PKEY *a, const EVP_PKEY *b) static int pkey_size_gost(const EVP_PKEY *pk) { - if (!pk) + int id; + if (!pk) return -1; - - switch (EVP_PKEY_base_id(pk)) { - case NID_id_GostR3410_94: - case NID_id_GostR3410_2001: - case NID_id_GostR3410_2012_256: + id = EVP_PKEY_base_id(pk); + if (id == NID_id_GostR3410_94 || + id == NID_id_GostR3410_2001 || + id ==NID_gost2012_256 ) + { return 64; - case NID_id_GostR3410_2012_512: + } else if (id == NID_gost2012_512) { return 128; - } + } return -1; } @@ -877,8 +865,7 @@ int register_ameth_gost(int nid, EVP_PKEY_ASN1_METHOD **ameth, *ameth = EVP_PKEY_asn1_new(nid, ASN1_PKEY_SIGPARAM_NULL, pemstr, info); if (!*ameth) return 0; - switch (nid) { - case NID_id_GostR3410_2001: + if (nid == NID_id_GostR3410_2001) { EVP_PKEY_asn1_set_free(*ameth, pkey_free_gost_ec); EVP_PKEY_asn1_set_private(*ameth, priv_decode_gost, priv_encode_gost, @@ -894,9 +881,7 @@ int register_ameth_gost(int nid, EVP_PKEY_ASN1_METHOD **ameth, pkey_size_gost, pkey_bits_gost); EVP_PKEY_asn1_set_ctrl(*ameth, pkey_ctrl_gost); - break; - case NID_id_GostR3410_2012_256: - case NID_id_GostR3410_2012_512: + } else if (nid == NID_gost2012_256 || nid == NID_gost2012_512) { EVP_PKEY_asn1_set_free(*ameth, pkey_free_gost_ec); EVP_PKEY_asn1_set_private(*ameth, priv_decode_gost, priv_encode_gost, @@ -913,15 +898,12 @@ int register_ameth_gost(int nid, EVP_PKEY_ASN1_METHOD **ameth, pkey_size_gost, pkey_bits_gost); EVP_PKEY_asn1_set_ctrl(*ameth, pkey_ctrl_gost); - break; - case NID_id_Gost28147_89_MAC: + } else if (nid == NID_id_Gost28147_89_MAC) { EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost); EVP_PKEY_asn1_set_ctrl(*ameth, mac_ctrl_gost); - break; - case NID_gost_mac_12: + } else if (nid == NID_gost_mac_12) { EVP_PKEY_asn1_set_free(*ameth, mackey_free_gost); EVP_PKEY_asn1_set_ctrl(*ameth, mac_ctrl_gost_12); - break; } return 1; } diff --git a/gost_crypt.c b/gost_crypt.c index d1e8113..0c6592a 100644 --- a/gost_crypt.c +++ b/gost_crypt.c @@ -99,7 +99,7 @@ EVP_CIPHER cipher_gost_cpacnt = { }; EVP_CIPHER cipher_gost_cpcnt_12 = { - NID_gost89_cnt_12, + NID_undef /* NID_gost89_cnt_12 */, 1, /* block_size */ 32, /* key_size */ 8, /* iv_len */ @@ -148,7 +148,7 @@ EVP_MD imit_gost_cpa = { }; EVP_MD imit_gost_cp_12 = { - NID_gost_mac_12, + NID_undef, /* NID_gost_mac_12,*/ NID_undef, 4, 0, @@ -188,7 +188,7 @@ struct gost_cipher_info gost_cipher_list[] = { 1}, {NID_id_Gost28147_89_CryptoPro_D_ParamSet, &Gost28147_CryptoProParamSetD, 1}, - {NID_id_tc26_gost_28147_param_Z, &Gost28147_TC26ParamSetZ, 1}, + {NID_undef/*,NID_id_tc26_gost_28147_param_Z*/, &Gost28147_TC26ParamSetZ, 1}, {NID_id_Gost28147_89_TestParamSet, &Gost28147_TestParamSet, 1}, {NID_undef, NULL, 0} }; diff --git a/gost_ec_keyx.c b/gost_ec_keyx.c index 929c786..60b5e77 100644 --- a/gost_ec_keyx.c +++ b/gost_ec_keyx.c @@ -29,9 +29,9 @@ static int VKO_compute_key(unsigned char *shared_key, size_t shared_key_size, BN_CTX *ctx = BN_CTX_new(); EVP_MD_CTX mdctx; const EVP_MD *md; - int effective_dgst_nid = (dgst_nid == NID_id_GostR3411_2012_512) ? - NID_id_GostR3411_2012_256 : dgst_nid; - int buf_len = (dgst_nid == NID_id_GostR3411_2012_512) ? 128 : 64, + int effective_dgst_nid = (dgst_nid == NID_md_gost12_512) ? + NID_md_gost12_256 : dgst_nid; + int buf_len = (dgst_nid == NID_md_gost12_512) ? 128 : 64, half_len = buf_len >> 1; if (!ctx) { diff --git a/gost_eng.c b/gost_eng.c index 86d1a05..aee0914 100644 --- a/gost_eng.c +++ b/gost_eng.c @@ -36,26 +36,26 @@ static int gost_pkey_asn1_meths(ENGINE *e, EVP_PKEY_ASN1_METHOD **ameth, static int gost_cipher_nids[] = { NID_id_Gost28147_89, NID_gost89_cnt, - NID_gost89_cnt_12, - NID_gost89_cbc, + NID_undef /*NID_gost89_cnt_12*/, + NID_undef /* NID_gost89_cbc */, 0 }; static int gost_digest_nids[] = { NID_id_GostR3411_94, NID_id_Gost28147_89_MAC, - NID_id_GostR3411_2012_256, - NID_id_GostR3411_2012_512, - NID_gost_mac_12, + NID_undef /*NID_md_gost12_256*/, + NID_undef /*NID_md_gost12_512*/, + NID_undef /*NID_gost_mac_12*/, 0 }; static int gost_pkey_meth_nids[] = { NID_id_GostR3410_2001, NID_id_Gost28147_89_MAC, - NID_id_GostR3410_2012_256, - NID_id_GostR3410_2012_512, - NID_gost_mac_12, + NID_undef /*NID_gost2012_256*/, + NID_undef /*NID_gost2012_512*/, + NID_undef /*NID_gost_mac_12*/, 0 }; @@ -99,38 +99,62 @@ static int gost_engine_destroy(ENGINE *e) return 1; } - +extern int gost_define_nids(void); static int bind_gost(ENGINE *e, const char *id) { int ret = 0; if (id && strcmp(id, engine_gost_id)) return 0; if (ameth_GostR3410_2001) { - printf("GOST engine already loaded\n"); - goto end; + /* Engine already loaded */ + return 1; } + if (!gost_define_nids()) { + return 0; + } + /* Set up nids which might be undefined in the core object database */ + /* Arrays of algoritmhs */ + gost_cipher_nids[1]=NID_gost89_cnt; + gost_cipher_nids[2]=NID_gost89_cnt_12; + gost_cipher_nids[3]=NID_gost89_cbc; + gost_digest_nids[2]=NID_md_gost12_256; + gost_digest_nids[3]=NID_md_gost12_512; + gost_digest_nids[4]=NID_gost_mac_12; + gost_pkey_meth_nids[2]=NID_gost2012_256; + gost_pkey_meth_nids[3]=NID_gost2012_512; + /* EVP_CIPHERs */ + cipher_gost_cbc.nid = NID_gost89_cbc; + cipher_gost_cpcnt_12.nid = NID_gost89_cnt_12; + /* EVP_MDs */ + digest_gost2012_512.type = NID_md_gost12_512; + digest_gost2012_256.type = NID_md_gost12_256; + imit_gost_cp_12.type = NID_gost_mac_12; + /* Algorithm parameters */ + R3410_2012_512_paramset[0].nid = NID_id_tc26_gost_3410_2012_512_paramSetA; + R3410_2012_512_paramset[1].nid = NID_id_tc26_gost_3410_2012_512_paramSetB; + if (!ENGINE_set_id(e, engine_gost_id)) { - printf("ENGINE_set_id failed\n"); + fprintf(stderr,"ENGINE_set_id failed\n"); goto end; } if (!ENGINE_set_name(e, engine_gost_name)) { - printf("ENGINE_set_name failed\n"); + fprintf(stderr,"ENGINE_set_name failed\n"); goto end; } if (!ENGINE_set_digests(e, gost_digests)) { - printf("ENGINE_set_digests failed\n"); + fprintf(stderr,"ENGINE_set_digests failed\n"); goto end; } if (!ENGINE_set_ciphers(e, gost_ciphers)) { - printf("ENGINE_set_ciphers failed\n"); + fprintf(stderr,"ENGINE_set_ciphers failed\n"); goto end; } if (!ENGINE_set_pkey_meths(e, gost_pkey_meths)) { - printf("ENGINE_set_pkey_meths failed\n"); + fprintf(stderr,"ENGINE_set_pkey_meths failed\n"); goto end; } if (!ENGINE_set_pkey_asn1_meths(e, gost_pkey_asn1_meths)) { - printf("ENGINE_set_pkey_asn1_meths failed\n"); + fprintf(stderr,"ENGINE_set_pkey_asn1_meths failed\n"); goto end; } /* Control function and commands */ @@ -153,11 +177,11 @@ static int bind_gost(ENGINE *e, const char *id) "GOST R 34.10-2001")) goto end; if (!register_ameth_gost - (NID_id_GostR3410_2012_256, &ameth_GostR3410_2012_256, "GOST2012_256", + (NID_gost2012_256, &ameth_GostR3410_2012_256, "GOST2012_256", "GOST R 34.10-2012 with 256 bit key")) goto end; if (!register_ameth_gost - (NID_id_GostR3410_2012_512, &ameth_GostR3410_2012_512, "GOST2012_512", + (NID_gost2012_512, &ameth_GostR3410_2012_512, "GOST2012_512", "GOST R 34.10-2012 with 512 bit key")) goto end; if (!register_ameth_gost(NID_id_Gost28147_89_MAC, &ameth_Gost28147_MAC, @@ -172,10 +196,10 @@ static int bind_gost(ENGINE *e, const char *id) goto end; if (!register_pmeth_gost - (NID_id_GostR3410_2012_256, &pmeth_GostR3410_2012_256, 0)) + (NID_gost2012_256, &pmeth_GostR3410_2012_256, 0)) goto end; if (!register_pmeth_gost - (NID_id_GostR3410_2012_512, &pmeth_GostR3410_2012_512, 0)) + (NID_gost2012_512, &pmeth_GostR3410_2012_512, 0)) goto end; if (!register_pmeth_gost (NID_id_Gost28147_89_MAC, &pmeth_Gost28147_MAC, 0)) @@ -219,9 +243,9 @@ static int gost_digests(ENGINE *e, const EVP_MD **digest, } if (nid == NID_id_GostR3411_94) { *digest = &digest_gost; - } else if (nid == NID_id_GostR3411_2012_256) { + } else if (nid == NID_md_gost12_256) { *digest = &digest_gost2012_256; - } else if (nid == NID_id_GostR3411_2012_512) { + } else if (nid == NID_md_gost12_512) { *digest = &digest_gost2012_512; } else if (nid == NID_id_Gost28147_89_MAC) { *digest = &imit_gost_cpa; @@ -266,26 +290,26 @@ static int gost_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth, return sizeof(gost_pkey_meth_nids)/sizeof(int) - 1; } - switch (nid) { - case NID_id_GostR3410_2001: + if (nid == NID_id_GostR3410_2001) { *pmeth = pmeth_GostR3410_2001; return 1; - case NID_id_GostR3410_2012_256: + } + if (nid == NID_gost2012_256) { *pmeth = pmeth_GostR3410_2012_256; return 1; - case NID_id_GostR3410_2012_512: + } + if (nid == NID_gost2012_512) { *pmeth = pmeth_GostR3410_2012_512; return 1; - case NID_id_Gost28147_89_MAC: + } + if (nid == NID_id_Gost28147_89_MAC) { *pmeth = pmeth_Gost28147_MAC; return 1; - case NID_gost_mac_12: + } + if (nid == NID_gost_mac_12) { *pmeth = pmeth_Gost28147_MAC_12; return 1; - - default:; - } - + } *pmeth = NULL; return 0; } @@ -297,25 +321,26 @@ static int gost_pkey_asn1_meths(ENGINE *e, EVP_PKEY_ASN1_METHOD **ameth, *nids = gost_pkey_meth_nids; return sizeof(gost_pkey_meth_nids)/sizeof(int) - 1; } - switch (nid) { - case NID_id_GostR3410_2001: + if (nid == NID_id_GostR3410_2001) { *ameth = ameth_GostR3410_2001; return 1; - case NID_id_GostR3410_2012_256: + } + if (nid == NID_gost2012_256) { *ameth = ameth_GostR3410_2012_256; return 1; - case NID_id_GostR3410_2012_512: + } + if (nid == NID_gost2012_512) { *ameth = ameth_GostR3410_2012_512; return 1; - case NID_id_Gost28147_89_MAC: + } + if (nid == NID_id_Gost28147_89_MAC) { *ameth = ameth_Gost28147_MAC; return 1; - case NID_gost_mac_12: + } + if (nid == NID_gost_mac_12) { *ameth = ameth_Gost28147_MAC_12; return 1; - - default:; - } + } *ameth = NULL; return 0; diff --git a/gost_md2012.c b/gost_md2012.c index e20e660..7afbed9 100644 --- a/gost_md2012.c +++ b/gost_md2012.c @@ -26,7 +26,7 @@ const char micalg_256[] = "gostr3411-2012-256"; const char micalg_512[] = "gostr3411-2012-512"; EVP_MD digest_gost2012_512 = { - NID_id_GostR3411_2012_512, + NID_undef /* NID_md_gost12_512 */, NID_undef, 64, /* digest size */ EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, @@ -44,7 +44,7 @@ EVP_MD digest_gost2012_512 = { }; EVP_MD digest_gost2012_256 = { - NID_id_GostR3411_2012_256, + NID_undef /*NID_md_gost12_256*/, NID_undef, 32, /* digest size */ EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, diff --git a/gost_obj.txt b/gost_obj.txt index c84b16f..b33ae03 100644 --- a/gost_obj.txt +++ b/gost_obj.txt @@ -19,7 +19,7 @@ :gost89-ecb: :gost89-ofb: :gost89-cnt: -:gost89-cin-12: +:gost89-cnt-12: :gost-mac-12: # Russia-specific DN fields and X.509v3 extensions 1.2.643.3.131.1.1:INN:Individual Fiscal Number diff --git a/gost_params.c b/gost_params.c index 3e70990..5e9979f 100644 --- a/gost_params.c +++ b/gost_params.c @@ -84,7 +84,7 @@ R3410_ec_params R3410_2001_paramset[] = { R3410_ec_params *R3410_2012_256_paramset = R3410_2001_paramset; R3410_ec_params R3410_2012_512_paramset[] = { - {NID_id_tc26_gost_3410_2012_512_paramSetA, + {0 /*NID_id_tc26_gost_3410_2012_512_paramSetA*/, /* a */ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC4", @@ -103,7 +103,7 @@ R3410_ec_params R3410_2012_512_paramset[] = { "7503CFE87A836AE3A61B8816E25450E6CE5E1C93ACF1ABC1778064FDCBEFA921DF16" "26BE4FD036E93D75E6A50E3A41E98028FE5FC235F5B889A589CB5215F2A4"} , - {NID_id_tc26_gost_3410_2012_512_paramSetB, + {0 /* NID_id_tc26_gost_3410_2012_512_paramSetB*/, /* a */ "8000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000006C", diff --git a/gost_pmeth.c b/gost_pmeth.c index 896dabb..166cf85 100644 --- a/gost_pmeth.c +++ b/gost_pmeth.c @@ -30,20 +30,19 @@ static int pkey_gost_init(EVP_PKEY_CTX *ctx) return 0; memset(data, 0, sizeof(*data)); if (pkey && EVP_PKEY_get0(pkey)) { - switch (EVP_PKEY_base_id(pkey)) { - case NID_id_GostR3410_2001: - case NID_id_GostR3410_2012_256: - case NID_id_GostR3410_2012_512: + int id = (EVP_PKEY_base_id(pkey)); + if (id == NID_id_GostR3410_2001 || + id == NID_gost2012_256 || + id == NID_gost2012_512) { const EC_GROUP *group = EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey)); if (group != NULL) { data->sign_param_nid = EC_GROUP_get_curve_name(group); - break; } - /* else */ } - default: + else + { OPENSSL_free(data); return 0; } @@ -97,28 +96,23 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) OPENSSL_assert(p2 != NULL); - switch (EVP_MD_type((const EVP_MD *)p2)) { - case NID_id_GostR3411_94: + int md_type = EVP_MD_type((const EVP_MD *)p2); + if (md_type == NID_id_GostR3411_94) { if (pkey_nid == NID_id_GostR3410_2001 || pkey_nid == NID_id_GostR3410_94) { pctx->md = (EVP_MD *)p2; return 1; } - break; - - case NID_id_GostR3411_2012_256: - if (pkey_nid == NID_id_GostR3410_2012_256) { + } else if (md_type == NID_md_gost12_256) { + if (pkey_nid == NID_gost2012_256) { pctx->md = (EVP_MD *)p2; return 1; } - break; - - case NID_id_GostR3411_2012_512: - if (pkey_nid == NID_id_GostR3410_2012_512) { + } else if ( md_type == NID_md_gost12_512) { + if (pkey_nid == NID_gost2012_512) { pctx->md = (EVP_MD *)p2; return 1; } - break; } GOSTerr(GOST_F_PKEY_GOST_CTRL, GOST_R_INVALID_DIGEST_TYPE); @@ -311,25 +305,19 @@ static int pkey_gost2012_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return 0; } - switch (data->sign_param_nid) { - case NID_id_tc26_gost_3410_2012_512_paramSetA: - case NID_id_tc26_gost_3410_2012_512_paramSetB: + if (data->sign_param_nid == NID_id_tc26_gost_3410_2012_512_paramSetA || + data->sign_param_nid == NID_id_tc26_gost_3410_2012_512_paramSetB) { result = - (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_512, ec)) ? 1 : 0; - break; - - case NID_id_GostR3410_2001_CryptoPro_A_ParamSet: - case NID_id_GostR3410_2001_CryptoPro_B_ParamSet: - case NID_id_GostR3410_2001_CryptoPro_C_ParamSet: - case NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet: - case NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet: - case NID_id_GostR3410_2001_TestParamSet: + (EVP_PKEY_assign(pkey, NID_gost2012_512, ec)) ? 1 : 0; + } else + if (data->sign_param_nid == NID_id_GostR3410_2001_CryptoPro_A_ParamSet || + data->sign_param_nid == NID_id_GostR3410_2001_CryptoPro_B_ParamSet || + data->sign_param_nid == NID_id_GostR3410_2001_CryptoPro_C_ParamSet || + data->sign_param_nid == NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet || + data->sign_param_nid == NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet || + data->sign_param_nid == NID_id_GostR3410_2001_TestParamSet) { result = - (EVP_PKEY_assign(pkey, NID_id_GostR3410_2012_256, ec)) ? 1 : 0; - break; - default: - result = 0; - break; + (EVP_PKEY_assign(pkey, NID_gost2012_256, ec)) ? 1 : 0; } if (result == 0) @@ -382,21 +370,18 @@ static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, DSA_SIG *unpacked_sig = NULL; EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); int order = 0; - + int id = EVP_PKEY_base_id(pkey); if (!siglen) return 0; if (!pkey) return 0; - switch (EVP_PKEY_base_id(pkey)) { - case NID_id_GostR3410_2001: - case NID_id_GostR3410_2012_256: + if (id == NID_id_GostR3410_2001 || + id == NID_gost2012_256) { order = 64; - break; - case NID_id_GostR3410_2012_512: + } else if (id == NID_gost2012_512) { order = 128; - break; - default: + } else { return 0; } @@ -671,8 +656,7 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags) if (!*pmeth) return 0; - switch (id) { - case NID_id_GostR3410_2001: + if (id == NID_id_GostR3410_2001) { EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256); EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign); @@ -688,8 +672,7 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags) pkey_gost_derive_init, pkey_gost_ec_derive); EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init, pkey_gost2001_paramgen); - break; - case NID_id_GostR3410_2012_256: + } else if (id == NID_gost2012_256) { EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_ctrl, pkey_gost_ec_ctrl_str_256); EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign); @@ -706,8 +689,7 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags) EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init, pkey_gost2012_paramgen); - break; - case NID_id_GostR3410_2012_512: + } else if (id == NID_gost2012_512 ) { EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_ctrl, pkey_gost_ec_ctrl_str_512); EVP_PKEY_meth_set_sign(*pmeth, NULL, pkey_gost_ec_cp_sign); @@ -724,8 +706,7 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags) EVP_PKEY_meth_set_paramgen(*pmeth, pkey_gost_paramgen_init, pkey_gost2012_paramgen); - break; - case NID_id_Gost28147_89_MAC: + } else if (id == NID_id_Gost28147_89_MAC) { EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl, pkey_gost_mac_ctrl_str); EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init, @@ -734,8 +715,8 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags) EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init); EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup); EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy); - return 1; - case NID_gost_mac_12: + return 1; + } else if (id == NID_gost_mac_12) { EVP_PKEY_meth_set_ctrl(*pmeth, pkey_gost_mac_ctrl, pkey_gost_mac_ctrl_str); EVP_PKEY_meth_set_signctx(*pmeth, pkey_gost_mac_signctx_init, @@ -744,8 +725,9 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags) EVP_PKEY_meth_set_init(*pmeth, pkey_gost_mac_init); EVP_PKEY_meth_set_cleanup(*pmeth, pkey_gost_mac_cleanup); EVP_PKEY_meth_set_copy(*pmeth, pkey_gost_mac_copy); - return 1; - default: /* Unsupported method */ + return 1; + } else { + /* Unsupported method */ return 0; } EVP_PKEY_meth_set_init(*pmeth, pkey_gost_init); -- 2.39.5