]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_omac.c
Explicitely setting cofactor
[openssl-gost/engine.git] / gost_omac.c
index ad96662f04fdc03a540a9a96bc68e90d17d0ab08..fa7ab746ba5119a485003521324f17803f47ab33 100644 (file)
@@ -89,6 +89,10 @@ int omac_imit_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
                {
                        return 0;
                }
+               if (c_to->cmac_ctx == c_from->cmac_ctx)
+               {
+                       return 1;
+               }
                return CMAC_CTX_copy(c_to->cmac_ctx, c_from->cmac_ctx);
 }
 
@@ -133,7 +137,23 @@ int omac_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
     case EVP_MD_CTRL_SET_KEY:
                                {
                                        OMAC_CTX *c = EVP_MD_CTX_md_data(ctx);
-                                       const EVP_CIPHER *cipher = EVP_get_cipherbynid(c->cipher_nid);
+                                       const EVP_MD *md = EVP_MD_CTX_md(ctx);
+                                       const EVP_CIPHER *cipher = NULL;
+
+                                       if (c->cipher_nid == NID_undef)
+                                       {
+                                               switch (EVP_MD_nid(md))
+                                               {
+                                                       case NID_magma_mac:
+                                                               c->cipher_nid = NID_magma_cbc;
+                                                               break;
+
+                                                       case NID_grasshopper_mac:
+                                                               c->cipher_nid = NID_grasshopper_cbc;
+                                                               break;
+                                               }
+                                       }
+                                       cipher = EVP_get_cipherbynid(c->cipher_nid);
 
                                        if (cipher == NULL)
                                        {