1 /**********************************************************************
3 * Copyright (c) 2005-2006 Cryptocom LTD *
4 * This file is distributed under the same license as OpenSSL *
6 * Implementation of control commands for GOST engine *
7 * OpenSSL 0.9.9 libraries required *
8 **********************************************************************/
11 #include <openssl/engine.h>
12 #include <openssl/buffer.h>
15 static char *gost_params[GOST_PARAM_MAX+1]={NULL};
16 static const char *gost_envnames[]={"CRYPT_PARAMS"};
17 const ENGINE_CMD_DEFN gost_cmds[]=
21 "Type of random number generator to use",
22 ENGINE_CMD_FLAG_STRING
24 { GOST_CTRL_RNG_PARAMS,
26 "Parameter for random number generator",
27 ENGINE_CMD_FLAG_STRING
29 */ { GOST_CTRL_CRYPT_PARAMS,
31 "OID of default GOST 28147-89 parameters",
32 ENGINE_CMD_FLAG_STRING
37 void gost_param_free()
40 for (i=0;i<=GOST_PARAM_MAX;i++)
41 if (gost_params[i]!=NULL)
43 OPENSSL_free(gost_params[i]);
49 int gost_control_func(ENGINE *e,int cmd,long i, void *p, void (*f)(void))
51 int param = cmd-ENGINE_CMD_BASE;
53 if (param <0 || param >GOST_PARAM_MAX) return -1;
54 ret=gost_set_default_param(param,p);
58 const char *get_gost_engine_param(int param)
61 if (param <0 || param >GOST_PARAM_MAX) return NULL;
62 if (gost_params[param]!=NULL)
64 return gost_params[param];
66 tmp = getenv(gost_envnames[param]);
69 if (gost_params[param]) OPENSSL_free(gost_params[param]);
70 gost_params[param] = BUF_strdup(tmp);
71 return gost_params[param];
76 int gost_set_default_param(int param, const char *value)
79 if (param <0 || param >GOST_PARAM_MAX) return 0;
80 tmp = getenv(gost_envnames[param]);
81 /* if there is value in the environment, use it, else -passed string * */
83 if (gost_params[param]) OPENSSL_free(gost_params[param]);
84 gost_params[param] = BUF_strdup(tmp);