Path: blob/main/crypto/openssl/providers/common/provider_ctx.c
48261 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}4142void43ossl_prov_ctx_set0_core_get_params(PROV_CTX *ctx,44OSSL_FUNC_core_get_params_fn *c_get_params)45{46if (ctx != NULL)47ctx->core_get_params = c_get_params;48}4950OSSL_LIB_CTX *ossl_prov_ctx_get0_libctx(PROV_CTX *ctx)51{52if (ctx == NULL)53return NULL;54return ctx->libctx;55}5657const OSSL_CORE_HANDLE *ossl_prov_ctx_get0_handle(PROV_CTX *ctx)58{59if (ctx == NULL)60return NULL;61return ctx->handle;62}6364BIO_METHOD *ossl_prov_ctx_get0_core_bio_method(PROV_CTX *ctx)65{66if (ctx == NULL)67return NULL;68return ctx->corebiometh;69}7071OSSL_FUNC_core_get_params_fn *ossl_prov_ctx_get0_core_get_params(PROV_CTX *ctx)72{73if (ctx == NULL)74return NULL;75return ctx->core_get_params;76}7778const char *79ossl_prov_ctx_get_param(PROV_CTX *ctx, const char *name, const char *defval)80{81char *val = NULL;82OSSL_PARAM param[2] = { OSSL_PARAM_END, OSSL_PARAM_END };8384if (ctx == NULL85|| ctx->handle == NULL86|| ctx->core_get_params == NULL)87return defval;8889param[0].key = (char *) name;90param[0].data_type = OSSL_PARAM_UTF8_PTR;91param[0].data = (void *) &val;92param[0].data_size = sizeof(val);93param[0].return_size = OSSL_PARAM_UNMODIFIED;9495/* Errors are ignored, returning the default value */96if (ctx->core_get_params(ctx->handle, param)97&& OSSL_PARAM_modified(param)98&& val != NULL)99return val;100return defval;101}102103int ossl_prov_ctx_get_bool_param(PROV_CTX *ctx, const char *name, int defval)104{105const char *val = ossl_prov_ctx_get_param(ctx, name, NULL);106107if (val != NULL) {108if ((strcmp(val, "1") == 0)109|| (OPENSSL_strcasecmp(val, "yes") == 0)110|| (OPENSSL_strcasecmp(val, "true") == 0)111|| (OPENSSL_strcasecmp(val, "on") == 0))112return 1;113else if ((strcmp(val, "0") == 0)114|| (OPENSSL_strcasecmp(val, "no") == 0)115|| (OPENSSL_strcasecmp(val, "false") == 0)116|| (OPENSSL_strcasecmp(val, "off") == 0))117return 0;118}119return defval;120}121122123