blob: d6c108d47a7068f2f278993dbc7caecc3f0242a3 [file] [log] [blame]
Austin Schuhdace2a62020-08-18 10:56:48 -07001/*
2
3Copyright 2012, Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library test suite.
6
7The GNU MP Library test suite is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 3 of the License,
10or (at your option) any later version.
11
12The GNU MP Library test suite is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15Public License for more details.
16
17You should have received a copy of the GNU General Public License along with
18the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
19
20#include <limits.h>
21#include <stdlib.h>
22#include <stdio.h>
23
24#include "testutils.h"
25
26#define MAXBITS 400
27#define COUNT 1000
28
29void
30testmain (int argc, char **argv)
31{
32 unsigned i;
33 mpz_t b, e, m, res, ref;
34
35 mpz_init (b);
36 mpz_init (e);
37 mpz_init (m);
38 mpz_init (res);
39 mpz_init (ref);
40
41 for (i = 0; i < COUNT; i++)
42 {
43 mini_random_op4 (OP_POWM, MAXBITS, b, e, m, ref);
44 mpz_powm (res, b, e, m);
45 if (mpz_cmp (res, ref))
46 {
47 fprintf (stderr, "mpz_powm failed:\n");
48 dump ("b", b);
49 dump ("e", e);
50 dump ("m", m);
51 dump ("r", res);
52 dump ("ref", ref);
53 abort ();
54 }
55 }
56 mpz_clear (b);
57 mpz_clear (e);
58 mpz_clear (m);
59 mpz_clear (res);
60 mpz_clear (ref);
61}