]> git.ipfire.org Git - thirdparty/openssl.git/blame - engines/ccgost/gost_ctl.c
Rename some BUF_xxx to OPENSSL_xxx
[thirdparty/openssl.git] / engines / ccgost / gost_ctl.c
CommitLineData
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 *
0f113f3e 8 **********************************************************************/
926c41bd
DSH
9#include <stdlib.h>
10#include <string.h>
1e26a8ba
GT
11#include <openssl/crypto.h>
12#include <openssl/err.h>
926c41bd 13#include <openssl/engine.h>
ea46f5e0 14#include <openssl/buffer.h>
926c41bd
DSH
15#include "gost_lcl.h"
16
0f113f3e
MC
17static char *gost_params[GOST_PARAM_MAX + 1] = { NULL };
18static const char *gost_envnames[] = { "CRYPT_PARAMS" };
926c41bd 19
0f113f3e 20const ENGINE_CMD_DEFN gost_cmds[] = {
35a1cc90
MC
21/*- { GOST_CTRL_RNG,
22 "RNG",
23 "Type of random number generator to use",
24 ENGINE_CMD_FLAG_STRING
25 },
26 { GOST_CTRL_RNG_PARAMS,
27 "RNG_PARAMS",
28 "Parameter for random number generator",
29 ENGINE_CMD_FLAG_STRING
30 },
0f113f3e 31*/ {GOST_CTRL_CRYPT_PARAMS,
35a1cc90
MC
32 "CRYPT_PARAMS",
33 "OID of default GOST 28147-89 parameters",
34 ENGINE_CMD_FLAG_STRING},
0f113f3e
MC
35 {0, NULL, NULL, 0}
36};
37
38void gost_param_free()
0e1dba93 39{
0f113f3e 40 int i;
b548a1f1
RS
41
42 for (i = 0; i <= GOST_PARAM_MAX; i++) {
43 OPENSSL_free(gost_params[i]);
44 gost_params[i] = NULL;
45 }
0f113f3e 46
0e1dba93 47}
926c41bd 48
0f113f3e
MC
49int 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)
54 return -1;
55 ret = gost_set_default_param(param, p);
56 return ret;
57}
926c41bd 58
0f113f3e
MC
59const char *get_gost_engine_param(int param)
60{
61 char *tmp;
62 if (param < 0 || param > GOST_PARAM_MAX)
63 return NULL;
64 if (gost_params[param] != NULL) {
65 return gost_params[param];
66 }
67 tmp = getenv(gost_envnames[param]);
68 if (tmp) {
b548a1f1 69 OPENSSL_free(gost_params[param]);
7644a9ae 70 gost_params[param] = OPENSSL_strdup(tmp);
0f113f3e
MC
71 return gost_params[param];
72 }
73 return NULL;
74}
926c41bd 75
0f113f3e
MC
76int gost_set_default_param(int param, const char *value)
77{
78 const char *tmp;
79 if (param < 0 || param > GOST_PARAM_MAX)
80 return 0;
81 tmp = getenv(gost_envnames[param]);
82 /*
83 * if there is value in the environment, use it, else -passed string *
84 */
85 if (!tmp)
86 tmp = value;
b548a1f1 87 OPENSSL_free(gost_params[param]);
7644a9ae 88 gost_params[param] = OPENSSL_strdup(tmp);
926c41bd 89
0f113f3e
MC
90 return 1;
91}