-
Notifications
You must be signed in to change notification settings - Fork 13
/
test-vectors.c
87 lines (78 loc) · 2.49 KB
/
test-vectors.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Test vectors for shishua
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#ifndef HEADER
# define HEADER "shishua.h"
#endif
#include HEADER
#define phi phi_half
#define prng_state prng_state_half
#define prng_init prng_init_half
#define prng_gen prng_gen_half
#ifndef HEADER_HALF
# define HEADER_HALF "shishua-half.h"
#endif
#include HEADER_HALF
#undef phi
#undef prng_state
#undef prng_init
#undef prng_gen
#include "test-vectors.h" // generated file
static size_t find_mismatch(const uint8_t *a, const uint8_t *b, size_t size) {
for (size_t i = 0; i < size; i++) {
if (a[i] != b[i])
return i;
}
return size;
}
int main(void) {
uint8_t buf[sizeof(shishua_vector_unseeded)] = {0};
prng_state state;
prng_init(&state, seed_zero);
memset(buf, 0, sizeof(buf));
prng_gen(&state, buf, sizeof(buf));
size_t offset = find_mismatch(shishua_vector_unseeded, buf, sizeof(buf));
if (offset >= sizeof(buf)) {
printf("shishua unseeded: ok\n");
} else {
printf("shishua: mismatch at position %zu.\n", offset);
printf("expected: %#02x, got %#02x\n", shishua_vector_unseeded[offset], buf[offset]);
return 1;
}
prng_state_half state_half;
prng_init_half(&state_half, seed_zero);
memset(buf, 0, sizeof(buf));
prng_gen_half(&state_half, buf, sizeof(buf));
offset = find_mismatch(shishua_half_vector_unseeded, buf, sizeof(buf));
if (offset >= sizeof(buf)) {
printf("shishua half unseeded: ok\n");
} else {
printf("shishua half unseeded: mismatch at position %zu.\n", offset);
printf("expected: %#02x, got %#02x\n", shishua_half_vector_unseeded[offset], buf[offset]);
return 1;
}
prng_init(&state, seed_pi);
memset(buf, 0, sizeof(buf));
prng_gen(&state, buf, sizeof(buf));
offset = find_mismatch(shishua_vector_seeded, buf, sizeof(buf));
if (offset >= sizeof(buf)) {
printf("shishua seeded: ok\n");
} else {
printf("shishua seeded: mismatch at position %zu.\n", offset);
printf("expected: %#02x, got %#02x\n", shishua_vector_seeded[offset], buf[offset]);
return 1;
}
prng_init_half(&state_half, seed_pi);
memset(buf, 0, sizeof(buf));
prng_gen_half(&state_half, buf, sizeof(buf));
offset = find_mismatch(shishua_half_vector_seeded, buf, sizeof(buf));
if (offset >= sizeof(buf)) {
printf("shishua half seeded: ok\n");
} else {
printf("shishua half seeded: mismatch at position %zu.\n", offset);
printf("expected: %#02x, got %#02x\n", shishua_half_vector_seeded[offset], buf[offset]);
return 1;
}
return 0;
}