summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-11-02 08:54:40 +0000
committertb <>2024-11-02 08:54:40 +0000
commit5a3101c1d5e1f9f99c2d29cfd71180caf58af69b (patch)
treebac3514e7fcb95420abcfd284cbcd8084cf14b64 /src
parent9284b0981039b2aa54d18a4c55a4abcd02b7de51 (diff)
downloadopenbsd-5a3101c1d5e1f9f99c2d29cfd71180caf58af69b.tar.gz
openbsd-5a3101c1d5e1f9f99c2d29cfd71180caf58af69b.tar.bz2
openbsd-5a3101c1d5e1f9f99c2d29cfd71180caf58af69b.zip
Inline last uses of CRYPTO_THREADID in err/
This is another Thorpian obfuscation scheme hiding nasty casts of pthread_t to unsigned long and comparing them. We can do this in a less underhanded way by calling the portable functions directly. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/err/err.c21
-rw-r--r--src/lib/libcrypto/err/err_prn.c8
2 files changed, 10 insertions, 19 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index ae20463cf9..8909c221e5 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.73 2024/10/11 13:32:22 tb Exp $ */ 1/* $OpenBSD: err.c,v 1.74 2024/11/02 08:54:40 tb 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 *
@@ -122,13 +122,11 @@
122#include <openssl/err.h> 122#include <openssl/err.h>
123#include <openssl/lhash.h> 123#include <openssl/lhash.h>
124 124
125#include "crypto_local.h"
126
127DECLARE_LHASH_OF(ERR_STRING_DATA); 125DECLARE_LHASH_OF(ERR_STRING_DATA);
128DECLARE_LHASH_OF(ERR_STATE); 126DECLARE_LHASH_OF(ERR_STATE);
129 127
130typedef struct err_state_st { 128typedef struct err_state_st {
131 CRYPTO_THREADID tid; 129 pthread_t tid;
132 int err_flags[ERR_NUM_ERRORS]; 130 int err_flags[ERR_NUM_ERRORS];
133 unsigned long err_buffer[ERR_NUM_ERRORS]; 131 unsigned long err_buffer[ERR_NUM_ERRORS];
134 char *err_data[ERR_NUM_ERRORS]; 132 char *err_data[ERR_NUM_ERRORS];
@@ -350,14 +348,14 @@ err_del_item(const ERR_STRING_DATA *d)
350static unsigned long 348static unsigned long
351err_state_hash(const ERR_STATE *a) 349err_state_hash(const ERR_STATE *a)
352{ 350{
353 return CRYPTO_THREADID_hash(&a->tid) * 13; 351 return 13 * (unsigned long)a->tid;
354} 352}
355static IMPLEMENT_LHASH_HASH_FN(err_state, ERR_STATE) 353static IMPLEMENT_LHASH_HASH_FN(err_state, ERR_STATE)
356 354
357static int 355static int
358err_state_cmp(const ERR_STATE *a, const ERR_STATE *b) 356err_state_cmp(const ERR_STATE *a, const ERR_STATE *b)
359{ 357{
360 return CRYPTO_THREADID_cmp(&a->tid, &b->tid); 358 return pthread_equal(a->tid, b->tid) == 0;
361} 359}
362static IMPLEMENT_LHASH_COMP_FN(err_state, ERR_STATE) 360static IMPLEMENT_LHASH_COMP_FN(err_state, ERR_STATE)
363 361
@@ -557,10 +555,8 @@ ERR_get_state(void)
557 static ERR_STATE fallback; 555 static ERR_STATE fallback;
558 ERR_STATE *ret, tmp, *tmpp = NULL; 556 ERR_STATE *ret, tmp, *tmpp = NULL;
559 int i; 557 int i;
560 CRYPTO_THREADID tid;
561 558
562 CRYPTO_THREADID_current(&tid); 559 tmp.tid = pthread_self();
563 CRYPTO_THREADID_cpy(&tmp.tid, &tid);
564 ret = err_thread_get_item(&tmp); 560 ret = err_thread_get_item(&tmp);
565 561
566 /* ret == the error state, if NULL, make a new one */ 562 /* ret == the error state, if NULL, make a new one */
@@ -568,7 +564,7 @@ ERR_get_state(void)
568 ret = malloc(sizeof(ERR_STATE)); 564 ret = malloc(sizeof(ERR_STATE));
569 if (ret == NULL) 565 if (ret == NULL)
570 return (&fallback); 566 return (&fallback);
571 CRYPTO_THREADID_cpy(&ret->tid, &tid); 567 ret->tid = pthread_self();
572 ret->top = 0; 568 ret->top = 0;
573 ret->bottom = 0; 569 ret->bottom = 0;
574 for (i = 0; i < ERR_NUM_ERRORS; i++) { 570 for (i = 0; i < ERR_NUM_ERRORS; i++) {
@@ -757,10 +753,7 @@ ERR_remove_thread_state(const CRYPTO_THREADID *id)
757{ 753{
758 ERR_STATE tmp; 754 ERR_STATE tmp;
759 755
760 if (id) 756 tmp.tid = pthread_self();
761 CRYPTO_THREADID_cpy(&tmp.tid, id);
762 else
763 CRYPTO_THREADID_current(&tmp.tid);
764 757
765 /* 758 /*
766 * err_thread_del_item automatically destroys the LHASH if the number of 759 * err_thread_del_item automatically destroys the LHASH if the number of
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c
index fb6e19c54c..4bd9482e61 100644
--- a/src/lib/libcrypto/err/err_prn.c
+++ b/src/lib/libcrypto/err/err_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: err_prn.c,v 1.23 2024/03/02 11:37:13 tb Exp $ */ 1/* $OpenBSD: err_prn.c,v 1.24 2024/11/02 08:54:40 tb 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 *
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <limits.h> 59#include <limits.h>
60#include <pthread.h>
60#include <stdio.h> 61#include <stdio.h>
61#include <string.h> 62#include <string.h>
62 63
@@ -66,7 +67,6 @@
66#include <openssl/lhash.h> 67#include <openssl/lhash.h>
67 68
68#include "bio_local.h" 69#include "bio_local.h"
69#include "crypto_local.h"
70 70
71void 71void
72ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), void *u) 72ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), void *u)
@@ -77,10 +77,8 @@ ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), void *u)
77 const char *file, *data; 77 const char *file, *data;
78 int line, flags; 78 int line, flags;
79 unsigned long es; 79 unsigned long es;
80 CRYPTO_THREADID cur;
81 80
82 CRYPTO_THREADID_current(&cur); 81 es = (unsigned long)pthread_self();
83 es = CRYPTO_THREADID_hash(&cur);
84 while ((l = ERR_get_error_line_data(&file, &line, &data, 82 while ((l = ERR_get_error_line_data(&file, &line, &data,
85 &flags)) != 0) { 83 &flags)) != 0) {
86 ERR_error_string_n(l, buf, sizeof buf); 84 ERR_error_string_n(l, buf, sizeof buf);