summaryrefslogtreecommitdiff
path: root/test/test-helpers.h
blob: cee7d195057c464d6a83b49817546c9d373eb72c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef TEST_HELPERS_H
#define TEST_HELPERS_H

#include <inttypes.h>
#include <stdio.h>

#include "constants.h"


#define ARRAY_NB(A) (sizeof(A)/sizeof(A[0]))
#define ARRAY_END(A) (A+ARRAY_NB(A))

#define REPORT_DIFFERENCE(VECTOR, ELEMENT) do {                         \
        fprintf(stderr, "%s: vector %s: %s differs from expected\n",    \
                __FILE__, (VECTOR), (ELEMENT));                         \
    } while (0)

#define REPORT_INVALID(VECTOR) do {                                     \
        fprintf(stderr, "%s: vector %s: ciphertext/tag invalid\n",      \
                __FILE__, (VECTOR));                                    \
    } while (0)


/* Used to update vectors when the specification changes. */
static inline void dump_c_initializer(size_t len, uint8_t buf[len])
{
    printf("{\n");

    const size_t columns = 8;

    for (size_t i=0; i<len; i++)
    {
        printf("0x%02"PRIx8, buf[i]);

        if (i == len-1)
        {
            printf("\n");
        }
        else if (i%columns == columns-1)
        {
            printf(",\n");
        }
        else
        {
            printf(", ");
        }
    }

    printf("}\n");
}



#endif /* TEST_HELPERS_H */