summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto.h
diff options
context:
space:
mode:
authorbcook <>2018-11-11 06:41:28 +0000
committerbcook <>2018-11-11 06:41:28 +0000
commitc3082ab78ba758ef51c552b6a91bdf1236de0cf8 (patch)
tree6d18ff101148258c403e820ff423d10a65fba89e /src/lib/libcrypto/crypto.h
parent32ccc9aa9f3dd1c0efa02d4b21376521a91e4705 (diff)
downloadopenbsd-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.h54
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. */
371void CRYPTO_cleanup_all_ex_data(void); 363void CRYPTO_cleanup_all_ex_data(void);
372 364
373int CRYPTO_get_new_lockid(char *name);
374
375int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
376void CRYPTO_lock(int mode, int type, const char *file, int line); 365void CRYPTO_lock(int mode, int type, const char *file, int line);
377void CRYPTO_set_locking_callback(void (*func)(int mode, int type, 366int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
378 const char *file, int line)); 367 int line);
379void (*CRYPTO_get_locking_callback(void))(int mode, int type,
380 const char *file, int line);
381void CRYPTO_set_add_lock_callback(int (*func)(int *num, int mount, int type,
382 const char *file, int line));
383int (*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. */
387typedef struct crypto_threadid_st { 370typedef 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 */
392void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val);
393void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr);
394int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID *));
395void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID *);
396void CRYPTO_THREADID_current(CRYPTO_THREADID *id); 374void CRYPTO_THREADID_current(CRYPTO_THREADID *id);
397int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a, const CRYPTO_THREADID *b); 375int CRYPTO_THREADID_cmp(const CRYPTO_THREADID *a, const CRYPTO_THREADID *b);
398void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest, const CRYPTO_THREADID *src); 376void CRYPTO_THREADID_cpy(CRYPTO_THREADID *dest, const CRYPTO_THREADID *src);
399unsigned long CRYPTO_THREADID_hash(const CRYPTO_THREADID *id); 377unsigned 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 */
401void CRYPTO_set_id_callback(unsigned long (*func)(void)); 381void CRYPTO_set_id_callback(unsigned long (*func)(void));
402unsigned long (*CRYPTO_get_id_callback(void))(void); 382unsigned long (*CRYPTO_get_id_callback(void))(void);
403unsigned long CRYPTO_thread_id(void); 383unsigned long CRYPTO_thread_id(void);
404#endif
405 384
385int CRYPTO_get_new_lockid(char *name);
406const char *CRYPTO_get_lock_name(int type); 386const char *CRYPTO_get_lock_name(int type);
407int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
408 int line);
409 387
388int CRYPTO_num_locks(void);
389void CRYPTO_set_locking_callback(void (*func)(int mode, int type,
390 const char *file, int line));
391void (*CRYPTO_get_locking_callback(void))(int mode, int type,
392 const char *file, int line);
393void CRYPTO_set_add_lock_callback(int (*func)(int *num, int mount, int type,
394 const char *file, int line));
395int (*CRYPTO_get_add_lock_callback(void))(int *num, int mount, int type,
396 const char *file, int line);
397
398void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val);
399void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr);
400int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID *));
401void (*CRYPTO_THREADID_get_callback(void))(CRYPTO_THREADID *);
402#endif
403
404#ifndef LIBRESSL_INTERNAL
410int CRYPTO_get_new_dynlockid(void); 405int CRYPTO_get_new_dynlockid(void);
411void CRYPTO_destroy_dynlockid(int i); 406void CRYPTO_destroy_dynlockid(int i);
412struct CRYPTO_dynlock_value *CRYPTO_get_dynlock_value(int i); 407struct 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
416struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file, int line); 411struct CRYPTO_dynlock_value *(*CRYPTO_get_dynlock_create_callback(void))(const char *file, int line);
417void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line); 412void (*CRYPTO_get_dynlock_lock_callback(void))(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line);
418void (*CRYPTO_get_dynlock_destroy_callback(void))(struct CRYPTO_dynlock_value *l, const char *file, int line); 413void (*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 */