mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-24 01:43:33 +00:00
tests
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
7d4f019810
commit
14bec1490f
@ -1,7 +1,6 @@
|
||||
/* BEGIN_HEADER */
|
||||
#include "mbedtls/base64.h"
|
||||
#include "constant_time_internal.h"
|
||||
#include "constant_time_invasive.h"
|
||||
#include <test/constant_flow.h>
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
@ -16,7 +15,7 @@ static const char base64_digits[] =
|
||||
* END_DEPENDENCIES
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_TEST_HOOKS */
|
||||
/* BEGIN_CASE */
|
||||
void mask_of_range(int low_arg, int high_arg)
|
||||
{
|
||||
unsigned char low = low_arg, high = high_arg;
|
||||
@ -24,7 +23,7 @@ void mask_of_range(int low_arg, int high_arg)
|
||||
for (c = 0; c <= 0xff; c++) {
|
||||
mbedtls_test_set_step(c);
|
||||
TEST_CF_SECRET(&c, sizeof(c));
|
||||
unsigned char m = mbedtls_ct_uchar_mask_of_range(low, high, c);
|
||||
unsigned char m = mbedtls_ct_uchar_in_range_if(low, high, c, 0xff);
|
||||
TEST_CF_PUBLIC(&c, sizeof(c));
|
||||
TEST_CF_PUBLIC(&m, sizeof(m));
|
||||
if (low <= c && c <= high) {
|
||||
|
@ -438,7 +438,7 @@ void mpi_lt_mpi_ct(int size_X, char *input_X,
|
||||
|
||||
TEST_ASSERT(mbedtls_mpi_lt_mpi_ct(&X, &Y, &ret) == input_err);
|
||||
if (input_err == 0) {
|
||||
TEST_ASSERT(ret == input_uret);
|
||||
TEST_EQUAL(ret, input_uret);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -358,7 +358,7 @@ void mpi_core_lt_ct(char *input_X, char *input_Y, int exp_ret)
|
||||
TEST_CF_SECRET(Y, X_limbs * sizeof(mbedtls_mpi_uint));
|
||||
|
||||
ret = mbedtls_mpi_core_lt_ct(X, Y, X_limbs);
|
||||
TEST_EQUAL(ret, exp_ret);
|
||||
TEST_EQUAL(!!ret, exp_ret);
|
||||
|
||||
exit:
|
||||
mbedtls_free(X);
|
||||
@ -384,25 +384,25 @@ void mpi_core_uint_le_mpi(char *input_A)
|
||||
|
||||
TEST_CF_SECRET(A, A_limbs * sizeof(*A));
|
||||
|
||||
TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi(0, A, A_limbs), 1);
|
||||
TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi(A[0], A, A_limbs), 1);
|
||||
TEST_EQUAL(!!mbedtls_mpi_core_uint_le_mpi(0, A, A_limbs), 1);
|
||||
TEST_EQUAL(!!mbedtls_mpi_core_uint_le_mpi(A[0], A, A_limbs), 1);
|
||||
|
||||
if (is_large) {
|
||||
TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi(A[0] + 1,
|
||||
A, A_limbs), 1);
|
||||
TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1) >> 1,
|
||||
A, A_limbs), 1);
|
||||
TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1),
|
||||
A, A_limbs), 1);
|
||||
TEST_EQUAL(!!mbedtls_mpi_core_uint_le_mpi(A[0] + 1,
|
||||
A, A_limbs), 1);
|
||||
TEST_EQUAL(!!mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1) >> 1,
|
||||
A, A_limbs), 1);
|
||||
TEST_EQUAL(!!mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1),
|
||||
A, A_limbs), 1);
|
||||
} else {
|
||||
TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi(A[0] + 1,
|
||||
A, A_limbs),
|
||||
TEST_EQUAL(!!mbedtls_mpi_core_uint_le_mpi(A[0] + 1,
|
||||
A, A_limbs),
|
||||
A[0] + 1 <= A[0]);
|
||||
TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1) >> 1,
|
||||
A, A_limbs),
|
||||
TEST_EQUAL(!!mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1) >> 1,
|
||||
A, A_limbs),
|
||||
(mbedtls_mpi_uint) (-1) >> 1 <= A[0]);
|
||||
TEST_EQUAL(mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1),
|
||||
A, A_limbs),
|
||||
TEST_EQUAL(!!mbedtls_mpi_core_uint_le_mpi((mbedtls_mpi_uint) (-1),
|
||||
A, A_limbs),
|
||||
(mbedtls_mpi_uint) (-1) <= A[0]);
|
||||
}
|
||||
|
||||
@ -447,7 +447,7 @@ void mpi_core_cond_assign(char *input_X,
|
||||
TEST_CF_SECRET(X, bytes);
|
||||
TEST_CF_SECRET(Y, bytes);
|
||||
|
||||
mbedtls_mpi_core_cond_assign(X, Y, copy_limbs, 1);
|
||||
mbedtls_mpi_core_cond_assign(X, Y, copy_limbs, mbedtls_ct_bool(1));
|
||||
|
||||
TEST_CF_PUBLIC(X, bytes);
|
||||
TEST_CF_PUBLIC(Y, bytes);
|
||||
@ -515,7 +515,7 @@ void mpi_core_cond_swap(char *input_X,
|
||||
TEST_CF_SECRET(X, bytes);
|
||||
TEST_CF_SECRET(Y, bytes);
|
||||
|
||||
mbedtls_mpi_core_cond_swap(X, Y, copy_limbs, 1);
|
||||
mbedtls_mpi_core_cond_swap(X, Y, copy_limbs, mbedtls_ct_bool(1));
|
||||
|
||||
TEST_CF_PUBLIC(X, bytes);
|
||||
TEST_CF_PUBLIC(Y, bytes);
|
||||
|
@ -134,7 +134,7 @@ void mpi_core_random_basic(int min, char *bound_bytes, int expected_ret)
|
||||
|
||||
if (expected_ret == 0) {
|
||||
TEST_EQUAL(0, mbedtls_mpi_core_lt_ct(result, lower_bound, limbs));
|
||||
TEST_EQUAL(1, mbedtls_mpi_core_lt_ct(result, upper_bound, limbs));
|
||||
TEST_ASSERT(0 != mbedtls_mpi_core_lt_ct(result, upper_bound, limbs));
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -429,8 +429,7 @@ void mpi_mod_random_validation(int min, char *bound_hex,
|
||||
* size as the modulus, otherwise it's a mistake in the test data. */
|
||||
TEST_EQUAL(result_limbs, N.limbs);
|
||||
/* Sanity check: check that the result is in range */
|
||||
TEST_EQUAL(mbedtls_mpi_core_lt_ct(result_digits, N.p, N.limbs),
|
||||
1);
|
||||
TEST_ASSERT(0 != mbedtls_mpi_core_lt_ct(result_digits, N.p, N.limbs));
|
||||
/* Check result >= min (changes result) */
|
||||
TEST_EQUAL(mbedtls_mpi_core_sub_int(result_digits, result_digits, min,
|
||||
result_limbs),
|
||||
@ -444,8 +443,7 @@ void mpi_mod_random_validation(int min, char *bound_hex,
|
||||
mbedtls_test_rnd_std_rand, NULL),
|
||||
expected_ret);
|
||||
if (expected_ret == 0) {
|
||||
TEST_EQUAL(mbedtls_mpi_core_lt_ct(result_digits, N.p, N.limbs),
|
||||
1);
|
||||
TEST_ASSERT(0 != mbedtls_mpi_core_lt_ct(result_digits, N.p, N.limbs));
|
||||
TEST_EQUAL(mbedtls_mpi_core_sub_int(result_digits, result.p, min,
|
||||
result_limbs),
|
||||
0);
|
||||
|
@ -1,14 +1,14 @@
|
||||
# these are the numbers we'd get with an empty plaintext and truncated HMAC
|
||||
Constant-flow memcpy from offset: small
|
||||
ssl_cf_memcpy_offset:0:5:10
|
||||
mbedtls_ct_memcpy_offset:0:5:10
|
||||
|
||||
# we could get this with 255-bytes plaintext and untruncated SHA-256
|
||||
Constant-flow memcpy from offset: medium
|
||||
ssl_cf_memcpy_offset:0:255:32
|
||||
mbedtls_ct_memcpy_offset:0:255:32
|
||||
|
||||
# we could get this with 255-bytes plaintext and untruncated SHA-384
|
||||
Constant-flow memcpy from offset: large
|
||||
ssl_cf_memcpy_offset:100:339:48
|
||||
mbedtls_ct_memcpy_offset:100:339:48
|
||||
|
||||
mbedtls_ct_memcmp NULL
|
||||
mbedtls_ct_memcmp_null
|
||||
@ -91,47 +91,492 @@ mbedtls_ct_memcmp:-1:17:2
|
||||
mbedtls_ct_memcmp len 17 offset 3
|
||||
mbedtls_ct_memcmp:-1:17:3
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 1 offset 0
|
||||
mbedtls_ct_memcpy_if_eq:1:1:0
|
||||
mbedtls_ct_memcpy_if len 1 offset 0
|
||||
mbedtls_ct_memcpy_if:1:1:0
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 1 offset 1
|
||||
mbedtls_ct_memcpy_if_eq:1:1:1
|
||||
mbedtls_ct_memcpy_if len 1 offset 1
|
||||
mbedtls_ct_memcpy_if:1:1:1
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 4 offset 0
|
||||
mbedtls_ct_memcpy_if_eq:1:1:0
|
||||
mbedtls_ct_memcpy_if len 4 offset 0
|
||||
mbedtls_ct_memcpy_if:1:1:0
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 4 offset 1
|
||||
mbedtls_ct_memcpy_if_eq:1:1:1
|
||||
mbedtls_ct_memcpy_if len 4 offset 1
|
||||
mbedtls_ct_memcpy_if:1:1:1
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 4 offset 2
|
||||
mbedtls_ct_memcpy_if_eq:1:1:2
|
||||
mbedtls_ct_memcpy_if len 4 offset 2
|
||||
mbedtls_ct_memcpy_if:1:1:2
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 4 offset 3
|
||||
mbedtls_ct_memcpy_if_eq:1:1:3
|
||||
mbedtls_ct_memcpy_if len 4 offset 3
|
||||
mbedtls_ct_memcpy_if:1:1:3
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 15 offset 0
|
||||
mbedtls_ct_memcpy_if_eq:1:15:0
|
||||
mbedtls_ct_memcpy_if len 15 offset 0
|
||||
mbedtls_ct_memcpy_if:1:15:0
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 15 offset 1
|
||||
mbedtls_ct_memcpy_if_eq:1:15:1
|
||||
mbedtls_ct_memcpy_if len 15 offset 1
|
||||
mbedtls_ct_memcpy_if:1:15:1
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 16 offset 0
|
||||
mbedtls_ct_memcpy_if_eq:1:16:0
|
||||
mbedtls_ct_memcpy_if len 16 offset 0
|
||||
mbedtls_ct_memcpy_if:1:16:0
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 16 offset 1
|
||||
mbedtls_ct_memcpy_if_eq:1:16:1
|
||||
mbedtls_ct_memcpy_if len 16 offset 1
|
||||
mbedtls_ct_memcpy_if:1:16:1
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 17 offset 0
|
||||
mbedtls_ct_memcpy_if_eq:1:17:0
|
||||
mbedtls_ct_memcpy_if len 17 offset 0
|
||||
mbedtls_ct_memcpy_if:1:17:0
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 17 offset 1
|
||||
mbedtls_ct_memcpy_if_eq:1:17:1
|
||||
mbedtls_ct_memcpy_if len 17 offset 1
|
||||
mbedtls_ct_memcpy_if:1:17:1
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 0 not eq
|
||||
mbedtls_ct_memcpy_if_eq:0:17:0
|
||||
mbedtls_ct_memcpy_if len 0 not eq
|
||||
mbedtls_ct_memcpy_if:0:17:0
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 5 offset 1 not eq
|
||||
mbedtls_ct_memcpy_if_eq:0:5:1
|
||||
mbedtls_ct_memcpy_if len 5 offset 1 not eq
|
||||
mbedtls_ct_memcpy_if:0:5:1
|
||||
|
||||
mbedtls_ct_memcpy_if len 17 offset 3 not eq
|
||||
mbedtls_ct_memcpy_if:0:17:3
|
||||
|
||||
mbedtls_ct_bool 0
|
||||
mbedtls_ct_bool:"0x0"
|
||||
|
||||
mbedtls_ct_bool 1
|
||||
mbedtls_ct_bool:"0x1"
|
||||
|
||||
mbedtls_ct_bool 4
|
||||
mbedtls_ct_bool:"0x4"
|
||||
|
||||
mbedtls_ct_bool 0xfffffff
|
||||
mbedtls_ct_bool:"0xfffffff"
|
||||
|
||||
mbedtls_ct_bool 0x7fffffff
|
||||
mbedtls_ct_bool:"0x7fffffff"
|
||||
|
||||
mbedtls_ct_bool 0xfffffffe
|
||||
mbedtls_ct_bool:"0xfffffffe"
|
||||
|
||||
mbedtls_ct_bool 0xffffffff
|
||||
mbedtls_ct_bool:"0xffffffff"
|
||||
|
||||
mbedtls_ct_bool 0x0fffffffffffffff
|
||||
mbedtls_ct_bool:"0x0fffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool 0x7fffffffffffffff
|
||||
mbedtls_ct_bool:"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool 0xffffffffffffffff
|
||||
mbedtls_ct_bool:"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x0 0x0
|
||||
mbedtls_ct_bool_xxx:"0x0":"0x0"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x0 0x1
|
||||
mbedtls_ct_bool_xxx:"0x0":"0x1"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x0 0x7fffffff
|
||||
mbedtls_ct_bool_xxx:"0x0":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x0 0xffffffff
|
||||
mbedtls_ct_bool_xxx:"0x0":"0xffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x0 0x7fffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0x0":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x0 0xffffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0x0":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x1 0x0
|
||||
mbedtls_ct_bool_xxx:"0x1":"0x0"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x1 0x1
|
||||
mbedtls_ct_bool_xxx:"0x1":"0x1"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x1 0x7fffffff
|
||||
mbedtls_ct_bool_xxx:"0x1":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x1 0xffffffff
|
||||
mbedtls_ct_bool_xxx:"0x1":"0xffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x1 0x7fffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0x1":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x1 0xffffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0x1":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffff 0x0
|
||||
mbedtls_ct_bool_xxx:"0x7fffffff":"0x0"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffff 0x1
|
||||
mbedtls_ct_bool_xxx:"0x7fffffff":"0x1"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffff 0x7fffffff
|
||||
mbedtls_ct_bool_xxx:"0x7fffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffff 0xffffffff
|
||||
mbedtls_ct_bool_xxx:"0x7fffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0x7fffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffff 0xffffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0x7fffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffff 0x0
|
||||
mbedtls_ct_bool_xxx:"0xffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffff 0x1
|
||||
mbedtls_ct_bool_xxx:"0xffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffff 0x7fffffff
|
||||
mbedtls_ct_bool_xxx:"0xffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffff 0xffffffff
|
||||
mbedtls_ct_bool_xxx:"0xffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0xffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0xffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffffffffffff 0x0
|
||||
mbedtls_ct_bool_xxx:"0x7fffffffffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffffffffffff 0x1
|
||||
mbedtls_ct_bool_xxx:"0x7fffffffffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffffffffffff 0x7fffffff
|
||||
mbedtls_ct_bool_xxx:"0x7fffffffffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffffffffffff 0xffffffff
|
||||
mbedtls_ct_bool_xxx:"0x7fffffffffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffffffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0x7fffffffffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0x7fffffffffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0x7fffffffffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffffffffffff 0x0
|
||||
mbedtls_ct_bool_xxx:"0xffffffffffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffffffffffff 0x1
|
||||
mbedtls_ct_bool_xxx:"0xffffffffffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffffffffffff 0x7fffffff
|
||||
mbedtls_ct_bool_xxx:"0xffffffffffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffffffffffff 0xffffffff
|
||||
mbedtls_ct_bool_xxx:"0xffffffffffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffffffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0xffffffffffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 0xffffffffffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_bool_xxx:"0xffffffffffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_bool_xxx 138 256
|
||||
mbedtls_ct_bool_xxx:"138":"256"
|
||||
|
||||
mbedtls_ct_bool_xxx 256 138
|
||||
mbedtls_ct_bool_xxx:"256":"138"
|
||||
|
||||
mbedtls_ct_bool_xxx 6 6
|
||||
mbedtls_ct_bool_xxx:"0x6":"0x6"
|
||||
|
||||
mbedtls_ct_uchar_in_range_if 0 0 0 0
|
||||
mbedtls_ct_uchar_in_range_if:0:0:0:0
|
||||
|
||||
mbedtls_ct_uchar_in_range_if 0 100 2 2
|
||||
mbedtls_ct_uchar_in_range_if:0:100:2:2
|
||||
|
||||
mbedtls_ct_uchar_in_range_if 0 100 2 0
|
||||
mbedtls_ct_uchar_in_range_if:0:100:2:0
|
||||
|
||||
mbedtls_ct_uchar_in_range_if 0 100 200 2
|
||||
mbedtls_ct_uchar_in_range_if:0:100:200:2
|
||||
|
||||
mbedtls_ct_uchar_in_range_if 0 255 0 2
|
||||
mbedtls_ct_uchar_in_range_if:0:255:0:2
|
||||
|
||||
mbedtls_ct_uchar_in_range_if 0 255 100 2
|
||||
mbedtls_ct_uchar_in_range_if:0:255:100:2
|
||||
|
||||
mbedtls_ct_uchar_in_range_if 0 255 255 2
|
||||
mbedtls_ct_uchar_in_range_if:0:255:255:2
|
||||
|
||||
mbedtls_ct_uchar_in_range_if 255 255 255 255
|
||||
mbedtls_ct_uchar_in_range_if:255:255:255:255
|
||||
|
||||
mbedtls_ct_if 0x0 0x0 0x0
|
||||
mbedtls_ct_if:"0x0":"0x0":"0x0"
|
||||
|
||||
mbedtls_ct_if 0x0 0x0 0x1
|
||||
mbedtls_ct_if:"0x0":"0x0":"0x1"
|
||||
|
||||
mbedtls_ct_if 0x0 0x0 0x7fffffff
|
||||
mbedtls_ct_if:"0x0":"0x0":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x0 0xffffffff
|
||||
mbedtls_ct_if:"0x0":"0x0":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x0 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0x0":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x0 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0x0":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x1 0x0
|
||||
mbedtls_ct_if:"0x0":"0x1":"0x0"
|
||||
|
||||
mbedtls_ct_if 0x0 0x1 0x1
|
||||
mbedtls_ct_if:"0x0":"0x1":"0x1"
|
||||
|
||||
mbedtls_ct_if 0x0 0x1 0x7fffffff
|
||||
mbedtls_ct_if:"0x0":"0x1":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x1 0xffffffff
|
||||
mbedtls_ct_if:"0x0":"0x1":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x1 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0x1":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x1 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0x1":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffff 0x0
|
||||
mbedtls_ct_if:"0x0":"0x7fffffff":"0x0"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffff 0x1
|
||||
mbedtls_ct_if:"0x0":"0x7fffffff":"0x1"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffff 0x7fffffff
|
||||
mbedtls_ct_if:"0x0":"0x7fffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffff 0xffffffff
|
||||
mbedtls_ct_if:"0x0":"0x7fffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0x7fffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffff 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0x7fffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffff 0x0
|
||||
mbedtls_ct_if:"0x0":"0xffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffff 0x1
|
||||
mbedtls_ct_if:"0x0":"0xffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffff 0x7fffffff
|
||||
mbedtls_ct_if:"0x0":"0xffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffff 0xffffffff
|
||||
mbedtls_ct_if:"0x0":"0xffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0xffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0xffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffffffffffff 0x0
|
||||
mbedtls_ct_if:"0x0":"0x7fffffffffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffffffffffff 0x1
|
||||
mbedtls_ct_if:"0x0":"0x7fffffffffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffffffffffff 0x7fffffff
|
||||
mbedtls_ct_if:"0x0":"0x7fffffffffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffffffffffff 0xffffffff
|
||||
mbedtls_ct_if:"0x0":"0x7fffffffffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffffffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0x7fffffffffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0x7fffffffffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0x7fffffffffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffffffffffff 0x0
|
||||
mbedtls_ct_if:"0x0":"0xffffffffffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffffffffffff 0x1
|
||||
mbedtls_ct_if:"0x0":"0xffffffffffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffffffffffff 0x7fffffff
|
||||
mbedtls_ct_if:"0x0":"0xffffffffffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffffffffffff 0xffffffff
|
||||
mbedtls_ct_if:"0x0":"0xffffffffffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffffffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0xffffffffffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0x0 0xffffffffffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0x0":"0xffffffffffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x0 0x0
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x0":"0x0"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x0 0x1
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x0":"0x1"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x0 0x7fffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x0":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x0 0xffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x0":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x0 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x0":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x0 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x0":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x1 0x0
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x1":"0x0"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x1 0x1
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x1":"0x1"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x1 0x7fffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x1":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x1 0xffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x1":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x1 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x1":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x1 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x1":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffff 0x0
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffff":"0x0"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffff 0x1
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffff":"0x1"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffff 0x7fffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffff 0xffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffff 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffff 0x0
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffff 0x1
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffff 0x7fffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffff 0xffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffffffffffff 0x0
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffffffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffffffffffff 0x1
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffffffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffffffffffff 0x7fffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffffffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffffffffffff 0xffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffffffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffffffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffffffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0x7fffffffffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0x7fffffffffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffffffffffff 0x0
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffffffffffff":"0x0"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffffffffffff 0x1
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffffffffffff":"0x1"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffffffffffff 0x7fffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffffffffffff":"0x7fffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffffffffffff 0xffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffffffffffff":"0xffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffffffffffff 0x7fffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffffffffffff":"0x7fffffffffffffff"
|
||||
|
||||
mbedtls_ct_if 0xffffffffffffffff 0xffffffffffffffff 0xffffffffffffffff
|
||||
mbedtls_ct_if:"0xffffffffffffffff":"0xffffffffffffffff":"0xffffffffffffffff"
|
||||
|
||||
mbedtls_ct_zeroize_if 0x0 0
|
||||
mbedtls_ct_zeroize_if:"0x0":0
|
||||
|
||||
mbedtls_ct_zeroize_if 0x0 1
|
||||
mbedtls_ct_zeroize_if:"0x0":1
|
||||
|
||||
mbedtls_ct_zeroize_if 0x0 1024
|
||||
mbedtls_ct_zeroize_if:"0x0":1024
|
||||
|
||||
mbedtls_ct_zeroize_if 0xffffffffffffffff 0
|
||||
mbedtls_ct_zeroize_if:"0xffffffffffffffff":0
|
||||
|
||||
mbedtls_ct_zeroize_if 0xffffffffffffffff 1
|
||||
mbedtls_ct_zeroize_if:"0xffffffffffffffff":1
|
||||
|
||||
mbedtls_ct_zeroize_if 0xffffffffffffffff 4
|
||||
mbedtls_ct_zeroize_if:"0xffffffffffffffff":4
|
||||
|
||||
mbedtls_ct_zeroize_if 0xffffffffffffffff 5
|
||||
mbedtls_ct_zeroize_if:"0xffffffffffffffff":5
|
||||
|
||||
mbedtls_ct_zeroize_if 0xffffffffffffffff 7
|
||||
mbedtls_ct_zeroize_if:"0xffffffffffffffff":7
|
||||
|
||||
mbedtls_ct_zeroize_if 0xffffffffffffffff 8
|
||||
mbedtls_ct_zeroize_if:"0xffffffffffffffff":8
|
||||
|
||||
mbedtls_ct_zeroize_if 0xffffffffffffffff 9
|
||||
mbedtls_ct_zeroize_if:"0xffffffffffffffff":9
|
||||
|
||||
mbedtls_ct_zeroize_if 0xffffffffffffffff 1024
|
||||
mbedtls_ct_zeroize_if:"0xffffffffffffffff":1024
|
||||
|
||||
mbedtls_ct_memmove_left 0 0
|
||||
mbedtls_ct_memmove_left:0:0
|
||||
|
||||
mbedtls_ct_memmove_left 1 0
|
||||
mbedtls_ct_memmove_left:1:0
|
||||
|
||||
mbedtls_ct_memmove_left 1 1
|
||||
mbedtls_ct_memmove_left:1:1
|
||||
|
||||
mbedtls_ct_memmove_left 16 0
|
||||
mbedtls_ct_memmove_left:16:0
|
||||
|
||||
mbedtls_ct_memmove_left 16 1
|
||||
mbedtls_ct_memmove_left:16:1
|
||||
|
||||
mbedtls_ct_memmove_left 16 4
|
||||
mbedtls_ct_memmove_left:16:4
|
||||
|
||||
mbedtls_ct_memmove_left 16 15
|
||||
mbedtls_ct_memmove_left:16:15
|
||||
|
||||
mbedtls_ct_memmove_left 16 16
|
||||
mbedtls_ct_memmove_left:16:16
|
||||
|
||||
mbedtls_ct_memcpy_if_eq len 17 offset 3 not eq
|
||||
mbedtls_ct_memcpy_if_eq:0:17:3
|
||||
|
@ -8,9 +8,15 @@
|
||||
* under MSan or Valgrind will detect a non-constant-time implementation.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <mbedtls/bignum.h>
|
||||
#include <mbedtls/constant_time.h>
|
||||
#include <constant_time_internal.h>
|
||||
#include <constant_time_invasive.h>
|
||||
|
||||
#include <test/constant_flow.h>
|
||||
/* END_HEADER */
|
||||
@ -25,6 +31,143 @@ void mbedtls_ct_memcmp_null()
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ct_bool(char *input)
|
||||
{
|
||||
mbedtls_ct_uint_t v = (mbedtls_ct_uint_t) strtoull(input, NULL, 16);
|
||||
TEST_ASSERT(errno == 0);
|
||||
|
||||
mbedtls_ct_condition_t expected = (v != 0) ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_CF_SECRET(&v, sizeof(v));
|
||||
TEST_EQUAL(mbedtls_ct_bool(v), expected);
|
||||
TEST_CF_PUBLIC(&v, sizeof(v));
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ct_bool_xxx(char *x_str, char *y_str)
|
||||
{
|
||||
mbedtls_ct_uint_t x = strtoull(x_str, NULL, 0);
|
||||
mbedtls_ct_uint_t y = strtoull(y_str, NULL, 0);
|
||||
|
||||
mbedtls_ct_uint_t x1 = x;
|
||||
mbedtls_ct_uint_t y1 = y;
|
||||
|
||||
TEST_CF_SECRET(&x, sizeof(x));
|
||||
TEST_CF_SECRET(&y, sizeof(y));
|
||||
|
||||
mbedtls_ct_condition_t expected = x1 ? MBEDTLS_CT_FALSE : MBEDTLS_CT_TRUE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_not(mbedtls_ct_bool(x)), expected);
|
||||
|
||||
expected = x1 != y1 ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_ne(x, y), expected);
|
||||
|
||||
expected = x1 == y1 ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_eq(x, y), expected);
|
||||
|
||||
expected = x1 > y1 ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_gt(x, y), expected);
|
||||
|
||||
expected = x1 < y1 ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_lt(x, y), expected);
|
||||
|
||||
expected = x1 >= y1 ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_ge(x, y), expected);
|
||||
|
||||
expected = x1 <= y1 ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_le(x, y), expected);
|
||||
|
||||
expected = mbedtls_ct_bool(x) ^ mbedtls_ct_bool(y) ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_xor(mbedtls_ct_bool(x), mbedtls_ct_bool(y)), expected);
|
||||
|
||||
expected = mbedtls_ct_bool(x) & mbedtls_ct_bool(y) ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_and(mbedtls_ct_bool(x), mbedtls_ct_bool(y)), expected);
|
||||
|
||||
expected = mbedtls_ct_bool(x) | mbedtls_ct_bool(y) ? MBEDTLS_CT_TRUE : MBEDTLS_CT_FALSE;
|
||||
TEST_EQUAL(mbedtls_ct_bool_or(mbedtls_ct_bool(x), mbedtls_ct_bool(y)), expected);
|
||||
|
||||
TEST_CF_PUBLIC(&x, sizeof(x));
|
||||
TEST_CF_PUBLIC(&y, sizeof(y));
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_BASE64_C */
|
||||
void mbedtls_ct_uchar_in_range_if(int li, int hi, int xi, int ti)
|
||||
{
|
||||
unsigned char l = li, h = hi, x = xi, t = ti;
|
||||
unsigned char expected = (x >= l) && (x <= h) ? t : 0;
|
||||
|
||||
TEST_CF_SECRET(&x, sizeof(x));
|
||||
TEST_CF_SECRET(&l, sizeof(l));
|
||||
TEST_CF_SECRET(&h, sizeof(h));
|
||||
TEST_CF_SECRET(&t, sizeof(t));
|
||||
|
||||
TEST_EQUAL(mbedtls_ct_uchar_in_range_if(l, h, x, t), expected);
|
||||
|
||||
TEST_CF_PUBLIC(&x, sizeof(x));
|
||||
TEST_CF_PUBLIC(&l, sizeof(l));
|
||||
TEST_CF_PUBLIC(&h, sizeof(h));
|
||||
TEST_CF_PUBLIC(&t, sizeof(t));
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ct_if(char *c_str, char *t_str, char *f_str)
|
||||
{
|
||||
mbedtls_ct_condition_t c = mbedtls_ct_bool(strtoull(c_str, NULL, 16));
|
||||
mbedtls_ct_uint_t t = (mbedtls_ct_uint_t) strtoull(t_str, NULL, 16);
|
||||
mbedtls_ct_uint_t f = (mbedtls_ct_uint_t) strtoull(f_str, NULL, 16);
|
||||
|
||||
mbedtls_ct_uint_t expected = c ? t : f;
|
||||
mbedtls_ct_uint_t expected0 = c ? t : 0;
|
||||
|
||||
TEST_CF_SECRET(&c, sizeof(c));
|
||||
TEST_CF_SECRET(&t, sizeof(t));
|
||||
TEST_CF_SECRET(&f, sizeof(f));
|
||||
|
||||
TEST_EQUAL(mbedtls_ct_if(c, t, f), expected);
|
||||
TEST_EQUAL(mbedtls_ct_size_if(c, t, f), (size_t) expected);
|
||||
TEST_EQUAL(mbedtls_ct_uint_if(c, t, f), (unsigned) expected);
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
TEST_EQUAL(mbedtls_ct_mpi_uint_if(c, t, f), (mbedtls_mpi_uint) expected);
|
||||
#endif
|
||||
|
||||
TEST_EQUAL(mbedtls_ct_uint_if0(c, t), (unsigned) expected0);
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
TEST_EQUAL(mbedtls_ct_mpi_uint_if0(c, t), (mbedtls_mpi_uint) expected0);
|
||||
#endif
|
||||
|
||||
TEST_CF_PUBLIC(&c, sizeof(c));
|
||||
TEST_CF_PUBLIC(&t, sizeof(t));
|
||||
TEST_CF_PUBLIC(&f, sizeof(f));
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PKCS1_V15:MBEDTLS_RSA_C:!MBEDTLS_RSA_ALT */
|
||||
void mbedtls_ct_zeroize_if(char *c_str, int len)
|
||||
{
|
||||
uint8_t *buf = NULL;
|
||||
mbedtls_ct_condition_t c = mbedtls_ct_bool(strtoull(c_str, NULL, 16));
|
||||
|
||||
ASSERT_ALLOC(buf, len);
|
||||
for (size_t i = 0; i < (size_t) len; i++) {
|
||||
buf[i] = 1;
|
||||
}
|
||||
|
||||
TEST_CF_SECRET(&c, sizeof(c));
|
||||
TEST_CF_SECRET(buf, len);
|
||||
mbedtls_ct_zeroize_if(c, buf, len);
|
||||
TEST_CF_PUBLIC(&c, sizeof(c));
|
||||
TEST_CF_PUBLIC(buf, len);
|
||||
|
||||
for (size_t i = 0; i < (size_t) len; i++) {
|
||||
TEST_EQUAL(buf[i], c != 0 ? 0 : 1);
|
||||
}
|
||||
exit:
|
||||
mbedtls_free(buf);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ct_memcmp(int same, int size, int offset)
|
||||
{
|
||||
@ -32,9 +175,6 @@ void mbedtls_ct_memcmp(int same, int size, int offset)
|
||||
ASSERT_ALLOC(a, size + offset);
|
||||
ASSERT_ALLOC(b, size + offset);
|
||||
|
||||
TEST_CF_SECRET(a + offset, size);
|
||||
TEST_CF_SECRET(b + offset, size);
|
||||
|
||||
/* Construct data that matches, if same == -1, otherwise
|
||||
* same gives the number of bytes (after the initial offset)
|
||||
* that will match; after that it will differ.
|
||||
@ -49,9 +189,15 @@ void mbedtls_ct_memcmp(int same, int size, int offset)
|
||||
}
|
||||
|
||||
int reference = memcmp(a + offset, b + offset, size);
|
||||
|
||||
TEST_CF_SECRET(a, size + offset);
|
||||
TEST_CF_SECRET(b, size + offset);
|
||||
|
||||
int actual = mbedtls_ct_memcmp(a + offset, b + offset, size);
|
||||
TEST_CF_PUBLIC(a + offset, size);
|
||||
TEST_CF_PUBLIC(b + offset, size);
|
||||
|
||||
TEST_CF_PUBLIC(a, size + offset);
|
||||
TEST_CF_PUBLIC(b, size + offset);
|
||||
TEST_CF_PUBLIC(&actual, sizeof(actual));
|
||||
|
||||
if (same == -1 || same >= size) {
|
||||
TEST_ASSERT(reference == 0);
|
||||
@ -66,30 +212,31 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_MAC */
|
||||
void mbedtls_ct_memcpy_if_eq(int eq, int size, int offset)
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ct_memcpy_if(int eq, int size, int offset)
|
||||
{
|
||||
uint8_t *src = NULL, *result = NULL, *expected = NULL;
|
||||
uint8_t *src = NULL, *src2 = NULL, *result = NULL, *expected = NULL;
|
||||
ASSERT_ALLOC(src, size + offset);
|
||||
ASSERT_ALLOC(src2, size + offset);
|
||||
ASSERT_ALLOC(result, size + offset);
|
||||
ASSERT_ALLOC(expected, size + offset);
|
||||
|
||||
for (int i = 0; i < size + offset; i++) {
|
||||
src[i] = 1;
|
||||
result[i] = 0xff;
|
||||
src[i] = 1;
|
||||
result[i] = 0xff;
|
||||
expected[i] = eq ? 1 : 0xff;
|
||||
}
|
||||
|
||||
int one, secret_eq;
|
||||
TEST_CF_SECRET(&one, sizeof(one));
|
||||
TEST_CF_SECRET(&secret_eq, sizeof(secret_eq));
|
||||
one = 1;
|
||||
secret_eq = eq;
|
||||
int secret_eq = eq;
|
||||
TEST_CF_SECRET(&secret_eq, sizeof(secret_eq));
|
||||
TEST_CF_SECRET(src, size + offset);
|
||||
TEST_CF_SECRET(result, size + offset);
|
||||
|
||||
mbedtls_ct_memcpy_if_eq(result + offset, src, size, secret_eq, one);
|
||||
mbedtls_ct_memcpy_if(mbedtls_ct_bool(secret_eq), result + offset, src, NULL, size);
|
||||
|
||||
TEST_CF_PUBLIC(&one, sizeof(one));
|
||||
TEST_CF_PUBLIC(&secret_eq, sizeof(secret_eq));
|
||||
TEST_CF_PUBLIC(src, size + offset);
|
||||
TEST_CF_PUBLIC(result, size + offset);
|
||||
|
||||
ASSERT_COMPARE(expected, size, result + offset, size);
|
||||
|
||||
@ -99,26 +246,80 @@ void mbedtls_ct_memcpy_if_eq(int eq, int size, int offset)
|
||||
expected[i] = eq ? 1 : 0xff;
|
||||
}
|
||||
|
||||
TEST_CF_SECRET(&one, sizeof(one));
|
||||
TEST_CF_SECRET(&secret_eq, sizeof(secret_eq));
|
||||
one = 1;
|
||||
secret_eq = eq;
|
||||
TEST_CF_SECRET(&secret_eq, sizeof(secret_eq));
|
||||
TEST_CF_SECRET(src, size + offset);
|
||||
TEST_CF_SECRET(result, size + offset);
|
||||
|
||||
mbedtls_ct_memcpy_if_eq(result, src + offset, size, secret_eq, one);
|
||||
mbedtls_ct_memcpy_if(mbedtls_ct_bool(secret_eq), result, src + offset, NULL, size);
|
||||
|
||||
TEST_CF_PUBLIC(&one, sizeof(one));
|
||||
TEST_CF_PUBLIC(&secret_eq, sizeof(secret_eq));
|
||||
TEST_CF_PUBLIC(src, size + offset);
|
||||
TEST_CF_PUBLIC(result, size + offset);
|
||||
|
||||
ASSERT_COMPARE(expected, size, result, size);
|
||||
|
||||
for (int i = 0; i < size + offset; i++) {
|
||||
src[i] = 1;
|
||||
src2[i] = 2;
|
||||
result[i] = 0xff;
|
||||
expected[i] = eq ? 1 : 2;
|
||||
}
|
||||
|
||||
TEST_CF_SECRET(&secret_eq, sizeof(secret_eq));
|
||||
TEST_CF_SECRET(src, size + offset);
|
||||
TEST_CF_SECRET(src2, size + offset);
|
||||
TEST_CF_SECRET(result, size + offset);
|
||||
|
||||
mbedtls_ct_memcpy_if(mbedtls_ct_bool(secret_eq), result, src + offset, src2 + offset, size);
|
||||
|
||||
TEST_CF_PUBLIC(&secret_eq, sizeof(secret_eq));
|
||||
TEST_CF_PUBLIC(src, size + offset);
|
||||
TEST_CF_SECRET(src2, size + offset);
|
||||
TEST_CF_PUBLIC(result, size + offset);
|
||||
|
||||
ASSERT_COMPARE(expected, size, result, size);
|
||||
exit:
|
||||
mbedtls_free(src);
|
||||
mbedtls_free(src2);
|
||||
mbedtls_free(result);
|
||||
mbedtls_free(expected);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC:MBEDTLS_TEST_HOOKS */
|
||||
void ssl_cf_memcpy_offset(int offset_min, int offset_max, int len)
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_PKCS1_V15:MBEDTLS_RSA_C:!MBEDTLS_RSA_ALT */
|
||||
void mbedtls_ct_memmove_left(int len, int offset)
|
||||
{
|
||||
size_t l = (size_t) len;
|
||||
size_t o = (size_t) offset;
|
||||
|
||||
uint8_t *buf = NULL, *buf_expected = NULL;
|
||||
ASSERT_ALLOC(buf, l);
|
||||
ASSERT_ALLOC(buf_expected, l);
|
||||
|
||||
for (size_t i = 0; i < l; i++) {
|
||||
buf[i] = (uint8_t) i;
|
||||
buf_expected[i] = buf[i];
|
||||
}
|
||||
|
||||
TEST_CF_SECRET(&o, sizeof(o));
|
||||
TEST_CF_SECRET(buf, l);
|
||||
mbedtls_ct_memmove_left(buf, l, o);
|
||||
TEST_CF_PUBLIC(&o, sizeof(o));
|
||||
TEST_CF_PUBLIC(buf, l);
|
||||
|
||||
if (l > 0) {
|
||||
memmove(buf_expected, buf_expected + o, l - o);
|
||||
memset(buf_expected + (l - o), 0, o);
|
||||
TEST_ASSERT(memcmp(buf, buf_expected, l) == 0);
|
||||
}
|
||||
exit:
|
||||
mbedtls_free(buf);
|
||||
mbedtls_free(buf_expected);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_MAC */
|
||||
void mbedtls_ct_memcpy_offset(int offset_min, int offset_max, int len)
|
||||
{
|
||||
unsigned char *dst = NULL;
|
||||
unsigned char *src = NULL;
|
||||
@ -135,9 +336,12 @@ void ssl_cf_memcpy_offset(int offset_min, int offset_max, int len)
|
||||
mbedtls_test_set_step((int) secret);
|
||||
|
||||
TEST_CF_SECRET(&secret, sizeof(secret));
|
||||
TEST_CF_SECRET(src, len);
|
||||
TEST_CF_SECRET(dst, len);
|
||||
mbedtls_ct_memcpy_offset(dst, src, secret,
|
||||
offset_min, offset_max, len);
|
||||
TEST_CF_PUBLIC(&secret, sizeof(secret));
|
||||
TEST_CF_PUBLIC(src, len);
|
||||
TEST_CF_PUBLIC(dst, len);
|
||||
|
||||
ASSERT_COMPARE(dst, len, src + secret, len);
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <test/constant_flow.h>
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC:MBEDTLS_TEST_HOOKS */
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SSL_SOME_SUITES_USE_MAC:MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC:MBEDTLS_TEST_HOOKS */
|
||||
void ssl_cf_hmac(int hash)
|
||||
{
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user