Skip to content

Commit aeb9fb3

Browse files
robnbehlendorf
authored andcommitted
sha2_test: do correctness checks for all implementations
Sponsored-by: TrueNAS Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Attila Fülöp <attila@fueloep.org> Reviewed-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com> Signed-off-by: Rob Norris <rob.norris@truenas.com> Closes #18232
1 parent b291d9a commit aeb9fb3

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

tests/zfs-tests/cmd/checksum/sha2_test.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
/*
2424
* Copyright 2013 Saso Kiselkov. All rights reserved.
25+
* Copyright (c) 2026, TrueNAS.
2526
*/
2627

2728
/*
@@ -142,15 +143,15 @@ main(int argc, char *argv[])
142143
if (!sha512)
143144
return (1);
144145

145-
#define SHA2_ALGO_TEST(_m, mode, diglen, testdigest) \
146+
#define SHA2_ALGO_TEST(_m, mode, diglen, testdigest, name) \
146147
do { \
147148
SHA2_CTX ctx; \
148149
uint8_t digest[diglen / 8]; \
149150
SHA2Init(mode, &ctx); \
150151
SHA2Update(&ctx, _m, strlen(_m)); \
151152
SHA2Final(digest, &ctx); \
152-
(void) printf("SHA%-9sMessage: " #_m \
153-
"\tResult: ", #mode); \
153+
(void) printf("%-11s %-9s Message: " #_m \
154+
"\tResult: ", #mode, name); \
154155
if (memcmp(digest, testdigest, diglen / 8) == 0) { \
155156
(void) printf("OK\n"); \
156157
} else { \
@@ -181,22 +182,38 @@ main(int argc, char *argv[])
181182
cpb = (cpu_mhz * 1e6 * ((double)delta / \
182183
1000000)) / (8192 * 128 * 1024); \
183184
} \
184-
(void) printf("sha%s-%-9s%7llu us (%.02f CPB)\n", #mode,\
185+
(void) printf("%s-%-9s %9llu us (%.02f CPB)\n", #mode, \
185186
name, (u_longlong_t)delta, cpb); \
186187
} while (0)
187188

188189
(void) printf("Running algorithm correctness tests:\n");
189-
SHA2_ALGO_TEST(test_msg0, SHA256, 256, sha256_test_digests[0]);
190-
SHA2_ALGO_TEST(test_msg1, SHA256, 256, sha256_test_digests[1]);
191-
SHA2_ALGO_TEST(test_msg0, SHA512, 512, sha512_test_digests[0]);
192-
SHA2_ALGO_TEST(test_msg2, SHA512, 512, sha512_test_digests[2]);
193-
SHA2_ALGO_TEST(test_msg0, SHA512_256, 256, sha512_256_test_digests[0]);
194-
SHA2_ALGO_TEST(test_msg2, SHA512_256, 256, sha512_256_test_digests[2]);
190+
191+
for (id = 0; id < sha256->getcnt(); id++) {
192+
sha256->setid(id);
193+
const char *name = sha256->getname();
194+
SHA2_ALGO_TEST(test_msg0, SHA256, 256,
195+
sha256_test_digests[0], name);
196+
SHA2_ALGO_TEST(test_msg1, SHA256, 256,
197+
sha256_test_digests[1], name);
198+
}
199+
200+
for (id = 0; id < sha512->getcnt(); id++) {
201+
sha512->setid(id);
202+
const char *name = sha512->getname();
203+
SHA2_ALGO_TEST(test_msg0, SHA512, 512,
204+
sha512_test_digests[0], name);
205+
SHA2_ALGO_TEST(test_msg2, SHA512, 512,
206+
sha512_test_digests[2], name);
207+
SHA2_ALGO_TEST(test_msg0, SHA512_256, 256,
208+
sha512_256_test_digests[0], name);
209+
SHA2_ALGO_TEST(test_msg2, SHA512_256, 256,
210+
sha512_256_test_digests[2], name);
211+
}
195212

196213
if (failed)
197214
return (1);
198215

199-
(void) printf("Running performance tests (hashing 1024 MiB of "
216+
(void) printf("\nRunning performance tests (hashing 1024 MiB of "
200217
"data):\n");
201218

202219
for (id = 0; id < sha256->getcnt(); id++) {

0 commit comments

Comments
 (0)