]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_eng.c
gost_crypt: Add Gost28147_89_cbc_cipher
[openssl-gost/engine.git] / gost_eng.c
index 25bbe38d8dbbdc91ea47697e531f3a39d44b4663..9090e7241f5ee639cfd1db2cfb49749b345e6ef6 100644 (file)
@@ -109,10 +109,12 @@ static struct gost_digest_minfo {
 static struct gost_cipher_minfo {
     int nid;
     const EVP_CIPHER *(*cipher)(void);
+    GOST_cipher *reg;
 } gost_cipher_array[] = {
     {
         NID_id_Gost28147_89,
-        cipher_gost,
+        NULL,
+       &Gost28147_89_cipher,
     },
     {
         NID_gost89_cnt,
@@ -124,7 +126,8 @@ static struct gost_cipher_minfo {
     },
     {
         NID_gost89_cbc,
-        cipher_gost_cbc,
+        NULL,
+       &Gost28147_89_cbc_cipher,
     },
     {
         NID_grasshopper_ecb,
@@ -234,7 +237,7 @@ static struct gost_meth_minfo {
         NID_grasshopper_mac,
         &pmeth_grasshopper_mac,
         &ameth_grasshopper_mac,
-        "GRASSHOPPER-MAC",
+        "KUZNYECHIK-MAC",
         "GOST R 34.13-2015 Grasshopper MAC",
     },
     {
@@ -279,9 +282,16 @@ static int gost_engine_destroy(ENGINE* e) {
         dinfo->destroy();
     }
 
-    cipher_gost_destroy();
-    cipher_gost_grasshopper_destroy();
-    wrap_ciphers_destroy();
+    struct gost_cipher_minfo *cinfo = gost_cipher_array;
+    for (; cinfo->nid; cinfo++) {
+       if (cinfo->reg)
+           GOST_deinit_cipher(cinfo->reg);
+       else
+           EVP_CIPHER_meth_free((EVP_CIPHER *)cinfo->cipher());
+    }
+
+    //cipher_gost_grasshopper_destroy();
+    //wrap_ciphers_destroy();
 
     gost_param_free();
 
@@ -363,9 +373,16 @@ static int bind_gost(ENGINE* e, const char* id) {
         goto end;
 
     struct gost_cipher_minfo *cinfo = gost_cipher_array;
-    for (; cinfo->nid; cinfo++)
-        if (!EVP_add_cipher(cinfo->cipher()))
+    for (; cinfo->nid; cinfo++) {
+       const EVP_CIPHER *cipher;
+
+       if (cinfo->reg)
+           cipher = GOST_init_cipher(cinfo->reg);
+       else
+           cipher = cinfo->cipher();
+       if (!EVP_add_cipher(cipher))
             goto end;
+    }
 
     struct gost_digest_minfo *dinfo = gost_digest_array;
     for (; dinfo->nid; dinfo++) {
@@ -430,7 +447,10 @@ static int gost_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
 
     for (; info->nid; info++)
         if (nid == info->nid) {
-            *cipher = info->cipher();
+           if (info->reg)
+               *cipher = GOST_init_cipher(info->reg);
+           else
+               *cipher = info->cipher();
             return 1;
         }
     *cipher = NULL;