]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gost_ctl.c
Make it possible to re-define OPENSSL_ENGINES_INSTALL_DIR
[openssl-gost/engine.git] / 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/crypto.h>
12 #include <openssl/err.h>
13 #include <openssl/engine.h>
14 #include <openssl/buffer.h>
15 #include "gost_lcl.h"
16
17 static char *gost_params[GOST_PARAM_MAX + 1] = { NULL };
18 static const char *gost_envnames[] = { "CRYPT_PARAMS", "GOST_PBE_HMAC", "GOST_PK_FORMAT" };
19
20 const ENGINE_CMD_DEFN gost_cmds[] = {
21     {GOST_CTRL_CRYPT_PARAMS,
22      "CRYPT_PARAMS",
23      "OID of default GOST 28147-89 parameters",
24      ENGINE_CMD_FLAG_STRING},
25     {GOST_CTRL_PBE_PARAMS,
26      "PBE_PARAMS",
27      "Shortname of default digest alg for PBE",
28      ENGINE_CMD_FLAG_STRING},
29      {GOST_CTRL_PK_FORMAT,
30      "GOST_PK_FORMAT",
31      "Private key format params",
32      ENGINE_CMD_FLAG_STRING},
33     {0, NULL, NULL, 0}
34 };
35
36 void gost_param_free()
37 {
38     int i;
39
40     for (i = 0; i <= GOST_PARAM_MAX; i++) {
41         OPENSSL_free(gost_params[i]);
42         gost_params[i] = NULL;
43     }
44
45 }
46
47 int gost_control_func(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
48 {
49     int param = cmd - ENGINE_CMD_BASE;
50     int ret = 0;
51     if (param < 0 || param > GOST_PARAM_MAX) {
52         return -1;
53     }
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)
62         return NULL;
63     if (gost_params[param] != NULL) {
64         return gost_params[param];
65     }
66     tmp = getenv(gost_envnames[param]);
67     if (tmp) {
68         OPENSSL_free(gost_params[param]);
69         gost_params[param] = BUF_strdup(tmp);
70         return gost_params[param];
71     }
72     return NULL;
73 }
74
75 int gost_set_default_param(int param, const char *value)
76 {
77     const char *tmp;
78     if (param < 0 || param > GOST_PARAM_MAX)
79         return 0;
80     tmp = getenv(gost_envnames[param]);
81
82     /*
83      * if there is value in the environment, use it, else -passed string *
84      */
85     if (!tmp) {
86         tmp = value;
87     }
88     OPENSSL_free(gost_params[param]);
89     gost_params[param] = BUF_strdup(tmp);
90
91     return 1;
92 }