Skip to content

Introduce PK_Decryptor(_EME)::ciphertext_length()#5717

Merged
reneme merged 2 commits into
randombit:masterfrom
reneme:rene/improve_pk_encryptor
Jul 8, 2026
Merged

Introduce PK_Decryptor(_EME)::ciphertext_length()#5717
reneme merged 2 commits into
randombit:masterfrom
reneme:rene/improve_pk_encryptor

Conversation

@reneme

@reneme reneme commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

This allows querying an instance of PK_Decryptor for 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_Decryptor has an encapsulated_key_length() accessor that can be implemented conveniently with this new method.

Additionally this fixes two confusing typos in the abstract public interface classes.

reneme added 2 commits July 8, 2026 14:03
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()
@reneme reneme self-assigned this Jul 8, 2026
@reneme reneme added the enhancement Enhancement or new feature label Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@randombit randombit left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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....

@reneme

reneme commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Unfortunate about having to create new cipher objects in DLIES/ECIES

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. 🤷

@reneme
reneme merged commit 7bf6146 into randombit:master Jul 8, 2026
47 checks passed
@reneme
reneme deleted the rene/improve_pk_encryptor branch July 8, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement or new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants