]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_ctl.c
Explicitely setting cofactor
[openssl-gost/engine.git] / gost_ctl.c
index caf3bd542269c461a830b45f0336095a78ba791c..04be66d2c541c6f2fb4be8a44e705a31ea34abda 100644 (file)
@@ -15,7 +15,7 @@
 #include "gost_lcl.h"
 
 static char *gost_params[GOST_PARAM_MAX + 1] = { NULL };
-static const char *gost_envnames[] = { "CRYPT_PARAMS", "GOST_PBE_HMAC" };
+static const char *gost_envnames[] = { "CRYPT_PARAMS", "GOST_PBE_HMAC", "GOST_PK_FORMAT" };
 
 const ENGINE_CMD_DEFN gost_cmds[] = {
     {GOST_CTRL_CRYPT_PARAMS,
@@ -26,17 +26,21 @@ const ENGINE_CMD_DEFN gost_cmds[] = {
      "PBE_PARAMS",
      "Shortname of default digest alg for PBE",
      ENGINE_CMD_FLAG_STRING},
+     {GOST_CTRL_PK_FORMAT,
+     "GOST_PK_FORMAT",
+     "Private key format params",
+     ENGINE_CMD_FLAG_STRING},
     {0, NULL, NULL, 0}
 };
 
 void gost_param_free()
 {
     int i;
-    for (i = 0; i <= GOST_PARAM_MAX; i++)
-        if (gost_params[i] != NULL) {
-            OPENSSL_free(gost_params[i]);
-            gost_params[i] = NULL;
-        }
+
+    for (i = 0; i <= GOST_PARAM_MAX; i++) {
+        OPENSSL_free(gost_params[i]);
+        gost_params[i] = NULL;
+    }
 
 }
 
@@ -44,8 +48,9 @@ int gost_control_func(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
 {
     int param = cmd - ENGINE_CMD_BASE;
     int ret = 0;
-    if (param < 0 || param > GOST_PARAM_MAX)
+    if (param < 0 || param > GOST_PARAM_MAX) {
         return -1;
+    }
     ret = gost_set_default_param(param, p);
     return ret;
 }
@@ -60,8 +65,7 @@ const char *get_gost_engine_param(int param)
     }
     tmp = getenv(gost_envnames[param]);
     if (tmp) {
-        if (gost_params[param])
-            OPENSSL_free(gost_params[param]);
+        OPENSSL_free(gost_params[param]);
         gost_params[param] = BUF_strdup(tmp);
         return gost_params[param];
     }
@@ -74,13 +78,14 @@ int gost_set_default_param(int param, const char *value)
     if (param < 0 || param > GOST_PARAM_MAX)
         return 0;
     tmp = getenv(gost_envnames[param]);
+
     /*
      * if there is value in the environment, use it, else -passed string *
      */
-    if (!tmp)
+    if (!tmp) {
         tmp = value;
-    if (gost_params[param])
-        OPENSSL_free(gost_params[param]);
+    }
+    OPENSSL_free(gost_params[param]);
     gost_params[param] = BUF_strdup(tmp);
 
     return 1;