2 * Copyright 2013-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
11 * DH low level APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
18 #ifndef OPENSSL_NO_CMS
20 # include <openssl/core_names.h>
21 # include <openssl/dh.h>
22 # include <openssl/evp.h>
23 # include <openssl/asn1.h>
24 # include <openssl/kdf.h>
25 # include <internal/provider.h>
27 int DH_KDF_X9_42(unsigned char *out, size_t outlen,
28 const unsigned char *Z, size_t Zlen,
30 const unsigned char *ukm, size_t ukmlen, const EVP_MD *md)
33 EVP_KDF_CTX *kctx = NULL;
36 OSSL_PARAM params[5], *p = params;
37 const char *mdname = EVP_MD_name(md);
38 const OSSL_PROVIDER *prov = EVP_MD_provider(md);
39 OPENSSL_CTX *provctx = ossl_provider_library_context(prov);
41 nid = OBJ_obj2nid(key_oid);
44 oid_sn = OBJ_nid2sn(nid);
48 kdf = EVP_KDF_fetch(provctx, OSSL_KDF_NAME_X942KDF, NULL);
49 if ((kctx = EVP_KDF_CTX_new(kdf)) == NULL)
51 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
53 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
54 (unsigned char *)Z, Zlen);
56 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_UKM,
57 (unsigned char *)ukm, ukmlen);
58 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CEK_ALG,
60 *p = OSSL_PARAM_construct_end();
61 ret = EVP_KDF_CTX_set_params(kctx, params) > 0
62 && EVP_KDF_derive(kctx, out, outlen) > 0;
64 EVP_KDF_CTX_free(kctx);
68 #endif /* OPENSSL_NO_CMS */