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
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"
19 OSSL_provider_init_fn ossl_legacy_provider_init;
20 # define OSSL_provider_init ossl_legacy_provider_init
23 /* Functions provided by the core */
24 static OSSL_core_gettable_params_fn *c_gettable_params = NULL;
25 static OSSL_core_get_params_fn *c_get_params = NULL;
27 /* Parameters we provide to the core */
28 static const OSSL_ITEM legacy_param_types[] = {
29 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME },
30 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION },
31 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO },
35 static const OSSL_ITEM *legacy_gettable_params(const OSSL_PROVIDER *prov)
37 return legacy_param_types;
40 static int legacy_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
44 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
45 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Legacy Provider"))
47 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
48 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
50 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
51 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
57 static const OSSL_ALGORITHM legacy_digests[] = {
58 #ifndef OPENSSL_NO_MD2
59 { "MD2", "provider=legacy", md2_functions },
62 #ifndef OPENSSL_NO_MD4
63 { "MD4", "provider=legacy", md4_functions },
66 #ifndef OPENSSL_NO_MDC2
67 { "MDC2", "provider=legacy", mdc2_functions },
68 #endif /* OPENSSL_NO_MDC2 */
70 #ifndef OPENSSL_NO_WHIRLPOOL
71 { "WHIRLPOOL", "provider=legacy", wp_functions },
72 #endif /* OPENSSL_NO_WHIRLPOOL */
74 #ifndef OPENSSL_NO_RMD160
75 { "RIPEMD-160:RIPEMD160:RIPEMD:RMD160", "provider=legacy", ripemd160_functions },
76 #endif /* OPENSSL_NO_RMD160 */
81 static const OSSL_ALGORITHM *legacy_query(OSSL_PROVIDER *prov,
86 switch (operation_id) {
88 return legacy_digests;
93 /* Functions we provide to the core */
94 static const OSSL_DISPATCH legacy_dispatch_table[] = {
95 { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))legacy_gettable_params },
96 { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))legacy_get_params },
97 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))legacy_query },
101 int OSSL_provider_init(const OSSL_PROVIDER *provider,
102 const OSSL_DISPATCH *in,
103 const OSSL_DISPATCH **out,
106 OSSL_core_get_library_context_fn *c_get_libctx = NULL;
108 for (; in->function_id != 0; in++) {
109 switch (in->function_id) {
110 case OSSL_FUNC_CORE_GETTABLE_PARAMS:
111 c_gettable_params = OSSL_get_core_gettable_params(in);
113 case OSSL_FUNC_CORE_GET_PARAMS:
114 c_get_params = OSSL_get_core_get_params(in);
116 case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT:
117 c_get_libctx = OSSL_get_core_get_library_context(in);
119 /* Just ignore anything we don't understand */
125 if (c_get_libctx == NULL)
128 *out = legacy_dispatch_table;
131 * We want to make sure that all calls from this provider that requires
132 * a library context use the same context as the one used to call our
133 * functions. We do that by passing it along as the provider context.
135 *provctx = c_get_libctx(provider);