From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH 19/33] keyctl27: Test KEYCTL_DH_COMPUTE KDF key derivation
Date: Wed, 02 Sep 2026 13:04:34 +0200 [thread overview]
Message-ID: <20260902-keyctl_coverage-v1-19-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 SP800-56A KDF key derivation: verify that
deriving a key using SHA-256 and otherinfo matches the precomputed
mathematical test vector.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/keyctl/.gitignore | 1 +
testcases/kernel/syscalls/keyctl/keyctl27.c | 78 +++++++++++++++++++++++
testcases/kernel/syscalls/keyctl/keyctl_dh_data.h | 5 ++
4 files changed, 85 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 108efa4a8..d23461c4b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -744,6 +744,7 @@ keyctl23 keyctl23
keyctl24 keyctl24
keyctl25 keyctl25
keyctl26 keyctl26
+keyctl27 keyctl27
kcmp01 kcmp01
kcmp02 kcmp02
diff --git a/testcases/kernel/syscalls/keyctl/.gitignore b/testcases/kernel/syscalls/keyctl/.gitignore
index dd282b7ce..720ba1de6 100644
--- a/testcases/kernel/syscalls/keyctl/.gitignore
+++ b/testcases/kernel/syscalls/keyctl/.gitignore
@@ -24,3 +24,4 @@
/keyctl24
/keyctl25
/keyctl26
+/keyctl27
diff --git a/testcases/kernel/syscalls/keyctl/keyctl27.c b/testcases/kernel/syscalls/keyctl/keyctl27.c
new file mode 100644
index 000000000..288bd0f37
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl27.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test ``KEYCTL_DH_COMPUTE`` KDF key derivation of :manpage:`keyctl(2)`.
+ *
+ * The KDF extension to ``KEYCTL_DH_COMPUTE`` (SP800-56A) landed in Linux 4.12.
+ *
+ * [Algorithm]
+ *
+ * - derive key with SP800-56A KDF (SHA-256 + otherinfo), verify derived
+ * key matches expected 32-byte value
+ */
+
+#include "keyctl_common.h"
+#include "keyctl_dh_data.h"
+
+#define KDF_OTHERINFO "LTP-KDF-TEST-INFO"
+
+static struct keyctl_dh_params *dh_params;
+static struct keyctl_kdf_params *kdf_params;
+static unsigned char out_buf[32];
+
+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(kdf_params, 0, sizeof(*kdf_params));
+ kdf_params->hashname = "sha256";
+ kdf_params->otherinfo = (char *)KDF_OTHERINFO;
+ kdf_params->otherinfolen = strlen(KDF_OTHERINFO);
+
+ 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_kdf_expected),
+ (unsigned long)kdf_params),
+ (long)sizeof(dh_kdf_expected));
+ if (!TST_PASS)
+ return;
+
+ if (memcmp(out_buf, dh_kdf_expected, sizeof(dh_kdf_expected))) {
+ tst_res(TFAIL, "derived KDF key does not match expected value");
+ return;
+ }
+
+ tst_res(TPASS, "KEYCTL_DH_COMPUTE with KDF derived expected key");
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .test_all = run,
+ .min_kver = "4.12",
+ .needs_kconfigs = (const char *[]) {
+ "CONFIG_KEYS=y",
+ "CONFIG_KEY_DH_OPERATIONS=y",
+ "CONFIG_CRYPTO_DH",
+ "CONFIG_CRYPTO_SHA256",
+ NULL
+ },
+ .bufs = (struct tst_buffers []) {
+ {&dh_params, .size = sizeof(*dh_params)},
+ {&kdf_params, .size = sizeof(*kdf_params)},
+ {},
+ },
+};
diff --git a/testcases/kernel/syscalls/keyctl/keyctl_dh_data.h b/testcases/kernel/syscalls/keyctl/keyctl_dh_data.h
index bc1432dc3..7ac7876a0 100644
--- a/testcases/kernel/syscalls/keyctl/keyctl_dh_data.h
+++ b/testcases/kernel/syscalls/keyctl/keyctl_dh_data.h
@@ -71,4 +71,9 @@ static const unsigned char dh_expected_secret[] = {
0xfb, 0xeb, 0xdd, 0x18, 0x54, 0x0d, 0x4c, 0xa7, 0x65, 0xc1, 0x0c, 0x11, 0xad, 0xea, 0x83, 0x9f,
};
+static const unsigned char dh_kdf_expected[] = {
+ 0x66, 0x39, 0xec, 0x41, 0x31, 0x33, 0xe6, 0xc0, 0x61, 0x67, 0x28, 0x51, 0x61, 0xf7, 0x8c, 0xd7,
+ 0xc0, 0x55, 0xc9, 0xcc, 0x83, 0x46, 0xf3, 0xaa, 0x62, 0xed, 0xca, 0x90, 0x99, 0x2d, 0xc4, 0x07,
+};
+
#endif /* KEYCTL_DH_DATA_H__ */
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-09-02 11:11 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 ` [LTP] [PATCH 17/33] keyctl25: Test KEYCTL_DH_COMPUTE shared secret computation Andrea Cervesato
2026-09-02 11:04 ` [LTP] [PATCH 18/33] keyctl26: Test KEYCTL_DH_COMPUTE size query Andrea Cervesato
2026-09-02 11:04 ` Andrea Cervesato [this message]
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-19-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox