summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@kernel.org>2025-09-06 14:35:19 -0700
committerEric Biggers <ebiggers@kernel.org>2025-09-06 16:32:42 -0700
commit643d79e531cc99da0dc5502dfccb6b3b305c65f3 (patch)
tree8c83a7d277061c6d45099c731dd3218b13cdb39e /lib
parentafc4e4a5f122183b38095daba2264123cc86d8ab (diff)
lib/crypto: tests: Add Curve25519 benchmark
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. Link: https://lore.kernel.org/r/20250906213523.84915-9-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/tests/curve25519_kunit.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/crypto/tests/curve25519_kunit.c b/lib/crypto/tests/curve25519_kunit.c
index 68eab75d40dc..248d05f66b35 100644
--- a/lib/crypto/tests/curve25519_kunit.c
+++ b/lib/crypto/tests/curve25519_kunit.c
@@ -5,6 +5,7 @@
#include <crypto/curve25519.h>
#include <kunit/test.h>
+#include <linux/timekeeping.h>
struct curve25519_test_vector {
u8 private[CURVE25519_KEY_SIZE];
@@ -1316,9 +1317,39 @@ static void test_curve25519_basepoint(struct kunit *test)
}
}
+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),
{},
};
@@ -1328,5 +1359,5 @@ static struct kunit_suite curve25519_test_suite = {
};
kunit_test_suite(curve25519_test_suite);
-MODULE_DESCRIPTION("KUnit tests for Curve25519");
+MODULE_DESCRIPTION("KUnit tests and benchmark for Curve25519");
MODULE_LICENSE("GPL");