1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
13 @file compare_testvector.c
14 Function to compare two testvectors and print a (detailed) error-message if required, Steffen Jaeckel
17 #if defined(LTC_TEST) && defined(LTC_TEST_DBG)
18 static void _print_hex(const char* what, const void* v, const unsigned long l)
20 const unsigned char* p = v;
21 unsigned long x, y = 0, z;
22 fprintf(stderr, "%s contents: \n", what);
23 for (x = 0; x < l; ) {
24 fprintf(stderr, "%02X ", p[x]);
25 if (!(++x % 16) || x == l) {
34 fprintf(stderr, " | ");
39 fprintf(stderr, "%c", p[y]);
43 fprintf(stderr, "\n");
45 else if((x % 8) == 0) {
53 Compare two test-vectors
55 @param is The data as it is
56 @param is_len The length of is
57 @param should The data as it should
58 @param should_len The length of should
59 @param what The type of the data
60 @param which The iteration count
61 @return 0 on equality, -1 or 1 on difference
63 int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)
66 if(is_len != should_len)
67 res = is_len > should_len ? -1 : 1;
69 res = XMEMCMP(is, should, is_len);
71 #if defined(LTC_TEST) && defined(LTC_TEST_DBG)
73 fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);
74 _print_hex("SHOULD", should, should_len);
75 _print_hex("IS ", is, is_len);
78 LTC_UNUSED_PARAM(which);
79 LTC_UNUSED_PARAM(what);
85 /* ref: $Format:%D$ */
86 /* git commit: $Format:%H$ */
87 /* commit time: $Format:%ai$ */