From 30bea14be6bbf77ed60acb9bd1befeb51d4c4b10 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Wed, 26 Apr 2017 12:39:46 -0400 Subject: [PATCH] Convert bntest to TEST_ framework Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/3265) --- test/bntest.c | 1328 +++++++++++++++++++------------------------- test/libtestutil.a | Bin 82398 -> 0 bytes 2 files changed, 582 insertions(+), 746 deletions(-) delete mode 100644 test/libtestutil.a diff --git a/test/bntest.c b/test/bntest.c index 0410e07d08a..97ad97aca63 100644 --- a/test/bntest.c +++ b/test/bntest.c @@ -70,6 +70,12 @@ static const int NUM1 = 50; /* additional tests for some functions */ static FILE *fp; static BN_CTX *ctx; +/* + * Polynomial coefficients used in GFM tests. + */ +static int p0[] = { 163, 7, 6, 3, 0, -1 }; +static int p1[] = { 193, 15, 0, -1 }; + /* * Look for |key| in the stanza and return it or NULL if not found. @@ -106,13 +112,12 @@ static BIGNUM *getBN(STANZA *s, const char *attribute) BIGNUM *ret = NULL; if ((hex = findattr(s, attribute)) == NULL) { - fprintf(stderr, "Can't find %s in test at line %d\n", - attribute, s->start); + TEST_error("Can't find %s in test at line %d", attribute, s->start); return NULL; } if (parseBN(&ret, hex) != (int)strlen(hex)) { - fprintf(stderr, "Could not decode '%s'.\n", hex); + TEST_error("Could not decode '%s'", hex); return NULL; } return ret; @@ -120,14 +125,12 @@ static BIGNUM *getBN(STANZA *s, const char *attribute) static int getint(STANZA *s, int *out, const char *attribute) { - BIGNUM *ret = getBN(s, attribute); + BIGNUM *ret; BN_ULONG word; int st = 0; - if (ret == NULL) - goto err; - - if ((word = BN_get_word(ret)) > INT_MAX) + if (!TEST_ptr(ret = getBN(s, attribute)) + || !TEST_ulong_le(word = BN_get_word(ret), INT_MAX)) goto err; *out = (int)word; @@ -153,13 +156,10 @@ static int equalBN(const char *op, const BIGNUM *expected, const BIGNUM *actual) actstr = OPENSSL_strdup("-0"); else actstr = BN_bn2hex(actual); - if (exstr == NULL || actstr == NULL) + if (!TEST_ptr(exstr) || !TEST_ptr(actstr)) goto err; - fprintf(stderr, "Got %s =\n", op); - fprintf(stderr, "\t%s\n", actstr); - fprintf(stderr, "wanted:\n"); - fprintf(stderr, "\t%s\n", exstr); + TEST_error("Got %s =\n\t%s\nwanted:\n\t%s", op, actstr, exstr); err: OPENSSL_free(exstr); @@ -182,19 +182,20 @@ static int rand_neg(void) static int test_sub() { - BIGNUM *a, *b, *c; - int i; + BIGNUM *a = NULL, *b = NULL, *c = NULL; + int i, st = 0; - a = BN_new(); - b = BN_new(); - c = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b = BN_new()) + || !TEST_ptr(c = BN_new())) + goto err; for (i = 0; i < NUM0 + NUM1; i++) { if (i < NUM1) { BN_bntest_rand(a, 512, 0, 0); BN_copy(b, a); - if (BN_set_bit(a, i) == 0) - return 0; + if (!TEST_int_ne(BN_set_bit(a, i), 0)) + goto err; BN_add_word(b, i); } else { BN_bntest_rand(b, 400 + i - NUM1, 0, 0); @@ -204,30 +205,31 @@ static int test_sub() BN_sub(c, a, b); BN_add(c, c, b); BN_sub(c, c, a); - if (!BN_is_zero(c)) { - printf("Subtract test failed!\n"); - return 0; - } + if (!TEST_true(BN_is_zero(c))) + goto err; } + st = 1; +err: BN_free(a); BN_free(b); BN_free(c); - return 1; + return st; } static int test_div_recip() { - BIGNUM *a, *b, *c, *d, *e; - BN_RECP_CTX *recp; - int i; + BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL; + BN_RECP_CTX *recp = NULL; + int st = 0, i; - recp = BN_RECP_CTX_new(); - a = BN_new(); - b = BN_new(); - c = BN_new(); - d = BN_new(); - e = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new()) + || !TEST_ptr(recp = BN_RECP_CTX_new())) + goto err; for (i = 0; i < NUM0 + NUM1; i++) { if (i < NUM1) { @@ -244,36 +246,32 @@ static int test_div_recip() BN_mul(e, d, b, ctx); BN_add(d, e, c); BN_sub(d, d, a); - if (!BN_is_zero(d)) { - printf("Reciprocal division test failed!\n"); - printf("a="); - BN_print_fp(stdout, a); - printf("\nb="); - BN_print_fp(stdout, b); - printf("\n"); - return 0; - } + if (!TEST_true(BN_is_zero(d))) + goto err; } + st = 1; +err: BN_free(a); BN_free(b); BN_free(c); BN_free(d); BN_free(e); BN_RECP_CTX_free(recp); - return 1; + return st; } static int test_mod() { - BIGNUM *a, *b, *c, *d, *e; - int i; + BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL; + int st = 0, i; - a = BN_new(); - b = BN_new(); - c = BN_new(); - d = BN_new(); - e = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new())) + goto err; BN_bntest_rand(a, 1024, 0, 0); for (i = 0; i < NUM0; i++) { @@ -283,17 +281,17 @@ static int test_mod() BN_mod(c, a, b, ctx); BN_div(d, e, a, b, ctx); BN_sub(e, e, c); - if (!BN_is_zero(e)) { - printf("Modulo test failed!\n"); - return 0; - } + if (!TEST_true(BN_is_zero(e))) + goto err; } + st = 1; +err: BN_free(a); BN_free(b); BN_free(c); BN_free(d); BN_free(e); - return 1; + return st; } static const char *bn1strings[] = { @@ -344,11 +342,10 @@ static char *glue(const char *list[]) for (i = 0; list[i] != NULL; i++) len += strlen(list[i]); - p = save = OPENSSL_malloc(len + 1); - if (p != NULL) { - for (i = 0; list[i] != NULL; i++) - p += strlen(strcpy(p, list[i])); - } + if (!TEST_ptr(p = save = OPENSSL_malloc(len + 1))) + return NULL; + for (i = 0; list[i] != NULL; i++) + p += strlen(strcpy(p, list[i])); return save; } @@ -358,30 +355,31 @@ static char *glue(const char *list[]) */ static int test_modexp_mont5() { - BIGNUM *a, *p, *m, *d, *e, *b, *n, *c; - BN_MONT_CTX *mont; + BIGNUM *a = NULL, *p = NULL, *m = NULL, *d = NULL, *e = NULL; + BIGNUM *b = NULL, *n = NULL, *c = NULL; + BN_MONT_CTX *mont = NULL; char *bigstring; + int st = 0; - a = BN_new(); - p = BN_new(); - m = BN_new(); - d = BN_new(); - e = BN_new(); - b = BN_new(); - n = BN_new(); - c = BN_new(); - mont = BN_MONT_CTX_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(p = BN_new()) + || !TEST_ptr(m = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new()) + || !TEST_ptr(b = BN_new()) + || !TEST_ptr(n = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(mont = BN_MONT_CTX_new())) + goto err; BN_bntest_rand(m, 1024, 0, 1); /* must be odd for montgomery */ /* Zero exponent */ BN_bntest_rand(a, 1024, 0, 0); BN_zero(p); - if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) - return 0; - if (!BN_is_one(d)) { - printf("Modular exponentiation test failed!\n"); - return 0; - } + if (!TEST_true(BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))) + goto err; + if (!TEST_true(BN_is_one(d))) + goto err; /* Regression test for carry bug in mulx4x_mont */ BN_hex2bn(&a, @@ -402,11 +400,8 @@ static int test_modexp_mont5() BN_MONT_CTX_set(mont, n, ctx); BN_mod_mul_montgomery(c, a, b, mont, ctx); BN_mod_mul_montgomery(d, b, a, mont, ctx); - if (BN_cmp(c, d)) { - fprintf(stderr, "Montgomery multiplication test failed:" - " a*b != b*a.\n"); - return 0; - } + if (!TEST_int_eq(BN_cmp(c, d), 0)) + goto err; /* Regression test for carry bug in sqr[x]8x_mont */ bigstring = glue(bn1strings); @@ -420,21 +415,16 @@ static int test_modexp_mont5() BN_MONT_CTX_set(mont, n, ctx); BN_mod_mul_montgomery(c, a, a, mont, ctx); BN_mod_mul_montgomery(d, a, b, mont, ctx); - if (BN_cmp(c, d)) { - fprintf(stderr, "Montgomery multiplication test failed:" - " a**2 != a*a.\n"); - return 0; - } + if (!TEST_int_eq(BN_cmp(c, d), 0)) + goto err; /* Zero input */ BN_bntest_rand(p, 1024, 0, 0); BN_zero(a); - if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) - return 0; - if (!BN_is_zero(d)) { - fprintf(stderr, "Modular exponentiation test failed!\n"); - return 0; - } + if (!TEST_true(BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) + || !TEST_true(BN_is_zero(d))) + goto err; + /* * Craft an input whose Montgomery representation is 1, i.e., shorter * than the modulus m, in order to test the const time precomputation @@ -442,26 +432,22 @@ static int test_modexp_mont5() */ BN_one(a); BN_MONT_CTX_set(mont, m, ctx); - if (!BN_from_montgomery(e, a, mont, ctx)) - return 0; - if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) - return 0; - if (!BN_mod_exp_simple(a, e, p, m, ctx)) - return 0; - if (BN_cmp(a, d) != 0) { - printf("Modular exponentiation test failed!\n"); - return 0; - } + if (!TEST_true(BN_from_montgomery(e, a, mont, ctx)) + || !TEST_true(BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) + || !TEST_true(BN_mod_exp_simple(a, e, p, m, ctx)) + || !TEST_int_eq(BN_cmp(a, d), 0)) + goto err; + /* Finally, some regular test vectors. */ BN_bntest_rand(e, 1024, 0, 0); - if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) - return 0; - if (!BN_mod_exp_simple(a, e, p, m, ctx)) - return 0; - if (BN_cmp(a, d) != 0) { - printf("Modular exponentiation test failed!\n"); - return 0; - } + if (!TEST_true(BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) + || !TEST_true(BN_mod_exp_simple(a, e, p, m, ctx)) + || !TEST_int_eq(BN_cmp(a, d), 0)) + goto err; + + st = 1; + +err: BN_MONT_CTX_free(mont); BN_free(a); BN_free(p); @@ -471,18 +457,19 @@ static int test_modexp_mont5() BN_free(b); BN_free(n); BN_free(c); - return 1; + return st; } #ifndef OPENSSL_NO_EC2M static int test_gf2m_add() { - BIGNUM *a, *b, *c; + BIGNUM *a = NULL, *b = NULL, *c = NULL; int i, st = 0; - a = BN_new(); - b = BN_new(); - c = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b = BN_new()) + || !TEST_ptr(c = BN_new())) + goto err; for (i = 0; i < NUM0; i++) { BN_rand(a, 512, 0, 0); @@ -491,17 +478,13 @@ static int test_gf2m_add() b->neg = rand_neg(); BN_GF2m_add(c, a, b); /* Test that two added values have the correct parity. */ - if ((BN_is_odd(a) && BN_is_odd(c)) - || (!BN_is_odd(a) && !BN_is_odd(c))) { - printf("GF(2^m) addition test (a) failed!\n"); + if (!TEST_false((BN_is_odd(a) && BN_is_odd(c)) + || (!BN_is_odd(a) && !BN_is_odd(c)))) goto err; - } BN_GF2m_add(c, c, c); /* Test that c + c = 0. */ - if (!BN_is_zero(c)) { - printf("GF(2^m) addition test (b) failed!\n"); + if (!TEST_true(BN_is_zero(c))) goto err; - } } st = 1; err: @@ -513,17 +496,16 @@ static int test_gf2m_add() static int test_gf2m_mod() { - static int p0[] = { 163, 7, 6, 3, 0, -1 }; - static int p1[] = { 193, 15, 0, -1 }; - BIGNUM *a, *b[2], *c, *d, *e; + BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL, *e = NULL; int i, j, st = 0; - a = BN_new(); - b[0] = BN_new(); - b[1] = BN_new(); - c = BN_new(); - d = BN_new(); - e = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b[0] = BN_new()) + || !TEST_ptr(b[1] = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new())) + goto err; BN_GF2m_arr2poly(p0, b[0]); BN_GF2m_arr2poly(p1, b[1]); @@ -535,10 +517,8 @@ static int test_gf2m_mod() BN_GF2m_add(d, a, c); BN_GF2m_mod(e, d, b[j]); /* Test that a + (a mod p) mod p == 0. */ - if (!BN_is_zero(e)) { - printf("GF(2^m) modulo test failed!\n"); + if (!TEST_true(BN_is_zero(e))) goto err; - } } } st = 1; @@ -554,20 +534,20 @@ static int test_gf2m_mod() static int test_gf2m_mul() { - BIGNUM *a, *b[2], *c, *d, *e, *f, *g, *h; + BIGNUM *a, *b[2] = {NULL, NULL}, *c = NULL, *d = NULL; + BIGNUM *e = NULL, *f = NULL, *g = NULL, *h = NULL; int i, j, st = 0; - int p0[] = { 163, 7, 6, 3, 0, -1 }; - int p1[] = { 193, 15, 0, -1 }; - - a = BN_new(); - b[0] = BN_new(); - b[1] = BN_new(); - c = BN_new(); - d = BN_new(); - e = BN_new(); - f = BN_new(); - g = BN_new(); - h = BN_new(); + + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b[0] = BN_new()) + || !TEST_ptr(b[1] = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new()) + || !TEST_ptr(f = BN_new()) + || !TEST_ptr(g = BN_new()) + || !TEST_ptr(h = BN_new())) + goto err; BN_GF2m_arr2poly(p0, b[0]); BN_GF2m_arr2poly(p1, b[1]); @@ -584,13 +564,12 @@ static int test_gf2m_mul() BN_GF2m_add(f, e, g); BN_GF2m_add(f, f, h); /* Test that (a+d)*c = a*c + d*c. */ - if (!BN_is_zero(f)) { - printf("GF(2^m) modular multiplication test failed!\n"); + if (!TEST_true(BN_is_zero(f))) goto err; - } } } st = 1; + err: BN_free(a); BN_free(b[0]); @@ -606,16 +585,15 @@ static int test_gf2m_mul() static int test_gf2m_sqr() { - BIGNUM *a, *b[2], *c, *d; + BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL; int i, j, st = 0; - int p0[] = { 163, 7, 6, 3, 0, -1 }; - int p1[] = { 193, 15, 0, -1 }; - a = BN_new(); - b[0] = BN_new(); - b[1] = BN_new(); - c = BN_new(); - d = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b[0] = BN_new()) + || !TEST_ptr(b[1] = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new())) + goto err; BN_GF2m_arr2poly(p0, b[0]); BN_GF2m_arr2poly(p1, b[1]); @@ -628,10 +606,8 @@ static int test_gf2m_sqr() BN_GF2m_mod_mul(d, a, d, b[j], ctx); BN_GF2m_add(d, c, d); /* Test that a*a = a^2. */ - if (!BN_is_zero(d)) { - printf("GF(2^m) modular squaring test failed!\n"); + if (!TEST_true(BN_is_zero(d))) goto err; - } } } st = 1; @@ -646,16 +622,15 @@ static int test_gf2m_sqr() static int test_gf2m_modinv() { - BIGNUM *a, *b[2], *c, *d; + BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL; int i, j, st = 0; - int p0[] = { 163, 7, 6, 3, 0, -1 }; - int p1[] = { 193, 15, 0, -1 }; - a = BN_new(); - b[0] = BN_new(); - b[1] = BN_new(); - c = BN_new(); - d = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b[0] = BN_new()) + || !TEST_ptr(b[1] = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new())) + goto err; BN_GF2m_arr2poly(p0, b[0]); BN_GF2m_arr2poly(p1, b[1]); @@ -666,10 +641,8 @@ static int test_gf2m_modinv() BN_GF2m_mod_inv(c, a, b[j], ctx); BN_GF2m_mod_mul(d, a, c, b[j], ctx); /* Test that ((1/a)*a) = 1. */ - if (!BN_is_one(d)) { - printf("GF(2^m) modular inversion test failed!\n"); + if (!TEST_true(BN_is_one(d))) goto err; - } } } st = 1; @@ -684,18 +657,18 @@ static int test_gf2m_modinv() static int test_gf2m_moddiv() { - BIGNUM *a, *b[2], *c, *d, *e, *f; + BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL; + BIGNUM *e = NULL, *f = NULL; int i, j, st = 0; - int p0[] = { 163, 7, 6, 3, 0, -1 }; - int p1[] = { 193, 15, 0, -1 }; - a = BN_new(); - b[0] = BN_new(); - b[1] = BN_new(); - c = BN_new(); - d = BN_new(); - e = BN_new(); - f = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b[0] = BN_new()) + || !TEST_ptr(b[1] = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new()) + || !TEST_ptr(f = BN_new())) + goto err; BN_GF2m_arr2poly(p0, b[0]); BN_GF2m_arr2poly(p1, b[1]); @@ -708,10 +681,8 @@ static int test_gf2m_moddiv() BN_GF2m_mod_mul(e, d, c, b[j], ctx); BN_GF2m_mod_div(f, a, e, b[j], ctx); /* Test that ((a/c)*c)/a = 1. */ - if (!BN_is_one(f)) { - printf("GF(2^m) modular division test failed!\n"); + if (!TEST_true(BN_is_one(f))) goto err; - } } } st = 1; @@ -728,18 +699,18 @@ static int test_gf2m_moddiv() static int test_gf2m_modexp() { - BIGNUM *a, *b[2], *c, *d, *e, *f; + BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL; + BIGNUM *e = NULL, *f = NULL; int i, j, st = 0; - int p0[] = { 163, 7, 6, 3, 0, -1 }; - int p1[] = { 193, 15, 0, -1 }; - a = BN_new(); - b[0] = BN_new(); - b[1] = BN_new(); - c = BN_new(); - d = BN_new(); - e = BN_new(); - f = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b[0] = BN_new()) + || !TEST_ptr(b[1] = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new()) + || !TEST_ptr(f = BN_new())) + goto err; BN_GF2m_arr2poly(p0, b[0]); BN_GF2m_arr2poly(p1, b[1]); @@ -756,10 +727,8 @@ static int test_gf2m_modexp() BN_GF2m_mod_exp(f, a, f, b[j], ctx); BN_GF2m_add(f, e, f); /* Test that a^(c+d)=a^c*a^d. */ - if (!BN_is_zero(f)) { - printf("GF(2^m) modular exponentiation test failed!\n"); + if (!TEST_true(BN_is_zero(f))) goto err; - } } } st = 1; @@ -776,18 +745,18 @@ static int test_gf2m_modexp() static int test_gf2m_modsqrt() { - BIGNUM *a, *b[2], *c, *d, *e, *f; + BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL; + BIGNUM *e = NULL, *f = NULL; int i, j, st = 0; - int p0[] = { 163, 7, 6, 3, 0, -1 }; - int p1[] = { 193, 15, 0, -1 }; - a = BN_new(); - b[0] = BN_new(); - b[1] = BN_new(); - c = BN_new(); - d = BN_new(); - e = BN_new(); - f = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b[0] = BN_new()) + || !TEST_ptr(b[1] = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new()) + || !TEST_ptr(f = BN_new())) + goto err; BN_GF2m_arr2poly(p0, b[0]); BN_GF2m_arr2poly(p1, b[1]); @@ -800,10 +769,8 @@ static int test_gf2m_modsqrt() BN_GF2m_mod_sqr(e, d, b[j], ctx); BN_GF2m_add(f, c, e); /* Test that d^2 = a, where d = sqrt(a). */ - if (!BN_is_zero(f)) { - printf("GF(2^m) modular square root test failed!\n"); + if (!TEST_true(BN_is_zero(f))) goto err; - } } } st = 1; @@ -820,17 +787,17 @@ static int test_gf2m_modsqrt() static int test_gf2m_modsolvequad() { - BIGNUM *a, *b[2], *c, *d, *e; + BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL; + BIGNUM *e = NULL; int i, j, s = 0, t, st = 0; - int p0[] = { 163, 7, 6, 3, 0, -1 }; - int p1[] = { 193, 15, 0, -1 }; - a = BN_new(); - b[0] = BN_new(); - b[1] = BN_new(); - c = BN_new(); - d = BN_new(); - e = BN_new(); + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b[0] = BN_new()) + || !TEST_ptr(b[1] = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new()) + || !TEST_ptr(e = BN_new())) + goto err; BN_GF2m_arr2poly(p0, b[0]); BN_GF2m_arr2poly(p1, b[1]); @@ -848,18 +815,13 @@ static int test_gf2m_modsolvequad() /* * Test that solution of quadratic c satisfies c^2 + c = a. */ - if (!BN_is_zero(e)) { - printf("GF(2^m) modular solve quadratic test failed!\n"); + if (!TEST_true(BN_is_zero(e))) goto err; - } - } } } - if (s == 0) { - printf("All %i tests of GF(2^m) modular solve quadratic resulted in no roots;\n", - NUM0); - printf("this is very unlikely and probably indicates an error.\n"); + if (!TEST_int_ge(s, 0)) { + TEST_info("%d tests found no roots; probably an error", NUM0); goto err; } st = 1; @@ -876,16 +838,13 @@ static int test_gf2m_modsolvequad() static int test_kronecker() { - BIGNUM *a, *b, *r, *t; - int i; - int legendre, kronecker; - int st = 0; + BIGNUM *a = NULL, *b = NULL, *r = NULL, *t = NULL; + int i, legendre, kronecker, st = 0; - a = BN_new(); - b = BN_new(); - r = BN_new(); - t = BN_new(); - if (a == NULL || b == NULL || r == NULL || t == NULL) + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b = BN_new()) + || !TEST_ptr(r = BN_new()) + || !TEST_ptr(t = BN_new())) goto err; /* @@ -898,27 +857,27 @@ static int test_kronecker() * is prime but whether BN_kronecker works.) */ - if (!BN_generate_prime_ex(b, 512, 0, NULL, NULL, NULL)) + if (!TEST_true(BN_generate_prime_ex(b, 512, 0, NULL, NULL, NULL))) goto err; b->neg = rand_neg(); for (i = 0; i < NUM0; i++) { - if (!BN_bntest_rand(a, 512, 0, 0)) + if (!TEST_true(BN_bntest_rand(a, 512, 0, 0))) goto err; a->neg = rand_neg(); /* t := (|b|-1)/2 (note that b is odd) */ - if (!BN_copy(t, b)) + if (!TEST_true(BN_copy(t, b))) goto err; t->neg = 0; - if (!BN_sub_word(t, 1)) + if (!TEST_true(BN_sub_word(t, 1))) goto err; - if (!BN_rshift1(t, t)) + if (!TEST_true(BN_rshift1(t, t))) goto err; /* r := a^t mod b */ b->neg = 0; - if (!BN_mod_exp_recp(r, a, t, b, ctx)) + if (!TEST_true(BN_mod_exp_recp(r, a, t, b, ctx))) goto err; b->neg = 1; @@ -927,30 +886,23 @@ static int test_kronecker() else if (BN_is_zero(r)) legendre = 0; else { - if (!BN_add_word(r, 1)) + if (!TEST_true(BN_add_word(r, 1))) goto err; - if (0 != BN_ucmp(r, b)) { - printf("Legendre symbol computation failed\n"); + if (!TEST_int_eq(BN_ucmp(r, b), 0)) { + TEST_info("Legendre symbol computation failed"); goto err; } legendre = -1; } - kronecker = BN_kronecker(a, b, ctx); - if (kronecker < -1) + if (!TEST_int_ge(kronecker = BN_kronecker(a, b, ctx), -1)) goto err; /* we actually need BN_kronecker(a, |b|) */ if (a->neg && b->neg) kronecker = -kronecker; - if (legendre != kronecker) { - printf("legendre != kronecker; a = "); - BN_print_fp(stdout, a); - printf(", b = "); - BN_print_fp(stdout, b); - printf("\n"); + if (!TEST_int_eq(legendre, kronecker)) goto err; - } } st = 1; @@ -964,21 +916,21 @@ static int test_kronecker() static int file_sum(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *b = getBN(s, "B"); - BIGNUM *sum = getBN(s, "Sum"); - BIGNUM *ret = BN_new(); + BIGNUM *a = NULL, *b = NULL, *sum = NULL, *ret = NULL; BN_ULONG b_word; int st = 0; - if (a == NULL || b == NULL || sum == NULL || ret == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(b = getBN(s, "B")) + || !TEST_ptr(sum = getBN(s, "Sum")) + || !TEST_ptr(ret = BN_new())) goto err; - if (!BN_add(ret, a, b) + if (!TEST_true(BN_add(ret, a, b)) || !equalBN("A + B", sum, ret) - || !BN_sub(ret, sum, a) + || !TEST_true(BN_sub(ret, sum, a)) || !equalBN("Sum - A", b, ret) - || !BN_sub(ret, sum, b) + || !TEST_true(BN_sub(ret, sum, b)) || !equalBN("Sum - B", a, ret)) goto err; @@ -987,23 +939,23 @@ static int file_sum(STANZA *s) * or when |r| and |b| point to the same BIGNUM. * TODO: Test where all of |r|, |a|, and |b| point to the same BIGNUM. */ - if (!BN_copy(ret, a) - || !BN_add(ret, ret, b) + if (!TEST_true(BN_copy(ret, a)) + || !TEST_true(BN_add(ret, ret, b)) || !equalBN("A + B (r is a)", sum, ret) - || !BN_copy(ret, b) - || !BN_add(ret, a, ret) + || !TEST_true(BN_copy(ret, b)) + || !TEST_true(BN_add(ret, a, ret)) || !equalBN("A + B (r is b)", sum, ret) - || !BN_copy(ret, sum) - || !BN_sub(ret, ret, a) + || !TEST_true(BN_copy(ret, sum)) + || !TEST_true(BN_sub(ret, ret, a)) || !equalBN("Sum - A (r is a)", b, ret) - || !BN_copy(ret, a) - || !BN_sub(ret, sum, ret) + || !TEST_true(BN_copy(ret, a)) + || !TEST_true(BN_sub(ret, sum, ret)) || !equalBN("Sum - A (r is b)", b, ret) - || !BN_copy(ret, sum) - || !BN_sub(ret, ret, b) + || !TEST_true(BN_copy(ret, sum)) + || !TEST_true(BN_sub(ret, ret, b)) || !equalBN("Sum - B (r is a)", a, ret) - || !BN_copy(ret, b) - || !BN_sub(ret, sum, ret) + || !TEST_true(BN_copy(ret, b)) + || !TEST_true(BN_sub(ret, sum, ret)) || !equalBN("Sum - B (r is b)", a, ret)) goto err; @@ -1015,11 +967,11 @@ static int file_sum(STANZA *s) * TODO: test that. */ if (!BN_is_negative(a) && !BN_is_negative(b) && BN_cmp(a, b) >= 0) { - if (!BN_uadd(ret, a, b) + if (!TEST_true(BN_uadd(ret, a, b)) || !equalBN("A +u B", sum, ret) - || !BN_usub(ret, sum, a) + || !TEST_true(BN_usub(ret, sum, a)) || !equalBN("Sum -u A", b, ret) - || !BN_usub(ret, sum, b) + || !TEST_true(BN_usub(ret, sum, b)) || !equalBN("Sum -u B", a, ret)) goto err; /* @@ -1027,23 +979,23 @@ static int file_sum(STANZA *s) * BIGNUM, or when |r| and |b| point to the same BIGNUM. * TODO: Test where all of |r|, |a|, and |b| point to the same BIGNUM. */ - if (!BN_copy(ret, a) - || !BN_uadd(ret, ret, b) + if (!TEST_true(BN_copy(ret, a)) + || !TEST_true(BN_uadd(ret, ret, b)) || !equalBN("A +u B (r is a)", sum, ret) - || !BN_copy(ret, b) - || !BN_uadd(ret, a, ret) + || !TEST_true(BN_copy(ret, b)) + || !TEST_true(BN_uadd(ret, a, ret)) || !equalBN("A +u B (r is b)", sum, ret) - || !BN_copy(ret, sum) - || !BN_usub(ret, ret, a) + || !TEST_true(BN_copy(ret, sum)) + || !TEST_true(BN_usub(ret, ret, a)) || !equalBN("Sum -u A (r is a)", b, ret) - || !BN_copy(ret, a) - || !BN_usub(ret, sum, ret) + || !TEST_true(BN_copy(ret, a)) + || !TEST_true(BN_usub(ret, sum, ret)) || !equalBN("Sum -u A (r is b)", b, ret) - || !BN_copy(ret, sum) - || !BN_usub(ret, ret, b) + || !TEST_true(BN_copy(ret, sum)) + || !TEST_true(BN_usub(ret, ret, b)) || !equalBN("Sum -u B (r is a)", a, ret) - || !BN_copy(ret, b) - || !BN_usub(ret, sum, ret) + || !TEST_true(BN_copy(ret, b)) + || !TEST_true(BN_usub(ret, sum, ret)) || !equalBN("Sum -u B (r is b)", a, ret)) goto err; } @@ -1053,11 +1005,11 @@ static int file_sum(STANZA *s) */ b_word = BN_get_word(b); if (!BN_is_negative(b) && b_word != (BN_ULONG)-1) { - if (!BN_copy(ret, a) - || !BN_add_word(ret, b_word) + if (!TEST_true(BN_copy(ret, a)) + || !TEST_true(BN_add_word(ret, b_word)) || !equalBN("A + B (word)", sum, ret) - || !BN_copy(ret, sum) - || !BN_sub_word(ret, b_word) + || !TEST_true(BN_copy(ret, sum)) + || !TEST_true(BN_sub_word(ret, b_word)) || !equalBN("Sum - B (word)", a, ret)) goto err; } @@ -1073,41 +1025,41 @@ err: static int file_lshift1(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *lshift1 = getBN(s, "LShift1"); - BIGNUM *zero = BN_new(); - BIGNUM *ret = BN_new(); - BIGNUM *two = BN_new(); - BIGNUM *remainder = BN_new(); + BIGNUM *a = NULL, *lshift1 = NULL, *zero = NULL, *ret = NULL; + BIGNUM *two = NULL, *remainder = NULL; int st = 0; - if (a == NULL || lshift1 == NULL || zero == NULL - || ret == NULL || two == NULL || remainder == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(lshift1 = getBN(s, "LShift1")) + || !TEST_ptr(zero = BN_new()) + || !TEST_ptr(ret = BN_new()) + || !TEST_ptr(two = BN_new()) + || !TEST_ptr(remainder = BN_new())) goto err; BN_zero(zero); - if (!BN_set_word(two, 2) - || !BN_add(ret, a, a) + if (!TEST_true(BN_set_word(two, 2)) + || !TEST_true(BN_add(ret, a, a)) || !equalBN("A + A", lshift1, ret) - || !BN_mul(ret, a, two, ctx) + || !TEST_true(BN_mul(ret, a, two, ctx)) || !equalBN("A * 2", lshift1, ret) - || !BN_div(ret, remainder, lshift1, two, ctx) + || !TEST_true(BN_div(ret, remainder, lshift1, two, ctx)) || !equalBN("LShift1 / 2", a, ret) || !equalBN("LShift1 % 2", zero, remainder) - || !BN_lshift1(ret, a) + || !TEST_true(BN_lshift1(ret, a)) || !equalBN("A << 1", lshift1, ret) - || !BN_rshift1(ret, lshift1) + || !TEST_true(BN_rshift1(ret, lshift1)) || !equalBN("LShift >> 1", a, ret) - || !BN_rshift1(ret, lshift1) + || !TEST_true(BN_rshift1(ret, lshift1)) || !equalBN("LShift >> 1", a, ret)) goto err; /* Set the LSB to 1 and test rshift1 again. */ - if (!BN_set_bit(lshift1, 0) - || !BN_div(ret, NULL /* rem */ , lshift1, two, ctx) + if (!TEST_true(BN_set_bit(lshift1, 0)) + || !TEST_true(BN_div(ret, NULL /* rem */ , lshift1, two, ctx)) || !equalBN("(LShift1 | 1) / 2", a, ret) - || !BN_rshift1(ret, lshift1) + || !TEST_true(BN_rshift1(ret, lshift1)) || !equalBN("(LShift | 1) >> 1", a, ret)) goto err; @@ -1125,18 +1077,16 @@ err: static int file_lshift(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *lshift = getBN(s, "LShift"); - BIGNUM *ret = BN_new(); - int n = 0; - int st = 0; + BIGNUM *a = NULL, *lshift = NULL, *ret = NULL; + int n = 0, st = 0; - if (a == NULL || lshift == NULL || ret == NULL || !getint(s, &n, "N")) - goto err; + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(lshift = getBN(s, "LShift")) + || !TEST_ptr(ret = BN_new())) - if (!BN_lshift(ret, a, n) + if (!TEST_true(BN_lshift(ret, a, n)) || !equalBN("A << N", lshift, ret) - || !BN_rshift(ret, lshift, n) + || !TEST_true(BN_rshift(ret, lshift, n)) || !equalBN("A >> N", a, ret)) goto err; @@ -1150,85 +1100,78 @@ err: static int file_rshift(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *rshift = getBN(s, "RShift"); - BIGNUM *ret = BN_new(); - int n = 0; - int errcnt = 1; + BIGNUM *a = NULL, *rshift = NULL, *ret = NULL; + int n = 0, st = 0; - if (a == NULL || rshift == NULL || ret == NULL || !getint(s, &n, "N")) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(rshift = getBN(s, "RShift")) + || !TEST_ptr(ret = BN_new()) + || !getint(s, &n, "N")) goto err; - errcnt = 0; - if (!BN_rshift(ret, a, n) + if (!TEST_true(BN_rshift(ret, a, n)) || !equalBN("A >> N", rshift, ret)) - errcnt++; + goto err; /* If N == 1, try with rshift1 as well */ if (n == 1) { - if (!BN_rshift1(ret, a) + if (!TEST_true(BN_rshift1(ret, a)) || !equalBN("A >> 1 (rshift1)", rshift, ret)) - errcnt++; + goto err; } + st = 1; err: BN_free(a); BN_free(rshift); BN_free(ret); - return errcnt == 0; + return st; } static int file_square(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *square = getBN(s, "Square"); - BIGNUM *zero = BN_new(); - BIGNUM *ret = BN_new(); - BIGNUM *remainder = BN_new(); - BIGNUM *tmp = NULL; + BIGNUM *a = NULL, *square = NULL, *zero = NULL, *ret = NULL; + BIGNUM *remainder = NULL, *tmp = NULL; int st = 0; - if (a == NULL || square == NULL || zero == NULL || ret == NULL - || remainder == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(square = getBN(s, "Square")) + || !TEST_ptr(zero = BN_new()) + || !TEST_ptr(ret = BN_new()) + || !TEST_ptr(remainder = BN_new())) goto err; BN_zero(zero); - - if (!BN_sqr(ret, a, ctx) + if (!TEST_true(BN_sqr(ret, a, ctx)) || !equalBN("A^2", square, ret) - || !BN_mul(ret, a, a, ctx) + || !TEST_true(BN_mul(ret, a, a, ctx)) || !equalBN("A * A", square, ret) - || !BN_div(ret, remainder, square, a, ctx) + || !TEST_true(BN_div(ret, remainder, square, a, ctx)) || !equalBN("Square / A", a, ret) || !equalBN("Square % A", zero, remainder)) goto err; #if HAVE_BN_SQRT BN_set_negative(a, 0); - if (!BN_sqrt(ret, square, ctx) + if (!TEST_true(BN_sqrt(ret, square, ctx)) || !equalBN("sqrt(Square)", a, ret)) goto err; /* BN_sqrt should fail on non-squares and negative numbers. */ - if (!BN_is_zero(square)) { - tmp = BN_new(); - if (tmp == NULL || !BN_copy(tmp, square)) + if (!TEST_true(BN_is_zero(square))) { + if (!TEST_ptr(tmp = BN_new()) || !TEST_true(BN_copy(tmp, square))) goto err; BN_set_negative(tmp, 1); - if (BN_sqrt(ret, tmp, ctx)) { - fprintf(stderr, "BN_sqrt succeeded on a negative number"); + if (!TEST_int_eq(BN_sqrt(ret, tmp, ctx), 0)) goto err; - } ERR_clear_error(); BN_set_negative(tmp, 0); if (BN_add(tmp, tmp, BN_value_one())) goto err; - if (BN_sqrt(ret, tmp, ctx)) { - fprintf(stderr, "BN_sqrt succeeded on a non-square"); + if (!TEST_int_eq(BN_sqrt(ret, tmp, ctx))) goto err; - } ERR_clear_error(); } #endif @@ -1246,26 +1189,26 @@ err: static int file_product(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *b = getBN(s, "B"); - BIGNUM *product = getBN(s, "Product"); - BIGNUM *ret = BN_new(); - BIGNUM *remainder = BN_new(); - BIGNUM *zero = BN_new(); + BIGNUM *a = NULL, *b = NULL, *product = NULL, *ret = NULL; + BIGNUM *remainder = NULL, *zero = NULL; int st = 0; - if (a == NULL || b == NULL || product == NULL || ret == NULL - || remainder == NULL || zero == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(b = getBN(s, "B")) + || !TEST_ptr(product = getBN(s, "Product")) + || !TEST_ptr(ret = BN_new()) + || !TEST_ptr(remainder = BN_new()) + || !TEST_ptr(zero = BN_new())) goto err; BN_zero(zero); - if (!BN_mul(ret, a, b, ctx) + if (!TEST_true(BN_mul(ret, a, b, ctx)) || !equalBN("A * B", product, ret) - || !BN_div(ret, remainder, product, a, ctx) + || !TEST_true(BN_div(ret, remainder, product, a, ctx)) || !equalBN("Product / A", b, ret) || !equalBN("Product % A", zero, remainder) - || !BN_div(ret, remainder, product, b, ctx) + || !TEST_true(BN_div(ret, remainder, product, b, ctx)) || !equalBN("Product / B", a, ret) || !equalBN("Product % B", zero, remainder)) goto err; @@ -1283,25 +1226,25 @@ err: static int file_quotient(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *b = getBN(s, "B"); - BIGNUM *quotient = getBN(s, "Quotient"); - BIGNUM *remainder = getBN(s, "Remainder"); - BIGNUM *ret = BN_new(); - BIGNUM *ret2 = BN_new(); - BIGNUM *nnmod = BN_new(); + BIGNUM *a = NULL, *b = NULL, *quotient = NULL, *remainder = NULL; + BIGNUM *ret = NULL, *ret2 = NULL, *nnmod = NULL; BN_ULONG b_word, ret_word; int st = 0; - if (a == NULL || b == NULL || quotient == NULL || remainder == NULL - || ret == NULL || ret2 == NULL || nnmod == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(b = getBN(s, "B")) + || !TEST_ptr(quotient = getBN(s, "Quotient")) + || !TEST_ptr(remainder = getBN(s, "Remainder")) + || !TEST_ptr(ret = BN_new()) + || !TEST_ptr(ret2 = BN_new()) + || !TEST_ptr(nnmod = BN_new())) goto err; - if (!BN_div(ret, ret2, a, b, ctx) + if (!TEST_true(BN_div(ret, ret2, a, b, ctx)) || !equalBN("A / B", quotient, ret) || !equalBN("A % B", remainder, ret2) - || !BN_mul(ret, quotient, b, ctx) - || !BN_add(ret, ret, remainder) + || !TEST_true(BN_mul(ret, quotient, b, ctx)) + || !TEST_true(BN_add(ret, ret, remainder)) || !equalBN("Quotient * B + Remainder", a, ret)) goto err; @@ -1314,16 +1257,16 @@ static int file_quotient(STANZA *s) BN_ULONG remainder_word = BN_get_word(remainder); assert(remainder_word != (BN_ULONG)-1); - if (!BN_copy(ret, a)) + if (!TEST_ptr(BN_copy(ret, a))) goto err; ret_word = BN_div_word(ret, b_word); if (ret_word != remainder_word) { #ifdef BN_DEC_FMT1 - fprintf(stderr, - "Got A %% B (word) = " BN_DEC_FMT1 ", wanted " BN_DEC_FMT1 "\n", + TEST_error( + "Got A %% B (word) = " BN_DEC_FMT1 ", wanted " BN_DEC_FMT1, ret_word, remainder_word); #else - fprintf(stderr, "Got A %% B (word) mismatch\n"); + TEST_error("Got A %% B (word) mismatch"); #endif goto err; } @@ -1333,11 +1276,11 @@ static int file_quotient(STANZA *s) ret_word = BN_mod_word(a, b_word); if (ret_word != remainder_word) { #ifdef BN_DEC_FMT1 - fprintf(stderr, - "Got A %% B (word) = " BN_DEC_FMT1 ", wanted " BN_DEC_FMT1 "\n", + TEST_error( + "Got A %% B (word) = " BN_DEC_FMT1 ", wanted " BN_DEC_FMT1 "", ret_word, remainder_word); #else - fprintf(stderr, "Got A %% B (word) mismatch\n"); + TEST_error("Got A %% B (word) mismatch"); #endif goto err; } @@ -1345,9 +1288,10 @@ static int file_quotient(STANZA *s) /* Test BN_nnmod. */ if (!BN_is_negative(b)) { - if (!BN_copy(nnmod, remainder) - || (BN_is_negative(nnmod) && !BN_add(nnmod, nnmod, b)) - || !BN_nnmod(ret, a, b, ctx) + if (!TEST_true(BN_copy(nnmod, remainder)) + || (BN_is_negative(nnmod) + && !TEST_true(BN_add(nnmod, nnmod, b))) + || !TEST_true(BN_nnmod(ret, a, b, ctx)) || !equalBN("A % B (non-negative)", nnmod, ret)) goto err; } @@ -1366,17 +1310,17 @@ err: static int file_modmul(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *b = getBN(s, "B"); - BIGNUM *m = getBN(s, "M"); - BIGNUM *mod_mul = getBN(s, "ModMul"); - BIGNUM *ret = BN_new(); + BIGNUM *a = NULL, *b = NULL, *m = NULL, *mod_mul = NULL, *ret = NULL; int st = 0; - if (a == NULL || b == NULL || m == NULL || mod_mul == NULL || ret == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(b = getBN(s, "B")) + || !TEST_ptr(m = getBN(s, "M")) + || !TEST_ptr(mod_mul = getBN(s, "ModMul")) + || !TEST_ptr(ret = BN_new())) goto err; - if (!BN_mod_mul(ret, a, b, m, ctx) + if (!TEST_true(BN_mod_mul(ret, a, b, m, ctx)) || !equalBN("A * B (mod M)", mod_mul, ret)) goto err; @@ -1385,19 +1329,20 @@ static int file_modmul(STANZA *s) BN_MONT_CTX *mont = BN_MONT_CTX_new(); BIGNUM *a_tmp = BN_new(); BIGNUM *b_tmp = BN_new(); + if (mont == NULL || a_tmp == NULL || b_tmp == NULL - || !BN_MONT_CTX_set(mont, m, ctx) - || !BN_nnmod(a_tmp, a, m, ctx) - || !BN_nnmod(b_tmp, b, m, ctx) - || !BN_to_montgomery(a_tmp, a_tmp, mont, ctx) - || !BN_to_montgomery(b_tmp, b_tmp, mont, ctx) - || !BN_mod_mul_montgomery(ret, a_tmp, b_tmp, mont, ctx) - || !BN_from_montgomery(ret, ret, mont, ctx) - || !equalBN("A * B (mod M) (mont)", mod_mul, ret)) { + || !TEST_true(BN_MONT_CTX_set(mont, m, ctx)) + || !TEST_true(BN_nnmod(a_tmp, a, m, ctx)) + || !TEST_true(BN_nnmod(b_tmp, b, m, ctx)) + || !TEST_true(BN_to_montgomery(a_tmp, a_tmp, mont, ctx)) + || !TEST_true(BN_to_montgomery(b_tmp, b_tmp, mont, ctx)) + || !TEST_true(BN_mod_mul_montgomery(ret, a_tmp, b_tmp, + mont, ctx)) + || !TEST_true(BN_from_montgomery(ret, ret, mont, ctx)) + || !equalBN("A * B (mod M) (mont)", mod_mul, ret)) st = 0; - } else { + else st = 1; - } BN_MONT_CTX_free(mont); BN_free(a_tmp); BN_free(b_tmp); @@ -1417,25 +1362,27 @@ err: static int file_modexp(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *e = getBN(s, "E"); - BIGNUM *m = getBN(s, "M"); - BIGNUM *mod_exp = getBN(s, "ModExp"); - BIGNUM *ret = BN_new(); - BIGNUM *b = NULL, *c = NULL, *d = BN_new(); + BIGNUM *a = NULL, *e = NULL, *m = NULL, *mod_exp = NULL, *ret = NULL; + BIGNUM *b = NULL, *c = NULL, *d = NULL; int st = 0; - if (a == NULL || e == NULL || m == NULL || mod_exp == NULL || ret == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(e = getBN(s, "E")) + || !TEST_ptr(m = getBN(s, "M")) + || !TEST_ptr(mod_exp = getBN(s, "ModExp")) + || !TEST_ptr(ret = BN_new()) + || !TEST_ptr(d = BN_new())) goto err; - if (!BN_mod_exp(ret, a, e, m, ctx) + if (!TEST_true(BN_mod_exp(ret, a, e, m, ctx)) || !equalBN("A ^ E (mod M)", mod_exp, ret)) goto err; if (BN_is_odd(m)) { - if (!BN_mod_exp_mont(ret, a, e, m, ctx, NULL) + if (!TEST_true(BN_mod_exp_mont(ret, a, e, m, ctx, NULL)) || !equalBN("A ^ E (mod M) (mont)", mod_exp, ret) - || !BN_mod_exp_mont_consttime(ret, a, e, m, ctx, NULL) + || !TEST_true(BN_mod_exp_mont_consttime(ret, a, e, m, + ctx, NULL)) || !equalBN("A ^ E (mod M) (mont const", mod_exp, ret)) goto err; } @@ -1452,10 +1399,8 @@ static int file_modexp(STANZA *s) "0000000000000000000000000000000000000000000000000000000001"); BN_mod_exp(d, a, b, c, ctx); BN_mul(e, a, a, ctx); - if (BN_cmp(d, e)) { - fprintf(stderr, "BN_mod_exp and BN_mul produce different results!\n"); + if (!TEST_int_eq(BN_cmp(d, e), 0)) goto err; - } st = 1; err: @@ -1472,16 +1417,16 @@ err: static int file_exp(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *e = getBN(s, "E"); - BIGNUM *exp = getBN(s, "Exp"); - BIGNUM *ret = BN_new(); + BIGNUM *a = NULL, *e = NULL, *exp = NULL, *ret = NULL; int st = 0; - if (a == NULL || e == NULL || exp == NULL || ret == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(e = getBN(s, "E")) + || !TEST_ptr(exp = getBN(s, "Exp")) + || !TEST_ptr(ret = BN_new())) goto err; - if (!BN_exp(ret, a, e, ctx) + if (!TEST_true(BN_exp(ret, a, e, ctx)) || !equalBN("A ^ E", exp, ret)) goto err; @@ -1496,21 +1441,22 @@ err: static int file_modsqrt(STANZA *s) { - BIGNUM *a = getBN(s, "A"); - BIGNUM *p = getBN(s, "P"); - BIGNUM *mod_sqrt = getBN(s, "ModSqrt"); - BIGNUM *ret = BN_new(); - BIGNUM *ret2 = BN_new(); + BIGNUM *a = NULL, *p = NULL, *mod_sqrt = NULL, *ret = NULL, *ret2 = NULL; int st = 0; - if (a == NULL || p == NULL || mod_sqrt == NULL - || ret == NULL || ret2 == NULL) + if (!TEST_ptr(a = getBN(s, "A")) + || !TEST_ptr(p = getBN(s, "P")) + || !TEST_ptr(mod_sqrt = getBN(s, "ModSqrt")) + || !TEST_ptr(ret = BN_new()) + || !TEST_ptr(ret2 = BN_new())) goto err; /* There are two possible answers. */ - if (!BN_mod_sqrt(ret, a, p, ctx) || !BN_sub(ret2, p, ret)) + if (!TEST_true(BN_mod_sqrt(ret, a, p, ctx)) + || !TEST_true(BN_sub(ret2, p, ret))) goto err; + /* The first condition should NOT be a test. */ if (BN_cmp(ret2, mod_sqrt) != 0 && !equalBN("sqrt(A) (mod P)", mod_sqrt, ret)) goto err; @@ -1535,71 +1481,46 @@ static int test_bn2padded() /* Test edge case at 0. */ if (n == NULL) goto err; - if (!BN_bn2bin_padded(NULL, 0, n)) { - fprintf(stderr, - "BN_bn2bin_padded failed to encode 0 in an empty buffer.\n"); + if (!TEST_true(BN_bn2bin_padded(NULL, 0, n))) goto err; - } memset(out, -1, sizeof(out)); - if (!BN_bn2bin_padded(out, sizeof(out), n)) { - fprintf(stderr, - "BN_bn2bin_padded failed to encode 0 in a non-empty buffer.\n"); + if (!TEST_true(BN_bn2bin_padded(out, sizeof(out)), n)) goto err; - } memset(zeros, 0, sizeof(zeros)); - if (memcmp(zeros, out, sizeof(out))) { - fprintf(stderr, "BN_bn2bin_padded did not zero buffer.\n"); + if (!TEST_mem_eq(zeros, sizeof(zeros), out, sizeof(out))) goto err; - } /* Test a random numbers at various byte lengths. */ for (size_t bytes = 128 - 7; bytes <= 128; bytes++) { #define TOP_BIT_ON 0 #define BOTTOM_BIT_NOTOUCH 0 - if (!BN_rand(n, bytes * 8, TOP_BIT_ON, BOTTOM_BIT_NOTOUCH)) { - ERR_print_errors_fp(stderr); + if (!TEST_true(BN_rand(n, bytes * 8, TOP_BIT_ON, BOTTOM_BIT_NOTOUCH))) goto err; - } - if (BN_num_bytes(n) != bytes - || BN_bn2bin(n, reference) != bytes) { - fprintf(stderr, "Bad result from BN_rand; bytes.\n"); + if (!TEST_int_eq(BN_num_bytes(n),A) bytes + || TEST_int_eq(BN_bn2bin(n, reference), bytes)) goto err; - } /* Empty buffer should fail. */ - if (BN_bn2bin_padded(NULL, 0, n)) { - fprintf(stderr, - "BN_bn2bin_padded incorrectly succeeded on empty buffer.\n"); + if (!TEST_int_eq(BN_bn2bin_padded(NULL, 0, n)), 0) goto err; - } /* One byte short should fail. */ - if (BN_bn2bin_padded(out, bytes - 1, n)) { - fprintf(stderr, - "BN_bn2bin_padded incorrectly succeeded on short.\n"); + if (BN_bn2bin_padded(out, bytes - 1, n)) goto err; - } /* Exactly right size should encode. */ - if (!BN_bn2bin_padded(out, bytes, n) - || memcmp(out, reference, bytes) != 0) { - fprintf(stderr, - "BN_bn2bin_padded gave a bad result.\n"); + if (!TEST_true(BN_bn2bin_padded(out, bytes, n)) + || TEST_mem_eq(out, bytes, reference, bytes)) goto err; - } /* Pad up one byte extra. */ - if (!BN_bn2bin_padded(out, bytes + 1, n) - || memcmp(out + 1, reference, bytes) - || memcmp(out, zeros, 1)) { - fprintf(stderr, - "BN_bn2bin_padded gave a bad result.\n"); + if (!TEST_true(BN_bn2bin_padded(out, bytes + 1, n)) + || !TEST_mem_eq(out + 1, bytes, reference, bytes) + || !TEST_mem_eq(out, 1, zeros, 1)) goto err; - } /* Pad up to 256. */ - if (!BN_bn2bin_padded(out, sizeof(out), n) - || memcmp(out + sizeof(out) - bytes, reference, bytes) - || memcmp(out, zeros, sizeof(out) - bytes)) { - fprintf(stderr, - "BN_bn2bin_padded gave a bad result.\n"); + if (!TEST_true(BN_bn2bin_padded(out, sizeof(out)), n) + || !TEST_mem_eq(out + sizeof(out) - bytes, bytes, + reference, bytes) + || !TEST_mem_eq(out, sizseof(out) - bytes, + zeros, sizeof(out) - bytes)) goto err; - } } st = 1; @@ -1616,40 +1537,34 @@ static int test_dec2bn() BIGNUM *bn = NULL; int st = 0; - int ret = parsedecBN(&bn, "0"); - if (ret != 1 || !BN_is_zero(bn) || BN_is_negative(bn)) { - fprintf(stderr, "BN_dec2bn(0) gave a bad result.\n"); + if (!TEST_int_eq(parsedecBN(&bn, "0"), 1) + || !TEST_true(BN_is_zero(bn)) + || !TEST_false(BN_is_negative(bn))) goto err; - } BN_free(bn); - ret = parsedecBN(&bn, "256"); - if (ret != 3 || !BN_is_word(bn, 256) || BN_is_negative(bn)) { - fprintf(stderr, "BN_dec2bn(256) gave a bad result.\n"); + if (!TEST_int_eq(parsedecBN(&bn, "256"), 3) + || !TEST_true(BN_is_word(bn, 256)) + || !TEST_false(BN_is_negative(bn))) goto err; - } BN_free(bn); - ret = parsedecBN(&bn, "-42"); - if (ret != 3 || !BN_abs_is_word(bn, 42) || !BN_is_negative(bn)) { - fprintf(stderr, "BN_dec2bn(42) gave a bad result.\n"); + if (!TEST_int_eq(parsedecBN(&bn, "-42"), 3) + || !TEST_true(BN_abs_is_word(bn, 42)) + || !TEST_true(BN_is_negative(bn))) goto err; - } BN_free(bn); - ret = parsedecBN(&bn, "-0"); - if (ret != 2 || !BN_is_zero(bn) || BN_is_negative(bn)) { - fprintf(stderr, "BN_dec2bn(-0) gave a bad result.\n"); + if (!TEST_int_eq(parsedecBN(&bn, "-0"), 2) + || !TEST_true(BN_is_zero(bn)) + || !TEST_false(BN_is_negative(bn))) goto err; - } BN_free(bn); - ret = parsedecBN(&bn, "42trailing garbage is ignored"); - if (ret != 2 || !BN_abs_is_word(bn, 42) - || BN_is_negative(bn)) { - fprintf(stderr, "BN_dec2bn(42trailing...) gave a bad result.\n"); + if (!TEST_int_eq(parsedecBN(&bn, "42trailing garbage is ignored"), 2) + || !TEST_true(BN_abs_is_word(bn, 42)) + || !TEST_false(BN_is_negative(bn))) goto err; - } st = 1; err: @@ -1660,41 +1575,36 @@ err: static int test_hex2bn() { BIGNUM *bn = NULL; - int ret, st = 0; + int st = 0; - ret = parseBN(&bn, "0"); - if (ret != 1 || !BN_is_zero(bn) || BN_is_negative(bn)) { - fprintf(stderr, "BN_hex2bn(0) gave a bad result.\n"); + if (!TEST_int_eq(parseBN(&bn, "0"), 1) + || !TEST_true(BN_is_zero(bn)) + || !TEST_false(BN_is_negative(bn))) goto err; - } BN_free(bn); - ret = parseBN(&bn, "256"); - if (ret != 3 || !BN_is_word(bn, 0x256) || BN_is_negative(bn)) { - fprintf(stderr, "BN_hex2bn(256) gave a bad result.\n"); + if (!TEST_int_eq(parseBN(&bn, "256"), 3) + || !TEST_true(BN_is_word(bn, 0x256)) + || !TEST_false(BN_is_negative(bn))) goto err; - } BN_free(bn); - ret = parseBN(&bn, "-42"); - if (ret != 3 || !BN_abs_is_word(bn, 0x42) || !BN_is_negative(bn)) { - fprintf(stderr, "BN_hex2bn(-42) gave a bad result.\n"); + if (!TEST_int_eq(parseBN(&bn, "-42"), 3) + || !TEST_true(BN_abs_is_word(bn, 0x42)) + || !TEST_true(BN_is_negative(bn))) goto err; - } BN_free(bn); - ret = parseBN(&bn, "-0"); - if (ret != 2 || !BN_is_zero(bn) || BN_is_negative(bn)) { - fprintf(stderr, "BN_hex2bn(-0) gave a bad result.\n"); + if (!TEST_int_eq(parseBN(&bn, "-0"), 2) + || !TEST_true(BN_is_zero(bn)) + || !TEST_false(BN_is_negative(bn))) goto err; - } BN_free(bn); - ret = parseBN(&bn, "abctrailing garbage is ignored"); - if (ret != 3 || !BN_is_word(bn, 0xabc) || BN_is_negative(bn)) { - fprintf(stderr, "BN_hex2bn(abctrail...) gave a bad result.\n"); + if (!TEST_int_eq(parseBN(&bn, "abctrailing garbage is ignored"), 3) + || !TEST_true(BN_is_word(bn, 0xabc)) + || !TEST_false(BN_is_negative(bn))) goto err; - } st = 1; err: @@ -1704,53 +1614,51 @@ err: static int test_asc2bn() { - BIGNUM *bn = BN_new(); + BIGNUM *bn = NULL; int st = 0; - if (!BN_asc2bn(&bn, "0") || !BN_is_zero(bn) || BN_is_negative(bn)) { - fprintf(stderr, "BN_asc2bn(0) gave a bad result.\n"); + if (!TEST_ptr(bn = BN_new())) goto err; - } - if (!BN_asc2bn(&bn, "256") || !BN_is_word(bn, 256) || BN_is_negative(bn)) { - fprintf(stderr, "BN_asc2bn(256) gave a bad result.\n"); + if (!TEST_true(BN_asc2bn(&bn, "0")) + || !TEST_true(BN_is_zero(bn)) + || !TEST_false(BN_is_negative(bn))) goto err; - } - if (!BN_asc2bn(&bn, "-42") - || !BN_abs_is_word(bn, 42) || !BN_is_negative(bn)) { - fprintf(stderr, "BN_asc2bn(-42) gave a bad result.\n"); + if (!TEST_true(BN_asc2bn(&bn, "256")) + || !TEST_true(BN_is_word(bn, 256)) + || !TEST_false(BN_is_negative(bn))) goto err; - } - if (!BN_asc2bn(&bn, "0x1234") - || !BN_is_word(bn, 0x1234) || BN_is_negative(bn)) { - fprintf(stderr, "BN_asc2bn(0x1234) gave a bad result.\n"); + if (!TEST_true(BN_asc2bn(&bn, "-42")) + || !TEST_true(BN_abs_is_word(bn, 42)) + || !TEST_true(BN_is_negative(bn))) goto err; - } - if (!BN_asc2bn(&bn, "0X1234") - || !BN_is_word(bn, 0x1234) || BN_is_negative(bn)) { - fprintf(stderr, "BN_asc2bn(0X1234) gave a bad result.\n"); + if (!TEST_true(BN_asc2bn(&bn, "0x1234")) + || !TEST_true(BN_is_word(bn, 0x1234)) + || !TEST_false(BN_is_negative(bn))) goto err; - } - if (!BN_asc2bn(&bn, "-0xabcd") - || !BN_abs_is_word(bn, 0xabcd) || !BN_is_negative(bn)) { - fprintf(stderr, "BN_asc2bn(-0xabcd) gave a bad result.\n"); + if (!TEST_true(BN_asc2bn(&bn, "0X1234")) + || !TEST_true(BN_is_word(bn, 0x1234)) + || !TEST_false(BN_is_negative(bn))) goto err; - } - if (!BN_asc2bn(&bn, "-0") || !BN_is_zero(bn) || BN_is_negative(bn)) { - fprintf(stderr, "BN_asc2bn(-0) gave a bad result.\n"); + if (!TEST_true(BN_asc2bn(&bn, "-0xabcd")) + || !TEST_true(BN_abs_is_word(bn, 0xabcd)) + || !TEST_true(BN_is_negative(bn))) goto err; - } - if (!BN_asc2bn(&bn, "123trailing garbage is ignored") - || !BN_is_word(bn, 123) || BN_is_negative(bn)) { - fprintf(stderr, "BN_asc2bn(123trail...) gave a bad result.\n"); + if (!TEST_true(BN_asc2bn(&bn, "-0")) + || !TEST_true(BN_is_zero(bn)) + || !TEST_false(BN_is_negative(bn))) + goto err; + + if (!TEST_true(BN_asc2bn(&bn, "123trailing garbage is ignored")) + || !TEST_true(BN_is_word(bn, 123)) + || !TEST_false(BN_is_negative(bn))) goto err; - } st = 1; err: @@ -1767,57 +1675,34 @@ static const MPITEST kMPITests[] = { {"-256", "\x00\x00\x00\x02\x81\x00", 6}, }; -static int test_mpi() +static int test_mpi(int i) { uint8_t scratch[8]; - int i = (int)sizeof(kMPITests) / sizeof(kMPITests[0]); - const MPITEST *test = kMPITests; + const MPITEST *test = &kMPITests[i]; size_t mpi_len, mpi_len2; - BIGNUM *bn = BN_new(); + BIGNUM *bn = NULL; BIGNUM *bn2 = NULL; int st = 0; - for ( ; --i >= 0; test++) { - if (!BN_asc2bn(&bn, test->base10)) { - fprintf(stderr, "Can't convert %s\n", test->base10); - goto err; - } - mpi_len = BN_bn2mpi(bn, NULL); - if (mpi_len > sizeof (scratch)) { - fprintf(stderr, - "MPI test #%u: MPI size is too large to test.\n", - (unsigned)i); - goto err; - } - - mpi_len2 = BN_bn2mpi(bn, scratch); - if (mpi_len != mpi_len2) { - fprintf(stderr, "MPI test #%u: length changes.\n", - (unsigned)i); - goto err; - } + if (!TEST_ptr(bn = BN_new()) + || !TEST_true(BN_asc2bn(&bn, test->base10))) + goto err; + mpi_len = BN_bn2mpi(bn, NULL); + if (!TEST_size_t_le(mpi_len, sizeof(scratch))) + goto err; - if (mpi_len != test->mpi_len - || memcmp(test->mpi, scratch, mpi_len) != 0) { - fprintf(stderr, "MPI test #%u failed:\n", (unsigned)i); - goto err; - } + if (!TEST_size_t_eq(mpi_len2 = BN_bn2mpi(bn, scratch), mpi_len) + || !TEST_mem_eq(test->mpi, test->mpi_len, scratch, mpi_len)) + goto err; - bn2 = BN_mpi2bn(scratch, mpi_len, NULL); - if (bn2 == NULL) { - fprintf(stderr, "MPI test #%u: failed to parse\n", - (unsigned)i); - goto err; - } + if (!TEST_ptr(bn2 = BN_mpi2bn(scratch, mpi_len, NULL))) + goto err; - if (BN_cmp(bn, bn2) != 0) { - fprintf(stderr, "MPI test #%u: wrong result\n", - (unsigned)i); - BN_free(bn2); - goto err; - } + if (!TEST_int_eq(BN_cmp(bn, bn2), 0)) { BN_free(bn2); + goto err; } + BN_free(bn2); st = 1; err: @@ -1827,41 +1712,23 @@ err: static int test_rand() { - BIGNUM *bn = BN_new(); + BIGNUM *bn = NULL; int st = 0; - if (bn == NULL) + if (!TEST_ptr(bn = BN_new())) return 0; - /* - * Test BN_rand for degenerate cases with |top| and |bottom| parameters. - */ - if (BN_rand(bn, 0, 0 /* top */ , 0 /* bottom */ )) { - fprintf(stderr, "BN_rand1 gave a bad result.\n"); - goto err; - } - if (BN_rand(bn, 0, 1 /* top */ , 1 /* bottom */ )) { - fprintf(stderr, "BN_rand2 gave a bad result.\n"); - goto err; - } - - if (!BN_rand(bn, 1, 0 /* top */ , 0 /* bottom */ ) || !BN_is_word(bn, 1)) { - fprintf(stderr, "BN_rand3 gave a bad result.\n"); - goto err; - } - if (BN_rand(bn, 1, 1 /* top */ , 0 /* bottom */ )) { - fprintf(stderr, "BN_rand4 gave a bad result.\n"); - goto err; - } - if (!BN_rand(bn, 1, -1 /* top */ , 1 /* bottom */ ) || !BN_is_word(bn, 1)) { - fprintf(stderr, "BN_rand5 gave a bad result.\n"); - goto err; - } - - if (!BN_rand(bn, 2, 1 /* top */ , 0 /* bottom */ ) || !BN_is_word(bn, 3)) { - fprintf(stderr, "BN_rand6 gave a bad result.\n"); + /* Test BN_rand for degenerate cases with |top| and |bottom| parameters. */ + if (!TEST_false(BN_rand(bn, 0, 0 /* top */ , 0 /* bottom */ )) + || !TEST_false(BN_rand(bn, 0, 1 /* top */ , 1 /* bottom */ )) + || !TEST_true(BN_rand(bn, 1, 0 /* top */ , 0 /* bottom */ )) + || !TEST_true(BN_is_word(bn, 1)) + || !TEST_false(BN_rand(bn, 1, 1 /* top */ , 0 /* bottom */ )) + || !TEST_true(BN_rand(bn, 1, -1 /* top */ , 1 /* bottom */ )) + || !TEST_true(BN_is_word(bn, 1)) + || !TEST_true(BN_rand(bn, 2, 1 /* top */ , 0 /* bottom */ )) + || !TEST_true(BN_is_word(bn, 3))) goto err; - } st = 1; err: @@ -1871,59 +1738,51 @@ err: static int test_negzero() { - BIGNUM *a = BN_new(); - BIGNUM *b = BN_new(); - BIGNUM *c = BN_new(); - BIGNUM *d = BN_new(); + BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL; BIGNUM *numerator = NULL, *denominator = NULL; int consttime, st = 0; - if (a == NULL || b == NULL || c == NULL || d == NULL) + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b = BN_new()) + || !TEST_ptr(c = BN_new()) + || !TEST_ptr(d = BN_new())) goto err; /* Test that BN_mul never gives negative zero. */ - if (!BN_set_word(a, 1)) + if (!TEST_true(BN_set_word(a, 1))) goto err; BN_set_negative(a, 1); BN_zero(b); - if (!BN_mul(c, a, b, ctx)) + if (!TEST_true(BN_mul(c, a, b, ctx))) goto err; - if (!BN_is_zero(c) || BN_is_negative(c)) { - fprintf(stderr, "Multiplication test failed!\n"); + if (!TEST_true(BN_is_zero(c)) + || !TEST_false(BN_is_negative(c))) goto err; - } for (consttime = 0; consttime < 2; consttime++) { - numerator = BN_new(); - denominator = BN_new(); - if (numerator == NULL || denominator == NULL) + if (!TEST_ptr(numerator = BN_new()) + || !TEST_ptr(denominator = BN_new())) goto err; if (consttime) { BN_set_flags(numerator, BN_FLG_CONSTTIME); BN_set_flags(denominator, BN_FLG_CONSTTIME); } /* Test that BN_div never gives negative zero in the quotient. */ - if (!BN_set_word(numerator, 1) || !BN_set_word(denominator, 2)) + if (!TEST_true(BN_set_word(numerator, 1)) + || !TEST_true(BN_set_word(denominator, 2))) goto err; BN_set_negative(numerator, 1); - if (!BN_div(a, b, numerator, denominator, ctx)) - goto err; - if (!BN_is_zero(a) || BN_is_negative(a)) { - fprintf(stderr, "Incorrect quotient (consttime = %d).\n", - consttime); + if (!TEST_true(BN_div(a, b, numerator, denominator, ctx)) + || !TEST_true(BN_is_zero(a)) + || !TEST_false(BN_is_negative(a))) goto err; - } /* Test that BN_div never gives negative zero in the remainder. */ - if (!BN_set_word(denominator, 1)) + if (!TEST_true(BN_set_word(denominator, 1)) + || !TEST_true(BN_div(a, b, numerator, denominator, ctx)) + || !TEST_true(BN_is_zero(b)) + || !TEST_false(BN_is_negative(b))) goto err; - if (!BN_div(a, b, numerator, denominator, ctx)) - goto err; - if (!BN_is_zero(b) || BN_is_negative(b)) { - fprintf(stderr, "Incorrect remainder (consttime = %d).\n", - consttime); - goto err; - } BN_free(numerator); BN_free(denominator); numerator = denominator = NULL; @@ -1932,12 +1791,10 @@ static int test_negzero() /* Test that BN_set_negative will not produce a negative zero. */ BN_zero(a); BN_set_negative(a, 1); - if (BN_is_negative(a)) { - fprintf(stderr, "BN_set_negative produced a negative zero.\n"); + if (BN_is_negative(a)) goto err; - } - st = 1; + err: BN_free(a); BN_free(b); @@ -1950,78 +1807,59 @@ err: static int test_badmod() { - BIGNUM *a = BN_new(); - BIGNUM *b = BN_new(); - BIGNUM *zero = BN_new(); - BN_MONT_CTX *mont = BN_MONT_CTX_new(); + BIGNUM *a = NULL, *b = NULL, *zero = NULL; + BN_MONT_CTX *mont = NULL; int st = 0; - if (a == NULL || b == NULL || zero == NULL || mont == NULL) + if (!TEST_ptr(a = BN_new()) + || !TEST_ptr(b = BN_new()) + || !TEST_ptr(zero = BN_new()) + || !TEST_ptr(mont = BN_MONT_CTX_new())) goto err; BN_zero(zero); - if (BN_div(a, b, BN_value_one(), zero, ctx)) { - fprintf(stderr, "Division by zero succeeded!\n"); + if (!TEST_false(BN_div(a, b, BN_value_one(), zero, ctx))) goto err; - } ERR_clear_error(); - if (BN_mod_mul(a, BN_value_one(), BN_value_one(), zero, ctx)) { - fprintf(stderr, "BN_mod_mul with zero modulus succeeded!\n"); + if (!TEST_false(BN_mod_mul(a, BN_value_one(), BN_value_one(), zero, ctx))) goto err; - } ERR_clear_error(); - if (BN_mod_exp(a, BN_value_one(), BN_value_one(), zero, ctx)) { - fprintf(stderr, "BN_mod_exp with zero modulus succeeded!\n"); + if (!TEST_false(BN_mod_exp(a, BN_value_one(), BN_value_one(), zero, ctx))) goto err; - } ERR_clear_error(); - if (BN_mod_exp_mont(a, BN_value_one(), BN_value_one(), zero, ctx, NULL)) { - fprintf(stderr, "BN_mod_exp_mont with zero modulus succeeded!\n"); + if (!TEST_false(BN_mod_exp_mont(a, BN_value_one(), BN_value_one(), + zero, ctx, NULL))) goto err; - } ERR_clear_error(); - if (BN_mod_exp_mont_consttime(a, BN_value_one(), BN_value_one(), - zero, ctx, NULL)) { - fprintf(stderr, - "BN_mod_exp_mont_consttime with zero modulus succeeded!\n"); + if (!TEST_false(BN_mod_exp_mont_consttime(a, BN_value_one(), BN_value_one(), + zero, ctx, NULL))) goto err; - } ERR_clear_error(); - if (BN_MONT_CTX_set(mont, zero, ctx)) { - fprintf(stderr, "BN_MONT_CTX_set succeeded for zero modulus!\n"); + if (!TEST_false(BN_MONT_CTX_set(mont, zero, ctx))) goto err; - } ERR_clear_error(); /* Some operations also may not be used with an even modulus. */ - if (!BN_set_word(b, 16)) + if (!TEST_true(BN_set_word(b, 16))) goto err; - if (BN_MONT_CTX_set(mont, b, ctx)) { - fprintf(stderr, - "BN_MONT_CTX_set succeeded for even modulus!\n"); + if (!TEST_false(BN_MONT_CTX_set(mont, b, ctx))) goto err; - } ERR_clear_error(); - if (BN_mod_exp_mont(a, BN_value_one(), BN_value_one(), b, ctx, NULL)) { - fprintf(stderr, - "BN_mod_exp_mont with even modulus succeeded!\n"); + if (!TEST_false(BN_mod_exp_mont(a, BN_value_one(), BN_value_one(), + b, ctx, NULL))) goto err; - } ERR_clear_error(); - if (BN_mod_exp_mont_consttime(a, BN_value_one(), BN_value_one(), - b, ctx, NULL)) { - fprintf(stderr, - "BN_mod_exp_mont_consttime with even modulus succeeded!\n"); + if (!TEST_false(BN_mod_exp_mont_consttime(a, BN_value_one(), BN_value_one(), + b, ctx, NULL))) goto err; - } ERR_clear_error(); st = 1; @@ -2035,23 +1873,27 @@ err: static int test_expmodzero() { - BIGNUM *zero = BN_new(); - BIGNUM *a = BN_new(); - BIGNUM *r = BN_new(); + BIGNUM *a = NULL, *r = NULL, *zero = NULL; int st = 0; - if (zero == NULL || a == NULL || r == NULL || !BN_rand(a, 1024, 0, 0)) + if (!TEST_ptr(zero = BN_new()) + || !TEST_ptr(a = BN_new()) + || !TEST_ptr(r = BN_new())) goto err; BN_zero(zero); - if (!BN_mod_exp(r, a, zero, BN_value_one(), NULL) - || !BN_is_zero(r) - || !BN_mod_exp_mont(r, a, zero, BN_value_one(), NULL, NULL) - || !BN_is_zero(r) - || !BN_mod_exp_mont_consttime(r, a, zero, BN_value_one(), NULL, NULL) - || !BN_is_zero(r) - || !BN_mod_exp_mont_word(r, 42, zero, BN_value_one(), NULL, NULL) - || !BN_is_zero(r)) + if (!TEST_true(BN_mod_exp(r, a, zero, BN_value_one(), NULL)) + || !TEST_true(BN_is_zero(r)) + || !TEST_true(BN_mod_exp_mont(r, a, zero, BN_value_one(), + NULL, NULL)) + || !TEST_true(BN_is_zero(r)) + || !TEST_true(BN_mod_exp_mont_consttime(r, a, zero, + BN_value_one(), + NULL, NULL)) + || !TEST_true(BN_is_zero(r)) + || !TEST_true(BN_mod_exp_mont_word(r, 42, zero, + BN_value_one(), NULL, NULL)) + || !TEST_true(BN_is_zero(r))) goto err; st = 1; @@ -2065,17 +1907,14 @@ err: static int test_smallprime() { static const int kBits = 10; - BIGNUM *r = BN_new(); + BIGNUM *r; int st = 0; - if (r == NULL - || !BN_generate_prime_ex(r, (int)kBits, 0, NULL, NULL, NULL)) - goto err; - if (BN_num_bits(r) != kBits) { - fprintf(stderr, "Expected %u bit prime, got %u bit number\n", - kBits, BN_num_bits(r)); + if (!TEST_ptr(r = BN_new()) + || !TEST_true(BN_generate_prime_ex(r, (int)kBits, 0, + NULL, NULL, NULL)) + || !TEST_int_eq(BN_num_bits(r), kBits)) goto err; - } st = 1; err: @@ -2086,18 +1925,19 @@ err: static int test_3_is_prime() { int ret = 0; - BIGNUM *r = BN_new(); + BIGNUM *r = NULL; - /* For a long time, small primes were not considered prime when - * do_trial_division was set. */ - if (r == NULL || - !BN_set_word(r, 3) || - BN_is_prime_fasttest_ex(r, 3 /* nchecks */, ctx, - 0 /* do_trial_division */, NULL) != 1 || - BN_is_prime_fasttest_ex(r, 3 /* nchecks */, ctx, - 1 /* do_trial_division */, NULL) != 1) { + /* + * For a long time, small primes were not considered prime when + * do_trial_division was set. + */ + if (!TEST_ptr(r = BN_new()) + || !TEST_true(BN_set_word(r, 3)) + || !TEST_int_eq(BN_is_prime_fasttest_ex(r, 3 /* nchecks */, ctx, + 0 /* do_trial_division */, NULL), 1) + || !TEST_int_eq(BN_is_prime_fasttest_ex(r, 3 /* nchecks */, ctx, + 1 /* do_trial_division */, NULL), 1)) goto err; - } ret = 1; @@ -2134,8 +1974,8 @@ static int readstanza(STANZA *s, int *linesread) while (fgets(buff, sizeof(buff), fp) != NULL) { (*linesread)++; - if ((p = strchr(buff, '\n')) == NULL) { - fprintf(stderr, "Line %d too long.\n", s->start); + if (!TEST_ptr(p = strchr(buff, '\n'))) { + TEST_info("Line %d too long", s->start); return 0; } *p = '\0'; @@ -2148,25 +1988,16 @@ static int readstanza(STANZA *s, int *linesread) if (buff[0] == '#') continue; - if ((equals = strchr(buff, '=')) == NULL) { - fprintf(stderr, "Line %d missing equals.\n", s->start); + if (!TEST_ptr(equals = strchr(buff, '='))) return 0; - } *equals++ = '\0'; - key = strip_spaces(buff); - value = strip_spaces(equals); - if (key == NULL || value == NULL) { - fprintf(stderr, "Line %d missing field.\n", s->start); - return 0; - } - s->numpairs++; - if (s->numpairs >= MAXPAIRS) { - fprintf(stderr, "Line %d too many lines\n", s->start); + if (!TEST_ptr(key = strip_spaces(buff)) + || !TEST_ptr(value = strip_spaces(equals)) + || !TEST_int_lt(s->numpairs++, MAXPAIRS) + || !TEST_ptr(pp->key = OPENSSL_strdup(key)) + || !TEST_ptr(pp->value = OPENSSL_strdup(value))) return 0; - } - pp->key = OPENSSL_strdup(key); - pp->value = OPENSSL_strdup(value); pp++; } @@ -2207,10 +2038,15 @@ static int file_test_run(STANZA *s) const FILETEST *tp = filetests; for ( ; --numtests >= 0; tp++) { - if (findattr(s, tp->name) != NULL) - return tp->func(s); + if (findattr(s, tp->name) != NULL) { + if (!tp->func(s)) { + TEST_info("Failed %s test at %d", tp->name, s->start); + return 0; + } + return 1; + } } - fprintf(stderr, "Unknown test at %d\n", s->start); + TEST_info("Unknown test at %d", s->start); return 0; } @@ -2225,7 +2061,6 @@ static int file_tests() if (s.numpairs == 0) continue; if (!file_test_run(&s)) { - fprintf(stderr, "Test at %d failed\n", s.start); errcnt++; } clearstanza(&s); @@ -2242,8 +2077,8 @@ int test_main(int argc, char *argv[]) int result = 0; if (argc != 2) { - fprintf(stderr, "%s TEST_FILE\n", argv[0]); - return 1; + TEST_error("%s TEST_FILE", argv[0]); + return 0; } ADD_TEST(test_sub); @@ -2256,7 +2091,7 @@ int test_main(int argc, char *argv[]) ADD_TEST(test_dec2bn); ADD_TEST(test_hex2bn); ADD_TEST(test_asc2bn); - ADD_TEST(test_mpi); + ADD_ALL_TESTS(test_mpi, (int)OSSL_NELEM(kMPITests)); ADD_TEST(test_negzero); ADD_TEST(test_badmod); ADD_TEST(test_expmodzero); @@ -2279,11 +2114,12 @@ int test_main(int argc, char *argv[]) ctx = BN_CTX_new(); TEST_check(ctx != NULL); - fp = fopen(argv[1], "r"); - TEST_check(fp != NULL); + if (!TEST_ptr(fp = fopen(argv[1], "r"))) + goto end; result = run_tests(argv[0]); fclose(fp); +end: BN_CTX_free(ctx); return result; } diff --git a/test/libtestutil.a b/test/libtestutil.a deleted file mode 100644 index 973419527666f587263016dfc41358af65077158..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc-jL100001 literal 82398 zc-rlK3wTt;+5b7adp4W z#ZPIit%~)A6)gP}r78-FT(q`W6|uF7iZ&=#yrZK0=elQRc4kRJ`mfLPu{`0-{N|mR z-@J114^q}s_Vzaahj%0(==mN z=l%xgMgCo~K-0WQnig30f8lR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