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()
This commit is contained in:
Patrick Pelletier
2011-09-25 18:04:05 -07:00
committed by Steffen Jaeckel
parent 9228cbbd1e
commit cecbbb88fc
3 changed files with 19 additions and 14 deletions
+5 -2
View File
@@ -1,9 +1,12 @@
#include <tomcrypt_test.h>
void run_cmd(int res, int line, char *file, char *cmd)
void run_cmd(int res, int line, char *file, char *cmd, const char *algorithm)
{
if (res != CRYPT_OK) {
fprintf(stderr, "%s (%d)\n%s:%d:%s\n", error_to_string(res), res, file, line, cmd);
fprintf(stderr, "%s (%d)%s%s\n%s:%d:%s\n",
error_to_string(res), res,
(algorithm ? " - " : ""), (algorithm ? algorithm : ""),
file, line, cmd);
if (res != CRYPT_NOP) {
exit(EXIT_FAILURE);
}