]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
gost_keyexpimp: Rework cipher registration
authorVitaly Chikunov <vt@altlinux.org>
Tue, 12 May 2020 02:40:00 +0000 (05:40 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Tue, 12 May 2020 09:55:47 +0000 (12:55 +0300)
gost_eng.c
gost_keyexpimp.c
gost_lcl.h

index 09fc4b27c2b9500b2a3eb62f9a11a781bebb8c8c..a095982afb96e9ad1dfc313d32300915cd10ab92 100644 (file)
@@ -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 },
 };
index d2c690c20c1f879f9576ebf4cb3bcb442c16518a..9a3ac879a1ec97f02f28e5acbe2820e74399dc67 100644 (file)
@@ -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 : */
index 3aafd9eca47405e281ec8c2dd7e690e9ccddfdc0..5e21e85be32473f52fce479da65567279a37e6e3 100644 (file)
@@ -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 : */