]>
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> |
7707526b | 11 | #include <openssl/core_names.h> |
768c53e1 | 12 | #include <openssl/ec.h> |
25af7a5d | 13 | #include <openssl/evp.h> |
8bbeaaa4 | 14 | #include <openssl/kdf.h> |
706457b7 | 15 | #include "ec_local.h" |
25af7a5d | 16 | |
ffd89124 | 17 | /* Key derivation function from X9.63/SECG */ |
ffd89124 | 18 | int ecdh_KDF_X9_63(unsigned char *out, size_t outlen, |
0f113f3e MC |
19 | const unsigned char *Z, size_t Zlen, |
20 | const unsigned char *sinfo, size_t sinfolen, | |
21 | const EVP_MD *md) | |
22 | { | |
7707526b | 23 | int ret = 0; |
8bbeaaa4 | 24 | EVP_KDF_CTX *kctx = NULL; |
7707526b P |
25 | OSSL_PARAM params[4], *p = params; |
26 | const char *mdname = EVP_MD_name(md); | |
64115f05 | 27 | EVP_KDF *kdf = EVP_KDF_fetch(NULL, OSSL_KDF_NAME_X963KDF, NULL); |
8bbeaaa4 | 28 | |
7707526b P |
29 | if ((kctx = EVP_KDF_CTX_new(kdf)) != NULL) { |
30 | *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, | |
31 | (char *)mdname, | |
32 | strlen(mdname) + 1); | |
33 | *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, | |
34 | (void *)Z, Zlen); | |
35 | *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, | |
36 | (void *)sinfo, sinfolen); | |
37 | *p = OSSL_PARAM_construct_end(); | |
8bbeaaa4 | 38 | |
7707526b P |
39 | ret = EVP_KDF_CTX_set_params(kctx, params) > 0 |
40 | && EVP_KDF_derive(kctx, out, outlen) > 0; | |
41 | EVP_KDF_CTX_free(kctx); | |
42 | } | |
43 | EVP_KDF_free(kdf); | |
8bbeaaa4 | 44 | return ret; |
0f113f3e | 45 | } |
ffd89124 AS |
46 | |
47 | /*- | |
48 | * The old name for ecdh_KDF_X9_63 | |
49 | * Retained for ABI compatibility | |
50 | */ | |
936c2b9e | 51 | #ifndef OPENSSL_NO_DEPRECATED_3_0 |
ffd89124 AS |
52 | int ECDH_KDF_X9_62(unsigned char *out, size_t outlen, |
53 | const unsigned char *Z, size_t Zlen, | |
54 | const unsigned char *sinfo, size_t sinfolen, | |
55 | const EVP_MD *md) | |
56 | { | |
57 | return ecdh_KDF_X9_63(out, outlen, Z, Zlen, sinfo, sinfolen, md); | |
58 | } | |
9453b196 | 59 | #endif |