2 * Copyright 2015-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
11 #include <openssl/ec.h>
12 #include <openssl/evp.h>
13 #include <openssl/kdf.h>
16 /* Key derivation function from X9.63/SECG */
17 int ecdh_KDF_X9_63(unsigned char *out, size_t outlen,
18 const unsigned char *Z, size_t Zlen,
19 const unsigned char *sinfo, size_t sinfolen,
23 EVP_KDF_CTX *kctx = NULL;
25 kctx = EVP_KDF_CTX_new(EVP_get_kdfbyname(SN_x963kdf));
28 && EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) > 0
29 && EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, Z, Zlen) > 0
30 && EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SHARED_INFO, sinfo, sinfolen) > 0
31 && EVP_KDF_derive(kctx, out, outlen) > 0;
33 EVP_KDF_CTX_free(kctx);
38 * The old name for ecdh_KDF_X9_63
39 * Retained for ABI compatibility
42 int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
43 const unsigned char *Z, size_t Zlen,
44 const unsigned char *sinfo, size_t sinfolen,
47 return ecdh_KDF_X9_63(out, outlen, Z, Zlen, sinfo, sinfolen, md);