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