]>
Commit | Line | Data |
---|---|---|
d0308923 MC |
1 | /* |
2 | * Copyright 2019 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> | |
af3e7e1b | 16 | #include "prov/implementations.h" |
d0308923 | 17 | |
318e074e RL |
18 | #ifdef STATIC_LEGACY |
19 | OSSL_provider_init_fn ossl_legacy_provider_init; | |
20 | # define OSSL_provider_init ossl_legacy_provider_init | |
21 | #endif | |
22 | ||
d0308923 | 23 | /* Functions provided by the core */ |
dca97d00 | 24 | static OSSL_core_gettable_params_fn *c_gettable_params = NULL; |
d0308923 MC |
25 | static OSSL_core_get_params_fn *c_get_params = NULL; |
26 | ||
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 }, | |
32 | { 0, NULL } | |
33 | }; | |
34 | ||
dca97d00 | 35 | static const OSSL_ITEM *legacy_gettable_params(const OSSL_PROVIDER *prov) |
d0308923 MC |
36 | { |
37 | return legacy_param_types; | |
38 | } | |
39 | ||
4e7991b4 | 40 | static int legacy_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]) |
d0308923 | 41 | { |
4e7991b4 | 42 | OSSL_PARAM *p; |
d0308923 MC |
43 | |
44 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME); | |
45 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Legacy Provider")) | |
46 | return 0; | |
47 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION); | |
48 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR)) | |
49 | return 0; | |
50 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO); | |
51 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR)) | |
52 | return 0; | |
53 | ||
54 | return 1; | |
55 | } | |
56 | ||
d0308923 MC |
57 | static const OSSL_ALGORITHM legacy_digests[] = { |
58 | #ifndef OPENSSL_NO_MD2 | |
745fc918 | 59 | { "MD2", "provider=legacy", md2_functions }, |
d0308923 | 60 | #endif |
d5e5e2ff SL |
61 | |
62 | #ifndef OPENSSL_NO_MD4 | |
745fc918 | 63 | { "MD4", "provider=legacy", md4_functions }, |
d5e5e2ff SL |
64 | #endif |
65 | ||
66 | #ifndef OPENSSL_NO_MDC2 | |
745fc918 | 67 | { "MDC2", "provider=legacy", mdc2_functions }, |
d5e5e2ff SL |
68 | #endif /* OPENSSL_NO_MDC2 */ |
69 | ||
70 | #ifndef OPENSSL_NO_WHIRLPOOL | |
745fc918 | 71 | { "WHIRLPOOL", "provider=legacy", wp_functions }, |
d5e5e2ff SL |
72 | #endif /* OPENSSL_NO_WHIRLPOOL */ |
73 | ||
74 | #ifndef OPENSSL_NO_RMD160 | |
745fc918 | 75 | { "RIPEMD-160:RIPEMD160:RIPEMD:RMD160", "provider=legacy", ripemd160_functions }, |
d5e5e2ff SL |
76 | #endif /* OPENSSL_NO_RMD160 */ |
77 | ||
d0308923 MC |
78 | { NULL, NULL, NULL } |
79 | }; | |
80 | ||
81 | static const OSSL_ALGORITHM *legacy_query(OSSL_PROVIDER *prov, | |
82 | int operation_id, | |
83 | int *no_cache) | |
84 | { | |
85 | *no_cache = 0; | |
86 | switch (operation_id) { | |
87 | case OSSL_OP_DIGEST: | |
88 | return legacy_digests; | |
89 | } | |
90 | return NULL; | |
91 | } | |
92 | ||
93 | /* Functions we provide to the core */ | |
94 | static const OSSL_DISPATCH legacy_dispatch_table[] = { | |
dca97d00 | 95 | { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))legacy_gettable_params }, |
d0308923 MC |
96 | { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))legacy_get_params }, |
97 | { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))legacy_query }, | |
98 | { 0, NULL } | |
99 | }; | |
100 | ||
101 | int OSSL_provider_init(const OSSL_PROVIDER *provider, | |
102 | const OSSL_DISPATCH *in, | |
a39eb840 RL |
103 | const OSSL_DISPATCH **out, |
104 | void **provctx) | |
d0308923 | 105 | { |
8013a933 RL |
106 | OSSL_core_get_library_context_fn *c_get_libctx = NULL; |
107 | ||
d0308923 MC |
108 | for (; in->function_id != 0; in++) { |
109 | switch (in->function_id) { | |
dca97d00 RL |
110 | case OSSL_FUNC_CORE_GETTABLE_PARAMS: |
111 | c_gettable_params = OSSL_get_core_gettable_params(in); | |
d0308923 MC |
112 | break; |
113 | case OSSL_FUNC_CORE_GET_PARAMS: | |
114 | c_get_params = OSSL_get_core_get_params(in); | |
115 | break; | |
8013a933 RL |
116 | case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT: |
117 | c_get_libctx = OSSL_get_core_get_library_context(in); | |
118 | break; | |
d0308923 MC |
119 | /* Just ignore anything we don't understand */ |
120 | default: | |
121 | break; | |
122 | } | |
123 | } | |
124 | ||
8013a933 RL |
125 | if (c_get_libctx == NULL) |
126 | return 0; | |
127 | ||
d0308923 | 128 | *out = legacy_dispatch_table; |
8013a933 RL |
129 | |
130 | /* | |
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. | |
134 | */ | |
135 | *provctx = c_get_libctx(provider); | |
d0308923 MC |
136 | return 1; |
137 | } |