2013-07-31 01:05:08 +08:00
|
|
|
/*
|
2019-07-09 07:33:18 +08:00
|
|
|
* Copyright 2013-2019 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
|
|
|
*/
|
|
|
|
|
2017-08-22 23:07:56 +08:00
|
|
|
#include "e_os.h"
|
2015-08-04 00:45:26 +08:00
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_CMS
|
2019-07-09 07:33:18 +08:00
|
|
|
# include <string.h>
|
|
|
|
# include <openssl/dh.h>
|
|
|
|
# include <openssl/evp.h>
|
|
|
|
# include <openssl/asn1.h>
|
|
|
|
# include <openssl/kdf.h>
|
2013-07-31 01:05:08 +08:00
|
|
|
|
2015-01-22 11:40:55 +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)
|
|
|
|
{
|
2019-07-09 07:33:18 +08: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 11:40:55 +08:00
|
|
|
return 0;
|
2019-07-09 07:33:18 +08:00
|
|
|
oid_sn = OBJ_nid2sn(nid);
|
|
|
|
if (oid_sn == NULL)
|
2015-11-27 21:02:12 +08:00
|
|
|
return 0;
|
2019-07-09 07:33:18 +08:00
|
|
|
|
|
|
|
kdf = EVP_get_kdfbyname(SN_x942kdf);
|
|
|
|
if (kdf == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
2019-07-09 07:33:18 +08: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 11:40:55 +08:00
|
|
|
}
|
2019-07-09 07:33:18 +08:00
|
|
|
#endif /* OPENSSL_NO_CMS */
|