diff options
author | bcook <> | 2018-11-11 06:41:28 +0000 |
---|---|---|
committer | bcook <> | 2018-11-11 06:41:28 +0000 |
commit | c3082ab78ba758ef51c552b6a91bdf1236de0cf8 (patch) | |
tree | 6d18ff101148258c403e820ff423d10a65fba89e /src/lib/libcrypto/crypto.h | |
parent | 32ccc9aa9f3dd1c0efa02d4b21376521a91e4705 (diff) | |
download | openbsd-c3082ab78ba758ef51c552b6a91bdf1236de0cf8.tar.gz openbsd-c3082ab78ba758ef51c552b6a91bdf1236de0cf8.tar.bz2 openbsd-c3082ab78ba758ef51c552b6a91bdf1236de0cf8.zip |
Add automatic threading initialization for libcrypto.
This implements automatic thread support initialization in libcrypto.
This does not remove any functions from the ABI, but does turn them into
no-ops. Stub implementations of pthread_mutex_(init|lock|unlock) are
provided for ramdisks.
This does not implement the new OpenSSL 1.1 thread API internally,
keeping the original CRYTPO_lock / CRYPTO_add_lock functions for library
locking. For -portable, crypto_lock.c can be reimplemented with
OS-specific primitives as needed.
ok beck@, tb@, looks sane guenther@
Diffstat (limited to 'src/lib/libcrypto/crypto.h')
-rw-r--r-- | src/lib/libcrypto/crypto.h | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h index e614c6ad65..744079b5bd 100644 --- a/src/lib/libcrypto/crypto.h +++ b/src/lib/libcrypto/crypto.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: crypto.h,v 1.47 2018/08/24 19:16:03 tb Exp $ */ | 1 | /* $OpenBSD: crypto.h,v 1.48 2018/11/11 06:41:28 bcook Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -203,7 +203,6 @@ typedef struct openssl_item_st { | |||
203 | #define CRYPTO_READ 4 | 203 | #define CRYPTO_READ 4 |
204 | #define CRYPTO_WRITE 8 | 204 | #define CRYPTO_WRITE 8 |
205 | 205 | ||
206 | #ifndef OPENSSL_NO_LOCKING | ||
207 | #ifndef CRYPTO_w_lock | 206 | #ifndef CRYPTO_w_lock |
208 | #define CRYPTO_w_lock(type) \ | 207 | #define CRYPTO_w_lock(type) \ |
209 | CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) | 208 | CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) |
@@ -216,13 +215,6 @@ typedef struct openssl_item_st { | |||
216 | #define CRYPTO_add(addr,amount,type) \ | 215 | #define CRYPTO_add(addr,amount,type) \ |
217 | CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__) | 216 | CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__) |
218 | #endif | 217 | #endif |
219 | #else | ||
220 | #define CRYPTO_w_lock(a) | ||
221 | #define CRYPTO_w_unlock(a) | ||
222 | #define CRYPTO_r_lock(a) | ||
223 | #define CRYPTO_r_unlock(a) | ||
224 | #define CRYPTO_add(a,b,c) ((*(a))+=(b)) | ||
225 | #endif | ||
226 | 218 | ||
227 | /* Some applications as well as some parts of OpenSSL need to allocate | 219 | /* Some applications as well as some parts of OpenSSL need to allocate |
228 | and deallocate locks in a dynamic fashion. The following typedef | 220 | and deallocate locks in a dynamic fashion. The following typedef |
@@ -370,43 +362,46 @@ void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx); | |||
370 | * potential race-conditions. */ | 362 | * potential race-conditions. */ |
371 | void CRYPTO_cleanup_all_ex_data(void); | 363 | void CRYPTO_cleanup_all_ex_data(void); |
372 | 364 | ||
373 | int CRYPTO_get_new_lockid(char *name); | ||
374 | |||
375 | int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */ | ||
376 | void CRYPTO_lock(int mode, int type, const char *file, int line); | 365 | void CRYPTO_lock(int mode, int type, const char *file, int line); |
377 | void CRYPTO_set_locking_callback(void (*func)(int mode, int type, | 366 | int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, |
378 | const char *file, int line)); | 367 | int line); |
379 | void (*CRYPTO_get_locking_callback(void))(int mode, int type, | ||
380 | const char *file, int line); | ||
381 | void CRYPTO_set_add_lock_callback(int (*func)(int *num, int mount, int type, | ||
382 | const char *file, int line)); | ||
383 | int (*CRYPTO_get_add_lock_callback(void))(int *num, int mount, int type, | ||
384 | const char *file, int line); | ||
385 | 368 | ||
386 | /* Don't use this structure directly. */ | 369 | /* Don't use this structure directly. */ |
387 | typedef struct crypto_threadid_st { | 370 | typedef struct crypto_threadid_st { |
388 | void *ptr; | 371 | void *ptr; |
389 | unsigned long val; | 372 | unsigned long val; |
390 | } CRYPTO_THREADID; | 373 | } CRYPTO_THREADID; |
391 | /* Only use CRYPTO_THREADID_set_[numeric|pointer]() within callbacks */ | ||
392 | void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val); | ||
393 | void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr); | ||
394 | int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID *)); | ||
395 | void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID *); | ||
396 | void CRYPTO_THREADID_current(CRYPTO_THREADID *id); | 374 | void CRYPTO_THREADID_current(CRYPTO_THREADID *id); |
397 | int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a, const CRYPTO_THREADID *b); | 375 | int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a, const CRYPTO_THREADID *b); |
398 | void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest, const CRYPTO_THREADID *src); | 376 | void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest, const CRYPTO_THREADID *src); |
399 | unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id); | 377 | unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id); |
400 | #ifndef OPENSSL_NO_DEPRECATED | 378 | |
379 | #ifndef LIBRESSL_INTERNAL | ||
380 | /* These functions are deprecated no-op stubs */ | ||
401 | void CRYPTO_set_id_callback(unsigned long (*func)(void)); | 381 | void CRYPTO_set_id_callback(unsigned long (*func)(void)); |
402 | unsigned long (*CRYPTO_get_id_callback(void))(void); | 382 | unsigned long (*CRYPTO_get_id_callback(void))(void); |
403 | unsigned long CRYPTO_thread_id(void); | 383 | unsigned long CRYPTO_thread_id(void); |
404 | #endif | ||
405 | 384 | ||
385 | int CRYPTO_get_new_lockid(char *name); | ||
406 | const char *CRYPTO_get_lock_name(int type); | 386 | const char *CRYPTO_get_lock_name(int type); |
407 | int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, | ||
408 | int line); | ||
409 | 387 | ||
388 | int CRYPTO_num_locks(void); | ||
389 | void CRYPTO_set_locking_callback(void (*func)(int mode, int type, | ||
390 | const char *file, int line)); | ||
391 | void (*CRYPTO_get_locking_callback(void))(int mode, int type, | ||
392 | const char *file, int line); | ||
393 | void CRYPTO_set_add_lock_callback(int (*func)(int *num, int mount, int type, | ||
394 | const char *file, int line)); | ||
395 | int (*CRYPTO_get_add_lock_callback(void))(int *num, int mount, int type, | ||
396 | const char *file, int line); | ||
397 | |||
398 | void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val); | ||
399 | void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr); | ||
400 | int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID *)); | ||
401 | void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID *); | ||
402 | #endif | ||
403 | |||
404 | #ifndef LIBRESSL_INTERNAL | ||
410 | int CRYPTO_get_new_dynlockid(void); | 405 | int CRYPTO_get_new_dynlockid(void); |
411 | void CRYPTO_destroy_dynlockid(int i); | 406 | void CRYPTO_destroy_dynlockid(int i); |
412 | struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i); | 407 | struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i); |
@@ -416,6 +411,7 @@ void CRYPTO_set_dynlock_destroy_callback(void (*dyn_destroy_function)(struct CRY | |||
416 | struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file, int line); | 411 | struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file, int line); |
417 | void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line); | 412 | void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line); |
418 | void (*CRYPTO_get_dynlock_destroy_callback(void))(struct CRYPTO_dynlock_value *l, const char *file, int line); | 413 | void (*CRYPTO_get_dynlock_destroy_callback(void))(struct CRYPTO_dynlock_value *l, const char *file, int line); |
414 | #endif | ||
419 | 415 | ||
420 | /* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions -- | 416 | /* CRYPTO_set_mem_functions includes CRYPTO_set_locked_mem_functions -- |
421 | * call the latter last if you need different functions */ | 417 | * call the latter last if you need different functions */ |