From: Vitaly Chikunov Date: Tue, 12 May 2020 02:40:00 +0000 (+0300) Subject: gost_keyexpimp: Rework cipher registration X-Git-Tag: v3.0.0~105 X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=cfe589b6345926b166f2e59c4d4c537f78382e21;p=openssl-gost%2Fengine.git gost_keyexpimp: Rework cipher registration --- diff --git a/gost_eng.c b/gost_eng.c index 09fc4b2..a095982 100644 --- a/gost_eng.c +++ b/gost_eng.c @@ -188,11 +188,13 @@ static struct gost_cipher_minfo { }, { NID_magma_kexp15, - cipher_magma_wrap, + NULL, + &magma_kexp15_cipher, }, { NID_kuznyechik_kexp15, - cipher_kuznyechik_wrap, + NULL, + &kuznyechik_kexp15_cipher }, { 0 }, }; diff --git a/gost_keyexpimp.c b/gost_keyexpimp.c index d2c690c..9a3ac87 100644 --- a/gost_keyexpimp.c +++ b/gost_keyexpimp.c @@ -412,55 +412,28 @@ int wrap_ctrl (EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) } } -static EVP_CIPHER *hidden_magma_wrap_cipher, *hidden_kuznyechik_wrap_cipher; - -const EVP_CIPHER *cipher_magma_wrap(void) -{ - if (hidden_magma_wrap_cipher == NULL - && ((hidden_magma_wrap_cipher = - EVP_CIPHER_meth_new(NID_magma_kexp15, 8 /* block_size */ , - GOSTKEYLEN*2 /* key_size */ )) == NULL - || !EVP_CIPHER_meth_set_iv_length(hidden_magma_wrap_cipher, 4) - || !EVP_CIPHER_meth_set_flags(hidden_magma_wrap_cipher, GOST_WRAP_FLAGS) - || !EVP_CIPHER_meth_set_init(hidden_magma_wrap_cipher, magma_wrap_init) - || !EVP_CIPHER_meth_set_ctrl(hidden_magma_wrap_cipher, wrap_ctrl) - || !EVP_CIPHER_meth_set_do_cipher(hidden_magma_wrap_cipher, magma_wrap_do) - || !EVP_CIPHER_meth_set_impl_ctx_size(hidden_magma_wrap_cipher, sizeof(GOST_WRAP_CTX)) - || !EVP_add_cipher(hidden_magma_wrap_cipher) - )) { - EVP_CIPHER_meth_free(hidden_magma_wrap_cipher); - hidden_magma_wrap_cipher = NULL; - } - - return hidden_magma_wrap_cipher; -} - -const EVP_CIPHER *cipher_kuznyechik_wrap(void) -{ - if (hidden_kuznyechik_wrap_cipher == NULL - && ((hidden_kuznyechik_wrap_cipher = - EVP_CIPHER_meth_new(NID_kuznyechik_kexp15, 16 /* FIXME block_size */ , - GOSTKEYLEN*2 /* key_size */ )) == NULL - || !EVP_CIPHER_meth_set_iv_length(hidden_kuznyechik_wrap_cipher, 8) - || !EVP_CIPHER_meth_set_flags(hidden_kuznyechik_wrap_cipher, GOST_WRAP_FLAGS) - || !EVP_CIPHER_meth_set_init(hidden_kuznyechik_wrap_cipher, kuznyechik_wrap_init) - || !EVP_CIPHER_meth_set_ctrl(hidden_kuznyechik_wrap_cipher, wrap_ctrl) - || !EVP_CIPHER_meth_set_do_cipher(hidden_kuznyechik_wrap_cipher, kuznyechik_wrap_do) - || !EVP_CIPHER_meth_set_impl_ctx_size(hidden_kuznyechik_wrap_cipher, sizeof(GOST_WRAP_CTX)) - || !EVP_add_cipher(hidden_kuznyechik_wrap_cipher) - )) { - EVP_CIPHER_meth_free(hidden_kuznyechik_wrap_cipher); - hidden_kuznyechik_wrap_cipher = NULL; - } - - return hidden_kuznyechik_wrap_cipher; -} - -void wrap_ciphers_destroy(void) -{ - EVP_CIPHER_meth_free(hidden_magma_wrap_cipher); - hidden_magma_wrap_cipher = NULL; - - EVP_CIPHER_meth_free(hidden_kuznyechik_wrap_cipher); - hidden_kuznyechik_wrap_cipher = NULL; -} +static GOST_cipher wrap_template_cipher = { + .key_len = GOSTKEYLEN * 2, + .flags = GOST_WRAP_FLAGS, + .ctx_size = sizeof(GOST_WRAP_CTX), + .ctrl = wrap_ctrl, +}; + +GOST_cipher magma_kexp15_cipher = { + .template = &wrap_template_cipher, + .nid = NID_magma_kexp15, + .block_size = 8, + .iv_len = 4, + .init = magma_wrap_init, + .do_cipher = magma_wrap_do, +}; + +GOST_cipher kuznyechik_kexp15_cipher = { + .template = &wrap_template_cipher, + .nid = NID_kuznyechik_kexp15, + .block_size = 16, + .iv_len = 8, + .init = kuznyechik_wrap_init, + .do_cipher = kuznyechik_wrap_do, +}; +/* vim: set expandtab cinoptions=\:0,l1,t0,g0,(0 sw=4 : */ diff --git a/gost_lcl.h b/gost_lcl.h index 3aafd9e..5e21e85 100644 --- a/gost_lcl.h +++ b/gost_lcl.h @@ -357,6 +357,8 @@ extern GOST_cipher grasshopper_ofb_cipher; extern GOST_cipher grasshopper_ctr_cipher; extern GOST_cipher grasshopper_ctr_acpkm_cipher; extern GOST_cipher grasshopper_ctr_acpkm_omac_cipher; +extern GOST_cipher magma_kexp15_cipher; +extern GOST_cipher kuznyechik_kexp15_cipher; #endif /* vim: set expandtab cinoptions=\:0,l1,t0,g0,(0 sw=4 : */