-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtry.c
174 lines (158 loc) · 4.01 KB
/
try.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* crypto_core/try.c version 20240530
* D. J. Bernstein
* Public domain.
* Auto-generated by trygen.py; do not edit.
*/
#include "crypto_core.h"
#include "try.h"
const char *primitiveimplementation = crypto_core_IMPLEMENTATION;
#ifdef TIMECOP
#define LOOPS TIMECOP_LOOPS
#else
#ifdef SMALL
#define LOOPS 512
#else
#define LOOPS 4096
#endif
#endif
#include "test-loops.inc"
static unsigned char *h;
static unsigned char *n;
static unsigned char *k;
static unsigned char *c;
static unsigned char *h2;
static unsigned char *n2;
static unsigned char *k2;
static unsigned char *c2;
#define hlen crypto_core_OUTPUTBYTES
#define nlen crypto_core_INPUTBYTES
#define klen crypto_core_KEYBYTES
#define clen crypto_core_CONSTBYTES
void preallocate(void)
{
}
void allocate(void)
{
unsigned long long alloclen = 0;
if (alloclen < crypto_core_OUTPUTBYTES) alloclen = crypto_core_OUTPUTBYTES;
if (alloclen < crypto_core_INPUTBYTES) alloclen = crypto_core_INPUTBYTES;
if (alloclen < crypto_core_KEYBYTES) alloclen = crypto_core_KEYBYTES;
if (alloclen < crypto_core_CONSTBYTES) alloclen = crypto_core_CONSTBYTES;
h = alignedcalloc(alloclen);
n = alignedcalloc(alloclen);
k = alignedcalloc(alloclen);
c = alignedcalloc(alloclen);
h2 = alignedcalloc(alloclen);
n2 = alignedcalloc(alloclen);
k2 = alignedcalloc(alloclen);
c2 = alignedcalloc(alloclen);
}
void unalign(void)
{
++h;
++n;
++k;
++c;
++h2;
++n2;
++k2;
++c2;
}
void realign(void)
{
--h;
--n;
--k;
--c;
--h2;
--n2;
--k2;
--c2;
}
void predoit(void)
{
}
void doit(void)
{
crypto_core(h,n,k,c);
}
void test(void)
{
unsigned long long loop;
int result;
for (loop = 0;loop < LOOPS;++loop) {
output_prepare(h2,h,hlen);
input_prepare(n2,n,nlen);
input_prepare(k2,k,klen);
input_prepare(c2,c,clen);
poison(n,nlen);
poison(k,klen);
poison(c,clen);
result = crypto_core(h,n,k,c);
unpoison(&result,sizeof result);
if (result != 0) fail("crypto_core returns nonzero");
unpoison(h,hlen);
unpoison(n,nlen);
unpoison(k,klen);
unpoison(c,clen);
checksum(h,hlen);
output_compare(h2,h,hlen,"crypto_core");
input_compare(n2,n,nlen,"crypto_core");
input_compare(k2,k,klen,"crypto_core");
input_compare(c2,c,clen,"crypto_core");
double_canary(h2,h,hlen);
double_canary(n2,n,nlen);
double_canary(k2,k,klen);
double_canary(c2,c,clen);
poison(n2,nlen);
poison(k2,klen);
poison(c2,clen);
result = crypto_core(h2,n2,k2,c2);
unpoison(&result,sizeof result);
if (result != 0) fail("crypto_core returns nonzero");
unpoison(h2,hlen);
unpoison(n2,nlen);
unpoison(k2,klen);
unpoison(c2,clen);
if (memcmp(h2,h,hlen) != 0) fail("crypto_core is nondeterministic");
double_canary(h2,h,hlen);
double_canary(n2,n,nlen);
double_canary(k2,k,klen);
double_canary(c2,c,clen);
poison(n2,nlen);
poison(k,klen);
poison(c,clen);
result = crypto_core(n2,n2,k,c);
unpoison(&result,sizeof result);
if (result != 0) fail("crypto_core with n=h overlap returns nonzero");
unpoison(n2,hlen);
unpoison(k,klen);
unpoison(c,clen);
if (memcmp(n2,h,hlen) != 0) fail("crypto_core does not handle n=h overlap");
memcpy(n2,n,nlen);
poison(n,nlen);
poison(k2,klen);
poison(c,clen);
result = crypto_core(k2,n,k2,c);
unpoison(&result,sizeof result);
if (result != 0) fail("crypto_core with k=h overlap returns nonzero");
unpoison(k2,hlen);
unpoison(n,nlen);
unpoison(c,clen);
if (memcmp(k2,h,hlen) != 0) fail("crypto_core does not handle k=h overlap");
memcpy(k2,k,klen);
poison(n,nlen);
poison(k,klen);
poison(c2,clen);
result = crypto_core(c2,n,k,c2);
unpoison(&result,sizeof result);
if (result != 0) fail("crypto_core with c=h overlap returns nonzero");
unpoison(c2,hlen);
unpoison(n,nlen);
unpoison(k,klen);
if (memcmp(c2,h,hlen) != 0) fail("crypto_core does not handle c=h overlap");
memcpy(c2,c,clen);
}
#include "test-more.inc"
}