]> git.ipfire.org Git - thirdparty/openssl.git/commit
Remove need for BN_BLINDING lock
authorNeil Horman <nhorman@openssl.org>
Wed, 25 Jun 2025 18:26:24 +0000 (14:26 -0400)
committerNeil Horman <nhorman@openssl.org>
Wed, 2 Jul 2025 16:21:35 +0000 (12:21 -0400)
commit902568bbd98a61d03495498b56e95e67e42cc71b
tree5f9d546f9113452ecc1dd519e0800e388f802104
parent8067e713a161adc18e47cf46bdaf9ced34bc63d0
Remove need for BN_BLINDING lock

Issue https://github.com/openssl/project/issues/1245 has identified that
we encounter a significant amount of time waiting to acquire the
BN_BLINDING_lock when running our handshake perf test with 10 threads
using an rsa key.  Specifically, with 10 threads we spend about 19327731
usecs just waiting.  So it would be great if we could eliminate the need
to get the write lock here.

Currently, the need for the lock is based off the fact that each rsa key
has only a single blinding pointer, for which exclusive access is
needed, with an attempt to use a fallback mt_blinding pointer in the
shared case.  If a key is shared by many threads, then we find ourselves
needing to maniuplate this lock quite frequently if we are doing lots of
ssl connections.

To address this, I've come up with this approach.  It replaces the
blinding pointer with a pointer to a sparse array.  The sparse array is
then indexed by thread id.  This allows us to do two things:

When getting the blinding, we only need to take the read lock in the
common case when looking up this threads blinding structure.  Only in
the first lookup for any thread do we need to take the write side lock
when updating the table, and only then for a very brief critical section
(i.e. we don't need to hold the lock when allocating/setting the
blinding up via RSA_setup_blinding

This trades off some extra memory usage for the above significant
reduction in execution time.

it also allows us to simplify the blinding code quite a bit by
eliminating the need to handle shared blindings because blindings are
never shared anymore

Fixes openssl/project#1245

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27913)
crypto/rsa/rsa_crpt.c
crypto/rsa/rsa_lib.c
crypto/rsa/rsa_local.h
crypto/rsa/rsa_ossl.c