2 * Copyright (c) 2006, Simon L. Nielsen <simon@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
35 MINT *c0, *c1, *c2, *c3, *c5, *c6, *c8, *c10, *c14, *c15, *c25, \
36 *c42,*c43, *c44, *c45, *t0, *t1;
40 testmcmp(const MINT *mp1, const MINT *mp2, const char *tname)
43 if (mp_mcmp(mp1, mp2) == 0)
44 printf("ok %d - %s\n", ++tnr, tname);
46 printf("not ok - %d %s\n", ++tnr, tname);
52 const char str42[] = "2a";
57 testmcmp(c43, t0, "madd0");
59 testmcmp(c44, t0, "madd1");
61 testmcmp(c43, t0, "msub0");
63 testmcmp(c42, t0, "msub1");
65 testmcmp(c42, t0, "move0");
68 testmcmp(c42, t2, "xtom");
70 if (strcmp(str42, s) == 0)
71 printf("ok %d - %s\n", ++tnr, "mtox0");
73 printf("not ok %d - %s\n", ++tnr, "mtox0");
82 testmcmp(t0, c5, "gcd0");
89 mp_msqrt(c25, t0, t1);
90 testmcmp(t0, c5, "msqrt0");
91 testmcmp(t1, c0, "msqrt1");
92 mp_msqrt(c42, t0, t1);
93 testmcmp(t0, c6, "msqrt2");
94 testmcmp(t1, c6, "msqrt3");
103 mp_mdiv(c42, c5, t0, t1);
104 testmcmp(t0, c8, "mdiv0");
105 testmcmp(t1, c2, "mdiv1");
107 mp_mdiv(c10, c8, t0, t1);
108 testmcmp(t0, c1, "mdiv2");
109 testmcmp(t1, c2, "mdiv3");
111 mp_sdiv(c42, 5, t0, &ro);
112 testmcmp(t0, c8, "sdiv0");
113 t2 = mp_itom(ro); // Simpler to use common testmcmp()
114 testmcmp(t2, c2, "sdiv1");
117 mp_sdiv(c10, 8, t0, &ro);
118 testmcmp(t0, c1, "sdiv2");
119 t2 = mp_itom(ro); // Simpler to use common testmcmp()
120 testmcmp(t2, c2, "sdiv3");
129 testmcmp(t0, c10, "mmult0");
130 mp_mult(c3, c14, t0);
131 testmcmp(t0, c42, "mmult1");
138 mp_pow(c2, c3, c10, t0);
139 testmcmp(t0, c8, "pow0");
140 mp_pow(c2, c3, c3, t0);
141 testmcmp(t0, c2, "pow1");
143 testmcmp(t0, c8, "rpow0");
147 * This program performs some very basic tests of libmp(3). It is by
148 * no means expected to perform a complete test of the library for
149 * correctness, but is meant to test the API to make sure libmp (or
150 * libcrypto) updates don't totally break the library.
153 main(int argc, char *argv[])
159 * Init "constants" variables - done in this somewhat
160 * cumbersome way to in theory be able to check for memory
179 // Init temp variables