Coverage Report

Created: 2022-11-30 06:20

/src/openssl/engines/ccgost/gost_ctl.c
Line
Count
Source (jump to first uncovered line)
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" };
19
20
const ENGINE_CMD_DEFN gost_cmds[] = {
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
    },
31
*/ {GOST_CTRL_CRYPT_PARAMS,
32
           "CRYPT_PARAMS",
33
           "OID of default GOST 28147-89 parameters",
34
           ENGINE_CMD_FLAG_STRING},
35
    {0, NULL, NULL, 0}
36
};
37
38
void gost_param_free()
39
0
{
40
0
    int i;
41
0
    for (i = 0; i <= GOST_PARAM_MAX; i++)
42
0
        if (gost_params[i] != NULL) {
43
0
            OPENSSL_free(gost_params[i]);
44
0
            gost_params[i] = NULL;
45
0
        }
46
47
0
}
48
49
int gost_control_func(ENGINE *e, int cmd, long i, void *p, void (*f) (void))
50
0
{
51
0
    int param = cmd - ENGINE_CMD_BASE;
52
0
    int ret = 0;
53
0
    if (param < 0 || param > GOST_PARAM_MAX)
54
0
        return -1;
55
0
    ret = gost_set_default_param(param, p);
56
0
    return ret;
57
0
}
58
59
const char *get_gost_engine_param(int param)
60
0
{
61
0
    char *tmp;
62
0
    if (param < 0 || param > GOST_PARAM_MAX)
63
0
        return NULL;
64
0
    if (gost_params[param] != NULL) {
65
0
        return gost_params[param];
66
0
    }
67
0
    tmp = getenv(gost_envnames[param]);
68
0
    if (tmp) {
69
0
        if (gost_params[param])
70
0
            OPENSSL_free(gost_params[param]);
71
0
        gost_params[param] = BUF_strdup(tmp);
72
0
        return gost_params[param];
73
0
    }
74
0
    return NULL;
75
0
}
76
77
int gost_set_default_param(int param, const char *value)
78
0
{
79
0
    const char *tmp;
80
0
    if (param < 0 || param > GOST_PARAM_MAX)
81
0
        return 0;
82
0
    tmp = getenv(gost_envnames[param]);
83
    /*
84
     * if there is value in the environment, use it, else -passed string *
85
     */
86
0
    if (!tmp)
87
0
        tmp = value;
88
0
    if (gost_params[param])
89
0
        OPENSSL_free(gost_params[param]);
90
0
    gost_params[param] = BUF_strdup(tmp);
91
92
0
    return 1;
93
0
}