| From: |
| Mike Lothian <mike-AT-fireburn.co.uk> |
| To: |
| rust-for-linux-AT-vger.kernel.org |
| Subject: |
| [RFC PATCH 0/2] rust: crypto: library AES-128 / SHA-256 / HMAC + RSA |
| Date: |
| Wed, 17 Jun 2026 16:01:31 +0100 |
| Message-ID: |
| <20260617150143.2152-1-mike@fireburn.co.uk> |
| Cc: |
| Mike Lothian <mike-AT-fireburn.co.uk>, linux-crypto-AT-vger.kernel.org, Eric Biggers <ebiggers-AT-kernel.org>, Herbert Xu <herbert-AT-gondor.apana.org.au>, "David S. Miller" <davem-AT-davemloft.net>, Ard Biesheuvel <ardb-AT-kernel.org>, Miguel Ojeda <ojeda-AT-kernel.org>, Boqun Feng <boqun-AT-kernel.org>, Gary Guo <gary-AT-garyguo.net>, Björn Roy Baron <bjorn3_gh-AT-protonmail.com>, Benno Lossin <lossin-AT-kernel.org>, Andreas Hindborg <a.hindborg-AT-kernel.org>, Alice Ryhl <aliceryhl-AT-google.com>, Trevor Gross <tmgross-AT-umich.edu>, Danilo Krummrich <dakr-AT-kernel.org>, linux-kernel-AT-vger.kernel.org |
| Archive-link: |
| Article |
This RFC series adds a small, reusable kernel::crypto module so in-kernel
Rust code can hash, encrypt a single AES block, and do RSA public-key
encryption:
1/2 sha256(), hmac_sha256(), Aes128 (single-block ECB)
2/2 Akcipher + rsa_pubkey_encrypt() over crypto_akcipher
Patch 1 binds the library crypto (lib/crypto) functions directly
(SHA-256 / HMAC-SHA256) and uses one rust_helper_ shim for aes_encrypt()
(its transparent union is unbindable). It runs synchronously in the
calling context with no allocation and is the independently-mergeable,
self-contained contribution.
Patch 2 adds crypto::Akcipher, a thin wrapper over the asynchronous
public-key API (crypto_akcipher) driven synchronously, and a
crypto::rsa_pubkey_encrypt() convenience built on it: it DER-encodes the
RSAPublicKey the "rsa" transform expects, runs one encrypt, and leaves
padding to the caller. The request/scatterlist/completion plumbing (all
static-inline or on-stack) plus a kmalloc bounce for the DMA data path
live in one rust_helper_ shim; crypto_free_akcipher() and
crypto_akcipher_set_pub_key() are exposed through 1:1 shims. Going
through crypto_akcipher rather than the MPI math library means it
composes with any registered RSA implementation, including hardware
offload. It is kept a separate patch so the public-key surface can be
reviewed (or deferred) on its own without touching patch 1.
Both were factored out of an out-of-tree in-kernel Rust DisplayLink DL3
dock driver (which needs SHA/HMAC/AES for HDCP 2.2 and RSA for the AKE),
but the module is generic. Compile-tested in-tree against drm-next.
Mike Lothian (2):
rust: crypto: add library AES-128 / SHA-256 / HMAC-SHA256 bindings
rust: crypto: add RSA public-key encryption via crypto_akcipher
rust/bindings/bindings_helper.h | 3 +
rust/helpers/crypto.c | 95 +++++++++++++++++++++++++++
rust/helpers/helpers.c | 1 +
rust/kernel/crypto.rs | 255 ++++++++++++++++++++++++++++++++++
rust/kernel/lib.rs | 1 +
5 files changed, 355 insertions(+)
--
2.54.0