+
+#define DEFINE_BN_COMPARISONS(opname, op, zero_cond) \
+ int test_BN_ ## opname(const char *file, int line, \
+ const char *s1, const char *s2, \
+ const BIGNUM *t1, const BIGNUM *t2) \
+ { \
+ if (BN_cmp(t1, t2) op 0) \
+ return 1; \
+ test_fail_bignum_message(NULL, file, line, "BIGNUM", s1, s2, \
+ #op, t1, t2); \
+ return 0; \
+ } \
+ int test_BN_ ## opname ## _zero(const char *file, int line, \
+ const char *s, const BIGNUM *a) \
+ { \
+ if (a != NULL &&(zero_cond)) \
+ return 1; \
+ test_fail_bignum_mono_message(NULL, file, line, "BIGNUM", \
+ s, "0", #op, a); \
+ return 0; \
+ }
+
+DEFINE_BN_COMPARISONS(eq, ==, BN_is_zero(a))
+DEFINE_BN_COMPARISONS(ne, !=, !BN_is_zero(a))
+DEFINE_BN_COMPARISONS(gt, >, !BN_is_negative(a) && !BN_is_zero(a))
+DEFINE_BN_COMPARISONS(ge, >=, !BN_is_negative(a) || BN_is_zero(a))
+DEFINE_BN_COMPARISONS(lt, <, BN_is_negative(a) && !BN_is_zero(a))
+DEFINE_BN_COMPARISONS(le, <=, BN_is_negative(a) || BN_is_zero(a))
+
+int test_BN_eq_one(const char *file, int line, const char *s, const BIGNUM *a)
+{
+ if (a != NULL && BN_is_one(a))
+ return 1;
+ test_fail_bignum_mono_message(NULL, file, line, "BIGNUM", s, "1", "==", a);
+ return 0;
+}
+
+int test_BN_odd(const char *file, int line, const char *s, const BIGNUM *a)
+{
+ if (a != NULL && BN_is_odd(a))
+ return 1;
+ test_fail_bignum_mono_message(NULL, file, line, "BIGNUM", "ODD(", ")", s, a);
+ return 0;
+}
+
+int test_BN_even(const char *file, int line, const char *s, const BIGNUM *a)
+{
+ if (a != NULL && !BN_is_odd(a))
+ return 1;
+ test_fail_bignum_mono_message(NULL, file, line, "BIGNUM", "EVEN(", ")", s,
+ a);
+ return 0;
+}
+
+int test_BN_eq_word(const char *file, int line, const char *bns, const char *ws,
+ const BIGNUM *a, BN_ULONG w)
+{
+ BIGNUM *bw;
+
+ if (a != NULL && BN_is_word(a, w))
+ return 1;
+ bw = BN_new();
+ BN_set_word(bw, w);
+ test_fail_bignum_message(NULL, file, line, "BIGNUM", bns, ws, "==", a, bw);
+ BN_free(bw);
+ return 0;
+}
+
+int test_BN_abs_eq_word(const char *file, int line, const char *bns,
+ const char *ws, const BIGNUM *a, BN_ULONG w)
+{
+ BIGNUM *bw, *aa;
+
+ if (a != NULL && BN_abs_is_word(a, w))
+ return 1;
+ bw = BN_new();
+ aa = BN_dup(a);
+ BN_set_negative(aa, 0);
+ BN_set_word(bw, w);
+ test_fail_bignum_message(NULL, file, line, "BIGNUM", bns, ws, "abs==",
+ aa, bw);
+ BN_free(bw);
+ BN_free(aa);
+ return 0;
+}
+
+static const char *print_time(const ASN1_TIME *t)
+{
+ return t == NULL ? "<null>" : (char *)ASN1_STRING_get0_data(t);
+}
+
+#define DEFINE_TIME_T_COMPARISON(opname, op) \
+ int test_time_t_ ## opname(const char *file, int line, \
+ const char *s1, const char *s2, \
+ const time_t t1, const time_t t2) \
+ { \
+ ASN1_TIME *at1 = ASN1_TIME_set(NULL, t1); \
+ ASN1_TIME *at2 = ASN1_TIME_set(NULL, t2); \
+ int r = at1 != NULL && at2 != NULL \
+ && ASN1_TIME_compare(at1, at2) op 0; \
+ if (!r) \
+ test_fail_message(NULL, file, line, "time_t", s1, s2, #op, \
+ "[%s] compared to [%s]", \
+ print_time(at1), print_time(at2)); \
+ ASN1_STRING_free(at1); \
+ ASN1_STRING_free(at2); \
+ return r; \
+ }
+DEFINE_TIME_T_COMPARISON(eq, ==)
+DEFINE_TIME_T_COMPARISON(ne, !=)
+DEFINE_TIME_T_COMPARISON(gt, >)
+DEFINE_TIME_T_COMPARISON(ge, >=)
+DEFINE_TIME_T_COMPARISON(lt, <)
+DEFINE_TIME_T_COMPARISON(le, <=)