]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_eng.c
gost_crypt: Add magma_ctr_acpkm_cipher
[openssl-gost/engine.git] / gost_eng.c
index 8257072a3c8637d94fa9c3282cc398201a1f872a..d3c0f748f1b2a39165fef69b29a3a81df0bc1643 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,
@@ -152,12 +157,34 @@ static struct gost_cipher_minfo {
     },
     {
         NID_magma_ctr,
-        cipher_magma_ctr,
+        NULL,
+       &magma_ctr_cipher,
+    },
+    {
+        NID_magma_ctr_acpkm,
+        NULL,
+       &magma_ctr_acpkm_cipher,
+    },
+    {
+        NID_magma_ctr_acpkm_omac,
+        cipher_magma_ctr_acpkm_omac,
     },
     {
         NID_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm,
         cipher_gost_grasshopper_ctracpkm,
     },
+    {
+        NID_kuznyechik_ctr_acpkm_omac,
+        cipher_gost_grasshopper_ctracpkm_omac,
+    },
+    {
+        NID_magma_kexp15,
+        cipher_magma_wrap,
+    },
+    {
+        NID_kuznyechik_kexp15,
+        cipher_kuznyechik_wrap,
+    },
     { 0 },
 };
 
@@ -214,7 +241,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",
     },
     {
@@ -259,8 +286,16 @@ static int gost_engine_destroy(ENGINE* e) {
         dinfo->destroy();
     }
 
-    cipher_gost_destroy();
-    cipher_gost_grasshopper_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();
 
@@ -342,9 +377,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++) {
@@ -409,7 +451,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;