summaryrefslogtreecommitdiff
path: root/lib/crypto/tests/nh_kunit.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto/tests/nh_kunit.c')
-rw-r--r--lib/crypto/tests/nh_kunit.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/crypto/tests/nh_kunit.c b/lib/crypto/tests/nh_kunit.c
new file mode 100644
index 000000000..49e0fb3dd
--- /dev/null
+++ b/lib/crypto/tests/nh_kunit.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2025 Google LLC
+ */
+#include <crypto/nh.h>
+#include <kunit/test.h>
+#include "nh-testvecs.h"
+#include "test-utils.h"
+
+static void test_nh(struct kunit *test)
+{
+ u32 *key = memdup_buf(test, nh_test_key, NH_KEY_BYTES);
+ __le64 hash[NH_NUM_PASSES];
+
+ le32_to_cpu_array(key, NH_KEY_WORDS);
+
+ nh(key, nh_test_msg, 16, hash);
+ KUNIT_ASSERT_MEMEQ(test, hash, nh_test_val16, NH_HASH_BYTES);
+
+ nh(key, nh_test_msg, 96, hash);
+ KUNIT_ASSERT_MEMEQ(test, hash, nh_test_val96, NH_HASH_BYTES);
+
+ nh(key, nh_test_msg, 256, hash);
+ KUNIT_ASSERT_MEMEQ(test, hash, nh_test_val256, NH_HASH_BYTES);
+
+ nh(key, nh_test_msg, 1024, hash);
+ KUNIT_ASSERT_MEMEQ(test, hash, nh_test_val1024, NH_HASH_BYTES);
+}
+
+static struct kunit_case nh_test_cases[] = {
+ KUNIT_CASE(test_nh),
+ {},
+};
+
+static struct kunit_suite nh_test_suite = {
+ .name = "nh",
+ .test_cases = nh_test_cases,
+};
+kunit_test_suite(nh_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for NH");
+MODULE_LICENSE("GPL");