diff options
| author | tb <> | 2023-07-28 10:19:20 +0000 |
|---|---|---|
| committer | tb <> | 2023-07-28 10:19:20 +0000 |
| commit | df077cec5ce229b03845385f6f75dbe7cd5f7080 (patch) | |
| tree | 2ee287d6ab4c68a054e3379b662b9a6d1a67c316 /src/lib/libcrypto/ex_data.c | |
| parent | e393551162848dd712d0c5a922f6ef5522fb5ca2 (diff) | |
| download | openbsd-df077cec5ce229b03845385f6f75dbe7cd5f7080.tar.gz openbsd-df077cec5ce229b03845385f6f75dbe7cd5f7080.tar.bz2 openbsd-df077cec5ce229b03845385f6f75dbe7cd5f7080.zip | |
Make ex_data implementations internal
To state the obvious: library suffers from way too much extensibility. In
theory, applications can implement their own ex_data implementation. In
practice, none did. A glance at ex_data.c might give an idea as to why.
Make this internal so this particular turd can be replaced with something
slightly saner.
Also sync up the CRYPTO_EX_INDEX_* defines with OpenSSL - at least
the parts we support.
ok jsing
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/ex_data.c | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c index 71b2fc397b..17db16e58d 100644 --- a/src/lib/libcrypto/ex_data.c +++ b/src/lib/libcrypto/ex_data.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ex_data.c,v 1.22 2023/07/08 08:28:23 beck Exp $ */ | 1 | /* $OpenBSD: ex_data.c,v 1.23 2023/07/28 10:19:20 tb Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Overhaul notes; | 4 | * Overhaul notes; |
| @@ -141,6 +141,26 @@ | |||
| 141 | #include <openssl/err.h> | 141 | #include <openssl/err.h> |
| 142 | #include <openssl/lhash.h> | 142 | #include <openssl/lhash.h> |
| 143 | 143 | ||
| 144 | typedef struct crypto_ex_data_func_st { | ||
| 145 | long argl; /* Arbitrary long */ | ||
| 146 | void *argp; /* Arbitrary void * */ | ||
| 147 | CRYPTO_EX_new *new_func; | ||
| 148 | CRYPTO_EX_free *free_func; | ||
| 149 | CRYPTO_EX_dup *dup_func; | ||
| 150 | } CRYPTO_EX_DATA_FUNCS; | ||
| 151 | |||
| 152 | DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS) | ||
| 153 | |||
| 154 | #define sk_CRYPTO_EX_DATA_FUNCS_new_null() SKM_sk_new_null(CRYPTO_EX_DATA_FUNCS) | ||
| 155 | #define sk_CRYPTO_EX_DATA_FUNCS_num(st) SKM_sk_num(CRYPTO_EX_DATA_FUNCS, (st)) | ||
| 156 | #define sk_CRYPTO_EX_DATA_FUNCS_value(st, i) SKM_sk_value(CRYPTO_EX_DATA_FUNCS, (st), (i)) | ||
| 157 | #define sk_CRYPTO_EX_DATA_FUNCS_set(st, i, val) SKM_sk_set(CRYPTO_EX_DATA_FUNCS, (st), (i), (val)) | ||
| 158 | #define sk_CRYPTO_EX_DATA_FUNCS_push(st, val) SKM_sk_push(CRYPTO_EX_DATA_FUNCS, (st), (val)) | ||
| 159 | #define sk_CRYPTO_EX_DATA_FUNCS_pop_free(st, free_func) SKM_sk_pop_free(CRYPTO_EX_DATA_FUNCS, (st), (free_func)) | ||
| 160 | |||
| 161 | /* An opaque type representing an implementation of "ex_data" support */ | ||
| 162 | typedef struct st_CRYPTO_EX_DATA_IMPL CRYPTO_EX_DATA_IMPL; | ||
| 163 | |||
| 144 | /* What an "implementation of ex_data functionality" looks like */ | 164 | /* What an "implementation of ex_data functionality" looks like */ |
| 145 | struct st_CRYPTO_EX_DATA_IMPL { | 165 | struct st_CRYPTO_EX_DATA_IMPL { |
| 146 | /*********************/ | 166 | /*********************/ |
| @@ -210,29 +230,6 @@ impl_check(void) | |||
| 210 | * invoking the function (which checks again inside a lock). */ | 230 | * invoking the function (which checks again inside a lock). */ |
| 211 | #define IMPL_CHECK if(!impl) impl_check(); | 231 | #define IMPL_CHECK if(!impl) impl_check(); |
| 212 | 232 | ||
| 213 | /* API functions to get/set the "ex_data" implementation */ | ||
| 214 | const CRYPTO_EX_DATA_IMPL * | ||
| 215 | CRYPTO_get_ex_data_implementation(void) | ||
| 216 | { | ||
| 217 | IMPL_CHECK | ||
| 218 | return impl; | ||
| 219 | } | ||
| 220 | LCRYPTO_ALIAS(CRYPTO_get_ex_data_implementation); | ||
| 221 | |||
| 222 | int | ||
| 223 | CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i) | ||
| 224 | { | ||
| 225 | int toret = 0; | ||
| 226 | CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); | ||
| 227 | if (!impl) { | ||
| 228 | impl = i; | ||
| 229 | toret = 1; | ||
| 230 | } | ||
| 231 | CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); | ||
| 232 | return toret; | ||
| 233 | } | ||
| 234 | LCRYPTO_ALIAS(CRYPTO_set_ex_data_implementation); | ||
| 235 | |||
| 236 | /****************************************************************************/ | 233 | /****************************************************************************/ |
| 237 | /* Interal (default) implementation of "ex_data" support. API functions are | 234 | /* Interal (default) implementation of "ex_data" support. API functions are |
| 238 | * further down. */ | 235 | * further down. */ |
| @@ -247,6 +244,7 @@ typedef struct st_ex_class_item { | |||
| 247 | } EX_CLASS_ITEM; | 244 | } EX_CLASS_ITEM; |
| 248 | 245 | ||
| 249 | /* When assigning new class indexes, this is our counter */ | 246 | /* When assigning new class indexes, this is our counter */ |
| 247 | #define CRYPTO_EX_INDEX_USER 100 | ||
| 250 | static int ex_class = CRYPTO_EX_INDEX_USER; | 248 | static int ex_class = CRYPTO_EX_INDEX_USER; |
| 251 | 249 | ||
| 252 | /* The global hash table of EX_CLASS_ITEM items */ | 250 | /* The global hash table of EX_CLASS_ITEM items */ |
| @@ -541,16 +539,6 @@ skip: | |||
| 541 | /* API functions that defer all "state" operations to the "ex_data" | 539 | /* API functions that defer all "state" operations to the "ex_data" |
| 542 | * implementation we have set. */ | 540 | * implementation we have set. */ |
| 543 | 541 | ||
| 544 | /* Obtain an index for a new class (not the same as getting a new index within | ||
| 545 | * an existing class - this is actually getting a new *class*) */ | ||
| 546 | int | ||
| 547 | CRYPTO_ex_data_new_class(void) | ||
| 548 | { | ||
| 549 | IMPL_CHECK | ||
| 550 | return EX_IMPL(new_class)(); | ||
| 551 | } | ||
| 552 | LCRYPTO_ALIAS(CRYPTO_ex_data_new_class); | ||
| 553 | |||
| 554 | /* Release all "ex_data" state to prevent memory leaks. This can't be made | 542 | /* Release all "ex_data" state to prevent memory leaks. This can't be made |
| 555 | * thread-safe without overhauling a lot of stuff, and shouldn't really be | 543 | * thread-safe without overhauling a lot of stuff, and shouldn't really be |
| 556 | * called under potential race-conditions anyway (it's for program shutdown | 544 | * called under potential race-conditions anyway (it's for program shutdown |
