Coverage Report

Created: 2024-03-22 06:04

/builds/xfbs/passgen/src/tests/siphash.c
Line
Count
Source
1
#include "passgen/util/siphash.h"
2
#include "tests.h"
3
4
1
test_result test_siphash64(void) {
5
1
    // test siphash64 (8 byte output)
6
1
    const char *key = "zppyfssftiwghlcy";
7
1
    struct {
8
1
        const char *input;
9
1
        uint8_t output[8];
10
1
    } testcases[] = {
11
1
        {.input = "input",
12
1
         .output = {0x6c, 0xef, 0x54, 0xb9, 0xcb, 0x8a, 0xe9, 0x43}},
13
1
        {.input = "test",
14
1
         .output = {0xf0, 0x32, 0x3b, 0x4f, 0x2d, 0x61, 0x5d, 0x99}},
15
1
        {.input = "passgen",
16
1
         .output = {0x45, 0x10, 0x48, 0x0e, 0x04, 0x58, 0xc0, 0xee}},
17
1
        {.input = "pattern",
18
1
         .output = {0x83, 0x99, 0xf6, 0xc6, 0x57, 0x7e, 0xdb, 0x7e}},
19
1
        {.input = "hash",
20
1
         .output = {0xbf, 0x27, 0xf4, 0x7b, 0xf8, 0xb4, 0xef, 0xbe}},
21
1
        {.input = "asam",
22
1
         .output = {0x9c, 0x7d, 0xae, 0x86, 0xdd, 0x97, 0x94, 0xe6}},
23
1
        {.input = "bsam",
24
1
         .output = {0xce, 0x87, 0x56, 0x58, 0xbb, 0x3c, 0x80, 0xe1}},
25
1
        {.input = "longjohn",
26
1
         .output = {0xbc, 0xfd, 0x5a, 0xf7, 0x43, 0xaf, 0x4a, 0x55}},
27
1
        {NULL}};
28
1
29
9
    for(size_t i = 0; testcases[i].input; 
i++8
) {
30
8
        uint8_t output[8];
31
8
        const char *input = testcases[i].input;
32
8
        assert_eq(
33
8
            0,
34
8
            passgen_siphash(input, strlen(input), key, output, sizeof(output)));
35
72
        for(size_t b = 0; b < sizeof(output); 
b++64
) {
36
64
            assert_eq(output[b], testcases[i].output[b]);
37
64
        }
38
8
    }
39
1
40
1
    return test_ok;
41
1
}
42
43
1
test_result test_siphash128(void) {
44
1
    // test siphash128 (16 byte output)
45
1
    const char *key = "zppyfssftiwghlcy";
46
1
    struct {
47
1
        const char *input;
48
1
        uint8_t output[16];
49
1
    } testcases[] = {
50
1
        {.input = "input",
51
1
         .output =
52
1
             {0xaa,
53
1
              0x06,
54
1
              0xb4,
55
1
              0x1b,
56
1
              0x1e,
57
1
              0x00,
58
1
              0xaa,
59
1
              0x80,
60
1
              0x07,
61
1
              0xdc,
62
1
              0xd5,
63
1
              0x7b,
64
1
              0x82,
65
1
              0x33,
66
1
              0x79,
67
1
              0x1a}},
68
1
        {.input = "test",
69
1
         .output =
70
1
             {0x9c,
71
1
              0x04,
72
1
              0x7e,
73
1
              0x22,
74
1
              0x1c,
75
1
              0x46,
76
1
              0x69,
77
1
              0xd6,
78
1
              0xd7,
79
1
              0xe1,
80
1
              0x73,
81
1
              0xa8,
82
1
              0x66,
83
1
              0xeb,
84
1
              0x93,
85
1
              0x2b}},
86
1
        {.input = "passgen",
87
1
         .output =
88
1
             {0xbf,
89
1
              0x62,
90
1
              0x3a,
91
1
              0xac,
92
1
              0x34,
93
1
              0x5a,
94
1
              0xd7,
95
1
              0x74,
96
1
              0xab,
97
1
              0x83,
98
1
              0xac,
99
1
              0xad,
100
1
              0x04,
101
1
              0xd4,
102
1
              0xa0,
103
1
              0xed}},
104
1
        {.input = "pattern",
105
1
         .output =
106
1
             {0x26,
107
1
              0xe5,
108
1
              0x55,
109
1
              0xd0,
110
1
              0xd1,
111
1
              0x90,
112
1
              0xbc,
113
1
              0x9e,
114
1
              0x8c,
115
1
              0x34,
116
1
              0x7f,
117
1
              0xe0,
118
1
              0x87,
119
1
              0xd6,
120
1
              0x87,
121
1
              0xdc}},
122
1
        {.input = "hash",
123
1
         .output =
124
1
             {0x34,
125
1
              0x70,
126
1
              0x1f,
127
1
              0x51,
128
1
              0xac,
129
1
              0xce,
130
1
              0x41,
131
1
              0x65,
132
1
              0x19,
133
1
              0x0f,
134
1
              0x1c,
135
1
              0x72,
136
1
              0x1b,
137
1
              0x84,
138
1
              0x45,
139
1
              0xd8}},
140
1
        {.input = "asam",
141
1
         .output =
142
1
             {0xd6,
143
1
              0x19,
144
1
              0x0d,
145
1
              0xfa,
146
1
              0xdc,
147
1
              0xfc,
148
1
              0xd2,
149
1
              0x5a,
150
1
              0xbf,
151
1
              0xa8,
152
1
              0xdc,
153
1
              0x78,
154
1
              0x41,
155
1
              0xb4,
156
1
              0xa9,
157
1
              0xd0}},
158
1
        {.input = "bsam",
159
1
         .output =
160
1
             {0xe3,
161
1
              0x70,
162
1
              0x02,
163
1
              0x94,
164
1
              0x4b,
165
1
              0xc4,
166
1
              0xeb,
167
1
              0xec,
168
1
              0x92,
169
1
              0x3e,
170
1
              0xee,
171
1
              0xa2,
172
1
              0xfb,
173
1
              0x18,
174
1
              0x5d,
175
1
              0xef}},
176
1
        {.input = "longjohn",
177
1
         .output =
178
1
             {0xdf,
179
1
              0xa7,
180
1
              0x8a,
181
1
              0x97,
182
1
              0xf0,
183
1
              0xdf,
184
1
              0x0e,
185
1
              0x62,
186
1
              0xc5,
187
1
              0x1b,
188
1
              0x8b,
189
1
              0x6b,
190
1
              0x79,
191
1
              0xda,
192
1
              0x3f,
193
1
              0xde}},
194
1
        {NULL}};
195
1
196
9
    for(size_t i = 0; testcases[i].input; 
i++8
) {
197
8
        uint8_t output[16];
198
8
        const char *input = testcases[i].input;
199
8
        assert_eq(
200
8
            0,
201
8
            passgen_siphash(input, strlen(input), key, output, sizeof(output)));
202
136
        for(size_t b = 0; b < sizeof(output); 
b++128
) {
203
128
            assert_eq(output[b], testcases[i].output[b]);
204
128
        }
205
8
    }
206
1
207
1
    return test_ok;
208
1
}