2013-07-31 01:05:08 +08:00
|
|
|
/*
|
2022-05-03 18:52:38 +08:00
|
|
|
* Copyright 2013-2022 The OpenSSL Project Authors. All Rights Reserved.
|
2013-07-31 01:05:08 +08:00
|
|
|
*
|
2018-12-06 20:36:05 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 03:38:09 +08:00
|
|
|
* 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
|
2013-07-31 01:05:08 +08:00
|
|
|
*/
|
|
|
|
|
2020-02-03 17:05:31 +08:00
|
|
|
/*
|
|
|
|
* DH low level APIs are deprecated for public use, but still ok for
|
|
|
|
* internal use.
|
|
|
|
*/
|
|
|
|
#include "internal/deprecated.h"
|
|
|
|
|
2022-02-04 22:13:01 +08:00
|
|
|
#include "internal/e_os.h"
|
2020-08-04 09:21:21 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <openssl/core_names.h>
|
|
|
|
#include <openssl/dh.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/asn1.h>
|
|
|
|
#include <openssl/kdf.h>
|
2021-05-26 03:08:03 +08:00
|
|
|
#include "internal/provider.h"
|
2021-05-26 03:09:07 +08:00
|
|
|
#include "crypto/dh.h"
|
2015-08-04 00:45:26 +08:00
|
|
|
|
2020-08-04 09:21:21 +08:00
|
|
|
/* Key derivation function from X9.63/SECG */
|
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
|
|
|
int ossl_dh_kdf_X9_42_asn1(unsigned char *out, size_t outlen,
|
|
|
|
const unsigned char *Z, size_t Zlen,
|
|
|
|
const char *cek_alg,
|
|
|
|
const unsigned char *ukm, size_t ukmlen,
|
|
|
|
const EVP_MD *md,
|
|
|
|
OSSL_LIB_CTX *libctx, const char *propq)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2020-08-04 09:21:21 +08:00
|
|
|
int ret = 0;
|
2019-07-09 07:33:18 +08:00
|
|
|
EVP_KDF_CTX *kctx = NULL;
|
2019-08-21 06:06:29 +08:00
|
|
|
EVP_KDF *kdf = NULL;
|
|
|
|
OSSL_PARAM params[5], *p = params;
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
const char *mdname = EVP_MD_get0_name(md);
|
2019-07-09 07:33:18 +08:00
|
|
|
|
2020-11-16 10:42:18 +08:00
|
|
|
kdf = EVP_KDF_fetch(libctx, OSSL_KDF_NAME_X942KDF_ASN1, propq);
|
2022-04-12 16:07:17 +08:00
|
|
|
if (kdf == NULL)
|
|
|
|
return 0;
|
2020-08-04 09:21:21 +08:00
|
|
|
kctx = EVP_KDF_CTX_new(kdf);
|
|
|
|
if (kctx == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
2020-08-04 09:21:21 +08:00
|
|
|
|
2019-08-21 06:06:29 +08:00
|
|
|
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
|
2020-02-05 13:13:49 +08:00
|
|
|
(char *)mdname, 0);
|
2019-08-21 06:06:29 +08:00
|
|
|
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
|
|
|
|
(unsigned char *)Z, Zlen);
|
|
|
|
if (ukm != NULL)
|
|
|
|
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_UKM,
|
|
|
|
(unsigned char *)ukm, ukmlen);
|
|
|
|
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CEK_ALG,
|
2020-08-04 09:21:21 +08:00
|
|
|
(char *)cek_alg, 0);
|
2019-08-21 06:06:29 +08:00
|
|
|
*p = OSSL_PARAM_construct_end();
|
2021-02-26 08:08:45 +08:00
|
|
|
ret = EVP_KDF_derive(kctx, out, outlen, params) > 0;
|
2019-07-09 07:33:18 +08:00
|
|
|
err:
|
2020-06-18 16:30:48 +08:00
|
|
|
EVP_KDF_CTX_free(kctx);
|
2019-08-21 06:06:29 +08:00
|
|
|
EVP_KDF_free(kdf);
|
2019-07-09 07:33:18 +08:00
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2020-08-04 09:21:21 +08:00
|
|
|
|
2020-08-19 11:27:31 +08:00
|
|
|
#if !defined(FIPS_MODULE)
|
2020-08-04 09:21:21 +08:00
|
|
|
int DH_KDF_X9_42(unsigned char *out, size_t outlen,
|
|
|
|
const unsigned char *Z, size_t Zlen,
|
|
|
|
ASN1_OBJECT *key_oid,
|
|
|
|
const unsigned char *ukm, size_t ukmlen, const EVP_MD *md)
|
|
|
|
{
|
2021-03-10 19:58:53 +08:00
|
|
|
char key_alg[OSSL_MAX_NAME_SIZE];
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
const OSSL_PROVIDER *prov = EVP_MD_get0_provider(md);
|
2020-10-15 17:55:50 +08:00
|
|
|
OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
|
2020-08-04 09:21:21 +08:00
|
|
|
|
2021-11-10 12:39:54 +08:00
|
|
|
if (OBJ_obj2txt(key_alg, sizeof(key_alg), key_oid, 0) <= 0)
|
2020-08-04 09:21:21 +08:00
|
|
|
return 0;
|
|
|
|
|
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
|
|
|
return ossl_dh_kdf_X9_42_asn1(out, outlen, Z, Zlen, key_alg,
|
|
|
|
ukm, ukmlen, md, libctx, NULL);
|
2020-08-04 09:21:21 +08:00
|
|
|
}
|
2020-08-19 11:27:31 +08:00
|
|
|
#endif /* !defined(FIPS_MODULE) */
|