]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gost_ctl.c
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[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[] =
19     { "CRYPT_PARAMS", "GOST_PBE_HMAC", "GOST_PK_FORMAT" };
20
21 void gost_param_free()
22 {
23     int i;
24
25     for (i = 0; i <= GOST_PARAM_MAX; i++) {
26         OPENSSL_free(gost_params[i]);
27         gost_params[i] = NULL;
28     }
29
30 }
31
32 int gost_control_func(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
33 {
34     int param = cmd - ENGINE_CMD_BASE;
35     int ret = 0;
36     if (param < 0 || param > GOST_PARAM_MAX) {
37         return -1;
38     }
39     ret = gost_set_default_param(param, p);
40     return ret;
41 }
42
43 const char *get_gost_engine_param(int param)
44 {
45     char *tmp;
46     if (param < 0 || param >= GOST_PARAM_MAX)
47         return NULL;
48     if (gost_params[param] != NULL) {
49         return gost_params[param];
50     }
51     tmp = getenv(gost_envnames[param]);
52     if (tmp) {
53         OPENSSL_free(gost_params[param]);
54         gost_params[param] = BUF_strdup(tmp);
55         return gost_params[param];
56     }
57     return NULL;
58 }
59
60 int gost_set_default_param(int param, const char *value)
61 {
62     const char *tmp;
63     if (param < 0 || param >= GOST_PARAM_MAX)
64         return 0;
65     tmp = getenv(gost_envnames[param]);
66
67     /*
68      * if there is value in the environment, use it, else -passed string *
69      */
70     if (!tmp) {
71         tmp = value;
72     }
73     OPENSSL_free(gost_params[param]);
74     gost_params[param] = BUF_strdup(tmp);
75
76     return 1;
77 }