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.