Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add abstract base classes for AEAD constructions / make AEAD constructions inheritable #12471

Open
loewexy opened this issue Feb 15, 2025 · 0 comments

Comments

@loewexy
Copy link

loewexy commented Feb 15, 2025

As discussed in #12108 it is possible to make own Implementations of rsa.RSAPrivateKey to use keys which are stored in a HSM. Therefore code can just assume to get a rsa.RSAPrivateKey and be agnostic of the underlying implementation.

However the same possibility does not exist for the AEAD constructions in cryptography.hazmat.primitives.ciphers.aead. Since they are not abstract base classes as for the asymmetric keys but direct aliases of Rust bindings. This is also preventing my from just subclassing one of this classes, this seems not possible for the Rust class.

It is therefore not possible to write some code which receives a AESGCM object and uses it agnostic of how this works internally. This would be very helpful to have generic code that just needs to encrypt something, and that can be supplied with a standard cryptography implementation with a key in memory, or with a implementation using the en/decrypt functionality of a HSM. With the current situation there must be a distinction between cases.

I am not sure on how to approach this in a backward compatible manner. Since just replacing the current classes with abstract base classes would break existing code which then would have to use the concrete subclass using the rust backend. So basically I see two options here, but maybe there are more.

  1. Make the current classes inheritable, so that one can just subclass it and override all methods to fit to the HSM implementation.
  2. Add abstract base classes in another module, and register the current classes as virtual Subclasses as it is done with the rsa keys. On could then write code expecting the ABC and the current objects would be valid.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant