Path: blob/main/crypto/openssl/providers/common/provider_ctx.c
107434 views
/*1* Copyright 2020-2025 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#include <stdlib.h>10#include <string.h>11#include "prov/provider_ctx.h"12#include "prov/bio.h"1314PROV_CTX *ossl_prov_ctx_new(void)15{16return OPENSSL_zalloc(sizeof(PROV_CTX));17}1819void ossl_prov_ctx_free(PROV_CTX *ctx)20{21OPENSSL_free(ctx);22}2324void ossl_prov_ctx_set0_libctx(PROV_CTX *ctx, OSSL_LIB_CTX *libctx)25{26if (ctx != NULL)27ctx->libctx = libctx;28}2930void ossl_prov_ctx_set0_handle(PROV_CTX *ctx, const OSSL_CORE_HANDLE *handle)31{32if (ctx != NULL)33ctx->handle = handle;34}3536void ossl_prov_ctx_set0_core_bio_method(PROV_CTX *ctx, BIO_METHOD *corebiometh)37{38if (ctx != NULL)39ctx->corebiometh = corebiometh;40}4142void ossl_prov_ctx_set0_core_get_params(PROV_CTX *ctx,43OSSL_FUNC_core_get_params_fn *c_get_params)44{45if (ctx != NULL)46ctx->core_get_params = c_get_params;47}4849OSSL_LIB_CTX *ossl_prov_ctx_get0_libctx(PROV_CTX *ctx)50{51if (ctx == NULL)52return NULL;53return ctx->libctx;54}5556const OSSL_CORE_HANDLE *ossl_prov_ctx_get0_handle(PROV_CTX *ctx)57{58if (ctx == NULL)59return NULL;60return ctx->handle;61}6263BIO_METHOD *ossl_prov_ctx_get0_core_bio_method(PROV_CTX *ctx)64{65if (ctx == NULL)66return NULL;67return ctx->corebiometh;68}6970OSSL_FUNC_core_get_params_fn *ossl_prov_ctx_get0_core_get_params(PROV_CTX *ctx)71{72if (ctx == NULL)73return NULL;74return ctx->core_get_params;75}7677const char *78ossl_prov_ctx_get_param(PROV_CTX *ctx, const char *name, const char *defval)79{80char *val = NULL;81OSSL_PARAM param[2] = { OSSL_PARAM_END, OSSL_PARAM_END };8283if (ctx == NULL84|| ctx->handle == NULL85|| ctx->core_get_params == NULL)86return defval;8788param[0].key = (char *)name;89param[0].data_type = OSSL_PARAM_UTF8_PTR;90param[0].data = (void *)&val;91param[0].data_size = sizeof(val);92param[0].return_size = OSSL_PARAM_UNMODIFIED;9394/* Errors are ignored, returning the default value */95if (ctx->core_get_params(ctx->handle, param)96&& OSSL_PARAM_modified(param)97&& val != NULL)98return val;99return defval;100}101102int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval)103{104const char *val = ossl_prov_ctx_get_param(ctx, name, NULL);105106if (val != NULL) {107if ((strcmp(val, "1") == 0)108|| (OPENSSL_strcasecmp(val, "yes") == 0)109|| (OPENSSL_strcasecmp(val, "true") == 0)110|| (OPENSSL_strcasecmp(val, "on") == 0))111return 1;112else if ((strcmp(val, "0") == 0)113|| (OPENSSL_strcasecmp(val, "no") == 0)114|| (OPENSSL_strcasecmp(val, "false") == 0)115|| (OPENSSL_strcasecmp(val, "off") == 0))116return 0;117}118return defval;119}120121122