xref: /freebsd/crypto/openssl/providers/nullprov.c (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
1 /*
2  * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9 
10 #include <string.h>
11 #include <stdio.h>
12 #include <openssl/core.h>
13 #include <openssl/core_dispatch.h>
14 #include <openssl/core_names.h>
15 #include <openssl/params.h>
16 #include "prov/implementations.h"
17 #include "prov/providercommon.h"
18 
19 OSSL_provider_init_fn ossl_null_provider_init;
20 
21 /* Parameters we provide to the core */
22 static const OSSL_PARAM null_param_types[] = {
23     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
24     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
25     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
26     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
27     OSSL_PARAM_END
28 };
29 
30 static const OSSL_PARAM *null_gettable_params(const OSSL_PROVIDER *prov)
31 {
32     return null_param_types;
33 }
34 
35 static int null_get_params(const OSSL_PROVIDER *provctx, OSSL_PARAM params[])
36 {
37     OSSL_PARAM *p;
38 
39     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
40     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Null Provider"))
41         return 0;
42     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
43     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
44         return 0;
45     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
46     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
47         return 0;
48     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
49     if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
50         return 0;
51     return 1;
52 }
53 
54 static const OSSL_ALGORITHM *null_query(OSSL_PROVIDER *prov,
55                                           int operation_id,
56                                           int *no_cache)
57 {
58     *no_cache = 0;
59     return NULL;
60 }
61 
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 },
67     { 0, NULL }
68 };
69 
70 int ossl_null_provider_init(const OSSL_CORE_HANDLE *handle,
71                             const OSSL_DISPATCH *in,
72                             const OSSL_DISPATCH **out,
73                             void **provctx)
74 {
75     *out = null_dispatch_table;
76 
77     /* Could be anything - we don't use it */
78     *provctx = (void *)handle;
79     return 1;
80 }
81