All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH 17/33] keyctl25: Test KEYCTL_DH_COMPUTE shared secret computation
Date: Wed, 02 Sep 2026 13:04:32 +0200	[thread overview]
Message-ID: <20260902-keyctl_coverage-v1-17-d29dfa2ebcef@suse.com> (raw)
In-Reply-To: <20260902-keyctl_coverage-v1-0-d29dfa2ebcef@suse.com>

From: Andrea Cervesato <andrea.cervesato@suse.com>

Test KEYCTL_DH_COMPUTE shared secret computation: verify that
computing a 256-byte DH shared secret with RFC 7919 FFDHE-2048
parameters matches the precomputed mathematical value.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore       |  1 +
 testcases/kernel/syscalls/keyctl/keyctl25.c       | 66 ++++++++++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl_dh_data.h | 74 +++++++++++++++++++++++
 4 files changed, 142 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index be35e9f93..1b059f652 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -742,6 +742,7 @@ keyctl21 keyctl21
 keyctl22 keyctl22
 keyctl23 keyctl23
 keyctl24 keyctl24
+keyctl25 keyctl25
 
 kcmp01 kcmp01
 kcmp02 kcmp02
diff --git a/testcases/kernel/syscalls/keyctl/.gitignore b/testcases/kernel/syscalls/keyctl/.gitignore
index 767ccf61a..4cf772558 100644
--- a/testcases/kernel/syscalls/keyctl/.gitignore
+++ b/testcases/kernel/syscalls/keyctl/.gitignore
@@ -22,3 +22,4 @@
 /keyctl22
 /keyctl23
 /keyctl24
+/keyctl25
diff --git a/testcases/kernel/syscalls/keyctl/keyctl25.c b/testcases/kernel/syscalls/keyctl/keyctl25.c
new file mode 100644
index 000000000..f2d94a9f0
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl25.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test ``KEYCTL_DH_COMPUTE`` shared secret computation of :manpage:`keyctl(2)`.
+ *
+ * [Algorithm]
+ *
+ * - compute DH shared secret using RFC 7919 FFDHE-2048 parameters and
+ *   verify the 256-byte result matches the expected secret
+ */
+
+#include "keyctl_common.h"
+#include "keyctl_dh_data.h"
+
+static struct keyctl_dh_params *dh_params;
+static unsigned char out_buf[256];
+
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	dh_params->priv = new_user_key("dh_priv", dh_priv, sizeof(dh_priv),
+				       KEY_SPEC_PROCESS_KEYRING);
+	dh_params->prime = new_user_key("dh_prime", dh_prime, sizeof(dh_prime),
+					KEY_SPEC_PROCESS_KEYRING);
+	dh_params->base = new_user_key("dh_base", dh_base, sizeof(dh_base),
+				       KEY_SPEC_PROCESS_KEYRING);
+}
+
+static void run(void)
+{
+	memset(out_buf, 0, sizeof(out_buf));
+
+	TST_EXP_EQ_LI_SILENT(keyctl(KEYCTL_DH_COMPUTE, (unsigned long)dh_params,
+				    (unsigned long)out_buf,
+				    sizeof(dh_expected_secret), 0),
+			     (long)sizeof(dh_expected_secret));
+	if (!TST_PASS)
+		return;
+
+	if (memcmp(out_buf, dh_expected_secret, sizeof(dh_expected_secret))) {
+		tst_res(TFAIL, "computed secret does not match expected value");
+		return;
+	}
+
+	tst_res(TPASS, "KEYCTL_DH_COMPUTE computed expected shared secret");
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.min_kver = "4.7",
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_KEYS=y",
+		"CONFIG_KEY_DH_OPERATIONS=y",
+		"CONFIG_CRYPTO_DH",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&dh_params, .size = sizeof(*dh_params)},
+		{},
+	},
+};
diff --git a/testcases/kernel/syscalls/keyctl/keyctl_dh_data.h b/testcases/kernel/syscalls/keyctl/keyctl_dh_data.h
new file mode 100644
index 000000000..bc1432dc3
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl_dh_data.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
+ *
+ * Static test vectors for KEYCTL_DH_COMPUTE tests (keyctl25..keyctl28).
+ */
+
+#ifndef KEYCTL_DH_DATA_H__
+#define KEYCTL_DH_DATA_H__
+
+/* RFC 7919 2048-bit FFDHE Group parameters (ffdhe2048) */
+static const unsigned char dh_prime[] = {
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34,
+	0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, 0xcc, 0x74,
+	0x02, 0x0b, 0xbe, 0xa6, 0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e, 0x34, 0x04, 0xdd,
+	0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a, 0x43, 0x1b, 0x30, 0x2b, 0x0a, 0x6d, 0xf2, 0x5f, 0x14, 0x37,
+	0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45, 0xe4, 0x85, 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6,
+	0xf4, 0x4c, 0x42, 0xe9, 0xa6, 0x37, 0xed, 0x6b, 0x0b, 0xff, 0x5c, 0xb6, 0xf4, 0x06, 0xb7, 0xed,
+	0xee, 0x38, 0x6b, 0xfb, 0x5a, 0x89, 0x9f, 0xa5, 0xae, 0x9f, 0x24, 0x11, 0x7c, 0x4b, 0x1f, 0xe6,
+	0x49, 0x28, 0x66, 0x51, 0xec, 0xe4, 0x5b, 0x3d, 0xc2, 0x00, 0x7c, 0xb8, 0xa1, 0x63, 0xbf, 0x05,
+	0x98, 0xda, 0x48, 0x36, 0x1c, 0x55, 0xd3, 0x9a, 0x69, 0x16, 0x3f, 0xa8, 0xfd, 0x24, 0xcf, 0x5f,
+	0x83, 0x65, 0x5d, 0x23, 0xdc, 0xa3, 0xad, 0x96, 0x1c, 0x62, 0xf3, 0x56, 0x20, 0x85, 0x52, 0xbb,
+	0x9e, 0xd5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6d, 0x67, 0x0c, 0x35, 0x4e, 0x4a, 0xbc, 0x98, 0x04,
+	0xf1, 0x74, 0x6c, 0x08, 0xca, 0x18, 0x21, 0x7c, 0x32, 0x90, 0x5e, 0x46, 0x2e, 0x36, 0xce, 0x3b,
+	0xe3, 0x9e, 0x77, 0x2c, 0x18, 0x0e, 0x86, 0x03, 0x9b, 0x27, 0x83, 0xa2, 0xec, 0x07, 0xa2, 0x8f,
+	0xb5, 0xc5, 0x5d, 0xf0, 0x6f, 0x4c, 0x52, 0xc9, 0xde, 0x2b, 0xcb, 0xf6, 0x95, 0x58, 0x17, 0x18,
+	0x39, 0x95, 0x49, 0x7c, 0xea, 0x95, 0x6a, 0xe5, 0x15, 0xd2, 0x26, 0x18, 0x98, 0xfa, 0x05, 0x10,
+	0x15, 0x72, 0x8e, 0x5a, 0x8a, 0xac, 0xaa, 0x68, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};
+
+static const unsigned char dh_priv[] = {
+	0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+	0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+};
+
+static const unsigned char dh_base[] = {
+	0xdd, 0x5d, 0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ea, 0x4a, 0x2e, 0x17, 0x76, 0x40, 0x74, 0x2d, 0x3c,
+	0xac, 0x85, 0x3e, 0x96, 0xfa, 0x49, 0x44, 0x13, 0xfe, 0xe9, 0x45, 0x97, 0x2b, 0x24, 0x23, 0xa0,
+	0xf5, 0x1b, 0xec, 0xf2, 0x85, 0x28, 0xc9, 0xdb, 0x92, 0x60, 0x02, 0xc5, 0x0f, 0xfe, 0x2b, 0x1a,
+	0x97, 0xc9, 0x78, 0xcf, 0x48, 0x8b, 0xa2, 0x9b, 0xbb, 0x47, 0x2e, 0x7e, 0x63, 0x28, 0x2d, 0xdd,
+	0x32, 0x0a, 0x15, 0xa0, 0x72, 0xd8, 0x17, 0x60, 0x75, 0x20, 0x4f, 0x7d, 0xed, 0x29, 0x35, 0x61,
+};
+
+static const unsigned char dh_expected_secret[] = {
+	0x61, 0xfc, 0x0d, 0x4d, 0x01, 0xce, 0xe1, 0x52, 0x34, 0x0f, 0x52, 0xb4, 0x53, 0x28, 0xaa, 0x11,
+	0xd8, 0x6e, 0x92, 0xce, 0x8e, 0x8f, 0x7b, 0xa2, 0x91, 0x80, 0xf6, 0x2d, 0x99, 0x9b, 0xc7, 0x71,
+	0x4c, 0xbb, 0x05, 0xef, 0xde, 0x22, 0xbd, 0xdf, 0x6f, 0x8d, 0xbb, 0x00, 0xdf, 0x4e, 0xfa, 0x1c,
+	0x14, 0xea, 0x54, 0x20, 0xac, 0xec, 0x51, 0xcd, 0xbd, 0xd0, 0x63, 0xfc, 0x35, 0x7b, 0xd9, 0xab,
+	0x36, 0x7f, 0x1b, 0x67, 0xc3, 0xb1, 0x51, 0x4e, 0x2d, 0x19, 0x05, 0x50, 0xbe, 0x1d, 0x44, 0x51,
+	0x5f, 0xfe, 0x65, 0xf8, 0xf6, 0x12, 0xad, 0x6c, 0xc5, 0x84, 0x96, 0xd9, 0xc3, 0xc9, 0x39, 0x7d,
+	0x87, 0x98, 0xa7, 0x8e, 0x52, 0x4d, 0x1f, 0x26, 0xbe, 0x62, 0x14, 0xf4, 0x66, 0xcf, 0x9a, 0x90,
+	0x4d, 0x28, 0xdd, 0x29, 0x11, 0x6e, 0x51, 0x0c, 0x7b, 0x18, 0x1e, 0xac, 0x55, 0x49, 0xce, 0x1d,
+	0xef, 0xcc, 0x6c, 0xa2, 0x0e, 0x80, 0xd3, 0x0d, 0x24, 0xc0, 0x77, 0x68, 0x87, 0xf8, 0xa3, 0x05,
+	0x0f, 0x8d, 0xaa, 0x58, 0x6b, 0xbb, 0x6b, 0xd0, 0x76, 0xea, 0x87, 0x5c, 0xc3, 0x3e, 0xef, 0x19,
+	0x66, 0x9e, 0xc7, 0xd4, 0x4e, 0x85, 0xdf, 0x06, 0x61, 0x0b, 0x94, 0x9c, 0xd3, 0x58, 0x23, 0xa7,
+	0xb1, 0xf6, 0x36, 0xaf, 0x6b, 0x4c, 0xf1, 0x88, 0x40, 0xd4, 0x5f, 0x6e, 0x9d, 0x1f, 0xa7, 0x3c,
+	0x8b, 0xc2, 0x71, 0xba, 0x87, 0xcd, 0xc2, 0x9b, 0x33, 0xcf, 0x18, 0xee, 0x59, 0x8e, 0xf6, 0x6c,
+	0x76, 0xcc, 0xed, 0xcc, 0x09, 0xfe, 0xe1, 0xf8, 0xce, 0x5c, 0x78, 0xb3, 0xb9, 0xe3, 0xf5, 0x29,
+	0x14, 0xaa, 0x67, 0xd0, 0xb5, 0xcb, 0x7a, 0x7e, 0xd1, 0x2e, 0x83, 0x97, 0xf1, 0x6b, 0xfb, 0xe4,
+	0xfb, 0xeb, 0xdd, 0x18, 0x54, 0x0d, 0x4c, 0xa7, 0x65, 0xc1, 0x0c, 0x11, 0xad, 0xea, 0x83, 0x9f,
+};
+
+#endif /* KEYCTL_DH_DATA_H__ */

-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-09-02 11:08 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 11:04 [LTP] [PATCH 00/33] Improve coverage for keyctl() syscall Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 01/33] lapi/keyctl.h: Add fallback definitions for extended ops Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 02/33] keyctl10: Test KEYCTL_DESCRIBE format parsing Andrea Cervesato
2026-09-02 14:07   ` [LTP] lapi/keyctl.h: Add fallback definitions for extended ops linuxtestproject.agent
2026-09-02 11:04 ` [LTP] [PATCH 03/33] keyctl11: Test KEYCTL_DESCRIBE with exact buffer size Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 04/33] keyctl12: Test KEYCTL_DESCRIBE with too small buffer Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 05/33] keyctl13: Test KEYCTL_DESCRIBE size query Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 06/33] keyctl14: Negative tests for KEYCTL_DESCRIBE Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 07/33] keyctl15: Test KEYCTL_GET_SECURITY label retrieval Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 08/33] keyctl16: Test KEYCTL_GET_SECURITY truncated copy Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 09/33] keyctl17: Negative tests for KEYCTL_GET_SECURITY Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 10/33] keyctl18: Test basic KEYCTL_MOVE Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 11/33] keyctl19: Test KEYCTL_MOVE with same source and destination Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 12/33] keyctl20: Test KEYCTL_MOVE displacement Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 13/33] keyctl21: Negative and boundary tests for KEYCTL_MOVE Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 14/33] keyctl22: Test KEYCTL_RESTRICT_KEYRING reject-all Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 15/33] keyctl23: Test KEYCTL_RESTRICT_KEYRING builtin_trusted Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 16/33] keyctl24: Negative tests for KEYCTL_RESTRICT_KEYRING Andrea Cervesato
2026-09-02 11:04 ` Andrea Cervesato [this message]
2026-09-02 11:04 ` [LTP] [PATCH 18/33] keyctl26: Test KEYCTL_DH_COMPUTE size query Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 19/33] keyctl27: Test KEYCTL_DH_COMPUTE KDF key derivation Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 20/33] keyctl28: Negative and boundary tests for KEYCTL_DH_COMPUTE Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 21/33] lapi/keyctl.h: Add fallback definitions for public key ops Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 22/33] keyctl29: Test KEYCTL_PKEY_QUERY on public key Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 23/33] keyctl30: Test KEYCTL_PKEY_QUERY on private key Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 24/33] keyctl31: Test KEYCTL_PKEY_ENCRYPT and KEYCTL_PKEY_DECRYPT Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 25/33] keyctl32: Test KEYCTL_PKEY_SIGN and VERIFY Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 26/33] keyctl33: Negative tests for KEYCTL_PKEY_* Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 27/33] lapi/keyctl.h: Add capability fallback defines Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 28/33] keyctl34: Test KEYCTL_CAPABILITIES flag retrieval Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 29/33] keyctl35: Test KEYCTL_CAPABILITIES size query Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 30/33] keyctl36: Test KEYCTL_CAPABILITIES buffer sizing Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 31/33] keyctl37: Negative tests for KEYCTL_CAPABILITIES Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 32/33] keyctl38: Test KEYCTL_WATCH_KEY add and remove Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 33/33] keyctl39: Negative tests for KEYCTL_WATCH_KEY Andrea Cervesato

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260902-keyctl_coverage-v1-17-d29dfa2ebcef@suse.com \
    --to=andrea.cervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.