From 03d8e9cb43da5c524e5890a5a51e2c77f1fbd789 Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 9 May 2017 07:58:55 +1000 Subject: [PATCH] Add test_test tests for bignums. Add relative tests for bignums. Reviewed-by: Rich Salz Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/3405) --- test/test_test.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ test/testutil.h | 4 +++ 2 files changed, 74 insertions(+) diff --git a/test/test_test.c b/test/test_test.c index 7d3af2f04a..0094c1c643 100644 --- a/test/test_test.c +++ b/test/test_test.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "e_os.h" #include "testutil.h" @@ -287,6 +288,74 @@ static int test_memory_overflow(void) return TEST(0, TEST_mem_eq(p, strlen(p), q, strlen(q))); } +static int test_bignum(void) +{ + BIGNUM *a = NULL, *b = NULL, *c = NULL; + int r = 0; + + if (!TEST(1, TEST_int_eq(BN_dec2bn(&a, "0"), 1)) + | !TEST(1, TEST_BN_eq_word(a, 0)) + | !TEST(0, TEST_BN_eq_word(a, 30)) + | !TEST(1, TEST_BN_abs_eq_word(a, 0)) + | !TEST(0, TEST_BN_eq_one(a)) + | !TEST(1, TEST_BN_eq_zero(a)) + | !TEST(0, TEST_BN_ne_zero(a)) + | !TEST(1, TEST_BN_le_zero(a)) + | !TEST(0, TEST_BN_lt_zero(a)) + | !TEST(1, TEST_BN_ge_zero(a)) + | !TEST(0, TEST_BN_gt_zero(a)) + | !TEST(1, TEST_BN_even(a)) + | !TEST(0, TEST_BN_odd(a)) + | !TEST(1, TEST_int_eq(BN_dec2bn(&b, "1"), 1)) + | !TEST(1, TEST_BN_eq_word(b, 1)) + | !TEST(1, TEST_BN_eq_one(b)) + | !TEST(0, TEST_BN_abs_eq_word(b, 0)) + | !TEST(1, TEST_BN_abs_eq_word(b, 1)) + | !TEST(0, TEST_BN_eq_zero(b)) + | !TEST(1, TEST_BN_ne_zero(b)) + | !TEST(0, TEST_BN_le_zero(b)) + | !TEST(0, TEST_BN_lt_zero(b)) + | !TEST(1, TEST_BN_ge_zero(b)) + | !TEST(1, TEST_BN_gt_zero(b)) + | !TEST(0, TEST_BN_even(b)) + | !TEST(1, TEST_BN_odd(b)) + | !TEST(1, TEST_int_eq(BN_dec2bn(&c, "-334739439"), 10)) + | !TEST(0, TEST_BN_eq_word(c, 334739439)) + | !TEST(1, TEST_BN_abs_eq_word(c, 334739439)) + | !TEST(0, TEST_BN_eq_zero(c)) + | !TEST(1, TEST_BN_ne_zero(c)) + | !TEST(1, TEST_BN_le_zero(c)) + | !TEST(1, TEST_BN_lt_zero(c)) + | !TEST(0, TEST_BN_ge_zero(c)) + | !TEST(0, TEST_BN_gt_zero(c)) + | !TEST(0, TEST_BN_even(c)) + | !TEST(1, TEST_BN_odd(c)) + | !TEST(1, TEST_BN_eq(a, a)) + | !TEST(0, TEST_BN_ne(a, a)) + | !TEST(0, TEST_BN_eq(a, b)) + | !TEST(1, TEST_BN_ne(a, b)) + | !TEST(0, TEST_BN_lt(a, c)) + | !TEST(1, TEST_BN_lt(c, b)) + | !TEST(0, TEST_BN_lt(b, c)) + | !TEST(0, TEST_BN_le(a, c)) + | !TEST(1, TEST_BN_le(c, b)) + | !TEST(0, TEST_BN_le(b, c)) + | !TEST(1, TEST_BN_gt(a, c)) + | !TEST(0, TEST_BN_gt(c, b)) + | !TEST(1, TEST_BN_gt(b, c)) + | !TEST(1, TEST_BN_ge(a, c)) + | !TEST(0, TEST_BN_ge(c, b)) + | !TEST(1, TEST_BN_ge(b, c))) + goto err; + + r = 1; +err: + BN_free(a); + BN_free(b); + BN_free(c); + return r; +} + static int test_long_output(void) { const char *p = "1234567890123456789012345678901234567890123456789012"; @@ -381,6 +450,7 @@ void register_tests(void) ADD_TEST(test_string); ADD_TEST(test_memory); ADD_TEST(test_memory_overflow); + ADD_TEST(test_bignum); ADD_TEST(test_long_output); ADD_TEST(test_messages); ADD_TEST(test_single_eval); diff --git a/test/testutil.h b/test/testutil.h index 36b7823e39..8e4481e413 100644 --- a/test/testutil.h +++ b/test/testutil.h @@ -356,6 +356,10 @@ void test_openssl_errors(void); # define TEST_BN_eq(a, b) test_BN_eq(__FILE__, __LINE__, #a, #b, a, b) # define TEST_BN_ne(a, b) test_BN_ne(__FILE__, __LINE__, #a, #b, a, b) +# define TEST_BN_lt(a, b) test_BN_lt(__FILE__, __LINE__, #a, #b, a, b) +# define TEST_BN_gt(a, b) test_BN_gt(__FILE__, __LINE__, #a, #b, a, b) +# define TEST_BN_le(a, b) test_BN_le(__FILE__, __LINE__, #a, #b, a, b) +# define TEST_BN_ge(a, b) test_BN_ge(__FILE__, __LINE__, #a, #b, a, b) # define TEST_BN_eq_zero(a) test_BN_eq_zero(__FILE__, __LINE__, #a, a) # define TEST_BN_ne_zero(a) test_BN_ne_zero(__FILE__, __LINE__, #a, a) # define TEST_BN_lt_zero(a) test_BN_lt_zero(__FILE__, __LINE__, #a, a) -- GitLab