summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/openssl.c
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/usr.bin/openssl/openssl.c
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/usr.bin/openssl/openssl.c')
-rw-r--r--src/usr.bin/openssl/openssl.c54
1 files changed, 1 insertions, 53 deletions
diff --git a/src/usr.bin/openssl/openssl.c b/src/usr.bin/openssl/openssl.c
index b3e85d63ba..255e34ec33 100644
--- a/src/usr.bin/openssl/openssl.c
+++ b/src/usr.bin/openssl/openssl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: openssl.c,v 1.26 2018/02/07 05:47:55 jsing Exp $ */ 1/* $OpenBSD: openssl.c,v 1.27 2018/11/11 06:41:28 bcook 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 *
@@ -344,56 +344,6 @@ CONF *config = NULL;
344BIO *bio_err = NULL; 344BIO *bio_err = NULL;
345 345
346static void 346static void
347lock_dbg_cb(int mode, int type, const char *file, int line)
348{
349 static int modes[CRYPTO_NUM_LOCKS]; /* = {0, 0, ... } */
350 const char *errstr = NULL;
351 int rw;
352
353 rw = mode & (CRYPTO_READ | CRYPTO_WRITE);
354 if (!((rw == CRYPTO_READ) || (rw == CRYPTO_WRITE))) {
355 errstr = "invalid mode";
356 goto err;
357 }
358 if (type < 0 || type >= CRYPTO_NUM_LOCKS) {
359 errstr = "type out of bounds";
360 goto err;
361 }
362 if (mode & CRYPTO_LOCK) {
363 if (modes[type]) {
364 errstr = "already locked";
365 /*
366 * must not happen in a single-threaded program
367 * (would deadlock)
368 */
369 goto err;
370 }
371 modes[type] = rw;
372 } else if (mode & CRYPTO_UNLOCK) {
373 if (!modes[type]) {
374 errstr = "not locked";
375 goto err;
376 }
377 if (modes[type] != rw) {
378 errstr = (rw == CRYPTO_READ) ?
379 "CRYPTO_r_unlock on write lock" :
380 "CRYPTO_w_unlock on read lock";
381 }
382 modes[type] = 0;
383 } else {
384 errstr = "invalid mode";
385 goto err;
386 }
387
388 err:
389 if (errstr) {
390 /* we cannot use bio_err here */
391 fprintf(stderr, "openssl (lock_dbg_cb): %s (mode=%d, type=%d) at %s:%d\n",
392 errstr, mode, type, file, line);
393 }
394}
395
396static void
397openssl_startup(void) 347openssl_startup(void)
398{ 348{
399 signal(SIGPIPE, SIG_IGN); 349 signal(SIGPIPE, SIG_IGN);
@@ -451,8 +401,6 @@ main(int argc, char **argv)
451 exit(1); 401 exit(1);
452 } 402 }
453 403
454 CRYPTO_set_locking_callback(lock_dbg_cb);
455
456 openssl_startup(); 404 openssl_startup();
457 405
458 /* Lets load up our environment a little */ 406 /* Lets load up our environment a little */