/src/openssl30/crypto/dh/dh_kdf.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 2013-2022 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 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 | 
| 8 |  |  */ | 
| 9 |  |  | 
| 10 |  | /* | 
| 11 |  |  * DH low level APIs are deprecated for public use, but still ok for | 
| 12 |  |  * internal use. | 
| 13 |  |  */ | 
| 14 |  | #include "internal/deprecated.h" | 
| 15 |  |  | 
| 16 |  | #include "e_os.h" | 
| 17 |  | #include "e_os.h" | 
| 18 |  | #include <string.h> | 
| 19 |  | #include <openssl/core_names.h> | 
| 20 |  | #include <openssl/dh.h> | 
| 21 |  | #include <openssl/evp.h> | 
| 22 |  | #include <openssl/asn1.h> | 
| 23 |  | #include <openssl/kdf.h> | 
| 24 |  | #include "internal/provider.h" | 
| 25 |  | #include "crypto/dh.h" | 
| 26 |  |  | 
| 27 |  | /* Key derivation function from X9.63/SECG */ | 
| 28 |  | int ossl_dh_kdf_X9_42_asn1(unsigned char *out, size_t outlen, | 
| 29 |  |                            const unsigned char *Z, size_t Zlen, | 
| 30 |  |                            const char *cek_alg, | 
| 31 |  |                            const unsigned char *ukm, size_t ukmlen, | 
| 32 |  |                            const EVP_MD *md, | 
| 33 |  |                            OSSL_LIB_CTX *libctx, const char *propq) | 
| 34 | 0 | { | 
| 35 | 0 |     int ret = 0; | 
| 36 | 0 |     EVP_KDF_CTX *kctx = NULL; | 
| 37 | 0 |     EVP_KDF *kdf = NULL; | 
| 38 | 0 |     OSSL_PARAM params[5], *p = params; | 
| 39 | 0 |     const char *mdname = EVP_MD_get0_name(md); | 
| 40 |  | 
 | 
| 41 | 0 |     kdf = EVP_KDF_fetch(libctx, OSSL_KDF_NAME_X942KDF_ASN1, propq); | 
| 42 | 0 |     if (kdf == NULL) | 
| 43 | 0 |         return 0; | 
| 44 | 0 |     kctx = EVP_KDF_CTX_new(kdf); | 
| 45 | 0 |     if (kctx == NULL) | 
| 46 | 0 |         goto err; | 
| 47 |  |  | 
| 48 | 0 |     *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, | 
| 49 | 0 |                                             (char *)mdname, 0); | 
| 50 | 0 |     *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, | 
| 51 | 0 |                                              (unsigned char *)Z, Zlen); | 
| 52 | 0 |     if (ukm != NULL) | 
| 53 | 0 |         *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_UKM, | 
| 54 | 0 |                                                  (unsigned char *)ukm, ukmlen); | 
| 55 | 0 |     *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CEK_ALG, | 
| 56 | 0 |                                             (char *)cek_alg, 0); | 
| 57 | 0 |     *p = OSSL_PARAM_construct_end(); | 
| 58 | 0 |     ret = EVP_KDF_derive(kctx, out, outlen, params) > 0; | 
| 59 | 0 | err: | 
| 60 | 0 |     EVP_KDF_CTX_free(kctx); | 
| 61 | 0 |     EVP_KDF_free(kdf); | 
| 62 | 0 |     return ret; | 
| 63 | 0 | } | 
| 64 |  |  | 
| 65 |  | #if !defined(FIPS_MODULE) | 
| 66 |  | int DH_KDF_X9_42(unsigned char *out, size_t outlen, | 
| 67 |  |                  const unsigned char *Z, size_t Zlen, | 
| 68 |  |                  ASN1_OBJECT *key_oid, | 
| 69 |  |                  const unsigned char *ukm, size_t ukmlen, const EVP_MD *md) | 
| 70 | 0 | { | 
| 71 | 0 |     char key_alg[OSSL_MAX_NAME_SIZE]; | 
| 72 | 0 |     const OSSL_PROVIDER *prov = EVP_MD_get0_provider(md); | 
| 73 | 0 |     OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov); | 
| 74 |  | 
 | 
| 75 | 0 |     if (OBJ_obj2txt(key_alg, sizeof(key_alg), key_oid, 0) <= 0) | 
| 76 | 0 |         return 0; | 
| 77 |  |  | 
| 78 | 0 |     return ossl_dh_kdf_X9_42_asn1(out, outlen, Z, Zlen, key_alg, | 
| 79 | 0 |                                   ukm, ukmlen, md, libctx, NULL); | 
| 80 | 0 | } | 
| 81 |  | #endif /* !defined(FIPS_MODULE) */ |