]>
Commit | Line | Data |
---|---|---|
25af7a5d | 1 | /* |
8bbeaaa4 | 2 | * Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved. |
25af7a5d | 3 | * |
a7f182b7 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
4f22f405 RS |
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 | |
25af7a5d DSH |
8 | */ |
9 | ||
25af7a5d | 10 | #include <string.h> |
768c53e1 | 11 | #include <openssl/ec.h> |
25af7a5d | 12 | #include <openssl/evp.h> |
8bbeaaa4 | 13 | #include <openssl/kdf.h> |
ffd89124 | 14 | #include "ec_lcl.h" |
25af7a5d | 15 | |
ffd89124 | 16 | /* Key derivation function from X9.63/SECG */ |
ffd89124 | 17 | int ecdh_KDF_X9_63(unsigned char *out, size_t outlen, |
0f113f3e MC |
18 | const unsigned char *Z, size_t Zlen, |
19 | const unsigned char *sinfo, size_t sinfolen, | |
20 | const EVP_MD *md) | |
21 | { | |
8bbeaaa4 SL |
22 | int ret; |
23 | EVP_KDF_CTX *kctx = NULL; | |
24 | ||
25 | kctx = EVP_KDF_CTX_new(EVP_get_kdfbyname(SN_x963kdf)); | |
26 | ret = | |
27 | kctx != NULL | |
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; | |
32 | ||
33 | EVP_KDF_CTX_free(kctx); | |
34 | return ret; | |
0f113f3e | 35 | } |
ffd89124 AS |
36 | |
37 | /*- | |
38 | * The old name for ecdh_KDF_X9_63 | |
39 | * Retained for ABI compatibility | |
40 | */ | |
fcd2d5a6 | 41 | #if !OPENSSL_API_3 |
ffd89124 AS |
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, | |
45 | const EVP_MD *md) | |
46 | { | |
47 | return ecdh_KDF_X9_63(out, outlen, Z, Zlen, sinfo, sinfolen, md); | |
48 | } | |
9453b196 | 49 | #endif |