| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-01-28 20:54:57 +08:00
										 |  |  |  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							|  |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:33 +08:00
										 |  |  | #include "crypto/cryptlib.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-20 18:25:39 +08:00
										 |  |  | #include <openssl/conf.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | #include "internal/thread_once.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-14 22:00:35 +08:00
										 |  |  | #include "internal/property.h"
 | 
					
						
							| 
									
										
										
										
											2021-04-07 09:32:59 +08:00
										 |  |  | #include "internal/core.h"
 | 
					
						
							| 
									
										
										
										
											2021-04-28 02:56:39 +08:00
										 |  |  | #include "internal/bio.h"
 | 
					
						
							| 
									
										
										
										
											2021-04-21 23:51:41 +08:00
										 |  |  | #include "internal/provider.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | struct ossl_lib_ctx_onfree_list_st { | 
					
						
							|  |  |  |     ossl_lib_ctx_onfree_fn *fn; | 
					
						
							|  |  |  |     struct ossl_lib_ctx_onfree_list_st *next; | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | struct ossl_lib_ctx_st { | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  |     CRYPTO_RWLOCK *lock; | 
					
						
							|  |  |  |     CRYPTO_EX_DATA data; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /*
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |      * For most data in the OSSL_LIB_CTX we just use ex_data to store it. But | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |      * that doesn't work for ex_data itself - so we store that directly. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     OSSL_EX_DATA_GLOBAL global; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Map internal static indexes to dynamically created indexes */ | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     int dyn_indexes[OSSL_LIB_CTX_MAX_INDEXES]; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |     /* Keep a separate lock for each index */ | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     CRYPTO_RWLOCK *index_locks[OSSL_LIB_CTX_MAX_INDEXES]; | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     CRYPTO_RWLOCK *oncelock; | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     int run_once_done[OSSL_LIB_CTX_MAX_RUN_ONCE]; | 
					
						
							|  |  |  |     int run_once_ret[OSSL_LIB_CTX_MAX_RUN_ONCE]; | 
					
						
							|  |  |  |     struct ossl_lib_ctx_onfree_list_st *onfreelist; | 
					
						
							| 
									
										
										
										
											2021-04-21 23:51:41 +08:00
										 |  |  |     unsigned int ischild:1; | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 09:32:59 +08:00
										 |  |  | int ossl_lib_ctx_write_lock(OSSL_LIB_CTX *ctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return CRYPTO_THREAD_write_lock(ossl_lib_ctx_get_concrete(ctx)->lock); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ossl_lib_ctx_read_lock(OSSL_LIB_CTX *ctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return CRYPTO_THREAD_read_lock(ossl_lib_ctx_get_concrete(ctx)->lock); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ossl_lib_ctx_unlock(OSSL_LIB_CTX *ctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return CRYPTO_THREAD_unlock(ossl_lib_ctx_get_concrete(ctx)->lock); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-21 23:51:41 +08:00
										 |  |  | int ossl_lib_ctx_is_child(OSSL_LIB_CTX *ctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ctx = ossl_lib_ctx_get_concrete(ctx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     return ctx->ischild; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static int context_init(OSSL_LIB_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     size_t i; | 
					
						
							| 
									
										
										
										
											2019-08-14 22:00:35 +08:00
										 |  |  |     int exdata_done = 0; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ctx->lock = CRYPTO_THREAD_lock_new(); | 
					
						
							|  |  |  |     if (ctx->lock == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ctx->oncelock = CRYPTO_THREAD_lock_new(); | 
					
						
							|  |  |  |     if (ctx->oncelock == NULL) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     for (i = 0; i < OSSL_LIB_CTX_MAX_INDEXES; i++) { | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |         ctx->index_locks[i] = CRYPTO_THREAD_lock_new(); | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |         ctx->dyn_indexes[i] = -1; | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |         if (ctx->index_locks[i] == NULL) | 
					
						
							|  |  |  |             goto err; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     /* OSSL_LIB_CTX is built on top of ex_data so we initialise that directly */ | 
					
						
							| 
									
										
										
										
											2021-02-24 16:07:52 +08:00
										 |  |  |     if (!ossl_do_ex_data_init(ctx)) | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |         goto err; | 
					
						
							| 
									
										
										
										
											2019-08-14 22:00:35 +08:00
										 |  |  |     exdata_done = 1; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 16:07:52 +08:00
										 |  |  |     if (!ossl_crypto_new_ex_data_ex(ctx, CRYPTO_EX_INDEX_OSSL_LIB_CTX, NULL, | 
					
						
							|  |  |  |                                     &ctx->data)) { | 
					
						
							|  |  |  |         ossl_crypto_cleanup_all_ex_data_int(ctx); | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |         goto err; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-14 22:00:35 +08:00
										 |  |  |     /* Everything depends on properties, so we also pre-initialise that */ | 
					
						
							|  |  |  |     if (!ossl_property_parse_init(ctx)) | 
					
						
							|  |  |  |         goto err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     return 1; | 
					
						
							|  |  |  |  err: | 
					
						
							| 
									
										
										
										
											2019-08-14 22:00:35 +08:00
										 |  |  |     if (exdata_done) | 
					
						
							| 
									
										
										
										
											2021-02-24 16:07:52 +08:00
										 |  |  |         ossl_crypto_cleanup_all_ex_data_int(ctx); | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     CRYPTO_THREAD_lock_free(ctx->oncelock); | 
					
						
							|  |  |  |     CRYPTO_THREAD_lock_free(ctx->lock); | 
					
						
							|  |  |  |     ctx->lock = NULL; | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static int context_deinit(OSSL_LIB_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     struct ossl_lib_ctx_onfree_list_st *tmp, *onfree; | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |     int i; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return 1; | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-27 23:31:27 +08:00
										 |  |  |     ossl_ctx_thread_stop(ctx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     onfree = ctx->onfreelist; | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  |     while (onfree != NULL) { | 
					
						
							|  |  |  |         onfree->fn(ctx); | 
					
						
							|  |  |  |         tmp = onfree; | 
					
						
							|  |  |  |         onfree = onfree->next; | 
					
						
							|  |  |  |         OPENSSL_free(tmp); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     CRYPTO_free_ex_data(CRYPTO_EX_INDEX_OSSL_LIB_CTX, NULL, &ctx->data); | 
					
						
							| 
									
										
										
										
											2021-02-24 16:07:52 +08:00
										 |  |  |     ossl_crypto_cleanup_all_ex_data_int(ctx); | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     for (i = 0; i < OSSL_LIB_CTX_MAX_INDEXES; i++) | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |         CRYPTO_THREAD_lock_free(ctx->index_locks[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     CRYPTO_THREAD_lock_free(ctx->oncelock); | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  |     CRYPTO_THREAD_lock_free(ctx->lock); | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     ctx->lock = NULL; | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-14 04:34:56 +08:00
										 |  |  | #ifndef FIPS_MODULE
 | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | /* The default default context */ | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static OSSL_LIB_CTX default_context_int; | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | static CRYPTO_ONCE default_context_init = CRYPTO_ONCE_STATIC_INIT; | 
					
						
							|  |  |  | static CRYPTO_THREAD_LOCAL default_context_thread_local; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DEFINE_RUN_ONCE_STATIC(default_context_do_init) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return CRYPTO_THREAD_init_local(&default_context_thread_local, NULL) | 
					
						
							|  |  |  |         && context_init(&default_context_int); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | void ossl_lib_ctx_default_deinit(void) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  |     context_deinit(&default_context_int); | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static OSSL_LIB_CTX *get_thread_default_context(void) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  |     if (!RUN_ONCE(&default_context_init, default_context_do_init)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  |     return CRYPTO_THREAD_get_local(&default_context_thread_local); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static OSSL_LIB_CTX *get_default_context(void) | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     OSSL_LIB_CTX *current_defctx = get_thread_default_context(); | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (current_defctx == NULL) | 
					
						
							|  |  |  |         current_defctx = &default_context_int; | 
					
						
							|  |  |  |     return current_defctx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static int set_default_context(OSSL_LIB_CTX *defctx) | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     if (defctx == &default_context_int) | 
					
						
							|  |  |  |         defctx = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return CRYPTO_THREAD_set_local(&default_context_thread_local, defctx); | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | OSSL_LIB_CTX *OSSL_LIB_CTX_new(void) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     OSSL_LIB_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (ctx != NULL && !context_init(ctx)) { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |         OSSL_LIB_CTX_free(ctx); | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  |         ctx = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ctx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-14 04:34:56 +08:00
										 |  |  | #ifndef FIPS_MODULE
 | 
					
						
							| 
									
										
										
										
											2021-04-21 23:51:41 +08:00
										 |  |  | OSSL_LIB_CTX *OSSL_LIB_CTX_new_from_dispatch(const OSSL_CORE_HANDLE *handle, | 
					
						
							|  |  |  |                                              const OSSL_DISPATCH *in) | 
					
						
							| 
									
										
										
										
											2021-04-28 02:56:39 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     OSSL_LIB_CTX *ctx = OSSL_LIB_CTX_new(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!ossl_bio_init_core(ctx, in)) { | 
					
						
							|  |  |  |         OSSL_LIB_CTX_free(ctx); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ctx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-21 23:51:41 +08:00
										 |  |  | OSSL_LIB_CTX *OSSL_LIB_CTX_new_child(const OSSL_CORE_HANDLE *handle, | 
					
						
							|  |  |  |                                      const OSSL_DISPATCH *in) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     OSSL_LIB_CTX *ctx = OSSL_LIB_CTX_new_from_dispatch(handle, in); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!ossl_provider_init_as_child(ctx, handle, in)) { | 
					
						
							|  |  |  |         OSSL_LIB_CTX_free(ctx); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ctx->ischild = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ctx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | int OSSL_LIB_CTX_load_config(OSSL_LIB_CTX *ctx, const char *config_file) | 
					
						
							| 
									
										
										
										
											2020-03-20 18:25:39 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-24 17:42:23 +08:00
										 |  |  |     return CONF_modules_load_file_ex(ctx, config_file, NULL, 0) > 0; | 
					
						
							| 
									
										
										
										
											2020-03-20 18:25:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | void OSSL_LIB_CTX_free(OSSL_LIB_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     if (ossl_lib_ctx_is_default(ctx)) | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context_deinit(ctx); | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  |     OPENSSL_free(ctx); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 18:13:30 +08:00
										 |  |  | #ifndef FIPS_MODULE
 | 
					
						
							|  |  |  | OSSL_LIB_CTX *OSSL_LIB_CTX_get0_global_default(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!RUN_ONCE(&default_context_init, default_context_do_init)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return &default_context_int; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | OSSL_LIB_CTX *OSSL_LIB_CTX_set0_default(OSSL_LIB_CTX *libctx) | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     OSSL_LIB_CTX *current_defctx; | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-15 23:46:35 +08:00
										 |  |  |     if ((current_defctx = get_default_context()) != NULL) { | 
					
						
							|  |  |  |         if (libctx != NULL) | 
					
						
							|  |  |  |             set_default_context(libctx); | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  |         return current_defctx; | 
					
						
							| 
									
										
										
										
											2021-04-15 23:46:35 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-04-16 18:13:30 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | OSSL_LIB_CTX *ossl_lib_ctx_get_concrete(OSSL_LIB_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2019-05-28 22:58:08 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-14 04:34:56 +08:00
										 |  |  | #ifndef FIPS_MODULE
 | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return get_default_context(); | 
					
						
							| 
									
										
										
										
											2019-05-28 22:58:08 +08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |     return ctx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | int ossl_lib_ctx_is_default(OSSL_LIB_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2020-03-25 20:12:59 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-14 04:34:56 +08:00
										 |  |  | #ifndef FIPS_MODULE
 | 
					
						
							| 
									
										
										
										
											2020-06-22 19:12:53 +08:00
										 |  |  |     if (ctx == NULL || ctx == get_default_context()) | 
					
						
							| 
									
										
										
										
											2020-03-25 20:12:59 +08:00
										 |  |  |         return 1; | 
					
						
							| 
									
										
										
										
											2020-06-23 16:09:20 +08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | int ossl_lib_ctx_is_global_default(OSSL_LIB_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2020-06-23 16:09:20 +08:00
										 |  |  | { | 
					
						
							|  |  |  | #ifndef FIPS_MODULE
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     if (ossl_lib_ctx_get_concrete(ctx) == &default_context_int) | 
					
						
							| 
									
										
										
										
											2020-06-23 16:09:20 +08:00
										 |  |  |         return 1; | 
					
						
							| 
									
										
										
										
											2020-03-25 20:12:59 +08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static void ossl_lib_ctx_generic_new(void *parent_ign, void *ptr_ign, | 
					
						
							|  |  |  |                                      CRYPTO_EX_DATA *ad, int index, | 
					
						
							|  |  |  |                                      long argl_ign, void *argp) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     const OSSL_LIB_CTX_METHOD *meth = argp; | 
					
						
							| 
									
										
										
										
											2021-02-24 16:07:52 +08:00
										 |  |  |     OSSL_LIB_CTX *ctx = ossl_crypto_ex_data_get_ossl_lib_ctx(ad); | 
					
						
							| 
									
										
										
										
											2021-01-08 21:22:59 +08:00
										 |  |  |     void *ptr = meth->new_func(ctx); | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 21:22:59 +08:00
										 |  |  |     if (ptr != NULL) { | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  |         if (!CRYPTO_THREAD_write_lock(ctx->lock)) | 
					
						
							|  |  |  |             /*
 | 
					
						
							|  |  |  |              * Can't return something, so best to hope that something will | 
					
						
							|  |  |  |              * fail later. :( | 
					
						
							|  |  |  |              */ | 
					
						
							|  |  |  |             return; | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  |         CRYPTO_set_ex_data(ad, index, ptr); | 
					
						
							| 
									
										
										
										
											2021-01-08 21:22:59 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->lock); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static void ossl_lib_ctx_generic_free(void *parent_ign, void *ptr, | 
					
						
							|  |  |  |                                       CRYPTO_EX_DATA *ad, int index, | 
					
						
							|  |  |  |                                       long argl_ign, void *argp) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     const OSSL_LIB_CTX_METHOD *meth = argp; | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     meth->free_func(ptr); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | static int ossl_lib_ctx_init_index(OSSL_LIB_CTX *ctx, int static_index, | 
					
						
							|  |  |  |                                    const OSSL_LIB_CTX_METHOD *meth) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     int idx; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     ctx = ossl_lib_ctx_get_concrete(ctx); | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 16:07:52 +08:00
										 |  |  |     idx = ossl_crypto_get_ex_new_index_ex(ctx, CRYPTO_EX_INDEX_OSSL_LIB_CTX, 0, | 
					
						
							|  |  |  |                                           (void *)meth, | 
					
						
							|  |  |  |                                           ossl_lib_ctx_generic_new, | 
					
						
							| 
									
										
										
										
											2021-04-26 18:35:17 +08:00
										 |  |  |                                           NULL, ossl_lib_ctx_generic_free, | 
					
						
							|  |  |  |                                           meth->priority); | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     if (idx < 0) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ctx->dyn_indexes[static_index] = idx; | 
					
						
							|  |  |  |     return 1; | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | void *ossl_lib_ctx_get_data(OSSL_LIB_CTX *ctx, int index, | 
					
						
							|  |  |  |                             const OSSL_LIB_CTX_METHOD *meth) | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     void *data = NULL; | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |     int dynidx; | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     ctx = ossl_lib_ctx_get_concrete(ctx); | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  |     if (!CRYPTO_THREAD_read_lock(ctx->lock)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |     dynidx = ctx->dyn_indexes[index]; | 
					
						
							|  |  |  |     CRYPTO_THREAD_unlock(ctx->lock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (dynidx != -1) { | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  |         if (!CRYPTO_THREAD_read_lock(ctx->index_locks[index])) | 
					
						
							|  |  |  |             return NULL; | 
					
						
							|  |  |  |         if (!CRYPTO_THREAD_read_lock(ctx->lock)) { | 
					
						
							|  |  |  |             CRYPTO_THREAD_unlock(ctx->index_locks[index]); | 
					
						
							|  |  |  |             return NULL; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |         data = CRYPTO_get_ex_data(&ctx->data, dynidx); | 
					
						
							| 
									
										
										
										
											2021-01-27 01:00:25 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->lock); | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->index_locks[index]); | 
					
						
							|  |  |  |         return data; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  |     if (!CRYPTO_THREAD_write_lock(ctx->index_locks[index])) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     if (!CRYPTO_THREAD_write_lock(ctx->lock)) { | 
					
						
							|  |  |  |         CRYPTO_THREAD_unlock(ctx->index_locks[index]); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     dynidx = ctx->dyn_indexes[index]; | 
					
						
							|  |  |  |     if (dynidx != -1) { | 
					
						
							|  |  |  |         data = CRYPTO_get_ex_data(&ctx->data, dynidx); | 
					
						
							| 
									
										
										
										
											2021-01-27 01:00:25 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->lock); | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->index_locks[index]); | 
					
						
							|  |  |  |         return data; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     if (!ossl_lib_ctx_init_index(ctx, index, meth)) { | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->lock); | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->index_locks[index]); | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |     CRYPTO_THREAD_unlock(ctx->lock); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 01:00:25 +08:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * The alloc call ensures there's a value there. We release the ctx->lock | 
					
						
							|  |  |  |      * for this, because the allocation itself may recursively call | 
					
						
							|  |  |  |      * ossl_lib_ctx_get_data for other indexes (never this one). The allocation | 
					
						
							|  |  |  |      * will itself aquire the ctx->lock when it actually comes to store the | 
					
						
							|  |  |  |      * allocated data (see ossl_lib_ctx_generic_new() above). We call | 
					
						
							|  |  |  |      * ossl_crypto_alloc_ex_data_intern() here instead of CRYPTO_alloc_ex_data(). | 
					
						
							|  |  |  |      * They do the same thing except that the latter calls CRYPTO_get_ex_data() | 
					
						
							|  |  |  |      * as well - which we must not do without holding the ctx->lock. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (ossl_crypto_alloc_ex_data_intern(CRYPTO_EX_INDEX_OSSL_LIB_CTX, NULL, | 
					
						
							|  |  |  |                                          &ctx->data, ctx->dyn_indexes[index])) { | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  |         if (!CRYPTO_THREAD_read_lock(ctx->lock)) | 
					
						
							|  |  |  |             goto end; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |         data = CRYPTO_get_ex_data(&ctx->data, ctx->dyn_indexes[index]); | 
					
						
							| 
									
										
										
										
											2021-01-27 01:00:25 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->lock); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  | end: | 
					
						
							| 
									
										
										
										
											2019-08-14 21:43:11 +08:00
										 |  |  |     CRYPTO_THREAD_unlock(ctx->index_locks[index]); | 
					
						
							| 
									
										
										
										
											2019-02-07 00:42:50 +08:00
										 |  |  |     return data; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | OSSL_EX_DATA_GLOBAL *ossl_lib_ctx_get_ex_data_global(OSSL_LIB_CTX *ctx) | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     ctx = ossl_lib_ctx_get_concrete(ctx); | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     return &ctx->global; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | int ossl_lib_ctx_run_once(OSSL_LIB_CTX *ctx, unsigned int idx, | 
					
						
							|  |  |  |                           ossl_lib_ctx_run_once_fn run_once_fn) | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     int done = 0, ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     ctx = ossl_lib_ctx_get_concrete(ctx); | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  |     if (ctx == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  |     if (!CRYPTO_THREAD_read_lock(ctx->oncelock)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  |     done = ctx->run_once_done[idx]; | 
					
						
							|  |  |  |     if (done) | 
					
						
							|  |  |  |         ret = ctx->run_once_ret[idx]; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     CRYPTO_THREAD_unlock(ctx->oncelock); | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (done) | 
					
						
							|  |  |  |         return ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 04:31:56 +08:00
										 |  |  |     if (!CRYPTO_THREAD_write_lock(ctx->oncelock)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  |     if (ctx->run_once_done[idx]) { | 
					
						
							|  |  |  |         ret = ctx->run_once_ret[idx]; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |         CRYPTO_THREAD_unlock(ctx->oncelock); | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  |         return ret; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ret = run_once_fn(ctx); | 
					
						
							|  |  |  |     ctx->run_once_done[idx] = 1; | 
					
						
							|  |  |  |     ctx->run_once_ret[idx] = ret; | 
					
						
							| 
									
										
										
										
											2019-05-01 18:02:43 +08:00
										 |  |  |     CRYPTO_THREAD_unlock(ctx->oncelock); | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  | int ossl_lib_ctx_onfree(OSSL_LIB_CTX *ctx, ossl_lib_ctx_onfree_fn onfreefn) | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-15 17:55:50 +08:00
										 |  |  |     struct ossl_lib_ctx_onfree_list_st *newonfree | 
					
						
							| 
									
										
										
										
											2019-04-30 22:15:48 +08:00
										 |  |  |         = OPENSSL_malloc(sizeof(*newonfree)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (newonfree == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     newonfree->fn = onfreefn; | 
					
						
							|  |  |  |     newonfree->next = ctx->onfreelist; | 
					
						
							|  |  |  |     ctx->onfreelist = newonfree; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-10-17 13:07:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const char *ossl_lib_ctx_get_descriptor(OSSL_LIB_CTX *libctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #ifdef FIPS_MODULE
 | 
					
						
							|  |  |  |     return "FIPS internal library context"; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |     if (ossl_lib_ctx_is_global_default(libctx)) | 
					
						
							|  |  |  |         return "Global default library context"; | 
					
						
							|  |  |  |     if (ossl_lib_ctx_is_default(libctx)) | 
					
						
							|  |  |  |         return "Thread-local default library context"; | 
					
						
							|  |  |  |     return "Non-default library context"; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } |