linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	Zhiqi Song <songzhiqi1@huawei.com>,
	Longfang Liu <liulongfang@huawei.com>,
	x86@kernel.org, linux-arm-kernel@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org, Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH v2 08/12] lib/crypto: tests: Add Curve25519 benchmark
Date: Sat,  6 Sep 2025 14:35:19 -0700	[thread overview]
Message-ID: <20250906213523.84915-9-ebiggers@kernel.org> (raw)
In-Reply-To: <20250906213523.84915-1-ebiggers@kernel.org>

Add a benchmark to curve25519_kunit.  This brings it in line with the
other crypto KUnit tests and provides an easy way to measure
performance.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crypto/tests/curve25519_kunit.c | 31 +++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/lib/crypto/tests/curve25519_kunit.c b/lib/crypto/tests/curve25519_kunit.c
index 0d1c46ca74018..355ad79a210d1 100644
--- a/lib/crypto/tests/curve25519_kunit.c
+++ b/lib/crypto/tests/curve25519_kunit.c
@@ -3,10 +3,11 @@
  * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
  */
 
 #include <crypto/curve25519.h>
 #include <kunit/test.h>
+#include <linux/timekeeping.h>
 
 struct curve25519_test_vector {
 	u8 private[CURVE25519_KEY_SIZE];
 	u8 public[CURVE25519_KEY_SIZE];
 	u8 result[CURVE25519_KEY_SIZE];
@@ -1314,13 +1315,43 @@ static void test_curve25519_basepoint(struct kunit *test)
 		KUNIT_EXPECT_MEMEQ_MSG(test, out, out2, CURVE25519_KEY_SIZE,
 				       "in=%*phN", CURVE25519_KEY_SIZE, in);
 	}
 }
 
+static void benchmark_curve25519(struct kunit *test)
+{
+	const u8 *private = curve25519_test_vectors[0].private;
+	const u8 *public = curve25519_test_vectors[0].public;
+	const size_t warmup_niter = 5000;
+	const size_t benchmark_niter = 1024;
+	u8 out[CURVE25519_KEY_SIZE];
+	bool ok = true;
+	u64 t;
+
+	if (!IS_ENABLED(CONFIG_CRYPTO_LIB_BENCHMARK))
+		kunit_skip(test, "not enabled");
+
+	/* Warm-up */
+	for (size_t i = 0; i < warmup_niter; i++)
+		ok &= curve25519(out, private, public);
+
+	/* Benchmark */
+	preempt_disable();
+	t = ktime_get_ns();
+	for (size_t i = 0; i < benchmark_niter; i++)
+		ok &= curve25519(out, private, public);
+	t = ktime_get_ns() - t;
+	preempt_enable();
+	KUNIT_EXPECT_TRUE(test, ok);
+	kunit_info(test, "%llu ops/s",
+		   div64_u64((u64)benchmark_niter * NSEC_PER_SEC, t ?: 1));
+}
+
 static struct kunit_case curve25519_test_cases[] = {
 	KUNIT_CASE(test_curve25519),
 	KUNIT_CASE(test_curve25519_basepoint),
+	KUNIT_CASE(benchmark_curve25519),
 	{},
 };
 
 static struct kunit_suite curve25519_test_suite = {
 	.name = "curve25519",
-- 
2.50.1



  parent reply	other threads:[~2025-09-06 21:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-06 21:35 [PATCH v2 00/12] Curve25519 cleanup Eric Biggers
2025-09-06 21:35 ` [PATCH v2 01/12] crypto: hisilicon/hpre - Remove unused curve25519 kpp support Eric Biggers
2025-09-06 21:35 ` [PATCH v2 02/12] crypto: arm/curve25519 - Remove unused " Eric Biggers
2025-09-06 21:35 ` [PATCH v2 03/12] crypto: powerpc/curve25519 " Eric Biggers
2025-09-06 21:35 ` [PATCH v2 04/12] crypto: x86/curve25519 " Eric Biggers
2025-09-06 21:35 ` [PATCH v2 05/12] crypto: testmgr - Remove curve25519 kpp tests Eric Biggers
2025-09-06 21:35 ` [PATCH v2 06/12] crypto: curve25519 - Remove unused kpp support Eric Biggers
2025-09-06 21:35 ` [PATCH v2 07/12] lib/crypto: tests: Migrate Curve25519 self-test to KUnit Eric Biggers
2025-09-06 23:30   ` Eric Biggers
2025-09-06 21:35 ` Eric Biggers [this message]
2025-09-06 21:35 ` [PATCH v2 09/12] lib/crypto: curve25519: Move a couple functions out-of-line Eric Biggers
2025-09-06 21:35 ` [PATCH v2 10/12] lib/crypto: curve25519: Consolidate into single module Eric Biggers
2025-09-06 21:35 ` [PATCH v2 11/12] lib/crypto: tests: Enable Curve25519 test when CRYPTO_SELFTESTS Eric Biggers
2025-09-06 21:35 ` [PATCH v2 12/12] wireguard: kconfig: Simplify crypto kconfig selections Eric Biggers
2025-09-08 16:35   ` Jason A. Donenfeld
2025-09-08 16:47     ` Eric Biggers
2025-09-08 16:49       ` Jason A. Donenfeld
2025-09-15 16:20 ` [PATCH v2 00/12] Curve25519 cleanup Eric Biggers

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=20250906213523.84915-9-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=liulongfang@huawei.com \
    --cc=songzhiqi1@huawei.com \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).