2 * Copyright 2013-2019 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
12 #ifndef OPENSSL_NO_CMS
14 # include <openssl/dh.h>
15 # include <openssl/evp.h>
16 # include <openssl/asn1.h>
17 # include <openssl/kdf.h>
19 int DH_KDF_X9_42(unsigned char *out, size_t outlen,
20 const unsigned char *Z, size_t Zlen,
22 const unsigned char *ukm, size_t ukmlen, const EVP_MD *md)
25 EVP_KDF_CTX *kctx = NULL;
26 const EVP_KDF *kdf = NULL;
29 nid = OBJ_obj2nid(key_oid);
32 oid_sn = OBJ_nid2sn(nid);
36 kdf = EVP_get_kdfbyname(SN_x942kdf);
39 kctx = EVP_KDF_CTX_new(kdf);
42 && EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) > 0
43 && EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, Z, Zlen) > 0
45 || EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_UKM, ukm, ukmlen) > 0)
46 && EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_CEK_ALG, oid_sn) > 0
47 && EVP_KDF_derive(kctx, out, outlen) > 0;
49 EVP_KDF_CTX_free(kctx);
52 #endif /* OPENSSL_NO_CMS */