Skip to content

Commit f2f573e

Browse files
committed
Merge tag 'libcrypto-tests-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux
Pull crypto library test updates from Eric Biggers: "Add KUnit test suites for the Poly1305, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512 library functions. These are the first KUnit tests for lib/crypto/. So in addition to being useful tests for these specific algorithms, they also establish some conventions for lib/crypto/ testing going forwards. The new tests are fairly comprehensive: more comprehensive than the generic crypto infrastructure's tests. They use a variety of techniques to check for the types of implementation bugs that tend to occur in the real world, rather than just naively checking some test vectors. (Interestingly, poly1305_kunit found a bug in QEMU) The core test logic is shared by all six algorithms, rather than being duplicated for each algorithm. Each algorithm's test suite also optionally includes a benchmark" * tag 'libcrypto-tests-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux: lib/crypto: tests: Annotate worker to be on stack lib/crypto: tests: Add KUnit tests for SHA-1 and HMAC-SHA1 lib/crypto: tests: Add KUnit tests for Poly1305 lib/crypto: tests: Add KUnit tests for SHA-384 and SHA-512 lib/crypto: tests: Add KUnit tests for SHA-224 and SHA-256 lib/crypto: tests: Add hash-test-template.h and gen-hash-testvecs.py
2 parents 1315074 + 8cd876e commit f2f573e

18 files changed

Lines changed: 2766 additions & 0 deletions

lib/crypto/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ config CRYPTO_LIB_SHA512_ARCH
194194
config CRYPTO_LIB_SM3
195195
tristate
196196

197+
source "lib/crypto/tests/Kconfig"
198+
197199
if !KMSAN # avoid false positives from assembly
198200
if ARM
199201
source "lib/crypto/arm/Kconfig"

lib/crypto/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ quiet_cmd_perlasm = PERLASM $@
88
quiet_cmd_perlasm_with_args = PERLASM $@
99
cmd_perlasm_with_args = $(PERL) $(<) void $(@)
1010

11+
obj-$(CONFIG_KUNIT) += tests/
12+
1113
obj-$(CONFIG_CRYPTO_HASH_INFO) += hash_info.o
1214

1315
obj-$(CONFIG_CRYPTO_LIB_UTILS) += libcryptoutils.o

lib/crypto/tests/Kconfig

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
config CRYPTO_LIB_POLY1305_KUNIT_TEST
4+
tristate "KUnit tests for Poly1305" if !KUNIT_ALL_TESTS
5+
depends on KUNIT
6+
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
7+
select CRYPTO_LIB_BENCHMARK_VISIBLE
8+
select CRYPTO_LIB_POLY1305
9+
help
10+
KUnit tests for the Poly1305 library functions.
11+
12+
config CRYPTO_LIB_SHA1_KUNIT_TEST
13+
tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS
14+
depends on KUNIT
15+
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
16+
select CRYPTO_LIB_BENCHMARK_VISIBLE
17+
select CRYPTO_LIB_SHA1
18+
help
19+
KUnit tests for the SHA-1 cryptographic hash function and its
20+
corresponding HMAC.
21+
22+
# Option is named *_SHA256_KUNIT_TEST, though both SHA-224 and SHA-256 tests are
23+
# included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA256).
24+
config CRYPTO_LIB_SHA256_KUNIT_TEST
25+
tristate "KUnit tests for SHA-224 and SHA-256" if !KUNIT_ALL_TESTS
26+
depends on KUNIT
27+
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
28+
select CRYPTO_LIB_BENCHMARK_VISIBLE
29+
select CRYPTO_LIB_SHA256
30+
help
31+
KUnit tests for the SHA-224 and SHA-256 cryptographic hash functions
32+
and their corresponding HMACs.
33+
34+
# Option is named *_SHA512_KUNIT_TEST, though both SHA-384 and SHA-512 tests are
35+
# included, for consistency with the naming used elsewhere (e.g. CRYPTO_SHA512).
36+
config CRYPTO_LIB_SHA512_KUNIT_TEST
37+
tristate "KUnit tests for SHA-384 and SHA-512" if !KUNIT_ALL_TESTS
38+
depends on KUNIT
39+
default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS
40+
select CRYPTO_LIB_BENCHMARK_VISIBLE
41+
select CRYPTO_LIB_SHA512
42+
help
43+
KUnit tests for the SHA-384 and SHA-512 cryptographic hash functions
44+
and their corresponding HMACs.
45+
46+
config CRYPTO_LIB_BENCHMARK_VISIBLE
47+
bool
48+
49+
config CRYPTO_LIB_BENCHMARK
50+
bool "Include benchmarks in KUnit tests for cryptographic functions"
51+
depends on CRYPTO_LIB_BENCHMARK_VISIBLE
52+
help
53+
Include benchmarks in the KUnit tests for cryptographic functions.
54+
The benchmark results are printed to the kernel log when the
55+
corresponding KUnit test suite runs.
56+
57+
This is useful for evaluating the performance of the cryptographic
58+
functions. However, it will increase the runtime of the KUnit tests.
59+
60+
If you're only interested in correctness testing, leave this disabled.

lib/crypto/tests/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
obj-$(CONFIG_CRYPTO_LIB_POLY1305_KUNIT_TEST) += poly1305_kunit.o
4+
obj-$(CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST) += sha1_kunit.o
5+
obj-$(CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST) += sha224_kunit.o sha256_kunit.o
6+
obj-$(CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST) += sha384_kunit.o sha512_kunit.o

0 commit comments

Comments
 (0)