]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
gost_crypt: Add magma_cbc_cipher
authorVitaly Chikunov <vt@altlinux.org>
Mon, 11 May 2020 23:34:54 +0000 (02:34 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Tue, 12 May 2020 09:55:47 +0000 (12:55 +0300)
gost_crypt.c
gost_eng.c
gost_lcl.h

index c1516d7cc51f1c05284cf13f01a11a70acafca2e..5f7e029c389b830743e62105c6bb1685f5ff1e7b 100644 (file)
@@ -235,33 +235,24 @@ GOST_cipher magma_ctr_acpkm_omac_cipher = {
     .ctrl = magma_cipher_ctl_acpkm_omac,
 };
 
-static EVP_CIPHER *_hidden_magma_cbc = NULL;
-const EVP_CIPHER *cipher_magma_cbc(void)
-{
-    if (_hidden_magma_cbc == NULL
-        && ((_hidden_magma_cbc =
-             EVP_CIPHER_meth_new(NID_magma_cbc, 8 /* block_size */ ,
-                                 32 /* key_size */ )) == NULL
-            || !EVP_CIPHER_meth_set_iv_length(_hidden_magma_cbc, 8)
-            || !EVP_CIPHER_meth_set_flags(_hidden_magma_cbc,
-                                          EVP_CIPH_CBC_MODE |
-                                          EVP_CIPH_CUSTOM_IV |
-                                          EVP_CIPH_RAND_KEY |
-                                          EVP_CIPH_ALWAYS_CALL_INIT)
-            || !EVP_CIPHER_meth_set_init(_hidden_magma_cbc, magma_cipher_init)
-            || !EVP_CIPHER_meth_set_do_cipher(_hidden_magma_cbc,
-                                              magma_cipher_do_cbc)
-            || !EVP_CIPHER_meth_set_cleanup(_hidden_magma_cbc,
-                                            gost_cipher_cleanup)
-            || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_magma_cbc,
-                                                  sizeof(struct
-                                                         ossl_gost_cipher_ctx))
-            || !EVP_CIPHER_meth_set_ctrl(_hidden_magma_cbc, magma_cipher_ctl))) {
-        EVP_CIPHER_meth_free(_hidden_magma_cbc);
-        _hidden_magma_cbc = NULL;
-    }
-    return _hidden_magma_cbc;
-}
+GOST_cipher magma_cbc_cipher = {
+    .nid = NID_magma_cbc,
+    .block_size = 8,
+    .key_len = 32,
+    .iv_len = 8,
+    .flags = EVP_CIPH_CBC_MODE |
+        EVP_CIPH_NO_PADDING |
+        EVP_CIPH_CUSTOM_IV |
+        EVP_CIPH_RAND_KEY |
+        EVP_CIPH_ALWAYS_CALL_INIT,
+    .init = magma_cipher_init,
+    .do_cipher = magma_cipher_do_cbc,
+    .cleanup = gost_cipher_cleanup,
+    .ctx_size = sizeof(struct ossl_gost_cipher_ctx),
+    .set_asn1_parameters = gost89_set_asn1_parameters,
+    .get_asn1_parameters = gost89_get_asn1_parameters,
+    .ctrl = magma_cipher_ctl,
+};
 
 /* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
 /* Init functions which set specific parameters */
index 1154701f5974a6aee5e20a2276850bf402a32140..84c0937235b1afd7ee4ff3bf8f0e7c30c7e8df0a 100644 (file)
@@ -153,7 +153,8 @@ static struct gost_cipher_minfo {
     },
     {
         NID_magma_cbc,
-        cipher_magma_cbc,
+        NULL,
+       &magma_cbc_cipher,
     },
     {
         NID_magma_ctr,
index 1591614cb719103f45b8040a6de6259fd6100b9a..e926d9a3d4950b982cbfc0dad7ea6261f930dd28 100644 (file)
@@ -348,5 +348,6 @@ extern GOST_cipher Gost28147_89_cnt_12_cipher;
 extern GOST_cipher magma_ctr_cipher;
 extern GOST_cipher magma_ctr_acpkm_cipher;
 extern GOST_cipher magma_ctr_acpkm_omac_cipher;
+extern GOST_cipher magma_cbc_cipher;
 #endif
 /* vim: set expandtab cinoptions=\:0,l1,t0,g0,(0 sw=4 : */