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
10 #include <openssl/core.h>
11 #include <openssl/core_numbers.h>
12 #include <openssl/core_names.h>
13 #include <openssl/params.h>
14 #include <openssl/opensslv.h>
15 #include "crypto/cryptlib.h"
16 #include "internal/nelem.h"
17 #include "internal/thread_once.h"
18 #include "internal/provider.h"
19 #include "internal/refcount.h"
20 #include "provider_local.h"
22 # include <openssl/self_test.h>
25 static OSSL_PROVIDER
*provider_new(const char *name
,
26 OSSL_provider_init_fn
*init_function
);
29 * Provider Object structure
30 * =========================
37 DEFINE_STACK_OF(INFOPAIR
)
39 struct provider_store_st
; /* Forward declaration */
41 struct ossl_provider_st
{
43 unsigned int flag_initialized
:1;
44 unsigned int flag_fallback
:1;
46 /* OpenSSL library side data */
47 CRYPTO_REF_COUNT refcnt
;
48 CRYPTO_RWLOCK
*refcnt_lock
; /* For the ref counter */
52 OSSL_provider_init_fn
*init_function
;
53 STACK_OF(INFOPAIR
) *parameters
;
54 OPENSSL_CTX
*libctx
; /* The library context this instance is in */
55 struct provider_store_st
*store
; /* The store this instance belongs to */
58 * In the FIPS module inner provider, this isn't needed, since the
59 * error upcalls are always direct calls to the outer provider.
61 int error_lib
; /* ERR library number, one for each provider */
62 # ifndef OPENSSL_NO_ERR
63 ERR_STRING_DATA
*error_strings
; /* Copy of what the provider gives us */
67 /* Provider side functions */
68 OSSL_provider_teardown_fn
*teardown
;
69 OSSL_provider_gettable_params_fn
*gettable_params
;
70 OSSL_provider_get_params_fn
*get_params
;
71 OSSL_provider_query_operation_fn
*query_operation
;
73 /* Provider side data */
76 DEFINE_STACK_OF(OSSL_PROVIDER
)
78 static int ossl_provider_cmp(const OSSL_PROVIDER
* const *a
,
79 const OSSL_PROVIDER
* const *b
)
81 return strcmp((*a
)->name
, (*b
)->name
);
85 * Provider Object store
86 * =====================
88 * The Provider Object store is a library context object, and therefore needs
92 struct provider_store_st
{
93 STACK_OF(OSSL_PROVIDER
) *providers
;
95 unsigned int use_fallbacks
:1;
98 static void provider_store_free(void *vstore
)
100 struct provider_store_st
*store
= vstore
;
104 sk_OSSL_PROVIDER_pop_free(store
->providers
, ossl_provider_free
);
105 CRYPTO_THREAD_lock_free(store
->lock
);
109 static void *provider_store_new(OPENSSL_CTX
*ctx
)
111 struct provider_store_st
*store
= OPENSSL_zalloc(sizeof(*store
));
112 const struct predefined_providers_st
*p
= NULL
;
115 || (store
->providers
= sk_OSSL_PROVIDER_new(ossl_provider_cmp
)) == NULL
116 || (store
->lock
= CRYPTO_THREAD_lock_new()) == NULL
) {
117 provider_store_free(store
);
120 store
->use_fallbacks
= 1;
122 for (p
= predefined_providers
; p
->name
!= NULL
; p
++) {
123 OSSL_PROVIDER
*prov
= NULL
;
126 * We use the internal constructor directly here,
127 * otherwise we get a call loop
129 prov
= provider_new(p
->name
, p
->init
);
132 || sk_OSSL_PROVIDER_push(store
->providers
, prov
) == 0) {
133 ossl_provider_free(prov
);
134 provider_store_free(store
);
135 CRYPTOerr(CRYPTO_F_PROVIDER_STORE_NEW
, ERR_R_INTERNAL_ERROR
);
141 prov
->error_lib
= ERR_get_next_error_library();
144 ossl_provider_set_fallback(prov
);
150 static const OPENSSL_CTX_METHOD provider_store_method
= {
155 static struct provider_store_st
*get_provider_store(OPENSSL_CTX
*libctx
)
157 struct provider_store_st
*store
= NULL
;
159 store
= openssl_ctx_get_data(libctx
, OPENSSL_CTX_PROVIDER_STORE_INDEX
,
160 &provider_store_method
);
162 CRYPTOerr(CRYPTO_F_GET_PROVIDER_STORE
, ERR_R_INTERNAL_ERROR
);
166 OSSL_PROVIDER
*ossl_provider_find(OPENSSL_CTX
*libctx
, const char *name
,
169 struct provider_store_st
*store
= NULL
;
170 OSSL_PROVIDER
*prov
= NULL
;
172 if ((store
= get_provider_store(libctx
)) != NULL
) {
173 OSSL_PROVIDER tmpl
= { 0, };
178 * Make sure any providers are loaded from config before we try to find
182 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG
, NULL
);
185 tmpl
.name
= (char *)name
;
186 CRYPTO_THREAD_write_lock(store
->lock
);
187 if ((i
= sk_OSSL_PROVIDER_find(store
->providers
, &tmpl
)) == -1
188 || (prov
= sk_OSSL_PROVIDER_value(store
->providers
, i
)) == NULL
189 || !ossl_provider_up_ref(prov
))
191 CRYPTO_THREAD_unlock(store
->lock
);
198 * Provider Object methods
199 * =======================
202 static OSSL_PROVIDER
*provider_new(const char *name
,
203 OSSL_provider_init_fn
*init_function
)
205 OSSL_PROVIDER
*prov
= NULL
;
207 if ((prov
= OPENSSL_zalloc(sizeof(*prov
))) == NULL
209 || (prov
->refcnt_lock
= CRYPTO_THREAD_lock_new()) == NULL
211 || !ossl_provider_up_ref(prov
) /* +1 One reference to be returned */
212 || (prov
->name
= OPENSSL_strdup(name
)) == NULL
) {
213 ossl_provider_free(prov
);
214 CRYPTOerr(CRYPTO_F_PROVIDER_NEW
, ERR_R_MALLOC_FAILURE
);
218 prov
->init_function
= init_function
;
222 int ossl_provider_up_ref(OSSL_PROVIDER
*prov
)
226 if (CRYPTO_UP_REF(&prov
->refcnt
, &ref
, prov
->refcnt_lock
) <= 0)
231 OSSL_PROVIDER
*ossl_provider_new(OPENSSL_CTX
*libctx
, const char *name
,
232 OSSL_provider_init_fn
*init_function
,
235 struct provider_store_st
*store
= NULL
;
236 OSSL_PROVIDER
*prov
= NULL
;
238 if ((store
= get_provider_store(libctx
)) == NULL
)
241 if ((prov
= ossl_provider_find(libctx
, name
,
242 noconfig
)) != NULL
) { /* refcount +1 */
243 ossl_provider_free(prov
); /* refcount -1 */
244 ERR_raise_data(ERR_LIB_CRYPTO
, CRYPTO_R_PROVIDER_ALREADY_EXISTS
, NULL
,
249 /* provider_new() generates an error, so no need here */
250 if ((prov
= provider_new(name
, init_function
)) == NULL
)
253 CRYPTO_THREAD_write_lock(store
->lock
);
254 if (!ossl_provider_up_ref(prov
)) { /* +1 One reference for the store */
255 ossl_provider_free(prov
); /* -1 Reference that was to be returned */
257 } else if (sk_OSSL_PROVIDER_push(store
->providers
, prov
) == 0) {
258 ossl_provider_free(prov
); /* -1 Store reference */
259 ossl_provider_free(prov
); /* -1 Reference that was to be returned */
262 prov
->libctx
= libctx
;
265 prov
->error_lib
= ERR_get_next_error_library();
268 CRYPTO_THREAD_unlock(store
->lock
);
271 CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_NEW
, ERR_R_MALLOC_FAILURE
);
274 * At this point, the provider is only partially "loaded". To be
275 * fully "loaded", ossl_provider_activate() must also be called.
281 static void free_infopair(INFOPAIR
*pair
)
283 OPENSSL_free(pair
->name
);
284 OPENSSL_free(pair
->value
);
288 void ossl_provider_free(OSSL_PROVIDER
*prov
)
293 CRYPTO_DOWN_REF(&prov
->refcnt
, &ref
, prov
->refcnt_lock
);
296 * When the refcount drops below two, the store is the only
297 * possible reference, or it has already been taken away from
298 * the store (this may happen if a provider was activated
299 * because it's a fallback, but isn't currently used)
300 * When that happens, the provider is inactivated.
302 if (ref
< 2 && prov
->flag_initialized
) {
304 ossl_init_thread_deregister(prov
);
306 if (prov
->teardown
!= NULL
)
307 prov
->teardown(prov
->provctx
);
308 #ifndef OPENSSL_NO_ERR
310 if (prov
->error_strings
!= NULL
) {
311 ERR_unload_strings(prov
->error_lib
, prov
->error_strings
);
312 OPENSSL_free(prov
->error_strings
);
313 prov
->error_strings
= NULL
;
317 prov
->flag_initialized
= 0;
321 * When the refcount drops to zero, it has been taken out of
322 * the store. All we have to do here is clean it out.
326 DSO_free(prov
->module
);
328 OPENSSL_free(prov
->name
);
329 OPENSSL_free(prov
->path
);
330 sk_INFOPAIR_pop_free(prov
->parameters
, free_infopair
);
332 CRYPTO_THREAD_lock_free(prov
->refcnt_lock
);
340 int ossl_provider_set_module_path(OSSL_PROVIDER
*prov
, const char *module_path
)
342 OPENSSL_free(prov
->path
);
343 if (module_path
== NULL
)
345 if ((prov
->path
= OPENSSL_strdup(module_path
)) != NULL
)
347 CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_SET_MODULE_PATH
, ERR_R_MALLOC_FAILURE
);
351 int ossl_provider_add_parameter(OSSL_PROVIDER
*prov
,
352 const char *name
, const char *value
)
354 INFOPAIR
*pair
= NULL
;
356 if ((pair
= OPENSSL_zalloc(sizeof(*pair
))) != NULL
357 && (prov
->parameters
!= NULL
358 || (prov
->parameters
= sk_INFOPAIR_new_null()) != NULL
)
359 && (pair
->name
= OPENSSL_strdup(name
)) != NULL
360 && (pair
->value
= OPENSSL_strdup(value
)) != NULL
361 && sk_INFOPAIR_push(prov
->parameters
, pair
) > 0)
365 OPENSSL_free(pair
->name
);
366 OPENSSL_free(pair
->value
);
369 CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_ADD_PARAMETER
, ERR_R_MALLOC_FAILURE
);
374 * Provider activation.
376 * What "activation" means depends on the provider form; for built in
377 * providers (in the library or the application alike), the provider
378 * can already be considered to be loaded, all that's needed is to
379 * initialize it. However, for dynamically loadable provider modules,
380 * we must first load that module.
382 * Built in modules are distinguished from dynamically loaded modules
383 * with an already assigned init function.
385 static const OSSL_DISPATCH
*core_dispatch
; /* Define further down */
388 * Internal version that doesn't affect the store flags, and thereby avoid
389 * locking. Direct callers must remember to set the store flags when
392 static int provider_activate(OSSL_PROVIDER
*prov
)
394 const OSSL_DISPATCH
*provider_dispatch
= NULL
;
395 #ifndef OPENSSL_NO_ERR
397 OSSL_provider_get_reason_strings_fn
*p_get_reason_strings
= NULL
;
401 if (prov
->flag_initialized
)
405 * If the init function isn't set, it indicates that this provider is
408 if (prov
->init_function
== NULL
) {
412 if (prov
->module
== NULL
) {
413 char *allocated_path
= NULL
;
414 const char *module_path
= NULL
;
415 char *merged_path
= NULL
;
416 const char *load_dir
= ossl_safe_getenv("OPENSSL_MODULES");
418 if ((prov
->module
= DSO_new()) == NULL
) {
419 /* DSO_new() generates an error already */
423 if (load_dir
== NULL
)
424 load_dir
= MODULESDIR
;
426 DSO_ctrl(prov
->module
, DSO_CTRL_SET_FLAGS
,
427 DSO_FLAG_NAME_TRANSLATION_EXT_ONLY
, NULL
);
429 module_path
= prov
->path
;
430 if (module_path
== NULL
)
431 module_path
= allocated_path
=
432 DSO_convert_filename(prov
->module
, prov
->name
);
433 if (module_path
!= NULL
)
434 merged_path
= DSO_merge(prov
->module
, module_path
, load_dir
);
436 if (merged_path
== NULL
437 || (DSO_load(prov
->module
, merged_path
, NULL
, 0)) == NULL
) {
438 DSO_free(prov
->module
);
442 OPENSSL_free(merged_path
);
443 OPENSSL_free(allocated_path
);
446 if (prov
->module
!= NULL
)
447 prov
->init_function
= (OSSL_provider_init_fn
*)
448 DSO_bind_func(prov
->module
, "OSSL_provider_init");
452 /* Call the initialise function for the provider. */
453 if (prov
->init_function
== NULL
454 || !prov
->init_function(prov
, core_dispatch
, &provider_dispatch
,
456 ERR_raise_data(ERR_LIB_CRYPTO
, ERR_R_INIT_FAIL
, NULL
,
457 "name=%s", prov
->name
);
459 DSO_free(prov
->module
);
465 for (; provider_dispatch
->function_id
!= 0; provider_dispatch
++) {
466 switch (provider_dispatch
->function_id
) {
467 case OSSL_FUNC_PROVIDER_TEARDOWN
:
469 OSSL_get_provider_teardown(provider_dispatch
);
471 case OSSL_FUNC_PROVIDER_GETTABLE_PARAMS
:
472 prov
->gettable_params
=
473 OSSL_get_provider_gettable_params(provider_dispatch
);
475 case OSSL_FUNC_PROVIDER_GET_PARAMS
:
477 OSSL_get_provider_get_params(provider_dispatch
);
479 case OSSL_FUNC_PROVIDER_QUERY_OPERATION
:
480 prov
->query_operation
=
481 OSSL_get_provider_query_operation(provider_dispatch
);
483 #ifndef OPENSSL_NO_ERR
485 case OSSL_FUNC_PROVIDER_GET_REASON_STRINGS
:
486 p_get_reason_strings
=
487 OSSL_get_provider_get_reason_strings(provider_dispatch
);
494 #ifndef OPENSSL_NO_ERR
496 if (p_get_reason_strings
!= NULL
) {
497 const OSSL_ITEM
*reasonstrings
= p_get_reason_strings(prov
->provctx
);
501 * ERR_load_strings() handles ERR_STRING_DATA rather than OSSL_ITEM,
502 * although they are essentially the same type.
503 * Furthermore, ERR_load_strings() patches the array's error number
504 * with the error library number, so we need to make a copy of that
507 cnt
= 1; /* One for the terminating item */
508 while (reasonstrings
[cnt
].id
!= 0) {
509 if (ERR_GET_LIB(reasonstrings
[cnt
].id
) != 0)
514 /* Allocate one extra item for the "library" name */
515 prov
->error_strings
=
516 OPENSSL_zalloc(sizeof(ERR_STRING_DATA
) * (cnt
+ 1));
517 if (prov
->error_strings
== NULL
)
521 * Set the "library" name.
523 prov
->error_strings
[0].error
= ERR_PACK(prov
->error_lib
, 0, 0);
524 prov
->error_strings
[0].string
= prov
->name
;
526 * Copy reasonstrings item 0..cnt-1 to prov->error_trings positions
529 for (cnt2
= 1; cnt2
<= cnt
; cnt2
++) {
530 prov
->error_strings
[cnt2
].error
= (int)reasonstrings
[cnt2
-1].id
;
531 prov
->error_strings
[cnt2
].string
= reasonstrings
[cnt2
-1].ptr
;
534 ERR_load_strings(prov
->error_lib
, prov
->error_strings
);
539 /* With this flag set, this provider has become fully "loaded". */
540 prov
->flag_initialized
= 1;
545 int ossl_provider_activate(OSSL_PROVIDER
*prov
)
547 if (provider_activate(prov
)) {
548 CRYPTO_THREAD_write_lock(prov
->store
->lock
);
549 prov
->store
->use_fallbacks
= 0;
550 CRYPTO_THREAD_unlock(prov
->store
->lock
);
557 void *ossl_provider_ctx(const OSSL_PROVIDER
*prov
)
559 return prov
->provctx
;
563 static int provider_forall_loaded(struct provider_store_st
*store
,
564 int *found_activated
,
565 int (*cb
)(OSSL_PROVIDER
*provider
,
573 num_provs
= sk_OSSL_PROVIDER_num(store
->providers
);
575 if (found_activated
!= NULL
)
576 *found_activated
= 0;
577 for (i
= 0; i
< num_provs
; i
++) {
578 OSSL_PROVIDER
*prov
=
579 sk_OSSL_PROVIDER_value(store
->providers
, i
);
581 if (prov
->flag_initialized
) {
582 if (found_activated
!= NULL
)
583 *found_activated
= 1;
584 if (!(ret
= cb(prov
, cbdata
)))
593 * This function only does something once when store->use_fallbacks == 1,
594 * and then sets store->use_fallbacks = 0, so the second call and so on is
595 * effectively a no-op.
597 static void provider_activate_fallbacks(struct provider_store_st
*store
)
599 if (store
->use_fallbacks
) {
600 int num_provs
= sk_OSSL_PROVIDER_num(store
->providers
);
601 int activated_fallback_count
= 0;
604 for (i
= 0; i
< num_provs
; i
++) {
605 OSSL_PROVIDER
*prov
= sk_OSSL_PROVIDER_value(store
->providers
, i
);
608 * Note that we don't care if the activation succeeds or not.
609 * If it doesn't succeed, then any attempt to use any of the
610 * fallback providers will fail anyway.
612 if (prov
->flag_fallback
) {
613 activated_fallback_count
++;
614 provider_activate(prov
);
619 * We assume that all fallbacks have been added to the store before
620 * any fallback is activated.
621 * TODO: We may have to reconsider this, IF we find ourselves adding
622 * fallbacks after any previous fallback has been activated.
624 if (activated_fallback_count
> 0)
625 store
->use_fallbacks
= 0;
629 int ossl_provider_forall_loaded(OPENSSL_CTX
*ctx
,
630 int (*cb
)(OSSL_PROVIDER
*provider
,
635 struct provider_store_st
*store
= get_provider_store(ctx
);
639 * Make sure any providers are loaded from config before we try to use
642 OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG
, NULL
);
646 CRYPTO_THREAD_read_lock(store
->lock
);
648 provider_activate_fallbacks(store
);
651 * Now, we sweep through all providers
653 ret
= provider_forall_loaded(store
, NULL
, cb
, cbdata
);
655 CRYPTO_THREAD_unlock(store
->lock
);
661 int ossl_provider_available(OSSL_PROVIDER
*prov
)
664 CRYPTO_THREAD_read_lock(prov
->store
->lock
);
665 provider_activate_fallbacks(prov
->store
);
666 CRYPTO_THREAD_unlock(prov
->store
->lock
);
668 return prov
->flag_initialized
;
673 /* Setters of Provider Object data */
674 int ossl_provider_set_fallback(OSSL_PROVIDER
*prov
)
679 prov
->flag_fallback
= 1;
683 /* Getters of Provider Object data */
684 const char *ossl_provider_name(const OSSL_PROVIDER
*prov
)
689 const DSO
*ossl_provider_dso(const OSSL_PROVIDER
*prov
)
694 const char *ossl_provider_module_name(const OSSL_PROVIDER
*prov
)
699 return DSO_get_filename(prov
->module
);
703 const char *ossl_provider_module_path(const OSSL_PROVIDER
*prov
)
708 /* FIXME: Ensure it's a full path */
709 return DSO_get_filename(prov
->module
);
713 OPENSSL_CTX
*ossl_provider_library_context(const OSSL_PROVIDER
*prov
)
715 /* TODO(3.0) just: return prov->libctx; */
716 return prov
!= NULL
? prov
->libctx
: NULL
;
719 /* Wrappers around calls to the provider */
720 void ossl_provider_teardown(const OSSL_PROVIDER
*prov
)
722 if (prov
->teardown
!= NULL
)
723 prov
->teardown(prov
->provctx
);
726 const OSSL_PARAM
*ossl_provider_gettable_params(const OSSL_PROVIDER
*prov
)
728 return prov
->gettable_params
== NULL
729 ? NULL
: prov
->gettable_params(prov
->provctx
);
732 int ossl_provider_get_params(const OSSL_PROVIDER
*prov
, OSSL_PARAM params
[])
734 return prov
->get_params
== NULL
735 ? 0 : prov
->get_params(prov
->provctx
, params
);
739 const OSSL_ALGORITHM
*ossl_provider_query_operation(const OSSL_PROVIDER
*prov
,
743 return prov
->query_operation(prov
->provctx
, operation_id
, no_cache
);
747 * Core functions for the provider
748 * ===============================
750 * This is the set of functions that the core makes available to the provider
754 * This returns a list of Provider Object parameters with their types, for
755 * discovery. We do not expect that many providers will use this, but one
758 static const OSSL_PARAM param_types
[] = {
759 OSSL_PARAM_DEFN("openssl-version", OSSL_PARAM_UTF8_PTR
, NULL
, 0),
760 OSSL_PARAM_DEFN("provider-name", OSSL_PARAM_UTF8_PTR
, NULL
, 0),
765 * Forward declare all the functions that are provided aa dispatch.
766 * This ensures that the compiler will complain if they aren't defined
767 * with the correct signature.
769 static OSSL_core_gettable_params_fn core_gettable_params
;
770 static OSSL_core_get_params_fn core_get_params
;
771 static OSSL_core_thread_start_fn core_thread_start
;
772 static OSSL_core_get_library_context_fn core_get_libctx
;
774 static OSSL_core_new_error_fn core_new_error
;
775 static OSSL_core_set_error_debug_fn core_set_error_debug
;
776 static OSSL_core_vset_error_fn core_vset_error
;
777 static OSSL_core_set_error_mark_fn core_set_error_mark
;
778 static OSSL_core_clear_last_error_mark_fn core_clear_last_error_mark
;
779 static OSSL_core_pop_error_to_mark_fn core_pop_error_to_mark
;
782 static const OSSL_PARAM
*core_gettable_params(const OSSL_PROVIDER
*prov
)
787 static int core_get_params(const OSSL_PROVIDER
*prov
, OSSL_PARAM params
[])
792 if ((p
= OSSL_PARAM_locate(params
, "openssl-version")) != NULL
)
793 OSSL_PARAM_set_utf8_ptr(p
, OPENSSL_VERSION_STR
);
794 if ((p
= OSSL_PARAM_locate(params
, "provider-name")) != NULL
)
795 OSSL_PARAM_set_utf8_ptr(p
, prov
->name
);
798 if ((p
= OSSL_PARAM_locate(params
, OSSL_PROV_PARAM_MODULE_FILENAME
)) != NULL
)
799 OSSL_PARAM_set_utf8_ptr(p
, ossl_provider_module_path(prov
));
802 if (prov
->parameters
== NULL
)
805 for (i
= 0; i
< sk_INFOPAIR_num(prov
->parameters
); i
++) {
806 INFOPAIR
*pair
= sk_INFOPAIR_value(prov
->parameters
, i
);
808 if ((p
= OSSL_PARAM_locate(params
, pair
->name
)) != NULL
)
809 OSSL_PARAM_set_utf8_ptr(p
, pair
->value
);
814 static OPENSSL_CTX
*core_get_libctx(const OSSL_PROVIDER
*prov
)
816 return ossl_provider_library_context(prov
);
819 static int core_thread_start(const OSSL_PROVIDER
*prov
,
820 OSSL_thread_stop_handler_fn handfn
)
822 return ossl_init_thread_start(prov
, prov
->provctx
, handfn
);
826 * The FIPS module inner provider doesn't implement these. They aren't
827 * needed there, since the FIPS module upcalls are always the outer provider
832 * TODO(3.0) These error functions should use |prov| to select the proper
833 * library context to report in the correct error stack, at least if error
834 * stacks become tied to the library context.
835 * We cannot currently do that since there's no support for it in the
838 static void core_new_error(const OSSL_PROVIDER
*prov
)
843 static void core_set_error_debug(const OSSL_PROVIDER
*prov
,
844 const char *file
, int line
, const char *func
)
846 ERR_set_debug(file
, line
, func
);
849 static void core_vset_error(const OSSL_PROVIDER
*prov
,
850 uint32_t reason
, const char *fmt
, va_list args
)
853 * If the uppermost 8 bits are non-zero, it's an OpenSSL library
854 * error and will be treated as such. Otherwise, it's a new style
855 * provider error and will be treated as such.
857 if (ERR_GET_LIB(reason
) != 0) {
858 ERR_vset_error(ERR_GET_LIB(reason
), ERR_GET_REASON(reason
), fmt
, args
);
860 ERR_vset_error(prov
->error_lib
, (int)reason
, fmt
, args
);
864 static int core_set_error_mark(const OSSL_PROVIDER
*prov
)
866 return ERR_set_mark();
869 static int core_clear_last_error_mark(const OSSL_PROVIDER
*prov
)
871 return ERR_clear_last_mark();
874 static int core_pop_error_to_mark(const OSSL_PROVIDER
*prov
)
876 return ERR_pop_to_mark();
881 * Functions provided by the core. Blank line separates "families" of related
884 static const OSSL_DISPATCH core_dispatch_
[] = {
885 { OSSL_FUNC_CORE_GETTABLE_PARAMS
, (void (*)(void))core_gettable_params
},
886 { OSSL_FUNC_CORE_GET_PARAMS
, (void (*)(void))core_get_params
},
887 { OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT
, (void (*)(void))core_get_libctx
},
888 { OSSL_FUNC_CORE_THREAD_START
, (void (*)(void))core_thread_start
},
890 { OSSL_FUNC_CORE_NEW_ERROR
, (void (*)(void))core_new_error
},
891 { OSSL_FUNC_CORE_SET_ERROR_DEBUG
, (void (*)(void))core_set_error_debug
},
892 { OSSL_FUNC_CORE_VSET_ERROR
, (void (*)(void))core_vset_error
},
893 { OSSL_FUNC_CORE_SET_ERROR_MARK
, (void (*)(void))core_set_error_mark
},
894 { OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK
,
895 (void (*)(void))core_clear_last_error_mark
},
896 { OSSL_FUNC_CORE_POP_ERROR_TO_MARK
,
897 (void (*)(void))core_pop_error_to_mark
},
898 { OSSL_FUNC_BIO_NEW_FILE
, (void (*)(void))BIO_new_file
},
899 { OSSL_FUNC_BIO_NEW_MEMBUF
, (void (*)(void))BIO_new_mem_buf
},
900 { OSSL_FUNC_BIO_READ_EX
, (void (*)(void))BIO_read_ex
},
901 { OSSL_FUNC_BIO_FREE
, (void (*)(void))BIO_free
},
902 { OSSL_FUNC_BIO_VPRINTF
, (void (*)(void))BIO_vprintf
},
903 { OSSL_FUNC_SELF_TEST_CB
, (void (*)(void))OSSL_SELF_TEST_get_callback
},
905 { OSSL_FUNC_CRYPTO_MALLOC
, (void (*)(void))CRYPTO_malloc
},
906 { OSSL_FUNC_CRYPTO_ZALLOC
, (void (*)(void))CRYPTO_zalloc
},
907 { OSSL_FUNC_CRYPTO_FREE
, (void (*)(void))CRYPTO_free
},
908 { OSSL_FUNC_CRYPTO_CLEAR_FREE
, (void (*)(void))CRYPTO_clear_free
},
909 { OSSL_FUNC_CRYPTO_REALLOC
, (void (*)(void))CRYPTO_realloc
},
910 { OSSL_FUNC_CRYPTO_CLEAR_REALLOC
, (void (*)(void))CRYPTO_clear_realloc
},
911 { OSSL_FUNC_CRYPTO_SECURE_MALLOC
, (void (*)(void))CRYPTO_secure_malloc
},
912 { OSSL_FUNC_CRYPTO_SECURE_ZALLOC
, (void (*)(void))CRYPTO_secure_zalloc
},
913 { OSSL_FUNC_CRYPTO_SECURE_FREE
, (void (*)(void))CRYPTO_secure_free
},
914 { OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE
,
915 (void (*)(void))CRYPTO_secure_clear_free
},
916 { OSSL_FUNC_CRYPTO_SECURE_ALLOCATED
,
917 (void (*)(void))CRYPTO_secure_allocated
},
918 { OSSL_FUNC_OPENSSL_CLEANSE
, (void (*)(void))OPENSSL_cleanse
},
922 static const OSSL_DISPATCH
*core_dispatch
= core_dispatch_
;