mirror of
https://github.com/torvalds/linux.git
synced 2026-05-03 14:02:43 -04:00
lib/crypto: tests: Add KUnit tests for SHA-224 and SHA-256
Add KUnit test suites for the SHA-224 and SHA-256 library functions, including the corresponding HMAC support. The core test logic is in the previously-added hash-test-template.h. This commit just adds the actual KUnit suites, and it adds the generated test vectors to the tree so that gen-hash-testvecs.py won't have to be run at build time. Acked-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20250709200112.258500-3-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
39
lib/crypto/tests/sha256_kunit.c
Normal file
39
lib/crypto/tests/sha256_kunit.c
Normal file
@@ -0,0 +1,39 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright 2025 Google LLC
|
||||
*/
|
||||
#include <crypto/sha2.h>
|
||||
#include "sha256-testvecs.h"
|
||||
|
||||
#define HASH sha256
|
||||
#define HASH_CTX sha256_ctx
|
||||
#define HASH_SIZE SHA256_DIGEST_SIZE
|
||||
#define HASH_INIT sha256_init
|
||||
#define HASH_UPDATE sha256_update
|
||||
#define HASH_FINAL sha256_final
|
||||
#define HMAC_KEY hmac_sha256_key
|
||||
#define HMAC_CTX hmac_sha256_ctx
|
||||
#define HMAC_PREPAREKEY hmac_sha256_preparekey
|
||||
#define HMAC_INIT hmac_sha256_init
|
||||
#define HMAC_UPDATE hmac_sha256_update
|
||||
#define HMAC_FINAL hmac_sha256_final
|
||||
#define HMAC hmac_sha256
|
||||
#define HMAC_USINGRAWKEY hmac_sha256_usingrawkey
|
||||
#include "hash-test-template.h"
|
||||
|
||||
static struct kunit_case hash_test_cases[] = {
|
||||
HASH_KUNIT_CASES,
|
||||
KUNIT_CASE(benchmark_hash),
|
||||
{},
|
||||
};
|
||||
|
||||
static struct kunit_suite hash_test_suite = {
|
||||
.name = "sha256",
|
||||
.test_cases = hash_test_cases,
|
||||
.suite_init = hash_suite_init,
|
||||
.suite_exit = hash_suite_exit,
|
||||
};
|
||||
kunit_test_suite(hash_test_suite);
|
||||
|
||||
MODULE_DESCRIPTION("KUnit tests and benchmark for SHA-256 and HMAC-SHA256");
|
||||
MODULE_LICENSE("GPL");
|
||||
Reference in New Issue
Block a user