X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fconstant_time_test.c;h=1b4b18d1990e6ae6ab1976ea26109741514e86d4;hb=3b7ab6f4b835c1ebcfbc66ba9521ab2d308cb28a;hp=0e51892af50816a6c34e5b280bbda866b70616b3;hpb=9bed73adaa6f834177f29e478d9a2247a6577c04;p=oweals%2Fopenssl.git diff --git a/crypto/constant_time_test.c b/crypto/constant_time_test.c index 0e51892af5..1b4b18d199 100644 --- a/crypto/constant_time_test.c +++ b/crypto/constant_time_test.c @@ -196,6 +196,45 @@ static int test_select_int(int a, int b) return 0; } +static int test_eq_int(int a, int b) + { + unsigned int equal = constant_time_eq_int(a, b); + if (a == b && equal != CONSTTIME_TRUE) + { + fprintf(stderr, "Test failed for constant_time_select(%d, %d): " + "expected %du(TRUE), got %du\n", + a, b, CONSTTIME_TRUE, equal); + return 1; + } + else if (a != b && equal != CONSTTIME_FALSE) + { + fprintf(stderr, "Test failed for constant_time_select(%d, %d): " + "expected %du(FALSE), got %du\n", + a, b, CONSTTIME_FALSE, equal); + return 1; + } + return 0; + } + +static int test_eq_int_8(int a, int b) + { + unsigned char equal = constant_time_eq_int_8(a, b); + if (a == b && equal != CONSTTIME_TRUE_8) + { + fprintf(stderr, "Test failed for constant_time_select(%d, %d): " + "expected %u(TRUE), got %u\n", + a, b, CONSTTIME_TRUE_8, equal); + return 1; + } + else if (a != b && equal != CONSTTIME_FALSE_8) + { + fprintf(stderr, "Test failed for constant_time_select(%d, %d): " + "expected %u(FALSE), got %u\n", + a, b, CONSTTIME_FALSE_8, equal); + return 1; + } + return 0; + } static unsigned int test_values[] = {0, 1, 1024, 12345, 32000, UINT_MAX/2-1, UINT_MAX/2, UINT_MAX/2+1, UINT_MAX-1,