| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* Copyright 2025 Google LLC |
| 4 |
*/ |
| 5 |
#include <crypto/nh.h> |
| 6 |
#include <kunit/test.h> |
| 7 |
#include "nh-testvecs.h" |
| 8 |
|
| 9 |
static void test_nh(struct kunit *test) |
| 10 |
{ |
| 11 |
u32 *key = kunit_kmalloc(test, NH_KEY_BYTES, GFP_KERNEL); |
| 12 |
__le64 hash[NH_NUM_PASSES]; |
| 13 |
|
| 14 |
KUNIT_ASSERT_NOT_NULL(test, key); |
| 15 |
memcpy(key, nh_test_key, NH_KEY_BYTES); |
| 16 |
le32_to_cpu_array(key, NH_KEY_WORDS); |
| 17 |
|
| 18 |
nh(key, nh_test_msg, 16, hash); |
| 19 |
KUNIT_ASSERT_MEMEQ(test, hash, nh_test_val16, NH_HASH_BYTES); |
| 20 |
|
| 21 |
nh(key, nh_test_msg, 96, hash); |
| 22 |
KUNIT_ASSERT_MEMEQ(test, hash, nh_test_val96, NH_HASH_BYTES); |
| 23 |
|
| 24 |
nh(key, nh_test_msg, 256, hash); |
| 25 |
KUNIT_ASSERT_MEMEQ(test, hash, nh_test_val256, NH_HASH_BYTES); |
| 26 |
|
| 27 |
nh(key, nh_test_msg, 1024, hash); |
| 28 |
KUNIT_ASSERT_MEMEQ(test, hash, nh_test_val1024, NH_HASH_BYTES); |
| 29 |
} |
| 30 |
|
| 31 |
static struct kunit_case nh_test_cases[] = { |
| 32 |
KUNIT_CASE(test_nh), |
| 33 |
{}, |
| 34 |
}; |
| 35 |
|
| 36 |
static struct kunit_suite nh_test_suite = { |
| 37 |
.name = "nh", |
| 38 |
.test_cases = nh_test_cases, |
| 39 |
}; |
| 40 |
kunit_test_suite(nh_test_suite); |
| 41 |
|
| 42 |
MODULE_DESCRIPTION("KUnit tests for NH"); |
| 43 |
MODULE_LICENSE("GPL"); |