]>
Dogcows Code - chaz/p5-File-KDBX-XS/blob - libtomcrypt/src/misc/compare_testvector.c
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
4 #include "tomcrypt_private.h"
7 @file compare_testvector.c
8 Function to compare two testvectors and print a (detailed) error-message if required, Steffen Jaeckel
11 #if defined(LTC_TEST) && defined(LTC_TEST_DBG)
12 static void s_print_hex(const char* what
, const void* v
, const unsigned long l
)
14 const unsigned char* p
= v
;
15 unsigned long x
, y
= 0, z
;
16 fprintf(stderr
, "%s contents: \n", what
);
17 for (x
= 0; x
< l
; ) {
18 fprintf(stderr
, "%02X ", p
[x
]);
19 if (!(++x
% 16) || x
== l
) {
28 fprintf(stderr
, " | ");
33 fprintf(stderr
, "%c", p
[y
]);
37 fprintf(stderr
, "\n");
39 else if((x
% 8) == 0) {
47 Compare two test-vectors
49 @param is The data as it is
50 @param is_len The length of is
51 @param should The data as it should
52 @param should_len The length of should
53 @param what The type of the data
54 @param which The iteration count
55 @return 0 on equality, -1 or 1 on difference
57 int compare_testvector(const void* is
, const unsigned long is_len
, const void* should
, const unsigned long should_len
, const char* what
, int which
)
60 if(is_len
!= should_len
) {
61 res
= is_len
> should_len
? -1 : 1;
63 res
= XMEMCMP(is
, should
, is_len
);
65 #if defined(LTC_TEST) && defined(LTC_TEST_DBG)
67 fprintf(stderr
, "Testvector #%i(0x%x) of %s failed:\n", which
, which
, what
);
68 s_print_hex("SHOULD", should
, should_len
);
69 s_print_hex("IS ", is
, is_len
);
72 fprintf(stderr
, "Testvector #%i(0x%x) of %s passed!\n", which
, which
, what
);
76 LTC_UNUSED_PARAM(which
);
77 LTC_UNUSED_PARAM(what
);
This page took 0.03697 seconds and 4 git commands to generate.