- unsigned int a, b, i, j;
- int c, d;
- unsigned char e, f;
- int num_failed = 0, num_all = 0;
- fprintf(stdout, "Testing constant time operations...\n");
-
- for (i = 0; i < OSSL_NELEM(test_values); ++i) {
- a = test_values[i];
- num_failed += test_is_zero(a);
- num_failed += test_is_zero_8(a);
- num_all += 2;
- for (j = 0; j < OSSL_NELEM(test_values); ++j) {
- b = test_values[j];
- num_failed += test_binary_op(&constant_time_lt,
- "constant_time_lt", a, b, a < b);
- num_failed += test_binary_op_8(&constant_time_lt_8,
- "constant_time_lt_8", a, b, a < b);
- num_failed += test_binary_op(&constant_time_lt,
- "constant_time_lt_8", b, a, b < a);
- num_failed += test_binary_op_8(&constant_time_lt_8,
- "constant_time_lt_8", b, a, b < a);
- num_failed += test_binary_op(&constant_time_ge,
- "constant_time_ge", a, b, a >= b);
- num_failed += test_binary_op_8(&constant_time_ge_8,
- "constant_time_ge_8", a, b,
- a >= b);
- num_failed +=
- test_binary_op(&constant_time_ge, "constant_time_ge", b, a,
- b >= a);
- num_failed +=
- test_binary_op_8(&constant_time_ge_8, "constant_time_ge_8", b,
- a, b >= a);
- num_failed +=
- test_binary_op(&constant_time_eq, "constant_time_eq", a, b,
- a == b);
- num_failed +=
- test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", a,
- b, a == b);
- num_failed +=
- test_binary_op(&constant_time_eq, "constant_time_eq", b, a,
- b == a);
- num_failed +=
- test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", b,
- a, b == a);
- num_failed += test_select(a, b);
- num_all += 13;
+ if (!TEST_uint_eq(OSSL_NELEM(test_values), OSSL_NELEM(test_values_s)))
+ return 0;
+ return 1;
+}
+
+static int test_binops(int i)
+{
+ unsigned int a = test_values[i];
+ unsigned int g = test_values_s[i];
+ int j;
+ int ret = 1;
+
+ if (!test_is_zero(a) || !test_is_zero_8(a) || !test_is_zero_s(g))
+ ret = 0;
+
+ for (j = 0; j < (int)OSSL_NELEM(test_values); ++j) {
+ unsigned int b = test_values[j];
+ unsigned int h = test_values[j];
+
+ if (!test_select(a, b)
+ || !test_select_s(g, h)
+ || !test_eq_s(g, h)
+ || !test_binary_op(&constant_time_lt, "ct_lt",
+ a, b, a < b)
+ || !test_binary_op_8(&constant_time_lt_8, "constant_time_lt_8",
+ a, b, a < b)
+ || !test_binary_op_s(&constant_time_lt_s, "constant_time_lt_s",
+ g, h, g < h)
+ || !test_binary_op(&constant_time_lt, "constant_time_lt",
+ b, a, b < a)
+ || !test_binary_op_8(&constant_time_lt_8, "constant_time_lt_8",
+ b, a, b < a)
+ || !test_binary_op_s(&constant_time_lt_s, "constant_time_lt_s",
+ h, g, h < g)
+ || !test_binary_op(&constant_time_ge, "constant_time_ge",
+ a, b, a >= b)
+ || !test_binary_op_8(&constant_time_ge_8, "constant_time_ge_8",
+ a, b, a >= b)
+ || !test_binary_op_s(&constant_time_ge_s, "constant_time_ge_s",
+ g, h, g >= h)
+ || !test_binary_op(&constant_time_ge, "constant_time_ge",
+ b, a, b >= a)
+ || !test_binary_op_8(&constant_time_ge_8, "constant_time_ge_8",
+ b, a, b >= a)
+ || !test_binary_op_s(&constant_time_ge_s, "constant_time_ge_s",
+ h, g, h >= g)
+ || !test_binary_op(&constant_time_eq, "constant_time_eq",
+ a, b, a == b)
+ || !test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8",
+ a, b, a == b)
+ || !test_binary_op_s(&constant_time_eq_s, "constant_time_eq_s",
+ g, h, g == h)
+ || !test_binary_op(&constant_time_eq, "constant_time_eq",
+ b, a, b == a)
+ || !test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8",
+ b, a, b == a)
+ || !test_binary_op_s(&constant_time_eq_s, "constant_time_eq_s",
+ h, g, h == g)) {
+ ret = 0;