2013-07-17 22:01:08 +08:00
|
|
|
/*
|
2019-05-16 09:43:41 +08:00
|
|
|
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
2013-07-17 22:01:08 +08:00
|
|
|
*
|
2018-12-06 20:38:06 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:04 +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-17 22:01:08 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2015-10-22 22:47:38 +08:00
|
|
|
#include <openssl/ec.h>
|
2013-07-17 22:01:08 +08:00
|
|
|
#include <openssl/evp.h>
|
2019-05-16 09:43:41 +08:00
|
|
|
#include <openssl/kdf.h>
|
2018-10-02 05:11:57 +08:00
|
|
|
#include "ec_lcl.h"
|
2013-07-17 22:01:08 +08:00
|
|
|
|
2018-10-02 05:11:57 +08:00
|
|
|
/* Key derivation function from X9.63/SECG */
|
|
|
|
int ecdh_KDF_X9_63(unsigned char *out, size_t outlen,
|
2015-01-22 11:40:55 +08:00
|
|
|
const unsigned char *Z, size_t Zlen,
|
|
|
|
const unsigned char *sinfo, size_t sinfolen,
|
|
|
|
const EVP_MD *md)
|
|
|
|
{
|
2019-05-16 09:43:41 +08:00
|
|
|
int ret;
|
|
|
|
EVP_KDF_CTX *kctx = NULL;
|
|
|
|
|
|
|
|
kctx = EVP_KDF_CTX_new(EVP_get_kdfbyname(SN_x963kdf));
|
|
|
|
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
|
|
|
|
&& EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SHARED_INFO, sinfo, sinfolen) > 0
|
|
|
|
&& EVP_KDF_derive(kctx, out, outlen) > 0;
|
|
|
|
|
|
|
|
EVP_KDF_CTX_free(kctx);
|
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2018-10-02 05:11:57 +08:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* The old name for ecdh_KDF_X9_63
|
|
|
|
* Retained for ABI compatibility
|
|
|
|
*/
|
2018-11-30 07:05:03 +08:00
|
|
|
#if !OPENSSL_API_3
|
2018-10-02 05:11:57 +08:00
|
|
|
int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
|
|
|
|
const unsigned char *Z, size_t Zlen,
|
|
|
|
const unsigned char *sinfo, size_t sinfolen,
|
|
|
|
const EVP_MD *md)
|
|
|
|
{
|
|
|
|
return ecdh_KDF_X9_63(out, outlen, Z, Zlen, sinfo, sinfolen, md);
|
|
|
|
}
|
2018-10-17 01:54:26 +08:00
|
|
|
#endif
|