public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
* [V1 0/4] User API for KPP
@ 2025-09-15  8:40 Rodolfo Giometti
  2025-09-15  8:40 ` [V1 1/4] crypto ecdh.h: set key memory region as const Rodolfo Giometti
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Rodolfo Giometti @ 2025-09-15  8:40 UTC (permalink / raw)
  To: linux-crypto; +Cc: Herbert Xu, David S . Miller, Rodolfo Giometti

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


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2025-09-16 19:03 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15  8:40 [V1 0/4] User API for KPP Rodolfo Giometti
2025-09-15  8:40 ` [V1 1/4] crypto ecdh.h: set key memory region as const Rodolfo Giometti
2025-09-16  6:50   ` kernel test robot
2025-09-16 17:19   ` kernel test robot
2025-09-15  8:40 ` [V1 2/4] crypto kpp.h: add new method set_secret_raw in struct kpp_alg Rodolfo Giometti
2025-09-15  8:40 ` [V1 3/4] crypto ecdh.c: define the ECDH set_secret_raw method Rodolfo Giometti
2025-09-15 14:46   ` kernel test robot
2025-09-15  8:40 ` [V1 4/4] crypto: add user-space interface for KPP algorithms Rodolfo Giometti
2025-09-15 14:50 ` [V1 0/4] User API for KPP Eric Biggers
2025-09-15 15:47   ` Rodolfo Giometti
2025-09-16  4:10     ` Herbert Xu
2025-09-16  8:22       ` Rodolfo Giometti
2025-09-16 10:21         ` Ignat Korchagin
2025-09-16 11:21           ` Rodolfo Giometti
2025-09-16 11:56             ` Ignat Korchagin
2025-09-16 12:33               ` Rodolfo Giometti
2025-09-16 12:43                 ` Ignat Korchagin
2025-09-16 13:07                   ` Rodolfo Giometti
2025-09-16 19:03                 ` Simo Sorce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox