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/crypto.h>
12 #include <openssl/err.h>
13 #include <openssl/engine.h>
14 #include <openssl/buffer.h>
17 static char *gost_params[GOST_PARAM_MAX + 1] = { NULL };
18 static const char *gost_envnames[] = { "CRYPT_PARAMS", "GOST_PBE_HMAC" };
20 const ENGINE_CMD_DEFN gost_cmds[] = {
21 {GOST_CTRL_CRYPT_PARAMS,
23 "OID of default GOST 28147-89 parameters",
24 ENGINE_CMD_FLAG_STRING},
25 {GOST_CTRL_PBE_PARAMS,
27 "Shortname of default digest alg for PBE",
28 ENGINE_CMD_FLAG_STRING},
32 void gost_param_free()
36 for (i = 0; i <= GOST_PARAM_MAX; i++) {
37 OPENSSL_free(gost_params[i]);
38 gost_params[i] = NULL;
43 int gost_control_func(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
45 int param = cmd - ENGINE_CMD_BASE;
47 if (param < 0 || param > GOST_PARAM_MAX)
49 ret = gost_set_default_param(param, p);
53 const char *get_gost_engine_param(int param)
56 if (param < 0 || param > GOST_PARAM_MAX)
58 if (gost_params[param] != NULL) {
59 return gost_params[param];
61 tmp = getenv(gost_envnames[param]);
63 OPENSSL_free(gost_params[param]);
64 gost_params[param] = BUF_strdup(tmp);
65 return gost_params[param];
70 int gost_set_default_param(int param, const char *value)
73 if (param < 0 || param > GOST_PARAM_MAX)
75 tmp = getenv(gost_envnames[param]);
77 * if there is value in the environment, use it, else -passed string *
81 OPENSSL_free(gost_params[param]);
82 gost_params[param] = BUF_strdup(tmp);