| From: |
| Rodolfo Giometti <giometti-AT-enneenne.com> |
| To: |
| linux-crypto-AT-vger.kernel.org |
| Subject: |
| [V1 0/4] User API for KPP |
| Date: |
| Mon, 15 Sep 2025 10:40:35 +0200 |
| Message-ID: |
| <20250915084039.2848952-1-giometti@enneenne.com> |
| Cc: |
| Herbert Xu <herbert-AT-gondor.apana.org.au>, "David S . Miller" <davem-AT-davemloft.net>, Rodolfo Giometti <giometti-AT-enneenne.com> |
| Archive-link: |
| Article |
This patchset adds a dedicated user interface for the Key-agreement
Protocol Primitive (KPP).
From user applications, we can now use the following specification for
AF_ALG sockets:
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "kpp",
.salg_name = "ecdh-nist-p256",
};
Once the private key is set with ALG_SET_KEY or (preferably)
ALG_SET_KEY_BY_KEY_SERIAL, the user program reads its public key from
the socket and then writes the peer's public key to the socket.
The shared secret calculated by the selected kernel algorithm is then
available for reading.
For example, if we create a trusted key like this:
kpriv_id=$(keyctl add trusted kpriv "new 32" @u)
A simple example code is as follows:
key_serial_t key_id;
/* Generate the socket for KPP operation */
sk_fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
bind(sk_fd, (struct sockaddr *)&sa, sizeof(sa));
/* kpriv_id holds the trusted key ID */
setsockopt(sk_fd, SOL_ALG, ALG_SET_KEY_BY_KEY_SERIAL,
&key_id, sizeof(key_id));
/* Get the operational socket */
op_fd = accept(sk_fd, NULL, 0);
/* Read our public key */
recv(op_fd, pubkey, pubkey_len, 0);
/* Write the peer's public key */
send(op_fd, peer_pubkey, peer_pubkey_len, 0);
/* Read the shared secret */
len = recv(op_fd, secret, secret_len, 0);
Each time we write a peer's public key, we can read a different shared
secret.
Rodolfo Giometti (4):
crypto ecdh.h: set key memory region as const
crypto kpp.h: add new method set_secret_raw in struct kpp_alg
crypto ecdh.c: define the ECDH set_secret_raw method
crypto: add user-space interface for KPP algorithms
crypto/Kconfig | 8 ++
crypto/Makefile | 1 +
crypto/algif_kpp.c | 286 ++++++++++++++++++++++++++++++++++++++++++
crypto/ecdh.c | 31 +++++
include/crypto/ecdh.h | 2 +-
include/crypto/kpp.h | 29 +++++
6 files changed, 356 insertions(+), 1 deletion(-)
create mode 100644 crypto/algif_kpp.c
--
2.34.1