Coverage Report

Created: 2025-06-13 06:55

/src/openssl/crypto/evp/dh_support.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2020-2024 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
    { "group", DH_PARAMGEN_TYPE_GROUP, TYPE_ANY },
33
    { "generator", DH_PARAMGEN_TYPE_GENERATOR, TYPE_DH },
34
    { "fips186_4", DH_PARAMGEN_TYPE_FIPS_186_4, TYPE_DHX },
35
    { "fips186_2", DH_PARAMGEN_TYPE_FIPS_186_2, TYPE_DHX },
36
};
37
38
const char *ossl_dh_gen_type_id2name(int id)
39
0
{
40
0
    size_t i;
41
42
0
    for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
43
0
        if (dhtype2id[i].id == id)
44
0
            return dhtype2id[i].name;
45
0
    }
46
0
    return NULL;
47
0
}
48
49
#ifndef OPENSSL_NO_DH
50
int ossl_dh_gen_type_name2id(const char *name, int type)
51
0
{
52
0
    size_t i;
53
54
0
    for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
55
0
        if ((dhtype2id[i].type == TYPE_ANY
56
0
             || type == dhtype2id[i].type)
57
0
            && strcmp(dhtype2id[i].name, name) == 0)
58
0
            return dhtype2id[i].id;
59
0
    }
60
0
    return -1;
61
0
}
62
#endif