1*b0d17251Schristos /*
2*b0d17251Schristos * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3*b0d17251Schristos *
4*b0d17251Schristos * Licensed under the Apache License 2.0 (the "License"). You may not use
5*b0d17251Schristos * this file except in compliance with the License. You can obtain a copy
6*b0d17251Schristos * in the file LICENSE in the source distribution or at
7*b0d17251Schristos * https://www.openssl.org/source/license.html
8*b0d17251Schristos */
9*b0d17251Schristos
10*b0d17251Schristos #include <string.h>
11*b0d17251Schristos #include <stdio.h>
12*b0d17251Schristos #include <openssl/core.h>
13*b0d17251Schristos #include <openssl/core_dispatch.h>
14*b0d17251Schristos #include <openssl/core_names.h>
15*b0d17251Schristos #include <openssl/params.h>
16*b0d17251Schristos #include "prov/implementations.h"
17*b0d17251Schristos #include "prov/providercommon.h"
18*b0d17251Schristos
19*b0d17251Schristos OSSL_provider_init_fn ossl_null_provider_init;
20*b0d17251Schristos
21*b0d17251Schristos /* Parameters we provide to the core */
22*b0d17251Schristos static const OSSL_PARAM null_param_types[] = {
23*b0d17251Schristos OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
24*b0d17251Schristos OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
25*b0d17251Schristos OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
26*b0d17251Schristos OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
27*b0d17251Schristos OSSL_PARAM_END
28*b0d17251Schristos };
29*b0d17251Schristos
null_gettable_params(const OSSL_PROVIDER * prov)30*b0d17251Schristos static const OSSL_PARAM *null_gettable_params(const OSSL_PROVIDER *prov)
31*b0d17251Schristos {
32*b0d17251Schristos return null_param_types;
33*b0d17251Schristos }
34*b0d17251Schristos
null_get_params(const OSSL_PROVIDER * provctx,OSSL_PARAM params[])35*b0d17251Schristos static int null_get_params(const OSSL_PROVIDER *provctx, OSSL_PARAM params[])
36*b0d17251Schristos {
37*b0d17251Schristos OSSL_PARAM *p;
38*b0d17251Schristos
39*b0d17251Schristos p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
40*b0d17251Schristos if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Null Provider"))
41*b0d17251Schristos return 0;
42*b0d17251Schristos p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
43*b0d17251Schristos if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
44*b0d17251Schristos return 0;
45*b0d17251Schristos p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
46*b0d17251Schristos if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
47*b0d17251Schristos return 0;
48*b0d17251Schristos p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
49*b0d17251Schristos if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
50*b0d17251Schristos return 0;
51*b0d17251Schristos return 1;
52*b0d17251Schristos }
53*b0d17251Schristos
null_query(OSSL_PROVIDER * prov,int operation_id,int * no_cache)54*b0d17251Schristos static const OSSL_ALGORITHM *null_query(OSSL_PROVIDER *prov,
55*b0d17251Schristos int operation_id,
56*b0d17251Schristos int *no_cache)
57*b0d17251Schristos {
58*b0d17251Schristos *no_cache = 0;
59*b0d17251Schristos return NULL;
60*b0d17251Schristos }
61*b0d17251Schristos
62*b0d17251Schristos /* Functions we provide to the core */
63*b0d17251Schristos static const OSSL_DISPATCH null_dispatch_table[] = {
64*b0d17251Schristos { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))null_gettable_params },
65*b0d17251Schristos { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))null_get_params },
66*b0d17251Schristos { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))null_query },
67*b0d17251Schristos { 0, NULL }
68*b0d17251Schristos };
69*b0d17251Schristos
ossl_null_provider_init(const OSSL_CORE_HANDLE * handle,const OSSL_DISPATCH * in,const OSSL_DISPATCH ** out,void ** provctx)70*b0d17251Schristos int ossl_null_provider_init(const OSSL_CORE_HANDLE *handle,
71*b0d17251Schristos const OSSL_DISPATCH *in,
72*b0d17251Schristos const OSSL_DISPATCH **out,
73*b0d17251Schristos void **provctx)
74*b0d17251Schristos {
75*b0d17251Schristos *out = null_dispatch_table;
76*b0d17251Schristos
77*b0d17251Schristos /* Could be anything - we don't use it */
78*b0d17251Schristos *provctx = (void *)handle;
79*b0d17251Schristos return 1;
80*b0d17251Schristos }
81