From: Vitaly Chikunov Date: Tue, 12 May 2020 21:53:01 +0000 (+0300) Subject: gost_crypt: Add Gost28147_89_MAC_digest, Gost28147_89_mac_12_digest X-Git-Tag: v3.0.0~101^2~11 X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=d3756bbed444cfe1072e9469c469bfba8b6c6dbe;p=openssl-gost%2Fengine.git gost_crypt: Add Gost28147_89_MAC_digest, Gost28147_89_mac_12_digest Covert their registration to table method. --- diff --git a/gost_crypt.c b/gost_crypt.c index 8277fa2..66885bf 100644 --- a/gost_crypt.c +++ b/gost_crypt.c @@ -256,69 +256,52 @@ static int gost_imit_cleanup(EVP_MD_CTX *ctx); /* Control function, knows how to set MAC key.*/ static int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr); -static EVP_MD *_hidden_Gost28147_89_MAC_md = NULL; -static EVP_MD *_hidden_Gost28147_89_12_MAC_md = NULL; +GOST_digest Gost28147_89_MAC_digest = { + .nid = NID_id_Gost28147_89_MAC, + .result_size = 4, + .input_blocksize = 8, + .app_datasize = sizeof(struct ossl_gost_imit_ctx), + .flags = EVP_MD_FLAG_XOF, + .init = gost_imit_init_cpa, + .update = gost_imit_update, + .final = gost_imit_final, + .copy = gost_imit_copy, + .cleanup = gost_imit_cleanup, + .ctrl = gost_imit_ctrl, +}; EVP_MD *imit_gost_cpa(void) { - if (_hidden_Gost28147_89_MAC_md == NULL) { - EVP_MD *md; - - if ((md = EVP_MD_meth_new(NID_id_Gost28147_89_MAC, NID_undef)) == NULL - || !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)) - || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_XOF) - || !EVP_MD_meth_set_init(md, gost_imit_init_cpa) - || !EVP_MD_meth_set_update(md, gost_imit_update) - || !EVP_MD_meth_set_final(md, gost_imit_final) - || !EVP_MD_meth_set_copy(md, gost_imit_copy) - || !EVP_MD_meth_set_cleanup(md, gost_imit_cleanup) - || !EVP_MD_meth_set_ctrl(md, gost_imit_ctrl)) { - EVP_MD_meth_free(md); - md = NULL; - } - _hidden_Gost28147_89_MAC_md = md; - } - return _hidden_Gost28147_89_MAC_md; + return GOST_init_digest(&Gost28147_89_MAC_digest); } void imit_gost_cpa_destroy(void) { - EVP_MD_meth_free(_hidden_Gost28147_89_MAC_md); - _hidden_Gost28147_89_MAC_md = NULL; + GOST_deinit_digest(&Gost28147_89_MAC_digest); } +GOST_digest Gost28147_89_mac_12_digest = { + .nid = NID_gost_mac_12, + .result_size = 4, + .input_blocksize = 8, + .app_datasize = sizeof(struct ossl_gost_imit_ctx), + .flags = EVP_MD_FLAG_XOF, + .init = gost_imit_init_cp_12, + .update = gost_imit_update, + .final = gost_imit_final, + .copy = gost_imit_copy, + .cleanup = gost_imit_cleanup, + .ctrl = gost_imit_ctrl, +}; + EVP_MD *imit_gost_cp_12(void) { - if (_hidden_Gost28147_89_12_MAC_md == NULL) { - EVP_MD *md; - - if ((md = EVP_MD_meth_new(NID_gost_mac_12, NID_undef)) == NULL - || !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)) - || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_XOF) - || !EVP_MD_meth_set_init(md, gost_imit_init_cp_12) - || !EVP_MD_meth_set_update(md, gost_imit_update) - || !EVP_MD_meth_set_final(md, gost_imit_final) - || !EVP_MD_meth_set_copy(md, gost_imit_copy) - || !EVP_MD_meth_set_cleanup(md, gost_imit_cleanup) - || !EVP_MD_meth_set_ctrl(md, gost_imit_ctrl)) { - EVP_MD_meth_free(md); - md = NULL; - } - _hidden_Gost28147_89_12_MAC_md = md; - } - return _hidden_Gost28147_89_12_MAC_md; + return GOST_init_digest(&Gost28147_89_mac_12_digest); } void imit_gost_cp_12_destroy(void) { - EVP_MD_meth_free(_hidden_Gost28147_89_12_MAC_md); - _hidden_Gost28147_89_12_MAC_md = NULL; + GOST_deinit_digest(&Gost28147_89_mac_12_digest); } /*