]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_grasshopper_cipher.c
Ensure proper cipher type for EVP_CTRL_KEY_MESH
[openssl-gost/engine.git] / gost_grasshopper_cipher.c
index a3f34d62054f12f333250c47d590aaecf839fb21..528a7ee6c5a35fcb5c376c8949191664eda9a1e5 100644 (file)
@@ -264,8 +264,8 @@ GRASSHOPPER_INLINE int gost_grasshopper_cipher_init_ctracpkm(EVP_CIPHER_CTX *ctx
     /* NB: setting type makes EVP do_cipher callback useless */
     c->c.type = GRASSHOPPER_CIPHER_CTRACPKM;
     EVP_CIPHER_CTX_set_num(ctx, 0);
-    c->section_size  = 0; /* by default meshing is turned off */
-    c->skip_sections = 0; /* will be set to 1 on EVP_CTRL_KEY_MESH */
+    c->section_size  = 4096;
+    c->skip_sections = 1;
 
     return gost_grasshopper_cipher_init(ctx, key, iv, enc);
 }
@@ -659,13 +659,16 @@ int gost_grasshopper_cipher_ctl(EVP_CIPHER_CTX* ctx, int type, int arg, void* pt
             }
             break;
         }
-        case EVP_CTRL_KEY_MESH:
-            if (arg <= 1 || ((arg - 1) & arg))
-                return -1;
+        case EVP_CTRL_KEY_MESH: {
             gost_grasshopper_cipher_ctx_ctr *c = EVP_CIPHER_CTX_get_cipher_data(ctx);
+            if (c->c.type != GRASSHOPPER_CIPHER_CTRACPKM ||
+                arg <= 1 ||
+                ((arg - 1) & arg))
+                return -1;
             c->section_size = arg;
             c->skip_sections = 1;
             break;
+        }
         default:
             GOSTerr(GOST_F_GOST_GRASSHOPPER_CIPHER_CTL, GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);
             return -1;