2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
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
10 #include <string.h> /* strcmp */
11 #include <openssl/dh.h>
12 #include "internal/nelem.h"
13 #include "crypto/dh.h"
15 typedef struct dh_name2id_st{
20 static const DH_GENTYPE_NAME2ID dhtype2id[]=
22 { "fips186_4", DH_PARAMGEN_TYPE_FIPS_186_4 },
23 { "fips186_2", DH_PARAMGEN_TYPE_FIPS_186_2 },
24 { "group", DH_PARAMGEN_TYPE_GROUP },
25 { "generator", DH_PARAMGEN_TYPE_GENERATOR }
28 const char *dh_gen_type_id2name(int id)
32 for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
33 if (dhtype2id[i].id == id)
34 return dhtype2id[i].name;
39 int dh_gen_type_name2id(const char *name)
43 for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
44 if (strcmp(dhtype2id[i].name, name) == 0)
45 return dhtype2id[i].id;