Skip to content

Conversation

@rhenium
Copy link
Member

@rhenium rhenium commented Nov 1, 2025

Fixes #902


With the introduction of OpenSSL 3 providers, newly implemented algorithms do not necessarily have a corresponding NID assigned. To use such an algorithm, it has to be "fetched" from providers using the new EVP_*_fetch() functions.

For digest algorithms, we have to use EVP_MD_fetch() instead of the existing EVP_get_digestbyname(). However, it is not a drop-in replacement because:

  • EVP_MD_fetch() does not support all algorithm name aliases recognized by EVP_get_digestbyname().

  • Both return an EVP_MD, but the one returned by EVP_MD_fetch() is sometimes reference counted and the user has to explicitly release it with EVP_MD_free().

So, keep using EVP_get_digestbyname() for all OpenSSL versions for now, and fall back to EVP_MD_fetch() if it fails. In the latter case, prepare a T_DATA object to manage the fetched EVP_MD's lifetime.

Use explicit strings instead of relying on OpenSSL::ASN1::ObjectId
methods. It is reduced to just SHA-256 because testing other algorithms
does not improve test coverage for ruby/openssl.
@rhenium rhenium force-pushed the ky/digest-fetch-md branch from 9e9f452 to c601f4c Compare November 1, 2025 16:24
We generally raise OpenSSL::OpenSSLError or its subclass for errors
originating from the OpenSSL library, which may include extra details
appended by ossl_raise().
Raise OpenSSL::Cipher::CipherError instead of ArgumentError or
RuntimeError for consistency.
With the introduction of OpenSSL 3 providers, newly implemented
algorithms do not necessarily have a corresponding NID assigned. To use
such an algorithm, it has to be "fetched" from providers using the new
EVP_*_fetch() functions.

For digest algorithms, we have to use EVP_MD_fetch() instead of the
existing EVP_get_digestbyname(). However, it is not a drop-in
replacement because:

 - EVP_MD_fetch() does not support all algorithm name aliases recognized
   by EVP_get_digestbyname().

 - Both return an EVP_MD, but the one returned by EVP_MD_fetch() is
   sometimes reference counted and the user has to explicitly release
   it with EVP_MD_free().

So, keep using EVP_get_digestbyname() for all OpenSSL versions for now,
and fall back to EVP_MD_fetch() if it fails. In the latter case, prepare
a T_DATA object to manage the fetched EVP_MD's lifetime.
Likewise, use EVP_MD_fetch() if it is available.

This adds support for AES-GCM-SIV with OpenSSL 3.2 or later.
@rhenium rhenium force-pushed the ky/digest-fetch-md branch from c601f4c to 1e68061 Compare November 3, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for "fetched" EVP_MD and EVP_CIPHER

1 participant