diff options
author | Kangheui Won <khwon@chromium.org> | 2021-09-03 17:06:01 +1000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-09-22 10:02:41 +0000 |
commit | 8d052c7151b543e787da8fdd8c9638227fc201d9 (patch) | |
tree | 12dd433ebff4cfc5914ada2b091917bb0c1f84bf /tests | |
parent | 20660716b0273d82ccf456bf990451276472593a (diff) | |
download | vboot-8d052c7151b543e787da8fdd8c9638227fc201d9.tar.gz |
vb2_sha256_x86_test: check sha-ni support by cpuid
The test uses sha-ni extension, so it crashes on platforms without
sha-ni. Add cpuid checks to avoid that.
BUG=b:162551138
BRANCH=none
TEST=run test on Haswell, which doesn't have sha-ni
Signed-off-by: Kangheui Won <khwon@chromium.org>
Change-Id: I6e18843a723d022c67832ef970d4dc470c1aadce
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3140849
Reviewed-by: Raul E Rangel <rrangel@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/vb2_sha256_x86_tests.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/vb2_sha256_x86_tests.c b/tests/vb2_sha256_x86_tests.c index ca934e47..06ba12e1 100644 --- a/tests/vb2_sha256_x86_tests.c +++ b/tests/vb2_sha256_x86_tests.c @@ -5,6 +5,7 @@ /* FIPS 180-2 Tests for message digest functions. */ +#include <cpuid.h> #include <stdio.h> #include "2api.h" @@ -114,6 +115,14 @@ static void known_value_tests(void) int main(int argc, char *argv[]) { + uint32_t a, b = 0, c, d; + /* EAX = 07H, sub-leaf 0 */ + __get_cpuid_count(7, 0, &a, &b, &c, &d); + if ((b & bit_SHA) == 0) { + fprintf(stderr, "SHA-NI not supported.\n"); + return 254; + } + /* Initialize long_msg with 'a' x 1,000,000 */ long_msg = (char *) malloc(1000001); memset(long_msg, 'a', 1000000); |