3 #include <openssl/core.h>
4 #include <openssl/core_numbers.h>
5 #include <openssl/core_names.h>
6 #include <openssl/params.h>
8 #define GOST_PROV_VERSION_STR "3.0.0"
9 #define GOST_PROV_FULL_VERSION_STR "3.0.0"
11 /* Functions provided by the core */
12 static OSSL_core_gettable_params_fn *c_gettable_params = NULL;
13 static OSSL_core_get_params_fn *c_get_params = NULL;
15 /* Parameters we provide to the core */
16 static const OSSL_ITEM gost_param_types[] = {
17 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME },
18 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION },
19 { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO },
23 static const OSSL_ITEM *gost_gettable_params(const OSSL_PROVIDER *prov)
25 return gost_param_types;
28 static int gost_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
32 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
33 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "GOST Provider"))
35 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
36 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, GOST_PROV_VERSION_STR))
38 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
39 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, GOST_PROV_FULL_VERSION_STR))
45 static const OSSL_ALGORITHM gost_digests[] = {
46 { "md_gost94", "gost.legacy=yes", NULL }, /* FIXME */
47 { "md_gost2012_256:streebog256", "gost.gost=yes", NULL },
48 { "md_gost2012_512:streebog512", "gost.gost=yes", NULL },
53 static const OSSL_ALGORITHM *gost_query(OSSL_PROVIDER *prov,
58 switch (operation_id) {
65 /* Functions we provide to the core */
66 static const OSSL_DISPATCH gost_dispatch_table[] = {
67 { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))gost_gettable_params },
68 { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))gost_get_params },
69 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))gost_query },
73 int OSSL_provider_init(const OSSL_PROVIDER *provider,
74 const OSSL_DISPATCH *in,
75 const OSSL_DISPATCH **out,
78 OSSL_core_get_library_context_fn *c_get_libctx = NULL;
80 for (; in->function_id != 0; in++) {
81 switch (in->function_id) {
82 case OSSL_FUNC_CORE_GETTABLE_PARAMS:
83 c_gettable_params = OSSL_get_core_gettable_params(in);
85 case OSSL_FUNC_CORE_GET_PARAMS:
86 c_get_params = OSSL_get_core_get_params(in);
88 case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT:
89 c_get_libctx = OSSL_get_core_get_library_context(in);
91 /* Just ignore anything we don't understand */
97 if (c_get_libctx == NULL)
100 *out = gost_dispatch_table;
103 * We want to make sure that all calls from this provider that requires
104 * a library context use the same context as the one used to call our
105 * functions. We do that by passing it along as the provider context.
107 *provctx = c_get_libctx(provider);