]> git.ipfire.org Git - thirdparty/tor.git/commit
Optimize the everloving heck out of OpenSSL AES as used by CGO.
authorNick Mathewson <nickm@torproject.org>
Thu, 15 May 2025 16:21:49 +0000 (12:21 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 21 May 2025 17:00:03 +0000 (13:00 -0400)
commita66bd83da63f7cd1f81656d106a06234e8b470e9
tree010995223a580966816ea4fd2e185501c0f72604
parent5054b1e8e291e26e41b9f95a62d0cae179738761
Optimize the everloving heck out of OpenSSL AES as used by CGO.

Optimizations:

1. Calling EVP_CryptInit with a cipher returned by
   e.g. EVP_aes_128_ctr() is quite slow, since it needs to look
   up the _actual_ EVP_CIPHER corresponding to the given EVP,
   which involves grabbing locks, doing a search through a
   provider, and so on.  We use EVP_CIPHER_fetch to speed
   that up a lot.

2. There is not in fact any need to EVP_CIPHER_CTX_Reset a
   cipher before calling EVP_CryptInit on it a second time

2. Using an ECB cipher + CRYPTO_ctr128_encrypt was not in fact
   the most efficient way to implement a counter mode with an
   adjustable IV.  Instead, the fastest way seems to be:
     - Set the IV manually
     - Ensure that we are always aligned to block boundary
       when we do so.
src/core/crypto/relay_crypto_cgo.c
src/core/crypto/relay_crypto_cgo.h
src/lib/crypt_ops/.may_include
src/lib/crypt_ops/aes.h
src/lib/crypt_ops/aes_nss.c
src/lib/crypt_ops/aes_openssl.c
src/test/bench.c
src/test/test_crypto.c