Add BN support to the test infrastructure.

This includes support for:

- comparisions between pairs of BIGNUMs
- comparisions between BIGNUMs and zero
- equality comparison between BIGNUMs and one
- equality comparisons between BIGNUMs and constants
- parity checks 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)
diff --git a/test/testutil.h b/test/testutil.h
index f1c1bba..36b7823 100644
--- a/test/testutil.h
+++ b/test/testutil.h
@@ -14,6 +14,7 @@
 
 #include <openssl/err.h>
 #include <openssl/e_os2.h>
+#include <openssl/bn.h>
 
 /*-
  * Simple unit tests should implement register_tests().
@@ -239,6 +240,27 @@
 int test_false(const char *file, int line, const char *s, int b);
 
 /*
+ * Comparisons between BIGNUMs.
+ * BIGNUMS can be compared against other BIGNUMs or zero.
+ * Some additional equality tests against 1 & specific values are provided.
+ * Tests for parity are included as well.
+ */
+DECLARE_COMPARISONS(BIGNUM *, BN)
+int test_BN_eq_zero(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_ne_zero(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_lt_zero(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_le_zero(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_gt_zero(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_ge_zero(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_eq_one(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_odd(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_even(const char *file, int line, const char *s, const BIGNUM *a);
+int test_BN_eq_word(const char *file, int line, const char *bns, const char *ws,
+                    const BIGNUM *a, BN_ULONG w);
+int test_BN_abs_eq_word(const char *file, int line, const char *bns,
+                        const char *ws, const BIGNUM *a, BN_ULONG w);
+
+/*
  * Pretty print a failure message.
  * These should not be called directly, use the TEST_xxx macros below instead.
  */
@@ -332,6 +354,20 @@
 # define TEST_true(a)         test_true(__FILE__, __LINE__, #a, (a) != 0)
 # define TEST_false(a)        test_false(__FILE__, __LINE__, #a, (a) != 0)
 
+# 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_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)
+# define TEST_BN_gt_zero(a)   test_BN_gt_zero(__FILE__, __LINE__, #a, a)
+# define TEST_BN_le_zero(a)   test_BN_le_zero(__FILE__, __LINE__, #a, a)
+# define TEST_BN_ge_zero(a)   test_BN_ge_zero(__FILE__, __LINE__, #a, a)
+# define TEST_BN_eq_one(a)    test_BN_eq_one(__FILE__, __LINE__, #a, a)
+# define TEST_BN_eq_word(a, w) test_BN_eq_word(__FILE__, __LINE__, #a, #w, a, w)
+# define TEST_BN_abs_eq_word(a, w) test_BN_abs_eq_word(__FILE__, __LINE__, #a, #w, a, w)
+# define TEST_BN_odd(a)       test_BN_odd(__FILE__, __LINE__, #a, a)
+# define TEST_BN_even(a)      test_BN_even(__FILE__, __LINE__, #a, a)
+
 /*
  * TEST_error(desc, ...) prints an informative error message in the standard
  * format.  |desc| is a printf format string.