static void test_all_sqrt() { test_sqrt(zero, zero, "0"); test_sqrt(half, dec64_new(7071067811865475, -16), "1/2"); test_sqrt(two, dec64_new(14142135623730950, -16), "2"); test_sqrt(one, one, "1"); test_sqrt(pi, dec64_new(17724538509055160, -16), "pi"); test_sqrt(dec64_new(10, 0), dec64_new(31622776601683793, -16), "10"); test_sqrt(dec64_new(16, 0), dec64_new(4, 0), "16"); test_sqrt(dec64_new(100, 0), dec64_new(10, 0), "100"); test_sqrt(dec64_new(10000, -2), dec64_new(10, 0), "100"); test_sqrt(dec64_new(1000000, -4), dec64_new(10, 0), "100"); }
int main(int argc, char *argv[]) { ULONG res = 0; MathIeeeSingTransBase = (BaseType *)OpenLibrary("mathieeesingtrans.library", 34); if(MathIeeeSingTransBase) { PutStr("ok!\n"); test_const(); test_acos(); test_asin(); test_atan(); test_cos(); test_cosh(); test_exp(); test_fieee(); test_log(); test_log10(); test_pow(); test_sin(); test_sincos(); test_sinh(); test_sqrt(); test_tan(); test_tanh(); test_tieee(); CloseLibrary((struct Library *)MathIeeeSingTransBase); } else { PutStr("No mathieeesingtrans.library!\n"); res = 1; } return res; }
int main ( int argc, char *argv[] ) /******************************************************************************/ /* Purpose: MAIN is the main program for C_INTRINSICS. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 April 2011 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "C_INTRINSICS:\n" ); printf ( " Test the C intrinsic library.\n" ); test_abs ( ); test_acos ( ); test_asin ( ); test_atan ( ); test_atan2 ( ); test_ceil ( ); test_cos ( ); test_cosh ( ); test_exp ( ); test_fabs ( ); test_floor ( ); test_fmod ( ); test_frexp ( ); test_ldexp ( ); test_log ( ); test_log10 ( ); test_modf ( ); test_pow ( ); test_sin ( ); test_sinh ( ); test_sqrt ( ); test_tan ( ); test_tanh ( ); /* Terminate. */ printf ( "\n" ); printf ( "C_INTRINSICS:\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; }
int test_main(int, char*[]) { BOOST_CHECK(test_mul(2, 3, 5, 7)); BOOST_CHECK(test_mul(2, 3, -5, 7)); BOOST_CHECK(test_mul(2, 3, -7, -5)); BOOST_CHECK(test_mul(-2, 3, 5, 7)); BOOST_CHECK(test_mul(-2, 3, -5, 7)); BOOST_CHECK(test_mul(-2, 3, -7, -5)); BOOST_CHECK(test_mul(-3, -2, 5, 7)); BOOST_CHECK(test_mul(-3, -2, -5, 7)); BOOST_CHECK(test_mul(-3, -2, -7, -5)); BOOST_CHECK(test_mul1(3, 5, 7)); BOOST_CHECK(test_mul1(3, -5, 7)); BOOST_CHECK(test_mul1(3, -7, -5)); BOOST_CHECK(test_mul1(-3, 5, 7)); BOOST_CHECK(test_mul1(-3, -5, 7)); BOOST_CHECK(test_mul1(-3, -7, -5)); BOOST_CHECK(test_div(30, 42, 2, 3)); BOOST_CHECK(test_div(30, 42, -3, -2)); BOOST_CHECK(test_div(-30, 42, 2, 3)); BOOST_CHECK(test_div(-30, 42, -3, -2)); BOOST_CHECK(test_div(-42, -30, 2, 3)); BOOST_CHECK(test_div(-42, -30, -3, -2)); BOOST_CHECK(test_div1(30, 42, 3)); BOOST_CHECK(test_div1(30, 42, -3)); BOOST_CHECK(test_div1(-30, 42, 3)); BOOST_CHECK(test_div1(-30, 42, -3)); BOOST_CHECK(test_div1(-42, -30, 3)); BOOST_CHECK(test_div1(-42, -30, -3)); BOOST_CHECK(test_div2(30, 2, 3)); BOOST_CHECK(test_div2(30, -3, -2)); BOOST_CHECK(test_div2(-30, 2, 3)); BOOST_CHECK(test_div2(-30, -3, -2)); BOOST_CHECK(test_square(2, 3)); BOOST_CHECK(test_square(-2, 3)); BOOST_CHECK(test_square(-3, 2)); BOOST_CHECK(test_sqrt(2, 3)); BOOST_CHECK(test_sqrt(5, 7)); BOOST_CHECK(test_sqrt(-1, 2)); return 0; }
static void check_nan (void) { mpfr_t x, got; mpfr_init2 (x, 100L); mpfr_init2 (got, 100L); /* sqrt(NaN) == NaN */ MPFR_SET_NAN (x); MPFR_ASSERTN (test_sqrt (got, x, MPFR_RNDZ) == 0); /* exact */ MPFR_ASSERTN (mpfr_nan_p (got)); /* sqrt(-1) == NaN */ mpfr_set_si (x, -1L, MPFR_RNDZ); MPFR_ASSERTN (test_sqrt (got, x, MPFR_RNDZ) == 0); /* exact */ MPFR_ASSERTN (mpfr_nan_p (got)); /* sqrt(+inf) == +inf */ MPFR_SET_INF (x); MPFR_SET_POS (x); MPFR_ASSERTN (test_sqrt (got, x, MPFR_RNDZ) == 0); /* exact */ MPFR_ASSERTN (mpfr_inf_p (got)); /* sqrt(-inf) == NaN */ MPFR_SET_INF (x); MPFR_SET_NEG (x); MPFR_ASSERTN (test_sqrt (got, x, MPFR_RNDZ) == 0); /* exact */ MPFR_ASSERTN (mpfr_nan_p (got)); /* sqrt(-0) == 0 */ mpfr_set_si (x, 0L, MPFR_RNDZ); MPFR_SET_NEG (x); MPFR_ASSERTN (test_sqrt (got, x, MPFR_RNDZ) == 0); /* exact */ MPFR_ASSERTN (mpfr_number_p (got)); MPFR_ASSERTN (mpfr_cmp_ui (got, 0L) == 0); mpfr_clear (x); mpfr_clear (got); }
void run_sqrt(void) { secp256k1_fe_t ns, x, s, t; /* Check sqrt(0) is 0 */ secp256k1_fe_set_int(&x, 0); secp256k1_fe_sqr(&s, &x); test_sqrt(&s, &x); /* Check sqrt of small squares (and their negatives) */ for (int i=1; i<=100; i++) { secp256k1_fe_set_int(&x, i); secp256k1_fe_sqr(&s, &x); test_sqrt(&s, &x); secp256k1_fe_negate(&t, &s, 1); test_sqrt(&t, NULL); } /* Consistency checks for large random values */ for (int i=0; i<10; i++) { random_fe_non_square(&ns); for (int j=0; j<count; j++) { random_fe(&x); secp256k1_fe_sqr(&s, &x); test_sqrt(&s, &x); secp256k1_fe_negate(&t, &s, 1); test_sqrt(&t, NULL); secp256k1_fe_mul(&t, &s, &ns); test_sqrt(&t, NULL); } } }
int main() { int Error(0); Error += test_pow(); Error += test_exp(); Error += test_log(); Error += test_exp2(); Error += test_log2(); Error += test_sqrt(); Error += test_inversesqrt(); return Error; }
int main() { test_cos_det(); test_sin_det(); test_atan2_det(); test_atan2(); test_pow_det(); test_pow_singleton_exp(); test_pow(); test_fmod_det(); test_fmod(); test_sqrt_det(); test_sqrt(); test_exp_det(); test_log_det(); test_log10_det(); test_powf_det(); test_powf_singleton_exp(); test_powf(); test_sqrtf_det(); test_sqrtf(); test_expf_det(); test_logf_det(); test_log10f_det(); test_diff_pow_powf(); test_floor_det(); test_ceil_det(); test_trunc_det(); test_round_det(); test_floor(); test_ceil(); test_trunc(); test_round(); test_floorf_det(); test_ceilf_det(); test_truncf_det(); test_roundf_det(); test_floorf(); test_ceilf(); test_truncf(); test_roundf(); return 0; }
static void check_diverse (const char *as, mpfr_prec_t p, const char *qs) { mpfr_t q; mpfr_init2 (q, p); mpfr_set_str1 (q, as); test_sqrt (q, q, MPFR_RNDN); if (mpfr_cmp_str1 (q, qs)) { printf ("mpfr_sqrt failed for a=%s, prec=%lu, rnd_mode=%s\n", as, (unsigned long) p, mpfr_print_rnd_mode (MPFR_RNDN)); printf ("expected sqrt is %s, got ", qs); mpfr_out_str (stdout, 10, 0, q, MPFR_RNDN); printf ("\n"); exit (1); } mpfr_clear (q); }
static void check24 (const char *as, mpfr_rnd_t rnd_mode, const char *qs) { mpfr_t q; mpfr_init2 (q, 24); mpfr_set_str1 (q, as); test_sqrt (q, q, rnd_mode); if (mpfr_cmp_str1 (q, qs)) { printf ("mpfr_sqrt failed for a=%s, prec=24, rnd_mode=%s\n", as, mpfr_print_rnd_mode(rnd_mode)); printf ("expected sqrt is %s, got ",qs); mpfr_out_str (stdout, 10, 0, q, MPFR_RNDN); printf ("\n"); exit (1); } mpfr_clear (q); }
static void check4 (const char *as, mpfr_rnd_t rnd_mode, const char *Qs) { mpfr_t q; mpfr_init2 (q, 53); mpfr_set_str1 (q, as); test_sqrt (q, q, rnd_mode); if (mpfr_cmp_str (q, Qs, 16, MPFR_RNDN)) { printf ("mpfr_sqrt failed for a=%s, rnd_mode=%s\n", as, mpfr_print_rnd_mode(rnd_mode)); printf ("expected "); mpfr_out_str (stdout, 16, 0, q, MPFR_RNDN); printf ("\ngot %s\n", Qs); mpfr_clear (q); exit (1); } mpfr_clear (q); }
//============================================ // //============================================ int main(void) { Field f; field_init(f, "bn254_fp6"); test_feature(f); test_arithmetic_operation(f); test_sqrt(f); //test_frob(f); test_io(f); field_clear(f); fprintf(stderr, "ok\n"); return 0; }
static void check_inexact (mpfr_prec_t p) { mpfr_t x, y, z; mpfr_rnd_t rnd; int inexact, sign; mpfr_init2 (x, p); mpfr_init2 (y, p); mpfr_init2 (z, 2*p); mpfr_urandomb (x, RANDS); rnd = RND_RAND (); inexact = test_sqrt (y, x, rnd); if (mpfr_mul (z, y, y, rnd)) /* exact since prec(z) = 2*prec(y) */ { printf ("Error: multiplication should be exact\n"); exit (1); } mpfr_sub (z, z, x, rnd); /* exact also */ sign = mpfr_cmp_ui (z, 0); if (((inexact == 0) && (sign)) || ((inexact > 0) && (sign <= 0)) || ((inexact < 0) && (sign >= 0))) { printf ("Error: wrong inexact flag, expected %d, got %d\n", sign, inexact); printf ("x="); mpfr_print_binary (x); printf (" rnd=%s\n", mpfr_print_rnd_mode (rnd)); printf ("y="); mpfr_print_binary (y); puts (""); exit (1); } mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); }
static void special (void) { mpfr_t x, y, z; int inexact; mpfr_prec_t p; mpfr_init (x); mpfr_init (y); mpfr_init (z); mpfr_set_prec (x, 64); mpfr_set_str_binary (x, "1010000010100011011001010101010010001100001101011101110001011001E-1"); mpfr_set_prec (y, 32); test_sqrt (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 2405743844UL)) { printf ("Error for n^2+n+1/2 with n=2405743843\n"); exit (1); } mpfr_set_prec (x, 65); mpfr_set_str_binary (x, "10100000101000110110010101010100100011000011010111011100010110001E-2"); mpfr_set_prec (y, 32); test_sqrt (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 2405743844UL)) { printf ("Error for n^2+n+1/4 with n=2405743843\n"); mpfr_dump (y); exit (1); } mpfr_set_prec (x, 66); mpfr_set_str_binary (x, "101000001010001101100101010101001000110000110101110111000101100011E-3"); mpfr_set_prec (y, 32); test_sqrt (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 2405743844UL)) { printf ("Error for n^2+n+1/4+1/8 with n=2405743843\n"); mpfr_dump (y); exit (1); } mpfr_set_prec (x, 66); mpfr_set_str_binary (x, "101000001010001101100101010101001000110000110101110111000101100001E-3"); mpfr_set_prec (y, 32); test_sqrt (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 2405743843UL)) { printf ("Error for n^2+n+1/8 with n=2405743843\n"); mpfr_dump (y); exit (1); } mpfr_set_prec (x, 27); mpfr_set_str_binary (x, "0.110100111010101000010001011"); if ((inexact = test_sqrt (x, x, MPFR_RNDZ)) >= 0) { printf ("Wrong inexact flag: expected -1, got %d\n", inexact); exit (1); } mpfr_set_prec (x, 2); for (p=2; p<1000; p++) { mpfr_set_prec (z, p); mpfr_set_ui (z, 1, MPFR_RNDN); mpfr_nexttoinf (z); test_sqrt (x, z, MPFR_RNDU); if (mpfr_cmp_ui_2exp(x, 3, -1)) { printf ("Error: sqrt(1+ulp(1), up) should give 1.5 (prec=%u)\n", (unsigned int) p); printf ("got "); mpfr_print_binary (x); puts (""); exit (1); } } /* check inexact flag */ mpfr_set_prec (x, 5); mpfr_set_str_binary (x, "1.1001E-2"); if ((inexact = test_sqrt (x, x, MPFR_RNDN))) { printf ("Wrong inexact flag: expected 0, got %d\n", inexact); exit (1); } mpfr_set_prec (x, 2); mpfr_set_prec (z, 2); /* checks the sign is correctly set */ mpfr_set_si (x, 1, MPFR_RNDN); mpfr_set_si (z, -1, MPFR_RNDN); test_sqrt (z, x, MPFR_RNDN); if (mpfr_cmp_ui (z, 0) < 0) { printf ("Error: square root of 1 gives "); mpfr_print_binary(z); putchar('\n'); exit (1); } mpfr_set_prec (x, 192); mpfr_set_prec (z, 160); mpfr_set_str_binary (z, "0.1011010100000100100100100110011001011100100100000011000111011001011101101101110000110100001000100001100001011000E1"); mpfr_set_prec (x, 160); test_sqrt(x, z, MPFR_RNDN); test_sqrt(z, x, MPFR_RNDN); mpfr_set_prec (x, 53); mpfr_set_str (x, "8093416094703476.0", 10, MPFR_RNDN); mpfr_div_2exp (x, x, 1075, MPFR_RNDN); test_sqrt (x, x, MPFR_RNDN); mpfr_set_str (z, "1e55596835b5ef@-141", 16, MPFR_RNDN); if (mpfr_cmp (x, z)) { printf ("Error: square root of 8093416094703476*2^(-1075)\n"); printf ("expected "); mpfr_dump (z); printf ("got "); mpfr_dump (x); exit (1); } mpfr_set_prec (x, 33); mpfr_set_str_binary (x, "0.111011011011110001100111111001000e-10"); mpfr_set_prec (z, 157); inexact = test_sqrt (z, x, MPFR_RNDN); mpfr_set_prec (x, 157); mpfr_set_str_binary (x, "0.11110110101100101111001011100011100011100001101010111011010000100111011000111110100001001011110011111100101110010110010110011001011011010110010000011001101E-5"); if (mpfr_cmp (x, z)) { printf ("Error: square root (1)\n"); exit (1); } if (inexact <= 0) { printf ("Error: wrong inexact flag (1)\n"); exit (1); } /* case prec(result) << prec(input) */ mpfr_set_prec (z, 2); for (p = 2; p < 1000; p++) { mpfr_set_prec (x, p); mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_nextabove (x); /* 1.0 < x <= 1.5 thus 1 < sqrt(x) <= 1.23 */ inexact = test_sqrt (z, x, MPFR_RNDN); MPFR_ASSERTN(inexact < 0 && mpfr_cmp_ui (z, 1) == 0); inexact = test_sqrt (z, x, MPFR_RNDZ); MPFR_ASSERTN(inexact < 0 && mpfr_cmp_ui (z, 1) == 0); inexact = test_sqrt (z, x, MPFR_RNDU); MPFR_ASSERTN(inexact > 0 && mpfr_cmp_ui_2exp (z, 3, -1) == 0); inexact = test_sqrt (z, x, MPFR_RNDD); MPFR_ASSERTN(inexact < 0 && mpfr_cmp_ui (z, 1) == 0); inexact = test_sqrt (z, x, MPFR_RNDA); MPFR_ASSERTN(inexact > 0 && mpfr_cmp_ui_2exp (z, 3, -1) == 0); } /* corner case rw = 0 in rounding to nearest */ mpfr_set_prec (z, GMP_NUMB_BITS - 1); mpfr_set_prec (y, GMP_NUMB_BITS - 1); mpfr_set_ui (y, 1, MPFR_RNDN); mpfr_mul_2exp (y, y, GMP_NUMB_BITS - 1, MPFR_RNDN); mpfr_nextabove (y); for (p = 2 * GMP_NUMB_BITS - 1; p <= 1000; p++) { mpfr_set_prec (x, p); mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_set_exp (x, GMP_NUMB_BITS); mpfr_add_ui (x, x, 1, MPFR_RNDN); /* now x = 2^(GMP_NUMB_BITS - 1) + 1 (GMP_NUMB_BITS bits) */ MPFR_ASSERTN (mpfr_mul (x, x, x, MPFR_RNDN) == 0); /* exact */ inexact = test_sqrt (z, x, MPFR_RNDN); /* even rule: z should be 2^(GMP_NUMB_BITS - 1) */ MPFR_ASSERTN (inexact < 0); MPFR_ASSERTN (mpfr_cmp_ui_2exp (z, 1, GMP_NUMB_BITS - 1) == 0); mpfr_nextbelow (x); /* now x is just below [2^(GMP_NUMB_BITS - 1) + 1]^2 */ inexact = test_sqrt (z, x, MPFR_RNDN); MPFR_ASSERTN(inexact < 0 && mpfr_cmp_ui_2exp (z, 1, GMP_NUMB_BITS - 1) == 0); mpfr_nextabove (x); mpfr_nextabove (x); /* now x is just above [2^(GMP_NUMB_BITS - 1) + 1]^2 */ inexact = test_sqrt (z, x, MPFR_RNDN); if (mpfr_cmp (z, y)) { printf ("Error for sqrt(x) in rounding to nearest\n"); printf ("x="); mpfr_dump (x); printf ("Expected "); mpfr_dump (y); printf ("Got "); mpfr_dump (z); exit (1); } if (inexact <= 0) { printf ("Wrong inexact flag in corner case for p = %lu\n", (unsigned long) p); exit (1); } } mpfr_set_prec (x, 1000); mpfr_set_ui (x, 9, MPFR_RNDN); mpfr_set_prec (y, 10); inexact = test_sqrt (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 3) || inexact != 0) { printf ("Error in sqrt(9:1000) for prec=10\n"); exit (1); } mpfr_set_prec (y, GMP_NUMB_BITS); mpfr_nextabove (x); inexact = test_sqrt (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 3) || inexact >= 0) { printf ("Error in sqrt(9:1000) for prec=%d\n", (int) GMP_NUMB_BITS); exit (1); } mpfr_set_prec (x, 2 * GMP_NUMB_BITS); mpfr_set_prec (y, GMP_NUMB_BITS); mpfr_set_ui (y, 1, MPFR_RNDN); mpfr_nextabove (y); mpfr_set (x, y, MPFR_RNDN); inexact = test_sqrt (y, x, MPFR_RNDN); if (mpfr_cmp_ui (y, 1) || inexact >= 0) { printf ("Error in sqrt(1) for prec=%d\n", (int) GMP_NUMB_BITS); mpfr_dump (y); exit (1); } mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); }
int main() { test_acos(); test_asin(); test_atan(); test_atan2(); test_ceil(); test_cos(); test_cosh(); test_exp(); test_fabs(); test_floor(); test_fmod(); test_frexp(); test_ldexp(); test_log(); test_log10(); test_modf(); test_pow(); test_sin(); test_sinh(); test_sqrt(); test_tan(); test_tanh(); test_signbit(); test_fpclassify(); test_isfinite(); test_isinf(); test_isnan(); test_isnormal(); test_isgreater(); test_isgreaterequal(); test_isless(); test_islessequal(); test_islessgreater(); test_isunordered(); test_acosh(); test_asinh(); test_atanh(); test_cbrt(); test_copysign(); test_erf(); test_erfc(); test_exp2(); test_expm1(); test_fdim(); test_fma(); test_fmax(); test_fmin(); test_hypot(); test_ilogb(); test_lgamma(); test_llrint(); test_llround(); test_log1p(); test_log2(); test_logb(); test_lrint(); test_lround(); test_nan(); test_nearbyint(); test_nextafter(); test_nexttoward(); test_remainder(); test_remquo(); test_rint(); test_round(); test_scalbln(); test_scalbn(); test_tgamma(); test_trunc(); }
double test_sqrt(double y, double x) { return (test_pow(y, 2) <= x+PRECISION && test_pow(y, 2) >= x-PRECISION) ? y : test_sqrt(((y + (x/y))/2), x); }
int main(void) { double y = 0.0001; printf("Result: %f\n", test_sqrt(y, 199)); return 0; }
int main(int argc, char *argv[]) { BN_CTX *ctx; BIO *out; char *outfile = NULL; results = 0; argc--; argv++; while (argc >= 1) { if (strcmp(*argv, "-results") == 0) results = 1; else if (strcmp(*argv, "-out") == 0) { if (--argc < 1) break; outfile= *(++argv); } argc--; argv++; } ctx = BN_CTX_new(); if (ctx == NULL) exit(1); out = BIO_new(BIO_s_file()); if (out == NULL) exit(1); if (outfile == NULL) { BIO_set_fp(out, stdout, BIO_NOCLOSE); } else { if (!BIO_write_filename(out, outfile)) { perror(outfile); exit(1); } } if (!results) BIO_puts(out, "obase=16\nibase=16\n"); message(out, "BN_add"); if (!test_add(out)) goto err; (void)BIO_flush(out); message(out, "BN_sub"); if (!test_sub(out)) goto err; (void)BIO_flush(out); message(out, "BN_lshift1"); if (!test_lshift1(out)) goto err; (void)BIO_flush(out); message(out, "BN_lshift (fixed)"); if (!test_lshift(out, ctx, BN_bin2bn(lst, sizeof(lst) - 1, NULL))) goto err; (void)BIO_flush(out); message(out, "BN_lshift"); if (!test_lshift(out, ctx, NULL)) goto err; (void)BIO_flush(out); message(out, "BN_rshift1"); if (!test_rshift1(out)) goto err; (void)BIO_flush(out); message(out, "BN_rshift"); if (!test_rshift(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_sqr"); if (!test_sqr(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mul"); if (!test_mul(out)) goto err; (void)BIO_flush(out); message(out, "BN_div"); if (!test_div(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_div_word"); if (!test_div_word(out)) goto err; (void)BIO_flush(out); message(out, "BN_div_recp"); if (!test_div_recp(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod"); if (!test_mod(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod_mul"); if (!test_mod_mul(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mont"); if (!test_mont(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod_exp"); if (!test_mod_exp(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod_exp_mont_consttime"); if (!test_mod_exp_mont_consttime(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_exp"); if (!test_exp(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_kronecker"); if (!test_kron(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_mod_sqrt"); if (!test_sqrt(out, ctx)) goto err; (void)BIO_flush(out); message(out, "Modexp with different sizes"); if (!test_mod_exp_sizes(out, ctx)) goto err; (void)BIO_flush(out); #ifndef OPENSSL_NO_EC2M message(out, "BN_GF2m_add"); if (!test_gf2m_add(out)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod"); if (!test_gf2m_mod(out)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_mul"); if (!test_gf2m_mod_mul(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_sqr"); if (!test_gf2m_mod_sqr(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_inv"); if (!test_gf2m_mod_inv(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_div"); if (!test_gf2m_mod_div(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_exp"); if (!test_gf2m_mod_exp(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_sqrt"); if (!test_gf2m_mod_sqrt(out, ctx)) goto err; (void)BIO_flush(out); message(out, "BN_GF2m_mod_solve_quad"); if (!test_gf2m_mod_solve_quad(out, ctx)) goto err; (void)BIO_flush(out); #endif BN_CTX_free(ctx); BIO_free(out); exit(0); err: BIO_puts(out,"1\n"); /* make sure the Perl script fed by bc notices * the failure, see test_bn in test/Makefile.ssl*/ (void)BIO_flush(out); ERR_load_crypto_strings(); ERR_print_errors_fp(stderr); exit(1); }
int main(int argc, char *argv[]) { BN_CTX *ctx; BIO *out; char *outfile=NULL; results = 0; RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */ argc--; argv++; while (argc >= 1) { if (strcmp(*argv,"-results") == 0) results=1; else if (strcmp(*argv,"-out") == 0) { if (--argc < 1) break; outfile= *(++argv); } argc--; argv++; } ctx=BN_CTX_new(); if (ctx == NULL) EXIT(1); out=BIO_new(BIO_s_file()); if (out == NULL) EXIT(1); if (outfile == NULL) { BIO_set_fp(out,stdout,BIO_NOCLOSE); } else { if (!BIO_write_filename(out,outfile)) { perror(outfile); EXIT(1); } } if (!results) BIO_puts(out,"obase=16\nibase=16\n"); message(out,"BN_add"); if (!test_add(out)) goto err; BIO_flush(out); message(out,"BN_sub"); if (!test_sub(out)) goto err; BIO_flush(out); message(out,"BN_lshift1"); if (!test_lshift1(out)) goto err; BIO_flush(out); message(out,"BN_lshift (fixed)"); if (!test_lshift(out,ctx,BN_bin2bn(lst,sizeof(lst)-1,NULL))) goto err; BIO_flush(out); message(out,"BN_lshift"); if (!test_lshift(out,ctx,NULL)) goto err; BIO_flush(out); message(out,"BN_rshift1"); if (!test_rshift1(out)) goto err; BIO_flush(out); message(out,"BN_rshift"); if (!test_rshift(out,ctx)) goto err; BIO_flush(out); message(out,"BN_sqr"); if (!test_sqr(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mul"); if (!test_mul(out)) goto err; BIO_flush(out); message(out,"BN_div"); if (!test_div(out,ctx)) goto err; BIO_flush(out); message(out,"BN_div_recp"); if (!test_div_recp(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod"); if (!test_mod(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod_mul"); if (!test_mod_mul(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mont"); if (!test_mont(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod_exp"); if (!test_mod_exp(out,ctx)) goto err; BIO_flush(out); message(out,"BN_exp"); if (!test_exp(out,ctx)) goto err; BIO_flush(out); message(out,"BN_kronecker"); if (!test_kron(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod_sqrt"); if (!test_sqrt(out,ctx)) goto err; BIO_flush(out); BN_CTX_free(ctx); BIO_free(out); /**/ EXIT(0); err: BIO_puts(out,"1\n"); /* make sure the Perl script fed by bc notices * the failure, see test_bn in test/Makefile.ssl*/ BIO_flush(out); ERR_load_crypto_strings(); ERR_print_errors_fp(stderr); EXIT(1); return(1); }