2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
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
12 #include <openssl/core.h>
13 #include <openssl/core_numbers.h>
14 #include <openssl/core_names.h>
15 #include <openssl/params.h>
16 #include "prov/implementations.h"
18 OSSL_provider_init_fn ossl_null_provider_init;
20 /* Functions provided by the core */
21 static OSSL_core_gettable_params_fn *c_gettable_params = NULL;
22 static OSSL_core_get_params_fn *c_get_params = NULL;
24 /* Parameters we provide to the core */
25 static const OSSL_ITEM null_param_types[] = {
26 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME },
27 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION },
28 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO },
32 static const OSSL_ITEM *null_gettable_params(const OSSL_PROVIDER *prov)
34 return null_param_types;
37 static int null_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
41 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
42 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Null Provider"))
44 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
45 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
47 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
48 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
54 static const OSSL_ALGORITHM *null_query(OSSL_PROVIDER *prov,
62 /* Functions we provide to the core */
63 static const OSSL_DISPATCH null_dispatch_table[] = {
64 { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))null_gettable_params },
65 { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))null_get_params },
66 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))null_query },
70 int ossl_null_provider_init(const OSSL_PROVIDER *provider,
71 const OSSL_DISPATCH *in,
72 const OSSL_DISPATCH **out,
75 OSSL_core_get_library_context_fn *c_get_libctx = NULL;
77 for (; in->function_id != 0; in++) {
78 switch (in->function_id) {
79 case OSSL_FUNC_CORE_GETTABLE_PARAMS:
80 c_gettable_params = OSSL_get_core_gettable_params(in);
82 case OSSL_FUNC_CORE_GET_PARAMS:
83 c_get_params = OSSL_get_core_get_params(in);
85 case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT:
86 c_get_libctx = OSSL_get_core_get_library_context(in);
88 /* Just ignore anything we don't understand */
94 if (c_get_libctx == NULL)
97 *out = null_dispatch_table;
100 * We want to make sure that all calls from this provider that requires
101 * a library context use the same context as the one used to call our
102 * functions. We do that by passing it along as the provider context.
104 *provctx = c_get_libctx(provider);