lib/crypto/tests/ghash_kunit.c

Source file repositories/reference/linux-study-clean/lib/crypto/tests/ghash_kunit.c

File Facts

System
Linux kernel
Corpus path
lib/crypto/tests/ghash_kunit.c
Extension
.c
Size
5799 bytes
Lines
195
Domain
Kernel Services
Bucket
lib
Inferred role
Kernel Services: implementation source
Status
source implementation candidate

Why This File Exists

Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ghash_irq_test_state {
	struct ghash_key expected_key;
	u8 raw_key[GHASH_BLOCK_SIZE];
};

static bool ghash_irq_test_func(void *state_)
{
	struct ghash_irq_test_state *state = state_;
	struct ghash_key key;

	ghash_preparekey(&key, state->raw_key);
	return memcmp(&key, &state->expected_key, sizeof(key)) == 0;
}

/*
 * Test that ghash_preparekey() produces the same output regardless of whether
 * FPU or vector registers are usable when it is called.
 */
static void test_ghash_preparekey_in_irqs(struct kunit *test)
{
	struct ghash_irq_test_state state;

	rand_bytes(state.raw_key, sizeof(state.raw_key));
	ghash_preparekey(&state.expected_key, state.raw_key);
	kunit_run_irq_test(test, ghash_irq_test_func, 200000, &state);
}

static int ghash_suite_init(struct kunit_suite *suite)
{
	u8 raw_key[GHASH_BLOCK_SIZE];

	rand_bytes_seeded_from_len(raw_key, sizeof(raw_key));
	ghash_preparekey(&test_key, raw_key);
	return hash_suite_init(suite);
}

static void ghash_suite_exit(struct kunit_suite *suite)
{
	hash_suite_exit(suite);
}

static struct kunit_case ghash_test_cases[] = {
	HASH_KUNIT_CASES,
	KUNIT_CASE(test_ghash_allones_key_and_message),
	KUNIT_CASE(test_ghash_with_guarded_key),
	KUNIT_CASE(test_ghash_with_minimally_aligned_key),
	KUNIT_CASE(test_ghash_preparekey_in_irqs),
	KUNIT_CASE(benchmark_hash),
	{},
};

static struct kunit_suite ghash_test_suite = {
	.name = "ghash",
	.test_cases = ghash_test_cases,
	.suite_init = ghash_suite_init,
	.suite_exit = ghash_suite_exit,
};
kunit_test_suite(ghash_test_suite);

MODULE_DESCRIPTION("KUnit tests and benchmark for GHASH");
MODULE_LICENSE("GPL");

Annotation

Implementation Notes