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