-cmake_minimum_required(VERSION 3.4)
+cmake_minimum_required(VERSION 2.8)
project(ccgost)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c98 -O3")
+++ /dev/null
-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
-
-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
-
-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:
-
-links:
-
-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
-
-gostsum$(EXE_EXT): gostsum.o gosthash.o gost89.o
-
-gost12sum$(EXE_EXT): gost12sum.o gosthash2012.o
-
-# DO NOT DELETE THIS LINE -- make depend depends on it.
-
-gost89.o: gost89.c gost89.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/conf.h ../../include/openssl/crypto.h
-gost_ameth.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
-gost_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.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/rand.h
-gost_ameth.o: ../../include/openssl/rsa.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/ui.h
-gost_ameth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-gost_ameth.o: ../../include/openssl/x509v3.h e_gost_err.h gost89.h gost_ameth.c
-gost_ameth.o: 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/dh.h ../../include/openssl/dsa.h
-gost_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-gost_asn1.o: ../../include/openssl/engine.h ../../include/openssl/err.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/rand.h
-gost_asn1.o: ../../include/openssl/rsa.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/ui.h
-gost_asn1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-gost_asn1.o: gost89.h gost_asn1.c gost_lcl.h 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/dh.h ../../include/openssl/dsa.h
-gost_crypt.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-gost_crypt.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-gost_crypt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
-gost_crypt.o: ../../include/openssl/obj_mac.h ../../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/rsa.h ../../include/openssl/safestack.h
-gost_crypt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-gost_crypt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.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/dh.h ../../include/openssl/dsa.h
-gost_ctl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-gost_ctl.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-gost_ctl.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
-gost_ctl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-gost_ctl.o: ../../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/rand.h
-gost_ctl.o: ../../include/openssl/rsa.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/ui.h
-gost_ctl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-gost_ctl.o: gost89.h gost_ctl.c gost_lcl.h 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/dh.h ../../include/openssl/dsa.h
-gost_ec_keyx.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-gost_ec_keyx.o: ../../include/openssl/engine.h ../../include/openssl/err.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/rsa.h
-gost_ec_keyx.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-gost_ec_keyx.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-gost_ec_keyx.o: ../../include/openssl/ui.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/dh.h ../../include/openssl/dsa.h
-gost_ec_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.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/rsa.h
-gost_ec_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-gost_ec_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-gost_ec_sign.o: ../../include/openssl/ui.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/dh.h ../../include/openssl/dsa.h
-gost_eng.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-gost_eng.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-gost_eng.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
-gost_eng.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-gost_eng.o: ../../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/rand.h
-gost_eng.o: ../../include/openssl/rsa.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/ui.h
-gost_eng.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-gost_eng.o: e_gost_err.h gost89.h gost_eng.c 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/dh.h ../../include/openssl/dsa.h
-gost_md.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-gost_md.o: ../../include/openssl/engine.h ../../include/openssl/err.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/rand.h ../../include/openssl/rsa.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/ui.h ../../include/openssl/x509.h
-gost_md.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h gost_lcl.h
-gost_md.o: gost_md.c gosthash.h
-gost_md2012.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-gost_md2012.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-gost_md2012.o: ../../include/openssl/e_os2.h ../../include/openssl/evp.h
-gost_md2012.o: ../../include/openssl/obj_mac.h ../../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/dh.h ../../include/openssl/dsa.h
-gost_params.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-gost_params.o: ../../include/openssl/engine.h ../../include/openssl/err.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/rand.h ../../include/openssl/rsa.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/ui.h ../../include/openssl/x509.h
-gost_params.o: ../../include/openssl/x509_vfy.h gost89.h gost_lcl.h
-gost_params.o: 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/dh.h
-gost_pmeth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
-gost_pmeth.o: ../../include/openssl/ec.h ../../include/openssl/engine.h
-gost_pmeth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-gost_pmeth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-gost_pmeth.o: ../../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/rand.h
-gost_pmeth.o: ../../include/openssl/rsa.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/ui.h
-gost_pmeth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-gost_pmeth.o: ../../include/openssl/x509v3.h e_gost_err.h gost89.h gost_lcl.h
-gost_pmeth.o: gost_pmeth.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
* The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run.
*/
-void ERR_load_GOST_strings(void);
-void ERR_unload_GOST_strings(void);
-void ERR_GOST_error(int function, int reason, char *file, int line);
+ void ERR_load_GOST_strings(void);
+ void ERR_unload_GOST_strings(void);
+ void ERR_GOST_error(int function, int reason, char *file, int line);
# define GOSTerr(f,r) ERR_GOST_error((f),(r),__FILE__,__LINE__)
/* Error codes for the GOST functions. */
# define GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND 126
# define GOST_R_UNSUPPORTED_PARAMETER_SET 127
-#ifdef __cplusplus
+# ifdef __cplusplus
}
-#endif
+# endif
#endif
return -1;
}
PKCS7_RECIP_INFO_get0_alg((PKCS7_RECIP_INFO *)arg2, &alg1);
- X509_ALGOR_set0(alg1, OBJ_nid2obj(pkey->type),
+ X509_ALGOR_set0(alg1, OBJ_nid2obj(EVP_PKEY_id(pkey)),
V_ASN1_SEQUENCE, params);
}
return 1;
}
CMS_RecipientInfo_ktri_get0_algs((CMS_RecipientInfo *)arg2, NULL,
NULL, &alg1);
- X509_ALGOR_set0(alg1, OBJ_nid2obj(pkey->type), V_ASN1_SEQUENCE,
- params);
+ X509_ALGOR_set0(alg1, OBJ_nid2obj(EVP_PKEY_id(pkey)),
+ V_ASN1_SEQUENCE, params);
}
return 1;
#endif
/* --------------------- free functions * ------------------------------*/
static void pkey_free_gost_ec(EVP_PKEY *key)
{
- EC_KEY_free(key->pkey.ec);
+ EC_KEY_free(EVP_PKEY_get0_EC_KEY(key));
}
/* ------------------ private key functions -----------------------------*/
int ptype = V_ASN1_UNDEF;
algobj = OBJ_nid2obj(EVP_PKEY_base_id(pk));
- if (pk->save_parameters) {
+ if (EVP_PKEY_save_parameters((EVP_PKEY *)pk, -1)) {
ASN1_STRING *params = encode_gost_algor_params(pk);
pval = params;
ptype = V_ASN1_SEQUENCE;
/* ---------------------- ASN1 METHOD for GOST MAC -------------------*/
static void mackey_free_gost(EVP_PKEY *pk)
{
- OPENSSL_free(pk->pkey.ptr);
+ OPENSSL_free(EVP_PKEY_get0(pk));
}
static int mac_ctrl_gost(EVP_PKEY *pkey, int op, long arg1, void *arg2)
ASN1_SIMPLE(GOST_KEY_INFO, encrypted_key, ASN1_OCTET_STRING),
ASN1_SIMPLE(GOST_KEY_INFO, imit, ASN1_OCTET_STRING)
} ASN1_NDEF_SEQUENCE_END(GOST_KEY_INFO)
- IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO)
- ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) =
+IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO)
+ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) =
{
ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, cipher, ASN1_OBJECT),
ASN1_IMP_OPT(GOST_KEY_AGREEMENT_INFO, ephem_key, X509_PUBKEY, 0),
ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, eph_iv, ASN1_OCTET_STRING)
} ASN1_NDEF_SEQUENCE_END(GOST_KEY_AGREEMENT_INFO)
- IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO)
- ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) =
+IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO)
+ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) =
{
ASN1_SIMPLE(GOST_KEY_PARAMS, key_params, ASN1_OBJECT),
ASN1_SIMPLE(GOST_KEY_PARAMS, hash_params, ASN1_OBJECT),
ASN1_OPT(GOST_KEY_PARAMS, cipher_params,
ASN1_OBJECT),} ASN1_NDEF_SEQUENCE_END(GOST_KEY_PARAMS)
- IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS)
- ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) =
+IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS)
+ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) =
{
ASN1_SIMPLE(GOST_CIPHER_PARAMS, iv, ASN1_OCTET_STRING),
ASN1_SIMPLE(GOST_CIPHER_PARAMS, enc_param_set,
ASN1_OBJECT),}
ASN1_NDEF_SEQUENCE_END(GOST_CIPHER_PARAMS)
- IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS)
- ASN1_NDEF_SEQUENCE(GOST_CLIENT_KEY_EXCHANGE_PARAMS) =
+IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS)
+ASN1_NDEF_SEQUENCE(GOST_CLIENT_KEY_EXCHANGE_PARAMS) =
{ /* FIXME incomplete */
ASN1_SIMPLE(GOST_CLIENT_KEY_EXCHANGE_PARAMS, gkt, GOST_KEY_TRANSPORT)
} ASN1_NDEF_SEQUENCE_END(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
ASN1_SIMPLE(MASKED_GOST_KEY, masked_priv_key, ASN1_OCTET_STRING),
ASN1_SIMPLE(MASKED_GOST_KEY, public_key, ASN1_OCTET_STRING)
} ASN1_NDEF_SEQUENCE_END(MASKED_GOST_KEY)
- IMPLEMENT_ASN1_FUNCTIONS(MASKED_GOST_KEY)
+IMPLEMENT_ASN1_FUNCTIONS(MASKED_GOST_KEY)
{
if (_hidden_Gost28147_89_cipher == NULL
&& ((_hidden_Gost28147_89_cipher =
- EVP_CIPHER_meth_new(NID_id_Gost28147_89,
- 1 /* block_size */,
- 32 /* key_size */)) == NULL
+ EVP_CIPHER_meth_new(NID_id_Gost28147_89, 1 /* block_size */ ,
+ 32 /* key_size */ )) == NULL
|| !EVP_CIPHER_meth_set_iv_length(_hidden_Gost28147_89_cipher, 8)
|| !EVP_CIPHER_meth_set_flags(_hidden_Gost28147_89_cipher,
EVP_CIPH_CFB_MODE |
|| !EVP_CIPHER_meth_set_cleanup(_hidden_Gost28147_89_cipher,
gost_cipher_cleanup)
|| !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_Gost28147_89_cipher,
- sizeof(struct ossl_gost_cipher_ctx))
- || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_Gost28147_89_cipher,
- gost89_set_asn1_parameters)
- || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_Gost28147_89_cipher,
- gost89_get_asn1_parameters)
+ sizeof(struct
+ ossl_gost_cipher_ctx))
+ ||
+ !EVP_CIPHER_meth_set_set_asn1_params(_hidden_Gost28147_89_cipher,
+ gost89_set_asn1_parameters)
+ ||
+ !EVP_CIPHER_meth_set_get_asn1_params(_hidden_Gost28147_89_cipher,
+ gost89_get_asn1_parameters)
|| !EVP_CIPHER_meth_set_ctrl(_hidden_Gost28147_89_cipher,
gost_cipher_ctl))) {
EVP_CIPHER_meth_free(_hidden_Gost28147_89_cipher);
}
return _hidden_Gost28147_89_cipher;
}
-
+
static EVP_CIPHER *_hidden_Gost28147_89_cbc = NULL;
const EVP_CIPHER *cipher_gost_cbc(void)
{
if (_hidden_Gost28147_89_cbc == NULL
&& ((_hidden_Gost28147_89_cbc =
- EVP_CIPHER_meth_new(NID_gost89_cbc,
- 8 /* block_size */,
- 32 /* key_size */)) == NULL
+ EVP_CIPHER_meth_new(NID_gost89_cbc, 8 /* block_size */ ,
+ 32 /* key_size */ )) == NULL
|| !EVP_CIPHER_meth_set_iv_length(_hidden_Gost28147_89_cbc, 8)
|| !EVP_CIPHER_meth_set_flags(_hidden_Gost28147_89_cbc,
- EVP_CIPH_CBC_MODE |
- EVP_CIPH_CUSTOM_IV |
- EVP_CIPH_RAND_KEY |
- EVP_CIPH_ALWAYS_CALL_INIT)
+ EVP_CIPH_CBC_MODE |
+ EVP_CIPH_CUSTOM_IV |
+ EVP_CIPH_RAND_KEY |
+ EVP_CIPH_ALWAYS_CALL_INIT)
|| !EVP_CIPHER_meth_set_init(_hidden_Gost28147_89_cbc,
gost_cipher_init_cbc)
|| !EVP_CIPHER_meth_set_do_cipher(_hidden_Gost28147_89_cbc,
|| !EVP_CIPHER_meth_set_cleanup(_hidden_Gost28147_89_cbc,
gost_cipher_cleanup)
|| !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_Gost28147_89_cbc,
- sizeof(struct ossl_gost_cipher_ctx))
+ sizeof(struct
+ ossl_gost_cipher_ctx))
|| !EVP_CIPHER_meth_set_set_asn1_params(_hidden_Gost28147_89_cbc,
gost89_set_asn1_parameters)
|| !EVP_CIPHER_meth_set_get_asn1_params(_hidden_Gost28147_89_cbc,
}
return _hidden_Gost28147_89_cbc;
}
+
static EVP_CIPHER *_hidden_gost89_cnt = NULL;
const EVP_CIPHER *cipher_gost_cpacnt(void)
{
if (_hidden_gost89_cnt == NULL
&& ((_hidden_gost89_cnt =
- EVP_CIPHER_meth_new(NID_gost89_cnt,
- 1 /* block_size */,
- 32 /* key_size */)) == NULL
+ EVP_CIPHER_meth_new(NID_gost89_cnt, 1 /* block_size */ ,
+ 32 /* key_size */ )) == NULL
|| !EVP_CIPHER_meth_set_iv_length(_hidden_gost89_cnt, 8)
|| !EVP_CIPHER_meth_set_flags(_hidden_gost89_cnt,
EVP_CIPH_OFB_MODE |
|| !EVP_CIPHER_meth_set_cleanup(_hidden_gost89_cnt,
gost_cipher_cleanup)
|| !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_gost89_cnt,
- sizeof(struct ossl_gost_cipher_ctx))
+ sizeof(struct
+ ossl_gost_cipher_ctx))
|| !EVP_CIPHER_meth_set_set_asn1_params(_hidden_gost89_cnt,
gost89_set_asn1_parameters)
|| !EVP_CIPHER_meth_set_get_asn1_params(_hidden_gost89_cnt,
{
if (_hidden_gost89_cnt_12 == NULL
&& ((_hidden_gost89_cnt_12 =
- EVP_CIPHER_meth_new(NID_gost89_cnt_12,
- 1 /* block_size */,
- 32 /* key_size */)) == NULL
+ EVP_CIPHER_meth_new(NID_gost89_cnt_12, 1 /* block_size */ ,
+ 32 /* key_size */ )) == NULL
|| !EVP_CIPHER_meth_set_iv_length(_hidden_gost89_cnt_12, 8)
|| !EVP_CIPHER_meth_set_flags(_hidden_gost89_cnt_12,
EVP_CIPH_OFB_MODE |
|| !EVP_CIPHER_meth_set_cleanup(_hidden_gost89_cnt_12,
gost_cipher_cleanup)
|| !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_gost89_cnt_12,
- sizeof(struct ossl_gost_cipher_ctx))
+ sizeof(struct
+ ossl_gost_cipher_ctx))
|| !EVP_CIPHER_meth_set_set_asn1_params(_hidden_gost89_cnt_12,
gost89_set_asn1_parameters)
|| !EVP_CIPHER_meth_set_get_asn1_params(_hidden_gost89_cnt_12,
_hidden_gost89_cnt_12 = NULL;
}
-
/* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
/* Init functions which set specific parameters */
static int gost_imit_init_cpa(EVP_MD_CTX *ctx);
|| !EVP_MD_meth_set_result_size(md, 4)
|| !EVP_MD_meth_set_input_blocksize(md, 8)
|| !EVP_MD_meth_set_app_datasize(md,
- sizeof(struct ossl_gost_imit_ctx))
+ sizeof(struct
+ ossl_gost_imit_ctx))
|| !EVP_MD_meth_set_flags(md, 0)
|| !EVP_MD_meth_set_init(md, gost_imit_init_cpa)
|| !EVP_MD_meth_set_update(md, gost_imit_update)
|| !EVP_MD_meth_set_result_size(md, 4)
|| !EVP_MD_meth_set_input_blocksize(md, 8)
|| !EVP_MD_meth_set_app_datasize(md,
- sizeof(struct ossl_gost_imit_ctx))
+ sizeof(struct
+ ossl_gost_imit_ctx))
|| !EVP_MD_meth_set_flags(md, 0)
|| !EVP_MD_meth_set_init(md, gost_imit_init_cp_12)
|| !EVP_MD_meth_set_update(md, gost_imit_update)
const unsigned char *iv, int enc,
int paramNID, int mode)
{
- struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
+ struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
if (EVP_CIPHER_CTX_get_app_data(ctx) == NULL) {
if (!gost_cipher_set_param(c, paramNID))
return 0;
- EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_cipher_data(ctx));
+ EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_get_cipher_data(ctx));
}
if (key)
gost_key(&(c->cctx), key);
EVP_CIPHER_CTX_iv_length(ctx));
}
memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
- EVP_CIPHER_CTX_original_iv(ctx),
- EVP_CIPHER_CTX_iv_length(ctx));
+ EVP_CIPHER_CTX_original_iv(ctx), EVP_CIPHER_CTX_iv_length(ctx));
return 1;
}
const unsigned char *iv,
gost_subst_block * block)
{
- struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
+ struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
gost_init(&(c->cctx), block);
c->key_meshing = 1;
c->count = 0;
EVP_CIPHER_CTX_iv_length(ctx));
}
memcpy(EVP_CIPHER_CTX_iv_noconst(ctx),
- EVP_CIPHER_CTX_original_iv(ctx),
- EVP_CIPHER_CTX_iv_length(ctx));
+ EVP_CIPHER_CTX_original_iv(ctx), EVP_CIPHER_CTX_iv_length(ctx));
return 1;
}
const unsigned char *in_ptr = in;
unsigned char *out_ptr = out;
int i;
- struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
+ struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx);
OPENSSL_assert(inl % 8 == 0);
if (EVP_CIPHER_CTX_encrypting(ctx)) {
while (inl > 0) {
-
+
for (i = 0; i < 8; i++) {
b[i] = iv[i] ^ in_ptr[i];
}
size_t i = 0;
size_t j = 0;
unsigned char *buf = EVP_CIPHER_CTX_buf_noconst(ctx);
- unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx);
+ unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx);
/* process partial block if any */
if (EVP_CIPHER_CTX_num(ctx)) {
for (j = EVP_CIPHER_CTX_num(ctx), i = 0; j < 8 && i < inl;
/*
* block cipher current iv
*/
- gost_crypt_mesh(EVP_CIPHER_CTX_cipher_data(ctx), iv, buf);
+ gost_crypt_mesh(EVP_CIPHER_CTX_get_cipher_data(ctx), iv, buf);
/*
* xor next block of input text with it and output it
*/
}
/* Process rest of buffer */
if (i < inl) {
- gost_crypt_mesh(EVP_CIPHER_CTX_cipher_data(ctx), iv, buf);
+ gost_crypt_mesh(EVP_CIPHER_CTX_get_cipher_data(ctx), iv, buf);
if (!EVP_CIPHER_CTX_encrypting(ctx))
memcpy(buf + 8, in_ptr, inl - i);
for (j = 0; i < inl; j++, i++) {
size_t i = 0;
size_t j;
unsigned char *buf = EVP_CIPHER_CTX_buf_noconst(ctx);
- unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx);
+ unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx);
/* process partial block if any */
if (EVP_CIPHER_CTX_num(ctx)) {
for (j = EVP_CIPHER_CTX_num(ctx), i = 0; j < 8 && i < inl;
* block cipher current iv
*/
/* Encrypt */
- gost_cnt_next(EVP_CIPHER_CTX_cipher_data(ctx), iv, buf);
+ gost_cnt_next(EVP_CIPHER_CTX_get_cipher_data(ctx), iv, buf);
/*
* xor next block of input text with it and output it
*/
}
/* Process rest of buffer */
if (i < inl) {
- gost_cnt_next(EVP_CIPHER_CTX_cipher_data(ctx), iv, buf);
+ gost_cnt_next(EVP_CIPHER_CTX_get_cipher_data(ctx), iv, buf);
for (j = 0; i < inl; j++, i++) {
out_ptr[j] = buf[j] ^ in_ptr[j];
}
/* Cleaning up of EVP_CIPHER_CTX */
int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx)
{
- gost_destroy(&((struct ossl_gost_cipher_ctx *)EVP_CIPHER_CTX_cipher_data(ctx))->cctx);
+ gost_destroy(&
+ ((struct ossl_gost_cipher_ctx *)
+ EVP_CIPHER_CTX_get_cipher_data(ctx))->cctx);
EVP_CIPHER_CTX_set_app_data(ctx, NULL);
return 1;
}
#if 0
case EVP_CTRL_INIT:
{
- struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
+ struct ossl_gost_cipher_ctx *c =
+ EVP_CIPHER_CTX_get_cipher_data(ctx);
if (c == NULL) {
return -1;
}
#endif
case EVP_CTRL_RAND_KEY:
{
- if (RAND_bytes((unsigned char *)ptr, EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
+ if (RAND_bytes
+ ((unsigned char *)ptr, EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
GOSTerr(GOST_F_GOST_CIPHER_CTL, GOST_R_RNG_ERROR);
return -1;
}
case EVP_CTRL_SET_SBOX:
if (ptr) {
- struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
+ struct ossl_gost_cipher_ctx *c =
+ EVP_CIPHER_CTX_get_cipher_data(ctx);
int nid;
int cur_meshing;
int ret;
c->key_meshing = cur_meshing;
return ret;
} else {
- return 0;
+ return 0;
}
case EVP_CTRL_KEY_MESH:
{
- struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
+ struct ossl_gost_cipher_ctx *c =
+ EVP_CIPHER_CTX_get_cipher_data(ctx);
if (c == NULL) {
return -1;
int len = 0;
unsigned char *buf = NULL;
unsigned char *p = NULL;
- struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
+ struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
ASN1_OCTET_STRING *os = NULL;
if (!gcp) {
GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
return 0;
}
- if (!ASN1_OCTET_STRING_set(gcp->iv, EVP_CIPHER_CTX_iv(ctx), EVP_CIPHER_CTX_iv_length(ctx))) {
+ if (!ASN1_OCTET_STRING_set
+ (gcp->iv, EVP_CIPHER_CTX_iv(ctx), EVP_CIPHER_CTX_iv_length(ctx))) {
GOST_CIPHER_PARAMS_free(gcp);
GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE);
return 0;
int len;
GOST_CIPHER_PARAMS *gcp = NULL;
unsigned char *p;
- struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_cipher_data(ctx);
+ struct ossl_gost_cipher_ctx *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
int nid;
if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
GOST_CIPHER_PARAMS_free(gcp);
return -1;
}
- /*XXX missing non-const accessor*/
+ /*XXX missing non-const accessor */
memcpy((unsigned char *)EVP_CIPHER_CTX_original_iv(ctx), gcp->iv->data,
- EVP_CIPHER_CTX_iv_length(ctx));
+ EVP_CIPHER_CTX_iv_length(ctx));
GOST_CIPHER_PARAMS_free(gcp);
return 1;
case EVP_MD_CTRL_SET_KEY:
{
- struct ossl_gost_imit_ctx *gost_imit_ctx = EVP_MD_CTX_md_data(ctx);
+ struct ossl_gost_imit_ctx *gost_imit_ctx =
+ EVP_MD_CTX_md_data(ctx);
- if (EVP_MD_meth_get_init(EVP_MD_CTX_md(ctx))(ctx) <= 0) {
+ if (EVP_MD_meth_get_init(EVP_MD_CTX_md(ctx)) (ctx) <= 0) {
GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_MAC_KEY_NOT_SET);
return 0;
}
}
mdctx = EVP_MD_CTX_new();
if (!mdctx) {
- GOSTerr(GOST_F_VKO_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);
- goto err;
+ GOSTerr(GOST_F_VKO_COMPUTE_KEY, ERR_R_MALLOC_FAILURE);
+ goto err;
}
EVP_MD_CTX_init(mdctx);
EVP_DigestInit_ex(mdctx, md, NULL);
const BIGNUM *priv_key;
BIGNUM *r = NULL, *s = NULL, *X = NULL, *tmp = NULL, *tmp2 = NULL,
*k = NULL, *e = NULL;
+
+ BIGNUM *new_r = NULL, *new_s = NULL;
+
EC_POINT *C = NULL;
BN_CTX *ctx;
}
while (BN_is_zero(s));
- newsig->s = BN_dup(s);
- newsig->r = BN_dup(r);
- if (!newsig->s || !newsig->r) {
+ DSA_SIG_get0(&new_r, &new_s, newsig);
+ new_s = BN_dup(s);
+ new_r = BN_dup(r);
+ if (!new_s || !new_r) {
GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE);
goto err;
}
BIGNUM *order;
BIGNUM *md = NULL, *e = NULL, *R = NULL, *v = NULL,
*z1 = NULL, *z2 = NULL;
+ BIGNUM *sig_s = NULL, *sig_r = NULL;
BIGNUM *X = NULL, *tmp = NULL;
EC_POINT *C = NULL;
const EC_POINT *pub_key = NULL;
goto err;
}
- if (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||
- (BN_cmp(sig->s, order) >= 1) || (BN_cmp(sig->r, order) >= 1)) {
+ DSA_SIG_get0(&sig_r, &sig_s, sig);
+
+ if (BN_is_zero(sig_s) || BN_is_zero(sig_r) ||
+ (BN_cmp(sig_s, order) >= 1) || (BN_cmp(sig_r, order) >= 1)) {
GOSTerr(GOST_F_GOST_EC_VERIFY, GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
goto err;
goto err;
}
v = BN_mod_inverse(v, e, order, ctx);
- if (!v || !BN_mod_mul(z1, sig->s, v, order, ctx)
- || !BN_sub(tmp, order, sig->r)
+ if (!v || !BN_mod_mul(z1, sig_s, v, order, ctx)
+ || !BN_sub(tmp, order, sig_r)
|| !BN_mod_mul(z2, tmp, v, order, ctx)) {
GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR);
goto err;
BN_print_fp(stderr, R);
fprintf(stderr, "\n");
#endif
- if (BN_cmp(R, sig->r) != 0) {
+ if (BN_cmp(R, sig_r) != 0) {
GOSTerr(GOST_F_GOST_EC_VERIFY, GOST_R_SIGNATURE_MISMATCH);
} else {
ok = 1;
/* Set 256 bit key into context */
static GRASSHOPPER_INLINE void gost_grasshopper_cipher_key(gost_grasshopper_cipher_ctx* c, const uint8_t* k) {
- for (int i = 0; i < 2; i++) {
+ int i;
+ for (i = 0; i < 2; i++) {
grasshopper_copy128(&c->key.k.k[i], (const grasshopper_w128_t*) (k + i * 16));
}
grasshopper_set_encrypt_key(&c->encrypt_round_keys, &c->key);
/* Cleans up key from context */
static GRASSHOPPER_INLINE void gost_grasshopper_cipher_destroy(gost_grasshopper_cipher_ctx* c) {
- for (int i = 0; i < 2; i++) {
+ int i;
+ for (i = 0; i < 2; i++) {
grasshopper_zero128(&c->key.k.k[i]);
}
- for (int i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
+ for (i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
grasshopper_zero128(&c->encrypt_round_keys.k[i]);
}
- for (int i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
+ for (i = 0; i < GRASSHOPPER_ROUND_KEYS_COUNT; i++) {
grasshopper_zero128(&c->decrypt_round_keys.k[i]);
}
grasshopper_zero128(&c->buffer);
static int gost_grasshopper_cipher_init(EVP_CIPHER_CTX* ctx, const unsigned char* key,
const unsigned char* iv, int enc) {
- gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
if (EVP_CIPHER_CTX_get_app_data(ctx) == NULL) {
- EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_cipher_data(ctx));
+ EVP_CIPHER_CTX_set_app_data(ctx, EVP_CIPHER_CTX_get_cipher_data(ctx));
}
if (key != NULL) {
static GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ecb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
const unsigned char* iv,
int enc) {
- gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
c->type = GRASSHOPPER_CIPHER_ECB;
return gost_grasshopper_cipher_init(ctx, key, iv, enc);
}
static GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_cbc(EVP_CIPHER_CTX* ctx, const unsigned char* key,
const unsigned char* iv,
int enc) {
- gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
c->type = GRASSHOPPER_CIPHER_CBC;
return gost_grasshopper_cipher_init(ctx, key, iv, enc);
}
static GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ofb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
const unsigned char* iv,
int enc) {
- gost_grasshopper_cipher_ctx_ofb* c = EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx_ofb* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
c->c.type = GRASSHOPPER_CIPHER_OFB;
static GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_cfb(EVP_CIPHER_CTX* ctx, const unsigned char* key,
const unsigned char* iv,
int enc) {
- gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
c->type = GRASSHOPPER_CIPHER_CFB;
return gost_grasshopper_cipher_init(ctx, key, iv, enc);
}
static GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ctr(EVP_CIPHER_CTX* ctx, const unsigned char* key,
const unsigned char* iv,
int enc) {
- gost_grasshopper_cipher_ctx_ctr* c = EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx_ctr* c = EVP_CIPHER_CTX_get_cipher_data(ctx);
c->c.type = GRASSHOPPER_CIPHER_CTR;
static GRASSHOPPER_INLINE int gost_grasshopper_cipher_do(EVP_CIPHER_CTX* ctx, unsigned char* out,
const unsigned char* in, size_t inl) {
- gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
struct GRASSHOPPER_CIPHER_PARAMS* params = &gost_cipher_params[c->type];
return params->do_cipher(ctx, out, in, inl);
static int gost_grasshopper_cipher_do_ecb(EVP_CIPHER_CTX* ctx, unsigned char* out,
const unsigned char* in, size_t inl) {
- gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
const unsigned char* current_in = in;
unsigned char* current_out = out;
static int gost_grasshopper_cipher_do_cbc(EVP_CIPHER_CTX* ctx, unsigned char* out,
const unsigned char* in, size_t inl) {
- gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
bool encrypting = (bool) EVP_CIPHER_CTX_encrypting(ctx);
const unsigned char* current_in = in;
static int gost_grasshopper_cipher_do_ctr(EVP_CIPHER_CTX* ctx, unsigned char* out,
const unsigned char* in, size_t inl) {
- gost_grasshopper_cipher_ctx_ctr* c = (gost_grasshopper_cipher_ctx_ctr*) EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx_ctr* c = (gost_grasshopper_cipher_ctx_ctr*) EVP_CIPHER_CTX_get_cipher_data(ctx);
unsigned char* iv = EVP_CIPHER_CTX_iv_noconst(ctx);
const unsigned char* current_in = in;
unsigned char* current_out = out;
static int gost_grasshopper_cipher_do_ofb(EVP_CIPHER_CTX* ctx, unsigned char* out,
const unsigned char* in, size_t inl) {
- gost_grasshopper_cipher_ctx_ofb* c = (gost_grasshopper_cipher_ctx_ofb*) EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx_ofb* c = (gost_grasshopper_cipher_ctx_ofb*) EVP_CIPHER_CTX_get_cipher_data(ctx);
const unsigned char* in_ptr = in;
unsigned char* out_ptr = out;
unsigned char* buf = EVP_CIPHER_CTX_buf_noconst(ctx);
static int gost_grasshopper_cipher_do_cfb(EVP_CIPHER_CTX* ctx, unsigned char* out,
const unsigned char* in, size_t inl) {
- gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
const unsigned char* in_ptr = in;
unsigned char* out_ptr = out;
unsigned char* buf = EVP_CIPHER_CTX_buf_noconst(ctx);
}
static int gost_grasshopper_cipher_cleanup(EVP_CIPHER_CTX* ctx) {
- gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_cipher_data(ctx);
+ gost_grasshopper_cipher_ctx* c = (gost_grasshopper_cipher_ctx*) EVP_CIPHER_CTX_get_cipher_data(ctx);
struct GRASSHOPPER_CIPHER_PARAMS* params = &gost_cipher_params[c->type];
gost_grasshopper_cipher_destroy(c);
static GRASSHOPPER_INLINE void grasshopper_l(grasshopper_w128_t* w) {
uint8_t x;
+ unsigned int j;
+ int i;
// 16 rounds
- for (unsigned int j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
+ for (j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
// An LFSR with 16 elements from GF(2^8)
x = w->b[15]; // since lvec[15] = 1
- for (int i = 14; i >= 0; i--) {
+ for (i = 14; i >= 0; i--) {
w->b[i + 1] = w->b[i];
x ^= grasshopper_galois_mul(w->b[i], grasshopper_lvec[i]);
}
static GRASSHOPPER_INLINE void grasshopper_l_inv(grasshopper_w128_t* w) {
uint8_t x;
+ unsigned int j;
+ int i;
// 16 rounds
- for (unsigned int j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
+ for (j = 0; j < sizeof(grasshopper_lvec) / sizeof(grasshopper_lvec[0]); j++) {
x = w->b[0];
- for (int i = 0; i < 15; i++) {
+ for (i = 0; i < 15; i++) {
w->b[i] = w->b[i + 1];
x ^= grasshopper_galois_mul(w->b[i], grasshopper_lvec[i]);
}
void grasshopper_set_encrypt_key(grasshopper_round_keys_t* subkeys, const grasshopper_key_t* key) {
grasshopper_w128_t c, x, y, z;
+ int i;
- for (int i = 0; i < 16; i++) {
+ for (i = 0; i < 16; i++) {
// this will be have to changed for little-endian systems
x.b[i] = key->k.b[i];
y.b[i] = key->k.b[i + 16];
grasshopper_copy128(&subkeys->k[0], &x);
grasshopper_copy128(&subkeys->k[1], &y);
- for (int i = 1; i <= 32; i++) {
+ for (i = 1; i <= 32; i++) {
// C Value
grasshopper_zero128(&c);
}
void grasshopper_set_decrypt_key(grasshopper_round_keys_t* subkeys, const grasshopper_key_t* key) {
+ int i;
grasshopper_set_encrypt_key(subkeys, key);
- for (int i = 1; i < 10; i++) {
+ for (i = 1; i < 10; i++) {
grasshopper_l_inv(&subkeys->k[i]);
}
}
void grasshopper_encrypt_block(grasshopper_round_keys_t* subkeys, grasshopper_w128_t* source,
grasshopper_w128_t* target, grasshopper_w128_t* buffer) {
+ int i;
grasshopper_copy128(target, source);
- for (int i = 0; i < 9; i++) {
+ for (i = 0; i < 9; i++) {
grasshopper_append128(target, &subkeys->k[i]);
grasshopper_append128multi(buffer, target, grasshopper_pil_enc128);
}
void grasshopper_decrypt_block(grasshopper_round_keys_t* subkeys, grasshopper_w128_t* source,
grasshopper_w128_t* target, grasshopper_w128_t* buffer) {
+ int i;
grasshopper_copy128(target, source);
grasshopper_append128multi(buffer, target, grasshopper_l_dec128);
- for (int i = 9; i > 1; i--) {
+ for (i = 9; i > 1; i--) {
grasshopper_append128(target, &subkeys->k[i]);
grasshopper_append128multi(buffer, target, grasshopper_pil_dec128);
}
#if(GRASSHOPPER_BITS == 8 || GRASSHOPPER_BITS == 16)
memset(&x, 0, sizeof(x));
#else
- for (int i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
+ int i;
+ for (i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
GRASSHOPPER_ACCESS_128_VALUE(*x, i) = 0;
}
#endif
#if(GRASSHOPPER_BITS == 8 || GRASSHOPPER_BITS == 16)
__builtin_memcpy(&to, &from, sizeof(w128_t));
#else
- for (int i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
+ int i;
+ for (i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
GRASSHOPPER_ACCESS_128_VALUE(*to, i) = GRASSHOPPER_ACCESS_128_VALUE(*from, i);
}
#endif
}
static GRASSHOPPER_INLINE void grasshopper_append128(grasshopper_w128_t* x, const grasshopper_w128_t* y) {
- for (int i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
+ int i;
+ for (i = 0; i < GRASSHOPPER_BIT_PARTS; i++) {
GRASSHOPPER_ACCESS_128_VALUE(*x, i) ^= GRASSHOPPER_ACCESS_128_VALUE(*y, i);
}
}
// result & x must be different
static GRASSHOPPER_INLINE void grasshopper_plus128multi(grasshopper_w128_t* result, const grasshopper_w128_t* x,
const grasshopper_w128_t array[][256]) {
+ int i;
grasshopper_zero128(result);
- for (int i = 0; i < GRASSHOPPER_MAX_BIT_PARTS; i++) {
+ for (i = 0; i < GRASSHOPPER_MAX_BIT_PARTS; i++) {
grasshopper_append128(result, &array[i][GRASSHOPPER_ACCESS_128_VALUE_8(*x, i)]);
}
}
}
static GRASSHOPPER_INLINE void grasshopper_convert128(grasshopper_w128_t* x, const uint8_t* array) {
- for (int i = 0; i < GRASSHOPPER_MAX_BIT_PARTS; i++) {
+ int i;
+ for (i = 0; i < GRASSHOPPER_MAX_BIT_PARTS; i++) {
GRASSHOPPER_ACCESS_128_VALUE_8(*x, i) = array[GRASSHOPPER_ACCESS_128_VALUE_8(*x, i)];
}
}
/* Find encryption params from ASN1_OBJECT */
const struct gost_cipher_info *get_encryption_params(ASN1_OBJECT *obj);
/* Implementation of GOST 28147-89 cipher in CFB and CNT modes */
-const EVP_CIPHER* cipher_gost();
-const EVP_CIPHER* cipher_gost_cbc();
-const EVP_CIPHER* cipher_gost_cpacnt();
-const EVP_CIPHER* cipher_gost_cpcnt_12();
+const EVP_CIPHER *cipher_gost();
+const EVP_CIPHER *cipher_gost_cbc();
+const EVP_CIPHER *cipher_gost_cpacnt();
+const EVP_CIPHER *cipher_gost_cpcnt_12();
void cipher_gost_destroy();
# define EVP_MD_CTRL_KEY_LEN (EVP_MD_CTRL_ALG_CTRL+3)
# define EVP_MD_CTRL_SET_KEY (EVP_MD_CTRL_ALG_CTRL+4)
|| !EVP_MD_meth_set_result_size(md, 32)
|| !EVP_MD_meth_set_input_blocksize(md, 32)
|| !EVP_MD_meth_set_app_datasize(md,
- sizeof(struct ossl_gost_digest_ctx))
+ sizeof(struct
+ ossl_gost_digest_ctx))
|| !EVP_MD_meth_set_init(md, gost_digest_init)
|| !EVP_MD_meth_set_update(md, gost_digest_update)
|| !EVP_MD_meth_set_final(md, gost_digest_final)
int gost_digest_cleanup(EVP_MD_CTX *ctx)
{
if (EVP_MD_CTX_md_data(ctx))
- memset(EVP_MD_CTX_md_data(ctx), 0, sizeof(struct ossl_gost_digest_ctx));
+ memset(EVP_MD_CTX_md_data(ctx), 0,
+ sizeof(struct ossl_gost_digest_ctx));
return 1;
}
if (_hidden_GostR3411_2012_256_md == NULL) {
EVP_MD *md;
- if ((md = EVP_MD_meth_new(NID_id_GostR3411_2012_256, NID_undef)) == NULL
+ if ((md =
+ EVP_MD_meth_new(NID_id_GostR3411_2012_256, NID_undef)) == NULL
|| !EVP_MD_meth_set_result_size(md, 32)
|| !EVP_MD_meth_set_input_blocksize(md, 64)
|| !EVP_MD_meth_set_app_datasize(md, sizeof(gost2012_hash_ctx))
if (_hidden_GostR3411_2012_512_md == NULL) {
EVP_MD *md;
- if ((md = EVP_MD_meth_new(NID_id_GostR3411_2012_512, NID_undef)) == NULL
+ if ((md =
+ EVP_MD_meth_new(NID_id_GostR3411_2012_512, NID_undef)) == NULL
|| !EVP_MD_meth_set_result_size(md, 64)
|| !EVP_MD_meth_set_input_blocksize(md, 64)
|| !EVP_MD_meth_set_app_datasize(md, sizeof(gost2012_hash_ctx))
static int gost_digest_init512(EVP_MD_CTX *ctx)
{
- init_gost2012_hash_ctx((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx), 512);
+ init_gost2012_hash_ctx((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx),
+ 512);
return 1;
}
static int gost_digest_init256(EVP_MD_CTX *ctx)
{
- init_gost2012_hash_ctx((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx), 256);
+ init_gost2012_hash_ctx((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx),
+ 256);
return 1;
}
static int gost_digest_update(EVP_MD_CTX *ctx, const void *data, size_t count)
{
- gost2012_hash_block((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx), data, count);
+ gost2012_hash_block((gost2012_hash_ctx *) EVP_MD_CTX_md_data(ctx), data,
+ count);
return 1;
}
static int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
{
if (EVP_MD_CTX_md_data(to) && EVP_MD_CTX_md_data(from))
- memcpy(EVP_MD_CTX_md_data(to), EVP_MD_CTX_md_data(from), sizeof(gost2012_hash_ctx));
+ memcpy(EVP_MD_CTX_md_data(to), EVP_MD_CTX_md_data(from),
+ sizeof(gost2012_hash_ctx));
return 1;
}
*/
int pack_sign_cp(DSA_SIG *s, int order, unsigned char *sig, size_t *siglen)
{
+ BIGNUM *sig_r = NULL, *sig_s = NULL;
+ DSA_SIG_get0(&sig_r, &sig_s, s);
*siglen = 2 * order;
memset(sig, 0, *siglen);
- store_bignum(s->s, sig, order);
- store_bignum(s->r, sig + order, order);
+ store_bignum(sig_s, sig, order);
+ store_bignum(sig_r, sig + order, order);
DSA_SIG_free(s);
return 1;
}
DSA_SIG *unpack_cp_signature(const unsigned char *sig, size_t siglen)
{
DSA_SIG *s;
+ BIGNUM *sig_r = NULL, *sig_s = NULL;
s = DSA_SIG_new();
if (s == NULL) {
GOSTerr(GOST_F_UNPACK_CP_SIGNATURE, ERR_R_MALLOC_FAILURE);
return NULL;
}
- s->s = BN_bin2bn(sig, siglen / 2, NULL);
- s->r = BN_bin2bn(sig + siglen / 2, siglen / 2, NULL);
+ DSA_SIG_get0(&sig_r, &sig_s, s);
+ sig_s = BN_bin2bn(sig, siglen / 2, NULL);
+ sig_r = BN_bin2bn(sig + siglen / 2, siglen / 2, NULL);
return s;
}
struct gost_mac_key *key = EVP_PKEY_get0(pkey);
if (key) {
data->mac_param_nid = key->mac_param_nid;
- data->mac_size = key->mac_size;
+ data->mac_size = key->mac_size;
}
}
GOST_R_MAC_KEY_NOT_SET);
return 0;
}
- return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
- (mctx, EVP_MD_CTRL_SET_KEY, 0, key);
+ return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
+ (mctx, EVP_MD_CTRL_SET_KEY, 0, key);
} else {
- return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
- (mctx, EVP_MD_CTRL_SET_KEY, 32, &(data->key));
+ return EVP_MD_meth_get_ctrl(EVP_MD_CTX_md(mctx))
+ (mctx, EVP_MD_CTRL_SET_KEY, 32, &(data->key));
}
}
case EVP_PKEY_CTRL_MAC_LEN:
return 0;
memcpy(keydata->key, data->key, 32);
keydata->mac_param_nid = data->mac_param_nid;
- keydata->mac_size = data->mac_size;
+ keydata->mac_size = data->mac_size;
EVP_PKEY_assign(pkey, mac_nid, keydata);
return 1;
}
{
struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
- if (data == NULL) {
- pkey_gost_mac_init(ctx);
- }
+ if (data == NULL) {
+ pkey_gost_mac_init(ctx);
+ }
data = EVP_PKEY_CTX_get_data(ctx);
if (!data) {