X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=test%2Fexptest.c;h=2b2d3fd549b10c9336df7bc5af1eb2555b9efa04;hp=e15c0519b9198f2dde507b1994cb34c57de6f10a;hb=11baa470a21b514ab247071e80273ddc0a80c504;hpb=7104351cd9f2289d9ffe7812668738a2c0fcb515 diff --git a/test/exptest.c b/test/exptest.c index e15c0519b9..2b2d3fd549 100644 --- a/test/exptest.c +++ b/test/exptest.c @@ -1,7 +1,7 @@ /* * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -11,7 +11,7 @@ #include #include -#include "../e_os.h" +#include "internal/nelem.h" #include #include @@ -22,14 +22,7 @@ #define NUM_BITS (BN_BITS2 * 4) -#define BN_print_var(v) bn_print_var(#v, v) - -static void bn_print_var(const char *var, const BIGNUM *bn) -{ - fprintf(stderr, "%s (%3d) = ", var, BN_num_bits(bn)); - BN_print_fp(stderr, bn); - fprintf(stderr, "\n"); -} +#define BN_print_var(v) test_output_bignum(#v, v) /* * Test that r == 0 in test_exp_mod_zero(). Returns one on success, @@ -39,8 +32,7 @@ static int a_is_zero_mod_one(const char *method, const BIGNUM *r, const BIGNUM *a) { if (!BN_is_zero(r)) { - fprintf(stderr, "%s failed:\n", method); - fprintf(stderr, "a ** 0 mod 1 = r (should be 0)\n"); + TEST_error("%s failed: a ** 0 mod 1 = r (should be 0)", method); BN_print_var(a); BN_print_var(r); return 0; @@ -51,7 +43,7 @@ static int a_is_zero_mod_one(const char *method, const BIGNUM *r, /* * test_mod_exp_zero tests that x**0 mod 1 == 0. It returns zero on success. */ -static int test_mod_exp_zero() +static int test_mod_exp_zero(void) { BIGNUM *a = NULL, *p = NULL, *m = NULL; BIGNUM *r = NULL; @@ -109,9 +101,9 @@ static int test_mod_exp_zero() if (!TEST_true(BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL))) goto err; - if (!TEST_true(BN_is_zero(r))) { - fprintf(stderr, "BN_mod_exp_mont_word failed:\n"); - fprintf(stderr, "1 ** 0 mod 1 = r (should be 0)\n"); + if (!TEST_BN_eq_zero(r)) { + TEST_error("BN_mod_exp_mont_word failed: " + "1 ** 0 mod 1 = r (should be 0)"); BN_print_var(r); goto err; } @@ -164,24 +156,23 @@ static int test_mod_exp(int round) c = (c % BN_BITS) - BN_BITS2; BN_rand(m, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD); - BN_mod(a, a, m, ctx); - BN_mod(b, b, m, ctx); - - if (!TEST_true(BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL)) + if (!TEST_true(BN_mod(a, a, m, ctx)) + || !TEST_true(BN_mod(b, b, m, ctx)) + || !TEST_true(BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL)) || !TEST_true(BN_mod_exp_recp(r_recp, a, b, m, ctx)) || !TEST_true(BN_mod_exp_simple(r_simple, a, b, m, ctx)) || !TEST_true(BN_mod_exp_mont_consttime(r_mont_const, a, b, m, ctx, NULL))) goto err; - if (!TEST_int_eq(BN_cmp(r_simple, r_mont), 0) - || !TEST_int_eq(BN_cmp(r_simple, r_recp), 0) - || !TEST_int_eq(BN_cmp(r_simple, r_mont_const), 0)) { + if (!TEST_BN_eq(r_simple, r_mont) + || !TEST_BN_eq(r_simple, r_recp) + || !TEST_BN_eq(r_simple, r_mont_const)) { if (BN_cmp(r_simple, r_mont) != 0) - fprintf(stderr, "simple and mont results differ\n"); + TEST_info("simple and mont results differ"); if (BN_cmp(r_simple, r_mont_const) != 0) - fprintf(stderr, "simple and mont const time results differ\n"); + TEST_info("simple and mont const time results differ"); if (BN_cmp(r_simple, r_recp) != 0) - fprintf(stderr, "simple and recp results differ\n"); + TEST_info("simple and recp results differ"); BN_print_var(a); BN_print_var(b); @@ -207,8 +198,9 @@ static int test_mod_exp(int round) return ret; } -void register_tests(void) +int setup_tests(void) { ADD_TEST(test_mod_exp_zero); ADD_ALL_TESTS(test_mod_exp, 200); + return 1; }