From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3603191484; Mon, 30 Jun 2025 16:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751300670; cv=none; b=Jx7U9/3+NWuL1ju7wpgZ+L+v23VIVe//t9tyPc+4S5ZiP27OliTEf4Lei4+ozse5nIBfbZtzyAYC0cqo0dauGX8xgEE8Kyh1KcjsWOG54HxYZobfFskBUrAgdvMth9D0qmXEmsB/5b2Hn9KauHth/ycB2fhAigN+twIGfEx5C88= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751300670; c=relaxed/simple; bh=aiWuN3GhqocDI35YBp5qTR55DHhbOh5tOWXvy8Qdgcc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SgbiAIEdu5ncc4W554zsAZaJj7qjTvU3mShLo5mYvu08JngDJ1Ono9wIXJ8JjhBu0t761Y4GxmYUNbjjko5A/4AVPxDlwoWRYZpdrpn9ohcIBbOP6uoLVvqcESG806s+BxMClhlpTNfAAXvGnVex/q3Pz7eFBetLBSM6hOvJ/VM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DnUaNgTr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DnUaNgTr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20D01C4CEE3; Mon, 30 Jun 2025 16:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751300670; bh=aiWuN3GhqocDI35YBp5qTR55DHhbOh5tOWXvy8Qdgcc=; h=From:To:Cc:Subject:Date:From; b=DnUaNgTrFrd5oOvO/6bSOKTcJRGYb1m3IgxrWXMjQ8qV6dHtKS2r1V7FDscI7TLZ9 7/SBtIZ2Bw62EgSgJ+1JXea1GgYOpgsogllqdf72Wlf/sL8uEXALO3KDlMAciWwCUQ L6e7czVtx3FcorhEPkyJenfU+EtPGpL/xbmYJpK1dAkB9Hv9/K4VQStsi8LYGeFk2J ElItXwJsm/GcdKFNdSd/Ruk2krjr8yuonuHHx6uT+nrRaIcFpavwsedaaeC1OJL8LD /tQxNcuwl8IklFsrj0JC5gOtL/M0vFWoggCEyDOTBdb31pNx3Jlj4LZuQLBh6ENBJ9 yZO3J4h/KcptQ== From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , "Jason A . Donenfeld" , Eric Biggers Subject: [PATCH v3 0/2] KUnit tests for SHA-2 library functions Date: Mon, 30 Jun 2025 09:20:12 -0700 Message-ID: <20250630162014.6463-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.50.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series is also available at: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git sha2-kunit-v3 This series adds KUnit tests for the SHA-2 library functions. Most of this code was originally part of my series "SHA-512 library functions". I made a few updates in "SHA-256 library improvements". As per the request from Linus that the tests be kept last on the branch for a separate pull request, I've reordered the history to add the tests last. Thus this patch series. Testing strategy: - Each SHA variant gets its own KUnit test suite, but a header is used to share most of the test code among the SHA variants. - Test against vectors generated by the Python hashlib and hmac modules. - Test incremental computation. - Test with a guard page to catch buffer overruns even in assembly code. - Test various overlap and alignment cases. - Compute hashes in task, softirq, and hardirq context in parallel, to verify that the functions work as expected in all contexts and that fallback code paths are exercised. - Test that the finalization functions zeroize their context. - Include benchmarks, guarded by a separate Kconfig option. Eric Biggers (2): lib/crypto: sha512: Add KUnit tests for SHA-384 and SHA-512 lib/crypto: sha256: Add KUnit tests for SHA-224 and SHA-256 lib/crypto/Kconfig | 2 + lib/crypto/Makefile | 2 + lib/crypto/tests/Kconfig | 25 + lib/crypto/tests/Makefile | 6 + lib/crypto/tests/hash-test-template.h | 512 ++++++++++++++++++++ lib/crypto/tests/sha224-testvecs.h | 470 ++++++++++++++++++ lib/crypto/tests/sha224_kunit.c | 48 ++ lib/crypto/tests/sha256-testvecs.h | 470 ++++++++++++++++++ lib/crypto/tests/sha256_kunit.c | 48 ++ lib/crypto/tests/sha384-testvecs.h | 566 ++++++++++++++++++++++ lib/crypto/tests/sha384_kunit.c | 48 ++ lib/crypto/tests/sha512-testvecs.h | 662 ++++++++++++++++++++++++++ lib/crypto/tests/sha512_kunit.c | 48 ++ scripts/crypto/gen-hash-testvecs.py | 83 ++++ 14 files changed, 2990 insertions(+) create mode 100644 lib/crypto/tests/Kconfig create mode 100644 lib/crypto/tests/Makefile create mode 100644 lib/crypto/tests/hash-test-template.h create mode 100644 lib/crypto/tests/sha224-testvecs.h create mode 100644 lib/crypto/tests/sha224_kunit.c create mode 100644 lib/crypto/tests/sha256-testvecs.h create mode 100644 lib/crypto/tests/sha256_kunit.c create mode 100644 lib/crypto/tests/sha384-testvecs.h create mode 100644 lib/crypto/tests/sha384_kunit.c create mode 100644 lib/crypto/tests/sha512-testvecs.h create mode 100644 lib/crypto/tests/sha512_kunit.c create mode 100755 scripts/crypto/gen-hash-testvecs.py -- 2.50.0