e31e1f977604b7554e857b3a46e797d71b4942a0
[openssl.git] / engines / ccgost / gost_ctl.c
1 /**********************************************************************
2  *                        gost_ctl.c                                  *
3  *             Copyright (c) 2005-2006 Cryptocom LTD                  *
4  *       This file is distributed under the same license as OpenSSL   *
5  *                                                                    *
6  *        Implementation of control commands for GOST engine          *
7  *            OpenSSL 0.9.9 libraries required                        *
8  **********************************************************************/            
9 #include <stdlib.h>
10 #include <string.h>
11 #include <openssl/engine.h>
12 #include "gost_lcl.h"
13
14 static char *gost_params[GOST_PARAM_MAX+1]={NULL};
15 static const char *gost_envnames[]={"CRYPT_PARAMS"};
16 const ENGINE_CMD_DEFN gost_cmds[]=
17         {
18 /*      { GOST_CTRL_RNG,
19         "RNG",
20         "Type of random number generator to use",
21         ENGINE_CMD_FLAG_STRING
22         },
23         { GOST_CTRL_RNG_PARAMS,
24         "RNG_PARAMS",
25         "Parameter for random number generator",
26         ENGINE_CMD_FLAG_STRING
27         },
28 */        { GOST_CTRL_CRYPT_PARAMS,
29                 "CRYPT_PARAMS",
30                 "OID of default GOST 28147-89 parameters",
31                 ENGINE_CMD_FLAG_STRING
32                         },
33 {0,NULL,NULL,0}
34         };
35
36
37 int gost_control_func(ENGINE *e,int cmd,long i, void *p, void (*f)(void))
38         {
39         int param = cmd-ENGINE_CMD_BASE;
40         int ret=0;
41         if (param <0 || param >GOST_PARAM_MAX) return -1;
42         ret=gost_set_default_param(param,p);
43         return ret;
44         }
45
46 const char *get_gost_engine_param(int param) 
47         {
48         char *tmp;
49         if (param <0 || param >GOST_PARAM_MAX) return NULL;
50         if (gost_params[param]!=NULL) 
51                 {
52                 return gost_params[param];
53                 }
54         tmp = getenv(gost_envnames[param]);
55         if (tmp) 
56                 {
57                 gost_params[param] = strdup(tmp);
58                 return gost_params[param];
59                 }       
60         return NULL;
61         }       
62
63 int gost_set_default_param(int param, const char *value) 
64         {
65         const char *tmp;
66         if (param <0 || param >GOST_PARAM_MAX) return 0;
67         tmp = getenv(gost_envnames[param]);
68         /* if there is value in the environment, use it, else -passed string * */
69         if (!tmp) tmp=value;
70         if (gost_params[param]) free(gost_params[param]);
71         gost_params[param] = strdup(tmp);
72
73         return 1;
74         }