]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/evp/dh_support.c
EVP_PKEY & DH: Make DH EVP_PKEY_CTX parameter ctrls / setters more available
[thirdparty/openssl.git] / crypto / evp / dh_support.c
1 /*
2 * Copyright 2020 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 } DH_GENTYPE_NAME2ID;
19
20 static const DH_GENTYPE_NAME2ID dhtype2id[]=
21 {
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 }
26 };
27
28 const char *dh_gen_type_id2name(int id)
29 {
30 size_t i;
31
32 for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
33 if (dhtype2id[i].id == id)
34 return dhtype2id[i].name;
35 }
36 return NULL;
37 }
38
39 int dh_gen_type_name2id(const char *name)
40 {
41 size_t i;
42
43 for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
44 if (strcmp(dhtype2id[i].name, name) == 0)
45 return dhtype2id[i].id;
46 }
47 return -1;
48 }