Re: [PATCH v3 2/2] rust: crypto: add synchronous RSA akcipher support
From: Mike Lothian
Date: Mon Aug 31 2026 - 16:43:48 EST
On Thu, 27 Aug 2026, Eric Biggers wrote:
> > +config RUST_CRYPTO_LIB_AES
> This is being added in the wrong patch.
[...]
> Likewise.
Sorry I'll get that sorted
> As I've been commenting on other of these bindings patches, it also
> doesn't really make sense to have the kconfig symbol be in lib/ but then
> have the actual code be in rust/. They should be in the same place.
That one isn't specific to these two patches, so I'm following Miguel's
reply on it and I'll go with whatever comes out.
> If you need RSA, then please just create an API for RSA specifically.
> The crypto_akcipher abstraction has never worked well, due to
> differences between the algorithms and various other reasons.
Will do. The generic akcipher wrapper goes and v4 has an RSA-only API.
The only operation I need is RSAES-OAEP-SHA256 public-key encryption
with a caller-supplied seed. The seed is explicit so the driver can pass
the kernel CSPRNG while the tests pass published deterministic vectors.
Would you rather that was a narrow Rust wrapper over the existing rsa
transform, or something in lib/crypto?
> > +__rust_helper void rust_helper_memzero_explicit(void *s, size_t count)
> Isn't there a standard Rust solution for this?
[...]
> > +__rust_helper void rust_helper_aes_enckey_zero(struct aes_enckey *key)
> Similarly, isn't there a standard Rust solution to zeroize memory?
There isn't one in the Rust standard library, so the memzero_explicit
forwarder stays -- Miguel covered that in his reply.
The aes_enckey_zero one was just wrong: it could have called the
memzero_explicit helper instead of existing at all. Miguel said the
same. v4 has one safe zeroize() in the kernel crate, used by Secret and
Aes128, and that helper is gone.
Mike
On Thu, 27 Aug 2026 at 04:05, Eric Biggers <ebiggers@xxxxxxxxxx> wrote:
>
> On Wed, Aug 26, 2026 at 05:29:49PM +0100, Mike Lothian wrote:
> > +config RUST_CRYPTO_LIB_AES
> > + bool
> > + depends on RUST
> > + select CRYPTO_LIB_AES
> > + select CRYPTO_LIB_AES_CBC_MACS
> > + help
> > + Enable the Rust bindings for the synchronous AES library functions.
> > + The selected C libraries are built into the kernel because Rust
> > + abstractions are part of the built-in kernel crate.
>
> This is being added in the wrong patch.
>
> > config CRYPTO_LIB_AESGCM
> > tristate
> > select CRYPTO_LIB_AES
> > @@ -216,6 +226,15 @@ config CRYPTO_LIB_SHA256
> > Select this if your module uses any of these functions from
> > <crypto/sha2.h>.
> >
> > +config RUST_CRYPTO_LIB_SHA256
> > + bool
> > + depends on RUST
> > + select CRYPTO_LIB_SHA256
> > + help
> > + Enable the Rust bindings for the synchronous SHA-256 and HMAC-SHA256
> > + library functions. The selected C library is built into the kernel
> > + because Rust abstractions are part of the built-in kernel crate.
>
> Likewise.
>
> As I've been commenting on other of these bindings patches, it also
> doesn't really make sense to have the kconfig symbol be in lib/ but then
> have the actual code be in rust/. They should be in the same place.
>
> > +__rust_helper void rust_helper_memzero_explicit(void *s, size_t count)
> > +{
> > + memzero_explicit(s, count);
> > +}
>
> Isn't there a standard Rust solution for this?
>
> > +#ifdef CONFIG_RUST_CRYPTO_AKCIPHER
> > +__rust_helper void rust_helper_crypto_free_akcipher(struct crypto_akcipher *tfm)
> > +{
> > + crypto_free_akcipher(tfm);
> > +}
>
> If you need RSA, then please just create an API for RSA specifically.
> The crypto_akcipher abstraction has never worked well, due to
> differences between the algorithms and various other reasons.
>
> > +__rust_helper void rust_helper_aes_enckey_zero(struct aes_enckey *key)
> > +{
> > + memzero_explicit(key, sizeof(*key));
> > +}
>
> Similarly, isn't there a standard Rust solution to zeroize memory?
>
> - Eric