libtomcrypt/testprof/cipher_hash_test.c
Patrick Pelletier cecbbb88fc When a test fails, print the algorithm that it failed on.
As near as I can tell, LibTomCrypt doesn't provide any way to tell
which cipher failed when it reports a cipher test failure.  For
example, I was getting:

Algorithm failed test vectors. (5)
cipher_hash_test.c:14:cipher_descriptor[x].test()

But there's no way to tell what value x has, and even if there was, it
would take a bit of digging to determine which algorithm that
corresponds to.  So, I added a variant of the DO() macro, DOX(), which
takes an additional string argument which is displayed on failure.  So
now I get:

Algorithm failed test vectors. (5) - camellia
cipher_hash_test.c:14:cipher_descriptor[x].test()
2012-11-18 15:20:10 +01:00

46 lines
1.5 KiB
C

/* test the ciphers and hashes using their built-in self-tests */
#include <tomcrypt_test.h>
int cipher_hash_test(void)
{
int x;
unsigned char buf[4096];
unsigned long n;
prng_state nprng;
/* test ciphers */
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
DOX(cipher_descriptor[x].test(), cipher_descriptor[x].name);
}
/* test hashes */
for (x = 0; hash_descriptor[x].name != NULL; x++) {
DOX(hash_descriptor[x].test(), hash_descriptor[x].name);
}
/* test prngs (test, import/export */
for (x = 0; prng_descriptor[x].name != NULL; x++) {
DOX(prng_descriptor[x].test(), prng_descriptor[x].name);
DOX(prng_descriptor[x].start(&nprng), prng_descriptor[x].name);
DOX(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng), prng_descriptor[x].name);
DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name);
n = sizeof(buf);
DOX(prng_descriptor[x].pexport(buf, &n, &nprng), prng_descriptor[x].name);
prng_descriptor[x].done(&nprng);
DOX(prng_descriptor[x].pimport(buf, n, &nprng), prng_descriptor[x].name);
DOX(prng_descriptor[x].ready(&nprng), prng_descriptor[x].name);
if (prng_descriptor[x].read(buf, 100, &nprng) != 100) {
fprintf(stderr, "Error reading from imported PRNG!\n");
exit(EXIT_FAILURE);
}
prng_descriptor[x].done(&nprng);
}
return 0;
}
/* $Source$ */
/* $Revision$ */
/* $Date$ */