]>
Commit | Line | Data |
---|---|---|
926c41bd DSH |
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> | |
ea46f5e0 | 12 | #include <openssl/buffer.h> |
926c41bd DSH |
13 | #include "gost_lcl.h" |
14 | ||
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[]= | |
18 | { | |
19 | /* { GOST_CTRL_RNG, | |
20 | "RNG", | |
21 | "Type of random number generator to use", | |
22 | ENGINE_CMD_FLAG_STRING | |
23 | }, | |
24 | { GOST_CTRL_RNG_PARAMS, | |
25 | "RNG_PARAMS", | |
26 | "Parameter for random number generator", | |
27 | ENGINE_CMD_FLAG_STRING | |
28 | }, | |
29 | */ { GOST_CTRL_CRYPT_PARAMS, | |
30 | "CRYPT_PARAMS", | |
31 | "OID of default GOST 28147-89 parameters", | |
32 | ENGINE_CMD_FLAG_STRING | |
33 | }, | |
34 | {0,NULL,NULL,0} | |
35 | }; | |
36 | ||
0e1dba93 DSH |
37 | void gost_param_free() |
38 | { | |
39 | int i; | |
40 | for (i=0;i<=GOST_PARAM_MAX;i++) | |
41 | if (gost_params[i]!=NULL) | |
42 | { | |
43 | OPENSSL_free(gost_params[i]); | |
44 | gost_params[i]=NULL; | |
45 | } | |
46 | ||
47 | } | |
926c41bd DSH |
48 | |
49 | int gost_control_func(ENGINE *e,int cmd,long i, void *p, void (*f)(void)) | |
50 | { | |
51 | int param = cmd-ENGINE_CMD_BASE; | |
52 | int ret=0; | |
53 | if (param <0 || param >GOST_PARAM_MAX) return -1; | |
54 | ret=gost_set_default_param(param,p); | |
55 | return ret; | |
56 | } | |
57 | ||
58 | const char *get_gost_engine_param(int param) | |
59 | { | |
60 | char *tmp; | |
61 | if (param <0 || param >GOST_PARAM_MAX) return NULL; | |
62 | if (gost_params[param]!=NULL) | |
63 | { | |
64 | return gost_params[param]; | |
65 | } | |
66 | tmp = getenv(gost_envnames[param]); | |
67 | if (tmp) | |
68 | { | |
0e1dba93 | 69 | if (gost_params[param]) OPENSSL_free(gost_params[param]); |
ea46f5e0 | 70 | gost_params[param] = BUF_strdup(tmp); |
926c41bd DSH |
71 | return gost_params[param]; |
72 | } | |
73 | return NULL; | |
74 | } | |
75 | ||
76 | int gost_set_default_param(int param, const char *value) | |
77 | { | |
78 | const char *tmp; | |
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 * */ | |
82 | if (!tmp) tmp=value; | |
0e1dba93 | 83 | if (gost_params[param]) OPENSSL_free(gost_params[param]); |
ea46f5e0 | 84 | gost_params[param] = BUF_strdup(tmp); |
926c41bd DSH |
85 | |
86 | return 1; | |
87 | } |