Add the concept of "Capabilities" to the default and fips providers
[openssl.git] / providers / nullprov.c
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_numbers.h>
14 #include <openssl/core_names.h>
15 #include <openssl/params.h>
16 #include "prov/implementations.h"
17
18 OSSL_provider_init_fn ossl_null_provider_init;
19
20 /* Parameters we provide to the core */
21 static const OSSL_ITEM null_param_types[] = {
22     { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME },
23     { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION },
24     { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO },
25     { 0, NULL }
26 };
27
28 static const OSSL_ITEM *null_gettable_params(const OSSL_PROVIDER *prov)
29 {
30     return null_param_types;
31 }
32
33 static int null_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
34 {
35     OSSL_PARAM *p;
36
37     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
38     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Null Provider"))
39         return 0;
40     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
41     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
42         return 0;
43     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
44     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
45         return 0;
46
47     return 1;
48 }
49
50 static const OSSL_ALGORITHM *null_query(OSSL_PROVIDER *prov,
51                                           int operation_id,
52                                           int *no_cache)
53 {
54     *no_cache = 0;
55     return NULL;
56 }
57
58 /* Functions we provide to the core */
59 static const OSSL_DISPATCH null_dispatch_table[] = {
60     { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))null_gettable_params },
61     { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))null_get_params },
62     { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))null_query },
63     { 0, NULL }
64 };
65
66 int ossl_null_provider_init(const OSSL_CORE_HANDLE *handle,
67                             const OSSL_DISPATCH *in,
68                             const OSSL_DISPATCH **out,
69                             void **provctx)
70 {
71     *out = null_dispatch_table;
72
73     /* Could be anything - we don't use it */
74     *provctx = (void *)handle;
75     return 1;
76 }