xref: /minix3/crypto/external/bsd/openssl/dist/crypto/constant_time_test.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* crypto/constant_time_test.c */
2*0a6a1f1dSLionel Sambuc /*-
3*0a6a1f1dSLionel Sambuc  * Utilities for constant-time cryptography.
4*0a6a1f1dSLionel Sambuc  *
5*0a6a1f1dSLionel Sambuc  * Author: Emilia Kasper (emilia@openssl.org)
6*0a6a1f1dSLionel Sambuc  * Based on previous work by Bodo Moeller, Emilia Kasper, Adam Langley
7*0a6a1f1dSLionel Sambuc  * (Google).
8*0a6a1f1dSLionel Sambuc  * ====================================================================
9*0a6a1f1dSLionel Sambuc  * Copyright (c) 2014 The OpenSSL Project.  All rights reserved.
10*0a6a1f1dSLionel Sambuc  *
11*0a6a1f1dSLionel Sambuc  * Redistribution and use in source and binary forms, with or without
12*0a6a1f1dSLionel Sambuc  * modification, are permitted provided that the following conditions
13*0a6a1f1dSLionel Sambuc  * are met:
14*0a6a1f1dSLionel Sambuc  * 1. Redistributions of source code must retain the copyright
15*0a6a1f1dSLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
16*0a6a1f1dSLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
17*0a6a1f1dSLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
18*0a6a1f1dSLionel Sambuc  *    documentation and/or other materials provided with the distribution.
19*0a6a1f1dSLionel Sambuc  * 3. All advertising materials mentioning features or use of this software
20*0a6a1f1dSLionel Sambuc  *    must display the following acknowledgement:
21*0a6a1f1dSLionel Sambuc  *    "This product includes cryptographic software written by
22*0a6a1f1dSLionel Sambuc  *     Eric Young (eay@cryptsoft.com)"
23*0a6a1f1dSLionel Sambuc  *    The word 'cryptographic' can be left out if the rouines from the library
24*0a6a1f1dSLionel Sambuc  *    being used are not cryptographic related :-).
25*0a6a1f1dSLionel Sambuc  * 4. If you include any Windows specific code (or a derivative thereof) from
26*0a6a1f1dSLionel Sambuc  *    the apps directory (application code) you must include an acknowledgement:
27*0a6a1f1dSLionel Sambuc  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
28*0a6a1f1dSLionel Sambuc  *
29*0a6a1f1dSLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
30*0a6a1f1dSLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31*0a6a1f1dSLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32*0a6a1f1dSLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
33*0a6a1f1dSLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34*0a6a1f1dSLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35*0a6a1f1dSLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36*0a6a1f1dSLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37*0a6a1f1dSLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38*0a6a1f1dSLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39*0a6a1f1dSLionel Sambuc  * SUCH DAMAGE.
40*0a6a1f1dSLionel Sambuc  *
41*0a6a1f1dSLionel Sambuc  * The licence and distribution terms for any publically available version or
42*0a6a1f1dSLionel Sambuc  * derivative of this code cannot be changed.  i.e. this code cannot simply be
43*0a6a1f1dSLionel Sambuc  * copied and put under another distribution licence
44*0a6a1f1dSLionel Sambuc  * [including the GNU Public Licence.]
45*0a6a1f1dSLionel Sambuc  */
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc #include "../crypto/constant_time_locl.h"
48*0a6a1f1dSLionel Sambuc 
49*0a6a1f1dSLionel Sambuc #include <limits.h>
50*0a6a1f1dSLionel Sambuc #include <stdio.h>
51*0a6a1f1dSLionel Sambuc #include <stdlib.h>
52*0a6a1f1dSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc static const unsigned int CONSTTIME_TRUE = (unsigned)(~0);
54*0a6a1f1dSLionel Sambuc static const unsigned int CONSTTIME_FALSE = 0;
55*0a6a1f1dSLionel Sambuc static const unsigned char CONSTTIME_TRUE_8 = 0xff;
56*0a6a1f1dSLionel Sambuc static const unsigned char CONSTTIME_FALSE_8 = 0;
57*0a6a1f1dSLionel Sambuc 
test_binary_op(unsigned int (* op)(unsigned int a,unsigned int b),const char * op_name,unsigned int a,unsigned int b,int is_true)58*0a6a1f1dSLionel Sambuc static int test_binary_op(unsigned int (*op) (unsigned int a, unsigned int b),
59*0a6a1f1dSLionel Sambuc                           const char *op_name, unsigned int a, unsigned int b,
60*0a6a1f1dSLionel Sambuc                           int is_true)
61*0a6a1f1dSLionel Sambuc {
62*0a6a1f1dSLionel Sambuc     unsigned c = op(a, b);
63*0a6a1f1dSLionel Sambuc     if (is_true && c != CONSTTIME_TRUE) {
64*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for %s(%du, %du): expected %du "
65*0a6a1f1dSLionel Sambuc                 "(TRUE), got %du\n", op_name, a, b, CONSTTIME_TRUE, c);
66*0a6a1f1dSLionel Sambuc         return 1;
67*0a6a1f1dSLionel Sambuc     } else if (!is_true && c != CONSTTIME_FALSE) {
68*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for  %s(%du, %du): expected %du "
69*0a6a1f1dSLionel Sambuc                 "(FALSE), got %du\n", op_name, a, b, CONSTTIME_FALSE, c);
70*0a6a1f1dSLionel Sambuc         return 1;
71*0a6a1f1dSLionel Sambuc     }
72*0a6a1f1dSLionel Sambuc     return 0;
73*0a6a1f1dSLionel Sambuc }
74*0a6a1f1dSLionel Sambuc 
test_binary_op_8(unsigned char (* op)(unsigned int a,unsigned int b),const char * op_name,unsigned int a,unsigned int b,int is_true)75*0a6a1f1dSLionel Sambuc static int test_binary_op_8(unsigned
76*0a6a1f1dSLionel Sambuc                             char (*op) (unsigned int a, unsigned int b),
77*0a6a1f1dSLionel Sambuc                             const char *op_name, unsigned int a,
78*0a6a1f1dSLionel Sambuc                             unsigned int b, int is_true)
79*0a6a1f1dSLionel Sambuc {
80*0a6a1f1dSLionel Sambuc     unsigned char c = op(a, b);
81*0a6a1f1dSLionel Sambuc     if (is_true && c != CONSTTIME_TRUE_8) {
82*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for %s(%du, %du): expected %u "
83*0a6a1f1dSLionel Sambuc                 "(TRUE), got %u\n", op_name, a, b, CONSTTIME_TRUE_8, c);
84*0a6a1f1dSLionel Sambuc         return 1;
85*0a6a1f1dSLionel Sambuc     } else if (!is_true && c != CONSTTIME_FALSE_8) {
86*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for  %s(%du, %du): expected %u "
87*0a6a1f1dSLionel Sambuc                 "(FALSE), got %u\n", op_name, a, b, CONSTTIME_FALSE_8, c);
88*0a6a1f1dSLionel Sambuc         return 1;
89*0a6a1f1dSLionel Sambuc     }
90*0a6a1f1dSLionel Sambuc     return 0;
91*0a6a1f1dSLionel Sambuc }
92*0a6a1f1dSLionel Sambuc 
test_is_zero(unsigned int a)93*0a6a1f1dSLionel Sambuc static int test_is_zero(unsigned int a)
94*0a6a1f1dSLionel Sambuc {
95*0a6a1f1dSLionel Sambuc     unsigned int c = constant_time_is_zero(a);
96*0a6a1f1dSLionel Sambuc     if (a == 0 && c != CONSTTIME_TRUE) {
97*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
98*0a6a1f1dSLionel Sambuc                 "expected %du (TRUE), got %du\n", a, CONSTTIME_TRUE, c);
99*0a6a1f1dSLionel Sambuc         return 1;
100*0a6a1f1dSLionel Sambuc     } else if (a != 0 && c != CONSTTIME_FALSE) {
101*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
102*0a6a1f1dSLionel Sambuc                 "expected %du (FALSE), got %du\n", a, CONSTTIME_FALSE, c);
103*0a6a1f1dSLionel Sambuc         return 1;
104*0a6a1f1dSLionel Sambuc     }
105*0a6a1f1dSLionel Sambuc     return 0;
106*0a6a1f1dSLionel Sambuc }
107*0a6a1f1dSLionel Sambuc 
test_is_zero_8(unsigned int a)108*0a6a1f1dSLionel Sambuc static int test_is_zero_8(unsigned int a)
109*0a6a1f1dSLionel Sambuc {
110*0a6a1f1dSLionel Sambuc     unsigned char c = constant_time_is_zero_8(a);
111*0a6a1f1dSLionel Sambuc     if (a == 0 && c != CONSTTIME_TRUE_8) {
112*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
113*0a6a1f1dSLionel Sambuc                 "expected %u (TRUE), got %u\n", a, CONSTTIME_TRUE_8, c);
114*0a6a1f1dSLionel Sambuc         return 1;
115*0a6a1f1dSLionel Sambuc     } else if (a != 0 && c != CONSTTIME_FALSE) {
116*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
117*0a6a1f1dSLionel Sambuc                 "expected %u (FALSE), got %u\n", a, CONSTTIME_FALSE_8, c);
118*0a6a1f1dSLionel Sambuc         return 1;
119*0a6a1f1dSLionel Sambuc     }
120*0a6a1f1dSLionel Sambuc     return 0;
121*0a6a1f1dSLionel Sambuc }
122*0a6a1f1dSLionel Sambuc 
test_select(unsigned int a,unsigned int b)123*0a6a1f1dSLionel Sambuc static int test_select(unsigned int a, unsigned int b)
124*0a6a1f1dSLionel Sambuc {
125*0a6a1f1dSLionel Sambuc     unsigned int selected = constant_time_select(CONSTTIME_TRUE, a, b);
126*0a6a1f1dSLionel Sambuc     if (selected != a) {
127*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_select(%du, %du,"
128*0a6a1f1dSLionel Sambuc                 "%du): expected %du(first value), got %du\n",
129*0a6a1f1dSLionel Sambuc                 CONSTTIME_TRUE, a, b, a, selected);
130*0a6a1f1dSLionel Sambuc         return 1;
131*0a6a1f1dSLionel Sambuc     }
132*0a6a1f1dSLionel Sambuc     selected = constant_time_select(CONSTTIME_FALSE, a, b);
133*0a6a1f1dSLionel Sambuc     if (selected != b) {
134*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_select(%du, %du,"
135*0a6a1f1dSLionel Sambuc                 "%du): expected %du(second value), got %du\n",
136*0a6a1f1dSLionel Sambuc                 CONSTTIME_FALSE, a, b, b, selected);
137*0a6a1f1dSLionel Sambuc         return 1;
138*0a6a1f1dSLionel Sambuc     }
139*0a6a1f1dSLionel Sambuc     return 0;
140*0a6a1f1dSLionel Sambuc }
141*0a6a1f1dSLionel Sambuc 
test_select_8(unsigned char a,unsigned char b)142*0a6a1f1dSLionel Sambuc static int test_select_8(unsigned char a, unsigned char b)
143*0a6a1f1dSLionel Sambuc {
144*0a6a1f1dSLionel Sambuc     unsigned char selected = constant_time_select_8(CONSTTIME_TRUE_8, a, b);
145*0a6a1f1dSLionel Sambuc     if (selected != a) {
146*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_select(%u, %u,"
147*0a6a1f1dSLionel Sambuc                 "%u): expected %u(first value), got %u\n",
148*0a6a1f1dSLionel Sambuc                 CONSTTIME_TRUE, a, b, a, selected);
149*0a6a1f1dSLionel Sambuc         return 1;
150*0a6a1f1dSLionel Sambuc     }
151*0a6a1f1dSLionel Sambuc     selected = constant_time_select_8(CONSTTIME_FALSE_8, a, b);
152*0a6a1f1dSLionel Sambuc     if (selected != b) {
153*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_select(%u, %u,"
154*0a6a1f1dSLionel Sambuc                 "%u): expected %u(second value), got %u\n",
155*0a6a1f1dSLionel Sambuc                 CONSTTIME_FALSE, a, b, b, selected);
156*0a6a1f1dSLionel Sambuc         return 1;
157*0a6a1f1dSLionel Sambuc     }
158*0a6a1f1dSLionel Sambuc     return 0;
159*0a6a1f1dSLionel Sambuc }
160*0a6a1f1dSLionel Sambuc 
test_select_int(int a,int b)161*0a6a1f1dSLionel Sambuc static int test_select_int(int a, int b)
162*0a6a1f1dSLionel Sambuc {
163*0a6a1f1dSLionel Sambuc     int selected = constant_time_select_int(CONSTTIME_TRUE, a, b);
164*0a6a1f1dSLionel Sambuc     if (selected != a) {
165*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_select(%du, %d,"
166*0a6a1f1dSLionel Sambuc                 "%d): expected %d(first value), got %d\n",
167*0a6a1f1dSLionel Sambuc                 CONSTTIME_TRUE, a, b, a, selected);
168*0a6a1f1dSLionel Sambuc         return 1;
169*0a6a1f1dSLionel Sambuc     }
170*0a6a1f1dSLionel Sambuc     selected = constant_time_select_int(CONSTTIME_FALSE, a, b);
171*0a6a1f1dSLionel Sambuc     if (selected != b) {
172*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_select(%du, %d,"
173*0a6a1f1dSLionel Sambuc                 "%d): expected %d(second value), got %d\n",
174*0a6a1f1dSLionel Sambuc                 CONSTTIME_FALSE, a, b, b, selected);
175*0a6a1f1dSLionel Sambuc         return 1;
176*0a6a1f1dSLionel Sambuc     }
177*0a6a1f1dSLionel Sambuc     return 0;
178*0a6a1f1dSLionel Sambuc }
179*0a6a1f1dSLionel Sambuc 
test_eq_int(int a,int b)180*0a6a1f1dSLionel Sambuc static int test_eq_int(int a, int b)
181*0a6a1f1dSLionel Sambuc {
182*0a6a1f1dSLionel Sambuc     unsigned int equal = constant_time_eq_int(a, b);
183*0a6a1f1dSLionel Sambuc     if (a == b && equal != CONSTTIME_TRUE) {
184*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_eq_int(%d, %d): "
185*0a6a1f1dSLionel Sambuc                 "expected %du(TRUE), got %du\n", a, b, CONSTTIME_TRUE, equal);
186*0a6a1f1dSLionel Sambuc         return 1;
187*0a6a1f1dSLionel Sambuc     } else if (a != b && equal != CONSTTIME_FALSE) {
188*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_eq_int(%d, %d): "
189*0a6a1f1dSLionel Sambuc                 "expected %du(FALSE), got %du\n",
190*0a6a1f1dSLionel Sambuc                 a, b, CONSTTIME_FALSE, equal);
191*0a6a1f1dSLionel Sambuc         return 1;
192*0a6a1f1dSLionel Sambuc     }
193*0a6a1f1dSLionel Sambuc     return 0;
194*0a6a1f1dSLionel Sambuc }
195*0a6a1f1dSLionel Sambuc 
test_eq_int_8(int a,int b)196*0a6a1f1dSLionel Sambuc static int test_eq_int_8(int a, int b)
197*0a6a1f1dSLionel Sambuc {
198*0a6a1f1dSLionel Sambuc     unsigned char equal = constant_time_eq_int_8(a, b);
199*0a6a1f1dSLionel Sambuc     if (a == b && equal != CONSTTIME_TRUE_8) {
200*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_eq_int_8(%d, %d): "
201*0a6a1f1dSLionel Sambuc                 "expected %u(TRUE), got %u\n", a, b, CONSTTIME_TRUE_8, equal);
202*0a6a1f1dSLionel Sambuc         return 1;
203*0a6a1f1dSLionel Sambuc     } else if (a != b && equal != CONSTTIME_FALSE_8) {
204*0a6a1f1dSLionel Sambuc         fprintf(stderr, "Test failed for constant_time_eq_int_8(%d, %d): "
205*0a6a1f1dSLionel Sambuc                 "expected %u(FALSE), got %u\n",
206*0a6a1f1dSLionel Sambuc                 a, b, CONSTTIME_FALSE_8, equal);
207*0a6a1f1dSLionel Sambuc         return 1;
208*0a6a1f1dSLionel Sambuc     }
209*0a6a1f1dSLionel Sambuc     return 0;
210*0a6a1f1dSLionel Sambuc }
211*0a6a1f1dSLionel Sambuc 
212*0a6a1f1dSLionel Sambuc static unsigned int test_values[] =
213*0a6a1f1dSLionel Sambuc     { 0, 1, 1024, 12345, 32000, UINT_MAX / 2 - 1,
214*0a6a1f1dSLionel Sambuc     UINT_MAX / 2, UINT_MAX / 2 + 1, UINT_MAX - 1,
215*0a6a1f1dSLionel Sambuc     UINT_MAX
216*0a6a1f1dSLionel Sambuc };
217*0a6a1f1dSLionel Sambuc 
218*0a6a1f1dSLionel Sambuc static unsigned char test_values_8[] =
219*0a6a1f1dSLionel Sambuc     { 0, 1, 2, 20, 32, 127, 128, 129, 255 };
220*0a6a1f1dSLionel Sambuc 
221*0a6a1f1dSLionel Sambuc static int signed_test_values[] = { 0, 1, -1, 1024, -1024, 12345, -12345,
222*0a6a1f1dSLionel Sambuc     32000, -32000, INT_MAX, INT_MIN, INT_MAX - 1,
223*0a6a1f1dSLionel Sambuc     INT_MIN + 1
224*0a6a1f1dSLionel Sambuc };
225*0a6a1f1dSLionel Sambuc 
main(int argc,char * argv[])226*0a6a1f1dSLionel Sambuc int main(int argc, char *argv[])
227*0a6a1f1dSLionel Sambuc {
228*0a6a1f1dSLionel Sambuc     unsigned int a, b, i, j;
229*0a6a1f1dSLionel Sambuc     int c, d;
230*0a6a1f1dSLionel Sambuc     unsigned char e, f;
231*0a6a1f1dSLionel Sambuc     int num_failed = 0, num_all = 0;
232*0a6a1f1dSLionel Sambuc     fprintf(stdout, "Testing constant time operations...\n");
233*0a6a1f1dSLionel Sambuc 
234*0a6a1f1dSLionel Sambuc     for (i = 0; i < sizeof(test_values) / sizeof(int); ++i) {
235*0a6a1f1dSLionel Sambuc         a = test_values[i];
236*0a6a1f1dSLionel Sambuc         num_failed += test_is_zero(a);
237*0a6a1f1dSLionel Sambuc         num_failed += test_is_zero_8(a);
238*0a6a1f1dSLionel Sambuc         num_all += 2;
239*0a6a1f1dSLionel Sambuc         for (j = 0; j < sizeof(test_values) / sizeof(int); ++j) {
240*0a6a1f1dSLionel Sambuc             b = test_values[j];
241*0a6a1f1dSLionel Sambuc             num_failed += test_binary_op(&constant_time_lt,
242*0a6a1f1dSLionel Sambuc                                          "constant_time_lt", a, b, a < b);
243*0a6a1f1dSLionel Sambuc             num_failed += test_binary_op_8(&constant_time_lt_8,
244*0a6a1f1dSLionel Sambuc                                            "constant_time_lt_8", a, b, a < b);
245*0a6a1f1dSLionel Sambuc             num_failed += test_binary_op(&constant_time_lt,
246*0a6a1f1dSLionel Sambuc                                          "constant_time_lt_8", b, a, b < a);
247*0a6a1f1dSLionel Sambuc             num_failed += test_binary_op_8(&constant_time_lt_8,
248*0a6a1f1dSLionel Sambuc                                            "constant_time_lt_8", b, a, b < a);
249*0a6a1f1dSLionel Sambuc             num_failed += test_binary_op(&constant_time_ge,
250*0a6a1f1dSLionel Sambuc                                          "constant_time_ge", a, b, a >= b);
251*0a6a1f1dSLionel Sambuc             num_failed += test_binary_op_8(&constant_time_ge_8,
252*0a6a1f1dSLionel Sambuc                                            "constant_time_ge_8", a, b,
253*0a6a1f1dSLionel Sambuc                                            a >= b);
254*0a6a1f1dSLionel Sambuc             num_failed +=
255*0a6a1f1dSLionel Sambuc                 test_binary_op(&constant_time_ge, "constant_time_ge", b, a,
256*0a6a1f1dSLionel Sambuc                                b >= a);
257*0a6a1f1dSLionel Sambuc             num_failed +=
258*0a6a1f1dSLionel Sambuc                 test_binary_op_8(&constant_time_ge_8, "constant_time_ge_8", b,
259*0a6a1f1dSLionel Sambuc                                  a, b >= a);
260*0a6a1f1dSLionel Sambuc             num_failed +=
261*0a6a1f1dSLionel Sambuc                 test_binary_op(&constant_time_eq, "constant_time_eq", a, b,
262*0a6a1f1dSLionel Sambuc                                a == b);
263*0a6a1f1dSLionel Sambuc             num_failed +=
264*0a6a1f1dSLionel Sambuc                 test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", a,
265*0a6a1f1dSLionel Sambuc                                  b, a == b);
266*0a6a1f1dSLionel Sambuc             num_failed +=
267*0a6a1f1dSLionel Sambuc                 test_binary_op(&constant_time_eq, "constant_time_eq", b, a,
268*0a6a1f1dSLionel Sambuc                                b == a);
269*0a6a1f1dSLionel Sambuc             num_failed +=
270*0a6a1f1dSLionel Sambuc                 test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", b,
271*0a6a1f1dSLionel Sambuc                                  a, b == a);
272*0a6a1f1dSLionel Sambuc             num_failed += test_select(a, b);
273*0a6a1f1dSLionel Sambuc             num_all += 13;
274*0a6a1f1dSLionel Sambuc         }
275*0a6a1f1dSLionel Sambuc     }
276*0a6a1f1dSLionel Sambuc 
277*0a6a1f1dSLionel Sambuc     for (i = 0; i < sizeof(signed_test_values) / sizeof(int); ++i) {
278*0a6a1f1dSLionel Sambuc         c = signed_test_values[i];
279*0a6a1f1dSLionel Sambuc         for (j = 0; j < sizeof(signed_test_values) / sizeof(int); ++j) {
280*0a6a1f1dSLionel Sambuc             d = signed_test_values[j];
281*0a6a1f1dSLionel Sambuc             num_failed += test_select_int(c, d);
282*0a6a1f1dSLionel Sambuc             num_failed += test_eq_int(c, d);
283*0a6a1f1dSLionel Sambuc             num_failed += test_eq_int_8(c, d);
284*0a6a1f1dSLionel Sambuc             num_all += 3;
285*0a6a1f1dSLionel Sambuc         }
286*0a6a1f1dSLionel Sambuc     }
287*0a6a1f1dSLionel Sambuc 
288*0a6a1f1dSLionel Sambuc     for (i = 0; i < sizeof(test_values_8); ++i) {
289*0a6a1f1dSLionel Sambuc         e = test_values_8[i];
290*0a6a1f1dSLionel Sambuc         for (j = 0; j < sizeof(test_values_8); ++j) {
291*0a6a1f1dSLionel Sambuc             f = test_values_8[j];
292*0a6a1f1dSLionel Sambuc             num_failed += test_select_8(e, f);
293*0a6a1f1dSLionel Sambuc             num_all += 1;
294*0a6a1f1dSLionel Sambuc         }
295*0a6a1f1dSLionel Sambuc     }
296*0a6a1f1dSLionel Sambuc 
297*0a6a1f1dSLionel Sambuc     if (!num_failed) {
298*0a6a1f1dSLionel Sambuc         fprintf(stdout, "ok (ran %d tests)\n", num_all);
299*0a6a1f1dSLionel Sambuc         return EXIT_SUCCESS;
300*0a6a1f1dSLionel Sambuc     } else {
301*0a6a1f1dSLionel Sambuc         fprintf(stdout, "%d of %d tests failed!\n", num_failed, num_all);
302*0a6a1f1dSLionel Sambuc         return EXIT_FAILURE;
303*0a6a1f1dSLionel Sambuc     }
304*0a6a1f1dSLionel Sambuc }
305