2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
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
11 * This is a very simple provider that does absolutely nothing except respond
12 * to provider global parameter requests. It does this by simply echoing back
13 * a parameter request it makes to the loading library.
20 * When built as an object file to link the application with, we get the
21 * init function name through the macro PROVIDER_INIT_FUNCTION_NAME. If
22 * not defined, we use the standard init function name for the shared
25 #ifdef PROVIDER_INIT_FUNCTION_NAME
26 # define OSSL_provider_init PROVIDER_INIT_FUNCTION_NAME
29 #include <openssl/core.h>
30 #include <openssl/core_numbers.h>
32 static OSSL_core_get_param_types_fn *c_get_param_types = NULL;
33 static OSSL_core_get_params_fn *c_get_params = NULL;
35 /* Tell the core what params we provide and what type they are */
36 static const OSSL_ITEM p_param_types[] = {
37 { OSSL_PARAM_UTF8_STRING, "greeting" },
41 static const OSSL_ITEM *p_get_param_types(const OSSL_PROVIDER *_)
46 static int p_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
48 const OSSL_PARAM *p = params;
51 for (; ok && p->key != NULL; p++) {
52 if (strcmp(p->key, "greeting") == 0) {
53 static char *opensslv = NULL;
54 static char *provname = NULL;
55 static OSSL_PARAM counter_request[] = {
56 { "openssl-version", OSSL_PARAM_UTF8_STRING_PTR,
57 &opensslv, sizeof(&opensslv), NULL },
58 { "provider-name", OSSL_PARAM_UTF8_STRING_PTR,
59 &provname, sizeof(&provname), NULL},
60 { NULL, 0, NULL, 0, NULL }
65 if (c_get_params(prov, counter_request)) {
66 const char *versionp = *(void **)counter_request[0].data;
67 const char *namep = *(void **)counter_request[1].data;
68 sprintf(buf, "Hello OpenSSL %.20s, greetings from %s!",
71 sprintf(buf, "Howdy stranger...");
74 *p->return_size = buf_l = strlen(buf) + 1;
75 if (p->data_size >= buf_l)
76 strncpy(p->data, buf, buf_l);
84 static const OSSL_DISPATCH p_test_table[] = {
85 { OSSL_FUNC_PROVIDER_GET_PARAM_TYPES, (void (*)(void))p_get_param_types },
86 { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))p_get_params },
90 int OSSL_provider_init(const OSSL_PROVIDER *provider,
91 const OSSL_DISPATCH *in,
92 const OSSL_DISPATCH **out)
94 for (; in->function_id != 0; in++) {
95 switch (in->function_id) {
96 case OSSL_FUNC_CORE_GET_PARAM_TYPES:
97 c_get_param_types = OSSL_get_core_get_param_types(in);
99 case OSSL_FUNC_CORE_GET_PARAMS:
100 c_get_params = OSSL_get_core_get_params(in);
103 /* Just ignore anything we don't understand */