2020-12-02 02:11:59 +08:00
|
|
|
/*
|
2021-03-11 21:27:36 +08:00
|
|
|
* Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2020-12-02 02:11:59 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h> /* strcmp */
|
|
|
|
#include <openssl/dh.h>
|
|
|
|
#include "internal/nelem.h"
|
|
|
|
#include "crypto/dh.h"
|
|
|
|
|
|
|
|
typedef struct dh_name2id_st{
|
|
|
|
const char *name;
|
|
|
|
int id;
|
2021-04-15 16:25:17 +08:00
|
|
|
int type;
|
2020-12-02 02:11:59 +08:00
|
|
|
} DH_GENTYPE_NAME2ID;
|
|
|
|
|
2021-04-15 16:25:17 +08:00
|
|
|
/* Indicates that the paramgen_type can be used for either DH or DHX */
|
|
|
|
#define TYPE_ANY -1
|
|
|
|
#ifndef OPENSSL_NO_DH
|
|
|
|
# define TYPE_DH DH_FLAG_TYPE_DH
|
|
|
|
# define TYPE_DHX DH_FLAG_TYPE_DHX
|
|
|
|
#else
|
|
|
|
# define TYPE_DH 0
|
|
|
|
# define TYPE_DHX 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const DH_GENTYPE_NAME2ID dhtype2id[] =
|
2020-12-02 02:11:59 +08:00
|
|
|
{
|
2021-04-15 16:25:17 +08:00
|
|
|
{ "group", DH_PARAMGEN_TYPE_GROUP, TYPE_ANY },
|
|
|
|
{ "generator", DH_PARAMGEN_TYPE_GENERATOR, TYPE_DH },
|
|
|
|
{ "fips186_4", DH_PARAMGEN_TYPE_FIPS_186_4, TYPE_DHX },
|
|
|
|
{ "fips186_2", DH_PARAMGEN_TYPE_FIPS_186_2, TYPE_DHX },
|
2020-12-02 02:11:59 +08:00
|
|
|
};
|
|
|
|
|
Fix external symbols related to dh keys
Partial fix for #12964
This adds ossl_ names for the following symbols:
dh_new_by_nid_ex, dh_new_ex, dh_generate_ffc_parameters, dh_generate_public_key,
dh_get_named_group_uid_from_size, dh_gen_type_id2name, dh_gen_type_name2id,
dh_cache_named_group, dh_get0_params, dh_get0_nid,
dh_params_fromdata, dh_key_fromdata, dh_params_todata, dh_key_todata,
dh_check_pub_key_partial, dh_check_priv_key, dh_check_pairwise,
dh_get_method, dh_buf2key, dh_key2buf, dh_KDF_X9_42_asn1,
dh_pkey_method, dhx_pkey_method
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14231)
2021-02-18 13:56:53 +08:00
|
|
|
const char *ossl_dh_gen_type_id2name(int id)
|
2020-12-02 02:11:59 +08:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
|
|
|
|
if (dhtype2id[i].id == id)
|
|
|
|
return dhtype2id[i].name;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-15 16:25:17 +08:00
|
|
|
#ifndef OPENSSL_NO_DH
|
|
|
|
int ossl_dh_gen_type_name2id(const char *name, int type)
|
2020-12-02 02:11:59 +08:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < OSSL_NELEM(dhtype2id); ++i) {
|
2021-04-15 16:25:17 +08:00
|
|
|
if ((dhtype2id[i].type == TYPE_ANY
|
|
|
|
|| type == dhtype2id[i].type)
|
|
|
|
&& strcmp(dhtype2id[i].name, name) == 0)
|
2020-12-02 02:11:59 +08:00
|
|
|
return dhtype2id[i].id;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2021-04-15 16:25:17 +08:00
|
|
|
#endif
|