2013-07-30 17:05:08 +00:00
|
|
|
/*
|
2019-07-08 23:33:18 +00:00
|
|
|
* Copyright 2013-2019 The OpenSSL Project Authors. All Rights Reserved.
|
2013-07-30 17:05:08 +00:00
|
|
|
*
|
2018-12-06 12:36:05 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 19:38:09 +00: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-30 17:05:08 +00:00
|
|
|
*/
|
|
|
|
|
2017-08-22 15:07:56 +00:00
|
|
|
#include "e_os.h"
|
2015-08-03 16:45:26 +00:00
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_CMS
|
2019-07-08 23:33:18 +00:00
|
|
|
# include <string.h>
|
|
|
|
# include <openssl/dh.h>
|
|
|
|
# include <openssl/evp.h>
|
|
|
|
# include <openssl/asn1.h>
|
|
|
|
# include <openssl/kdf.h>
|
2013-07-30 17:05:08 +00:00
|
|
|
|
2015-01-22 03:40:55 +00: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)
|
|
|
|
{
|
2019-07-08 23:33:18 +00:00
|
|
|
int ret = 0, nid;
|
|
|
|
EVP_KDF_CTX *kctx = NULL;
|
|
|
|
const EVP_KDF *kdf = NULL;
|
|
|
|
const char *oid_sn;
|
|
|
|
|
|
|
|
nid = OBJ_obj2nid(key_oid);
|
|
|
|
if (nid == NID_undef)
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
2019-07-08 23:33:18 +00:00
|
|
|
oid_sn = OBJ_nid2sn(nid);
|
|
|
|
if (oid_sn == NULL)
|
2015-11-27 13:02:12 +00:00
|
|
|
return 0;
|
2019-07-08 23:33:18 +00:00
|
|
|
|
|
|
|
kdf = EVP_get_kdfbyname(SN_x942kdf);
|
|
|
|
if (kdf == NULL)
|
2015-01-22 03:40:55 +00:00
|
|
|
goto err;
|
2019-07-08 23:33:18 +00:00
|
|
|
kctx = EVP_KDF_CTX_new(kdf);
|
|
|
|
ret =
|
|
|
|
kctx != NULL
|
|
|
|
&& EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) > 0
|
|
|
|
&& EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, Z, Zlen) > 0
|
|
|
|
&& (ukm == NULL
|
|
|
|
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_UKM, ukm, ukmlen) > 0)
|
|
|
|
&& EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_CEK_ALG, oid_sn) > 0
|
|
|
|
&& EVP_KDF_derive(kctx, out, outlen) > 0;
|
|
|
|
err:
|
|
|
|
EVP_KDF_CTX_free(kctx);
|
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2019-07-08 23:33:18 +00:00
|
|
|
#endif /* OPENSSL_NO_CMS */
|