From nobody Fri Oct 3 12:37:53 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D59826F2A0; Mon, 1 Sep 2025 20:20:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756758004; cv=none; b=telw62HORmdTS1zptn/voWgU8VhsYYUk+UmxQwi+q+uwoFuYK3hZoEb3paG77US8rzN7cUXe7V7UziEJsP0RGJq+yb8FcIZ9Z/Q/WaU1/oZIEChgDeGnjhYn0uJiBLjQt11031RqAuvIX5KsZA1674Pnbgf6dLX55HGpc7ATxdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756758004; c=relaxed/simple; bh=JT5BiLSYDda9F7JFlPUyma7+VlywOSy3ji25SAsdSjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BLKuJ6Z3cdDeLXB14LzoyYqrSR1GpipciuU3vUcNrzuQMb6bP/umYO9ni3o0ZzYJpBk4T2Fj55GQcdXhcy0SEfi/iJIthZLmUVOkYI6Sl9vZEK1oqOipSY7IafkforNOJKM1vrO0DE7pdfy9+p20x1bA00av5qb7Agv0aRJ/rFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cIv556mj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cIv556mj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92E76C4CEF7; Mon, 1 Sep 2025 20:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756758003; bh=JT5BiLSYDda9F7JFlPUyma7+VlywOSy3ji25SAsdSjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cIv556mj78srUYKhhiIsf5bRS5w3KmxqdTYYJ3t9pCTlMTQrWVdEk8o4UiDSI4da8 TwsnQcPkOLEGWnNN1i2BvzYxwKRZ2OL0Xta/6Ry1WG3dir2IyTPt2hQxAUf4ntRghe Qe3qXPdw4iRHmCGfnZEdjb7cuzGd6mJy/wkpeWJB8sF6j3htHmWrVaTt4a9x6uB2BJ 8z++/1e0hOWXaqiyejBAk+ZC8jwyKDjZw3SRztPnBveuthxLs3GaAFdqU/wbcFpAj1 pOllmIj46N5FxKdsXbpS96eu3Mb7G6CjI/62ePYuW+7e0qpRcA4nQMVPFDzXmezuRQ CxtulhW2ELojA== From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , "Jason A . Donenfeld" , Zhiqi Song , Longfang Liu , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Eric Biggers Subject: [PATCH 3/6] lib/crypto: tests: Add Curve25519 benchmark Date: Mon, 1 Sep 2025 13:18:12 -0700 Message-ID: <20250901201815.594177-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250901201815.594177-1-ebiggers@kernel.org> References: <20250901201815.594177-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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/curve25= 519_kunit.c index 585f7ad3ed5f7..2e1d781563648 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 . All Right= s Reserved. */ =20 #include #include +#include =20 struct curve25519_test_vector { u8 private[CURVE25519_KEY_SIZE]; u8 public[CURVE25519_KEY_SIZE]; u8 result[CURVE25519_KEY_SIZE]; @@ -1317,13 +1318,43 @@ static void test_curve25519_basepoint(struct kunit = *test) KUNIT_EXPECT_MEMEQ_MSG(test, out, out2, CURVE25519_KEY_SIZE, "in=3D%*phN", CURVE25519_KEY_SIZE, in); } } =20 +static void benchmark_curve25519(struct kunit *test) +{ + const u8 *private =3D curve25519_test_vectors[0].private; + const u8 *public =3D curve25519_test_vectors[0].public; + u8 out[CURVE25519_KEY_SIZE]; + const size_t warmup_niter =3D 5000; + const size_t benchmark_niter =3D 1024; + bool ok =3D true; + u64 t; + + if (!IS_ENABLED(CONFIG_CRYPTO_LIB_BENCHMARK)) + kunit_skip(test, "not enabled"); + + /* Warm-up */ + for (size_t i =3D 0; i < warmup_niter; i++) + ok &=3D curve25519(out, private, public); + + /* Benchmark */ + preempt_disable(); + t =3D ktime_get_ns(); + for (size_t i =3D 0; i < benchmark_niter; i++) + ok &=3D curve25519(out, private, public); + t =3D ktime_get_ns() - t; + preempt_enable(); + KUNIT_EXPECT_TRUE(test, ok); + kunit_info(test, "%llu ops/s", + div64_u64((u64)benchmark_niter * 1000000000, t ?: 1)); +} + static struct kunit_case curve25519_test_cases[] =3D { KUNIT_CASE(test_curve25519), KUNIT_CASE(test_curve25519_basepoint), + KUNIT_CASE(benchmark_curve25519), {}, }; =20 static struct kunit_suite curve25519_test_suite =3D { .name =3D "curve25519", --=20 2.50.1