test-helpers.h (1212B)
1 #ifndef TEST_HELPERS_H 2 #define TEST_HELPERS_H 3 4 #include <inttypes.h> 5 #include <stdio.h> 6 7 #include "constants.h" 8 9 10 #define ARRAY_NB(A) (sizeof(A)/sizeof(A[0])) 11 #define ARRAY_END(A) (A+ARRAY_NB(A)) 12 13 #define REPORT_DIFFERENCE(VECTOR, ELEMENT) do { \ 14 fprintf(stderr, "%s: vector %s: %s differs from expected\n", \ 15 __FILE__, (VECTOR), (ELEMENT)); \ 16 } while (0) 17 18 #define REPORT_INVALID(VECTOR) do { \ 19 fprintf(stderr, "%s: vector %s: ciphertext/tag invalid\n", \ 20 __FILE__, (VECTOR)); \ 21 } while (0) 22 23 24 /* Used to update vectors when the specification changes. */ 25 static inline void dump_c_initializer(size_t len, uint8_t buf[len]) 26 { 27 printf("{\n"); 28 29 const size_t columns = 8; 30 31 for (size_t i=0; i<len; i++) 32 { 33 printf("0x%02"PRIx8, buf[i]); 34 35 if (i == len-1) 36 { 37 printf("\n"); 38 } 39 else if (i%columns == columns-1) 40 { 41 printf(",\n"); 42 } 43 else 44 { 45 printf(", "); 46 } 47 } 48 49 printf("}\n"); 50 } 51 52 53 54 #endif /* TEST_HELPERS_H */