]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
gost_crypt: Add Gost28147_89_cbc_cipher
authorVitaly Chikunov <vt@altlinux.org>
Mon, 11 May 2020 23:10:07 +0000 (02:10 +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 cc9be5eb2bbf32bb5aeeac6ae018d68150754dee..943d873fb91527f3907da0f698136ea18f44a1a3 100644 (file)
@@ -119,39 +119,23 @@ GOST_cipher Gost28147_89_cipher = {
     .ctrl = gost_cipher_ctl,
 };
 
-static EVP_CIPHER *_hidden_Gost28147_89_cbc = NULL;
-const EVP_CIPHER *cipher_gost_cbc(void)
-{
-    if (_hidden_Gost28147_89_cbc == NULL
-        && ((_hidden_Gost28147_89_cbc =
-             EVP_CIPHER_meth_new(NID_gost89_cbc, 8 /* block_size */ ,
-                                 32 /* key_size */ )) == NULL
-            || !EVP_CIPHER_meth_set_iv_length(_hidden_Gost28147_89_cbc, 8)
-            || !EVP_CIPHER_meth_set_flags(_hidden_Gost28147_89_cbc,
-                                          EVP_CIPH_CBC_MODE |
-                                          EVP_CIPH_CUSTOM_IV |
-                                          EVP_CIPH_RAND_KEY |
-                                          EVP_CIPH_ALWAYS_CALL_INIT)
-            || !EVP_CIPHER_meth_set_init(_hidden_Gost28147_89_cbc,
-                                         gost_cipher_init_cbc)
-            || !EVP_CIPHER_meth_set_do_cipher(_hidden_Gost28147_89_cbc,
-                                              gost_cipher_do_cbc)
-            || !EVP_CIPHER_meth_set_cleanup(_hidden_Gost28147_89_cbc,
-                                            gost_cipher_cleanup)
-            || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_Gost28147_89_cbc,
-                                                  sizeof(struct
-                                                         ossl_gost_cipher_ctx))
-            || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_Gost28147_89_cbc,
-                                                    gost89_set_asn1_parameters)
-            || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_Gost28147_89_cbc,
-                                                    gost89_get_asn1_parameters)
-            || !EVP_CIPHER_meth_set_ctrl(_hidden_Gost28147_89_cbc,
-                                         gost_cipher_ctl))) {
-        EVP_CIPHER_meth_free(_hidden_Gost28147_89_cbc);
-        _hidden_Gost28147_89_cbc = NULL;
-    }
-    return _hidden_Gost28147_89_cbc;
-}
+GOST_cipher Gost28147_89_cbc_cipher = {
+    .nid = NID_gost89_cbc,
+    .block_size = 8,
+    .key_len = 32,
+    .iv_len = 8,
+    .flags = EVP_CIPH_CBC_MODE |
+        EVP_CIPH_CUSTOM_IV |
+        EVP_CIPH_RAND_KEY |
+        EVP_CIPH_ALWAYS_CALL_INIT,
+    .init = gost_cipher_init_cbc,
+    .do_cipher = gost_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 = gost_cipher_ctl,
+};
 
 static EVP_CIPHER *_hidden_gost89_cnt = NULL;
 const EVP_CIPHER *cipher_gost_cpacnt(void)
@@ -353,26 +337,6 @@ const EVP_CIPHER *cipher_magma_cbc(void)
     return _hidden_magma_cbc;
 }
 
-void cipher_gost_destroy(void)
-{
-    //EVP_CIPHER_meth_free(_hidden_Gost28147_89_cipher);
-    //_hidden_Gost28147_89_cipher = NULL;
-    EVP_CIPHER_meth_free(_hidden_gost89_cnt);
-    _hidden_gost89_cnt = NULL;
-    EVP_CIPHER_meth_free(_hidden_Gost28147_89_cbc);
-    _hidden_Gost28147_89_cbc = NULL;
-    EVP_CIPHER_meth_free(_hidden_gost89_cnt_12);
-    _hidden_gost89_cnt_12 = NULL;
-    EVP_CIPHER_meth_free(_hidden_magma_cbc);
-    _hidden_magma_cbc = NULL;
-    EVP_CIPHER_meth_free(_hidden_magma_ctr);
-    _hidden_magma_ctr = NULL;
-    EVP_CIPHER_meth_free(_hidden_magma_ctr_acpkm);
-    _hidden_magma_ctr_acpkm = NULL;
-    EVP_CIPHER_meth_free(_hidden_magma_ctr_acpkm_omac);
-    _hidden_magma_ctr_acpkm_omac = NULL;
-}
-
 /* Implementation of GOST 28147-89 in MAC (imitovstavka) mode */
 /* Init functions which set specific parameters */
 static int gost_imit_init_cpa(EVP_MD_CTX *ctx);
index 7997530a0475607a1b0a359a7937300bbcc6d5c3..9090e7241f5ee639cfd1db2cfb49749b345e6ef6 100644 (file)
@@ -126,7 +126,8 @@ static struct gost_cipher_minfo {
     },
     {
         NID_gost89_cbc,
-        cipher_gost_cbc,
+        NULL,
+       &Gost28147_89_cbc_cipher,
     },
     {
         NID_grasshopper_ecb,
index 3bb8128a3f4a06c9a058413735ebaf224aaf0a75..9c2126ee04d35d55497e7782fb84941a22d47d1e 100644 (file)
@@ -244,7 +244,6 @@ extern struct gost_cipher_info gost_cipher_list[];
 /* Find encryption params from ASN1_OBJECT */
 const struct gost_cipher_info *get_encryption_params(ASN1_OBJECT *obj);
 /* Implementation of GOST 28147-89 cipher in CFB and CNT modes */
-const EVP_CIPHER *cipher_gost_cbc();
 const EVP_CIPHER *cipher_gost_cpacnt();
 const EVP_CIPHER *cipher_gost_cpcnt_12();
 const EVP_CIPHER *cipher_magma_cbc();
@@ -343,5 +342,6 @@ EVP_CIPHER *GOST_init_cipher(GOST_cipher *c);
 void GOST_deinit_cipher(GOST_cipher *c);
 
 extern GOST_cipher Gost28147_89_cipher;
+extern GOST_cipher Gost28147_89_cbc_cipher;
 #endif
 /* vim: set expandtab cinoptions=\:0,l1,t0,g0,(0 sw=4 : */