]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_eng.c
gost_crypt: Add Gost28147_89_cnt_12_cipher
[openssl-gost/engine.git] / gost_eng.c
index 0ae4c9baa89a95eeb21b7192086633d5ad41be37..fb71d3b40e0cc5c4e8f31db7211c184bd8bf2d2c 100644 (file)
@@ -109,22 +109,27 @@ 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,
-        cipher_gost_cpacnt,
+        NULL,
+       &Gost28147_89_cnt_cipher,
     },
     {
         NID_gost89_cnt_12,
-        cipher_gost_cpcnt_12,
+        NULL,
+       &Gost28147_89_cnt_12_cipher,
     },
     {
         NID_gost89_cbc,
-        cipher_gost_cbc,
+        NULL,
+       &Gost28147_89_cbc_cipher,
     },
     {
         NID_grasshopper_ecb,
@@ -154,6 +159,14 @@ static struct gost_cipher_minfo {
         NID_magma_ctr,
         cipher_magma_ctr,
     },
+    {
+        NID_magma_ctr_acpkm,
+        cipher_magma_ctr_acpkm,
+    },
+    {
+        NID_magma_ctr_acpkm_omac,
+        cipher_magma_ctr_acpkm_omac,
+    },
     {
         NID_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm,
         cipher_gost_grasshopper_ctracpkm,
@@ -226,7 +239,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",
     },
     {
@@ -271,9 +284,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();
 
@@ -355,9 +375,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++) {
@@ -422,7 +449,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;