Path: blob/main/crypto/openssl/providers/implementations/keymgmt/kdf_legacy_kmgmt.c
48292 views
/*1* Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89/*10* This implemments a dummy key manager for legacy KDFs that still support the11* old way of performing a KDF via EVP_PKEY_derive(). New KDFs should not be12* implemented this way. In reality there is no key data for such KDFs, so this13* key manager does very little.14*/1516#include <openssl/core_dispatch.h>17#include <openssl/core_names.h>18#include <openssl/err.h>19#include "prov/implementations.h"20#include "prov/providercommon.h"21#include "prov/provider_ctx.h"22#include "prov/kdfexchange.h"2324static OSSL_FUNC_keymgmt_new_fn kdf_newdata;25static OSSL_FUNC_keymgmt_free_fn kdf_freedata;26static OSSL_FUNC_keymgmt_has_fn kdf_has;2728KDF_DATA *ossl_kdf_data_new(void *provctx)29{30KDF_DATA *kdfdata;3132if (!ossl_prov_is_running())33return NULL;3435kdfdata = OPENSSL_zalloc(sizeof(*kdfdata));36if (kdfdata == NULL)37return NULL;3839if (!CRYPTO_NEW_REF(&kdfdata->refcnt, 1)) {40OPENSSL_free(kdfdata);41return NULL;42}43kdfdata->libctx = PROV_LIBCTX_OF(provctx);4445return kdfdata;46}4748void ossl_kdf_data_free(KDF_DATA *kdfdata)49{50int ref = 0;5152if (kdfdata == NULL)53return;5455CRYPTO_DOWN_REF(&kdfdata->refcnt, &ref);56if (ref > 0)57return;5859CRYPTO_FREE_REF(&kdfdata->refcnt);60OPENSSL_free(kdfdata);61}6263int ossl_kdf_data_up_ref(KDF_DATA *kdfdata)64{65int ref = 0;6667/* This is effectively doing a new operation on the KDF_DATA and should be68* adequately guarded again modules' error states. However, both current69* calls here are guarded properly in exchange/kdf_exch.c. Thus, it70* could be removed here. The concern is that something in the future71* might call this function without adequate guards. It's a cheap call,72* it seems best to leave it even though it is currently redundant.73*/74if (!ossl_prov_is_running())75return 0;7677CRYPTO_UP_REF(&kdfdata->refcnt, &ref);78return 1;79}8081static void *kdf_newdata(void *provctx)82{83return ossl_kdf_data_new(provctx);84}8586static void kdf_freedata(void *kdfdata)87{88ossl_kdf_data_free(kdfdata);89}9091static int kdf_has(const void *keydata, int selection)92{93return 1; /* nothing is missing */94}9596const OSSL_DISPATCH ossl_kdf_keymgmt_functions[] = {97{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))kdf_newdata },98{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))kdf_freedata },99{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))kdf_has },100OSSL_DISPATCH_END101};102103104