Introduce PK_Decryptor(_EME)::ciphertext_length()#5717
Merged
Conversation
In general this accessor is likely not very useful, because the expected plaintext size might not be known upfront. However, there are use cases where it is and we need a way to query the expected ciphertext length for a certain asymmetric algorithm. Also, this provides consistency with PK_KEM_Decryptor::encapsulated_key_length()
randombit
approved these changes
Jul 8, 2026
randombit
left a comment
Owner
There was a problem hiding this comment.
Interface looks fine. Unfortunate about having to create new cipher objects in DLIES/ECIES but given we allow CBC or indeed effectively arbitrary transforms here, would be hard to do anything else without some kind of significant refactoring, the shape of which I'm not even sure of....
Collaborator
Author
Yeah, but frankly: I doubt that there's a substantial user base for those. Even less so users that would start actually using this API. 🤷 |
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.
This allows querying an instance of
PK_Decryptorfor an estimate of the expected ciphertext size given an expected plaintext length. In the general use case that might not be overly useful, assuming that the plaintext size is not known before decryption.However, for many algorithms (most notably RSA or ElGamal) the expected ciphertext size is actually fixed and only dependent on the key length. For those, the new method facilitates an algorithm-agnostic querying of the expected ciphertext size, e.g. for input validation, pre-allocation and such.
Concretely, it comes in handy in the context of #5686 where we need an RSA-to-KEM Adapter and
PK_KEM_Decryptorhas anencapsulated_key_length()accessor that can be implemented conveniently with this new method.Additionally this fixes two confusing typos in the abstract public interface classes.