summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rsa/rsa_eay.c
diff options
context:
space:
mode:
authortb <>2023-08-09 12:09:06 +0000
committertb <>2023-08-09 12:09:06 +0000
commitd7d2735b3bfc925a72116d82cd0515de75328df8 (patch)
treef4fecd7ecfa8d410a74dcbae6bc89fcfc2d35975 /src/lib/libcrypto/rsa/rsa_eay.c
parentbd98bb41d5e625bf39e15b2f99590f61f9496f22 (diff)
downloadopenbsd-d7d2735b3bfc925a72116d82cd0515de75328df8.tar.gz
openbsd-d7d2735b3bfc925a72116d82cd0515de75328df8.tar.bz2
openbsd-d7d2735b3bfc925a72116d82cd0515de75328df8.zip
Rework BN_BLINDING to use pthread_t directly
Instead of CRYPTO_THREADID, which passes pthread_via through unsigned long, we can use pthread_self() and pthread_equal() directly. This commit keeps using the awkward 'local' nomenclature as that is used throughout the rsa code. This will be changed after the blinding code will have been fully merged into rsa_blinding.c. ok jsing
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_eay.c')
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index 35b32f6d02..c2e1e22f9a 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_eay.c,v 1.64 2023/08/09 09:32:23 tb Exp $ */ 1/* $OpenBSD: rsa_eay.c,v 1.65 2023/08/09 12:09:06 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 *
@@ -222,7 +222,6 @@ rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx)
222{ 222{
223 BN_BLINDING *ret; 223 BN_BLINDING *ret;
224 int got_write_lock = 0; 224 int got_write_lock = 0;
225 CRYPTO_THREADID cur;
226 225
227 CRYPTO_r_lock(CRYPTO_LOCK_RSA); 226 CRYPTO_r_lock(CRYPTO_LOCK_RSA);
228 227
@@ -235,24 +234,14 @@ rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx)
235 rsa->blinding = RSA_setup_blinding(rsa, ctx); 234 rsa->blinding = RSA_setup_blinding(rsa, ctx);
236 } 235 }
237 236
238 ret = rsa->blinding; 237 if ((ret = rsa->blinding) == NULL)
239 if (ret == NULL)
240 goto err; 238 goto err;
241 239
242 CRYPTO_THREADID_current(&cur); 240 /*
243 if (!CRYPTO_THREADID_cmp(&cur, BN_BLINDING_thread_id(ret))) { 241 * We need a shared blinding. Accesses require locks and a copy of the
244 /* rsa->blinding is ours! */ 242 * blinding factor needs to be retained on use.
245 *local = 1; 243 */
246 } else { 244 if ((*local = BN_BLINDING_is_local(ret)) == 0) {
247 /* resort to rsa->mt_blinding instead */
248 /*
249 * Instruct rsa_blinding_convert(), rsa_blinding_invert()
250 * that the BN_BLINDING is shared, meaning that accesses
251 * require locks, and that the blinding factor must be
252 * stored outside the BN_BLINDING
253 */
254 *local = 0;
255
256 if (rsa->mt_blinding == NULL) { 245 if (rsa->mt_blinding == NULL) {
257 if (!got_write_lock) { 246 if (!got_write_lock) {
258 CRYPTO_r_unlock(CRYPTO_LOCK_RSA); 247 CRYPTO_r_unlock(CRYPTO_LOCK_RSA);
@@ -266,11 +255,12 @@ rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx)
266 ret = rsa->mt_blinding; 255 ret = rsa->mt_blinding;
267 } 256 }
268 257
269err: 258 err:
270 if (got_write_lock) 259 if (got_write_lock)
271 CRYPTO_w_unlock(CRYPTO_LOCK_RSA); 260 CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
272 else 261 else
273 CRYPTO_r_unlock(CRYPTO_LOCK_RSA); 262 CRYPTO_r_unlock(CRYPTO_LOCK_RSA);
263
274 return ret; 264 return ret;
275} 265}
276 266