Coverage Report

Created: 2025-06-13 06:58

/src/openssl31/crypto/evp/dh_support.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <string.h> /* strcmp */
11
#include <openssl/dh.h>
12
#include "internal/nelem.h"
13
#include "crypto/dh.h"
14
15
typedef struct dh_name2id_st{
16
    const char *name;
17
    int id;
18
    int type;
19
} DH_GENTYPE_NAME2ID;
20
21
/* Indicates that the paramgen_type can be used for either DH or DHX */
22
0
#define TYPE_ANY -1
23
#ifndef OPENSSL_NO_DH
24
# define TYPE_DH    DH_FLAG_TYPE_DH
25
# define TYPE_DHX   DH_FLAG_TYPE_DHX
26
#else
27
# define TYPE_DH    0
28
# define TYPE_DHX   0
29
#endif
30
31
static const DH_GENTYPE_NAME2ID dhtype2id[] =
32
{
33
    { "group", DH_PARAMGEN_TYPE_GROUP, TYPE_ANY },
34
    { "generator", DH_PARAMGEN_TYPE_GENERATOR, TYPE_DH },
35
    { "fips186_4", DH_PARAMGEN_TYPE_FIPS_186_4, TYPE_DHX },
36
    { "fips186_2", DH_PARAMGEN_TYPE_FIPS_186_2, TYPE_DHX },
37
};
38
39
const char *ossl_dh_gen_type_id2name(int id)
40
0
{
41
0
    size_t i;
42
43
0
    for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
44
0
        if (dhtype2id[i].id == id)
45
0
            return dhtype2id[i].name;
46
0
    }
47
0
    return NULL;
48
0
}
49
50
#ifndef OPENSSL_NO_DH
51
int ossl_dh_gen_type_name2id(const char *name, int type)
52
0
{
53
0
    size_t i;
54
55
0
    for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
56
0
        if ((dhtype2id[i].type == TYPE_ANY
57
0
             || type == dhtype2id[i].type)
58
0
            && strcmp(dhtype2id[i].name, name) == 0)
59
0
            return dhtype2id[i].id;
60
0
    }
61
0
    return -1;
62
0
}
63
#endif