Add test_test tests for bignums.

Add relative tests for bignums.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3405)
This commit is contained in:
Pauli 2017-05-09 07:58:55 +10:00 committed by Richard Levitte
parent dc352c1937
commit 03d8e9cb43
2 changed files with 74 additions and 0 deletions

View file

@ -17,6 +17,7 @@
#include <openssl/opensslconf.h>
#include <openssl/err.h>
#include <openssl/crypto.h>
#include <openssl/bn.h>
#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);

View file

@ -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)