summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/err
diff options
context:
space:
mode:
authorbeck <>2018-03-17 16:20:01 +0000
committerbeck <>2018-03-17 16:20:01 +0000
commitd18ae25f28e72831dc3c51f78e0735342540098b (patch)
tree12cc674e7652f4d67e57ec9e1882e6e824b4808d /src/lib/libcrypto/err
parent736fdc7bedf7fe8b17717032f7380c5c6e247d0d (diff)
downloadopenbsd-d18ae25f28e72831dc3c51f78e0735342540098b.tar.gz
openbsd-d18ae25f28e72831dc3c51f78e0735342540098b.tar.bz2
openbsd-d18ae25f28e72831dc3c51f78e0735342540098b.zip
Bring in compatibility for OpenSSL 1.1 style init functions.
This adds OPENSSL_init_crypto and OPENSSL_init_ssl, as well thread safety modifications for the existing LibreSSL init functions. The initialization routines are called automatically by the normal entry points into the library, as in newer OpenSSL ok jsing@, nits by tb@ and deraadt@
Diffstat (limited to 'src/lib/libcrypto/err')
-rw-r--r--src/lib/libcrypto/err/err.c32
-rw-r--r--src/lib/libcrypto/err/err_all.c18
2 files changed, 44 insertions, 6 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index ffe25bf465..320078da66 100644
--- a/src/lib/libcrypto/err/err.c
+++ b/src/lib/libcrypto/err/err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: err.c,v 1.45 2017/02/20 23:21:19 beck Exp $ */ 1/* $OpenBSD: err.c,v 1.46 2018/03/17 16:20:01 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -109,6 +109,7 @@
109 * 109 *
110 */ 110 */
111 111
112#include <pthread.h>
112#include <stdarg.h> 113#include <stdarg.h>
113#include <stdio.h> 114#include <stdio.h>
114#include <string.h> 115#include <string.h>
@@ -282,6 +283,8 @@ static LHASH_OF(ERR_STATE) *int_thread_hash = NULL;
282static int int_thread_hash_references = 0; 283static int int_thread_hash_references = 0;
283static int int_err_library_number = ERR_LIB_USER; 284static int int_err_library_number = ERR_LIB_USER;
284 285
286static pthread_t err_init_thread;
287
285/* Internal function that checks whether "err_fns" is set and if not, sets it to 288/* Internal function that checks whether "err_fns" is set and if not, sets it to
286 * the defaults. */ 289 * the defaults. */
287static void 290static void
@@ -650,8 +653,9 @@ ERR_STATE_free(ERR_STATE *s)
650} 653}
651 654
652void 655void
653ERR_load_ERR_strings(void) 656ERR_load_ERR_strings_internal(void)
654{ 657{
658 err_init_thread = pthread_self();
655 err_fns_check(); 659 err_fns_check();
656#ifndef OPENSSL_NO_ERR 660#ifndef OPENSSL_NO_ERR
657 err_load_strings(0, ERR_str_libraries); 661 err_load_strings(0, ERR_str_libraries);
@@ -662,6 +666,21 @@ ERR_load_ERR_strings(void)
662#endif 666#endif
663} 667}
664 668
669
670void
671ERR_load_ERR_strings(void)
672{
673 static pthread_once_t once = PTHREAD_ONCE_INIT;
674
675 if (pthread_equal(pthread_self(), err_init_thread))
676 return; /* don't recurse */
677
678 /* Prayer and clean living lets you ignore errors, OpenSSL style */
679 (void) OPENSSL_init_crypto(0, NULL);
680
681 (void) pthread_once(&once, ERR_load_ERR_strings_internal);
682}
683
665static void 684static void
666err_load_strings(int lib, ERR_STRING_DATA *str) 685err_load_strings(int lib, ERR_STRING_DATA *str)
667{ 686{
@@ -683,6 +702,9 @@ ERR_load_strings(int lib, ERR_STRING_DATA *str)
683void 702void
684ERR_unload_strings(int lib, ERR_STRING_DATA *str) 703ERR_unload_strings(int lib, ERR_STRING_DATA *str)
685{ 704{
705 /* Prayer and clean living lets you ignore errors, OpenSSL style */
706 (void) OPENSSL_init_crypto(0, NULL);
707
686 while (str->error) { 708 while (str->error) {
687 if (lib) 709 if (lib)
688 str->error |= ERR_PACK(lib, 0, 0); 710 str->error |= ERR_PACK(lib, 0, 0);
@@ -694,6 +716,9 @@ ERR_unload_strings(int lib, ERR_STRING_DATA *str)
694void 716void
695ERR_free_strings(void) 717ERR_free_strings(void)
696{ 718{
719 /* Prayer and clean living lets you ignore errors, OpenSSL style */
720 (void) OPENSSL_init_crypto(0, NULL);
721
697 err_fns_check(); 722 err_fns_check();
698 ERRFN(err_del)(); 723 ERRFN(err_del)();
699} 724}
@@ -953,6 +978,9 @@ ERR_lib_error_string(unsigned long e)
953 ERR_STRING_DATA d, *p; 978 ERR_STRING_DATA d, *p;
954 unsigned long l; 979 unsigned long l;
955 980
981 if (!OPENSSL_init_crypto(0, NULL))
982 return NULL;
983
956 err_fns_check(); 984 err_fns_check();
957 l = ERR_GET_LIB(e); 985 l = ERR_GET_LIB(e);
958 d.error = ERR_PACK(l, 0, 0); 986 d.error = ERR_PACK(l, 0, 0);
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
index 40009cbe88..24de3c9c15 100644
--- a/src/lib/libcrypto/err/err_all.c
+++ b/src/lib/libcrypto/err/err_all.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: err_all.c,v 1.23 2016/10/19 16:49:11 jsing Exp $ */ 1/* $OpenBSD: err_all.c,v 1.24 2018/03/17 16:20:01 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,6 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <pthread.h>
59#include <stdio.h> 60#include <stdio.h>
60 61
61#include <openssl/opensslconf.h> 62#include <openssl/opensslconf.h>
@@ -103,11 +104,13 @@
103#include <openssl/gost.h> 104#include <openssl/gost.h>
104#endif 105#endif
105 106
106void 107void ERR_load_ERR_strings_internal(void);
107ERR_load_crypto_strings(void) 108
109static void
110ERR_load_crypto_strings_internal(void)
108{ 111{
109#ifndef OPENSSL_NO_ERR 112#ifndef OPENSSL_NO_ERR
110 ERR_load_ERR_strings(); /* include error strings for SYSerr */ 113 ERR_load_ERR_strings_internal(); /* include error strings for SYSerr */
111 ERR_load_BN_strings(); 114 ERR_load_BN_strings();
112#ifndef OPENSSL_NO_RSA 115#ifndef OPENSSL_NO_RSA
113 ERR_load_RSA_strings(); 116 ERR_load_RSA_strings();
@@ -153,3 +156,10 @@ ERR_load_crypto_strings(void)
153#endif 156#endif
154#endif 157#endif
155} 158}
159
160void
161ERR_load_crypto_strings(void)
162{
163 static pthread_once_t loaded = PTHREAD_ONCE_INIT;
164 (void) pthread_once(&loaded, ERR_load_crypto_strings_internal);
165}