]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
gost_crypt: Add magma_ctr_cipher
authorVitaly Chikunov <vt@altlinux.org>
Mon, 11 May 2020 23:23:34 +0000 (02:23 +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 ab5197e4dd8bfbb60161d80654419d9eb4966ee5..22765ee1b08d5bf9c62949ca6a40bbc6a16b9a1b 100644 (file)
@@ -175,38 +175,24 @@ GOST_cipher Gost28147_89_cnt_12_cipher = {
     .ctrl = gost_cipher_ctl,
 };
 
-static EVP_CIPHER *_hidden_magma_ctr = NULL;
-const EVP_CIPHER *cipher_magma_ctr(void)
-{
-    if (_hidden_magma_ctr == NULL
-        && ((_hidden_magma_ctr =
-             EVP_CIPHER_meth_new(NID_magma_ctr, 1 /* block_size */ ,
-                                 32 /* key_size */ )) == NULL
-            || !EVP_CIPHER_meth_set_iv_length(_hidden_magma_ctr, 4)
-            || !EVP_CIPHER_meth_set_flags(_hidden_magma_ctr,
-                                          EVP_CIPH_CTR_MODE |
-                                          EVP_CIPH_NO_PADDING |
-                                          EVP_CIPH_CUSTOM_IV |
-                                          EVP_CIPH_RAND_KEY |
-                                          EVP_CIPH_ALWAYS_CALL_INIT)
-            || !EVP_CIPHER_meth_set_init(_hidden_magma_ctr, magma_cipher_init)
-            || !EVP_CIPHER_meth_set_do_cipher(_hidden_magma_ctr,
-                                              magma_cipher_do_ctr)
-            || !EVP_CIPHER_meth_set_cleanup(_hidden_magma_ctr,
-                                            gost_cipher_cleanup)
-            || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_magma_ctr,
-                                                  sizeof(struct
-                                                         ossl_gost_cipher_ctx))
-            || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_magma_ctr,
-                                                    magma_set_asn1_parameters)
-            || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_magma_ctr,
-                                                    magma_get_asn1_parameters)
-            || !EVP_CIPHER_meth_set_ctrl(_hidden_magma_ctr, magma_cipher_ctl))) {
-        EVP_CIPHER_meth_free(_hidden_magma_ctr);
-        _hidden_magma_ctr = NULL;
-    }
-    return _hidden_magma_ctr;
-}
+GOST_cipher magma_ctr_cipher = {
+    .nid = NID_magma_ctr,
+    .block_size = 1,
+    .key_len = 32,
+    .iv_len = 4,
+    .flags = EVP_CIPH_CTR_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_ctr,
+    .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,
+};
 
 static EVP_CIPHER *_hidden_magma_ctr_acpkm = NULL;
 const EVP_CIPHER *cipher_magma_ctr_acpkm(void)
index fb71d3b40e0cc5c4e8f31db7211c184bd8bf2d2c..d129ed2bbf70edc733c68edaaf50e58735f07419 100644 (file)
@@ -157,7 +157,8 @@ static struct gost_cipher_minfo {
     },
     {
         NID_magma_ctr,
-        cipher_magma_ctr,
+        NULL,
+       &magma_ctr_cipher,
     },
     {
         NID_magma_ctr_acpkm,
index 0369f820ade2497b4b41944ba53ddaa3c128ce71..29ab7a9f1e46fea0ae7f3c63896dda518d11a2d2 100644 (file)
@@ -345,5 +345,6 @@ extern GOST_cipher Gost28147_89_cipher;
 extern GOST_cipher Gost28147_89_cbc_cipher;
 extern GOST_cipher Gost28147_89_cnt_cipher;
 extern GOST_cipher Gost28147_89_cnt_12_cipher;
+extern GOST_cipher magma_ctr_cipher;
 #endif
 /* vim: set expandtab cinoptions=\:0,l1,t0,g0,(0 sw=4 : */