digest: add OpenSSL::Digest#squeeze#1083
Open
rhenium wants to merge 2 commits into
Open
Conversation
vcsjones
reviewed
Jul 8, 2026
| GetDigest(self, ctx); | ||
| str = rb_str_new(NULL, EVP_MD_CTX_size(ctx)); | ||
| int size = EVP_MD_CTX_size(ctx); | ||
| if (size < 0) { |
There was a problem hiding this comment.
In OpenSSL 1.1.1, EVP_MD_CTX_size actually return positive values and SHAKE128 and SHAKE256 actually "work". OpenSSL 3.0 broke this intentionally because it was kind of wrong to return anything, and what OpenSSL 1.1.1 returned was actually even more wrong.
Perhaps this is the behavior you want and SHAKE128 working in OpenSSL 1.1.1 is fine using just #digest.
With OpenSSL 1.1.1
EVP_shake128() -> 16
EVP_shake256() -> 32
The reason why this is "bad" is because SHAKE256 should actually return a 512-bit value for 256-bits of security, and SHAKE128 should return 256.
Member
Author
There was a problem hiding this comment.
It seems this was changed in OpenSSL 3.4. The old defaults don't seem right, but it's probably not ruby/openssl's job to fix it.
ad1fdd4 to
6b5de36
Compare
Add support for extendable-output functions (XOFs). An XOF is a hash function that can produce arbitrary length of output. The interface of the existing Digest::Class#digest and its variants is unsuitable for this purpose. Add a new method to "squeeze" the specified amount of output from the XOF. This method can be called repeatedly. OpenSSL 3.3 or later and AWS-LC support this.
In OpenSSL 3.4 or later, SHAKE digests do not have a default output length and EVP_MD_CTX_size() returns -1. Raise OpenSSL::Digest::DigestError if the function returns a negative number. Fortunately, this is currently caught by a sanity check in rb_str_new() and leads to ArgumentError with the message "negative string size (or size too big)". Still, the caller should check it. Also, override #inspect to rescue an exception raised in #hexdigest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1082