legacy_test.c (160786) | legacy_test.c (189092) |
---|---|
1/*- 2 * Copyright (c) 2006, Simon L. Nielsen <simon@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 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 24 * SUCH DAMAGE. 25 * 26 */ 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006, Simon L. Nielsen <simon@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 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 24 * SUCH DAMAGE. 25 * 26 */ 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/tools/regression/lib/libmp/test-libmp.c 160786 2006-07-28 16:00:59Z simon $"); | 28__FBSDID("$FreeBSD: head/tools/regression/lib/libmp/test-libmp.c 189092 2009-02-26 21:43:15Z ed $"); |
29 30#include <mp.h> 31#include <stdio.h> 32#include <string.h> 33#include <sysexits.h> 34 35MINT *c0, *c1, *c2, *c3, *c5, *c6, *c8, *c10, *c14, *c15, *c25, \ 36 *c42,*c43, *c44, *c45, *t0, *t1; 37static int tnr = 0; 38 39static void 40testmcmp(const MINT *mp1, const MINT *mp2, const char *tname) 41{ 42 | 29 30#include <mp.h> 31#include <stdio.h> 32#include <string.h> 33#include <sysexits.h> 34 35MINT *c0, *c1, *c2, *c3, *c5, *c6, *c8, *c10, *c14, *c15, *c25, \ 36 *c42,*c43, *c44, *c45, *t0, *t1; 37static int tnr = 0; 38 39static void 40testmcmp(const MINT *mp1, const MINT *mp2, const char *tname) 41{ 42 |
43 if (mcmp(mp1, mp2) == 0) | 43 if (mp_mcmp(mp1, mp2) == 0) |
44 printf("ok %d - %s\n", ++tnr, tname); 45 else 46 printf("not ok - %d %s\n", ++tnr, tname); 47} 48 49static int 50testsimpel(void) 51{ 52 const char str42[] = "2a"; 53 MINT *t2; 54 char *s; 55 | 44 printf("ok %d - %s\n", ++tnr, tname); 45 else 46 printf("not ok - %d %s\n", ++tnr, tname); 47} 48 49static int 50testsimpel(void) 51{ 52 const char str42[] = "2a"; 53 MINT *t2; 54 char *s; 55 |
56 madd(c42, c1, t0); | 56 mp_madd(c42, c1, t0); |
57 testmcmp(c43, t0, "madd0"); | 57 testmcmp(c43, t0, "madd0"); |
58 madd(t0, c1, t0); | 58 mp_madd(t0, c1, t0); |
59 testmcmp(c44, t0, "madd1"); | 59 testmcmp(c44, t0, "madd1"); |
60 msub(t0, c1, t0); | 60 mp_msub(t0, c1, t0); |
61 testmcmp(c43, t0, "msub0"); | 61 testmcmp(c43, t0, "msub0"); |
62 msub(t0, c1, t0); | 62 mp_msub(t0, c1, t0); |
63 testmcmp(c42, t0, "msub1"); | 63 testmcmp(c42, t0, "msub1"); |
64 move(c42, t0); | 64 mp_move(c42, t0); |
65 testmcmp(c42, t0, "move0"); 66 | 65 testmcmp(c42, t0, "move0"); 66 |
67 t2 = xtom(str42); | 67 t2 = mp_xtom(str42); |
68 testmcmp(c42, t2, "xtom"); | 68 testmcmp(c42, t2, "xtom"); |
69 s = mtox(t2); | 69 s = mp_mtox(t2); |
70 if (strcmp(str42, s) == 0) 71 printf("ok %d - %s\n", ++tnr, "mtox0"); 72 else 73 printf("not ok %d - %s\n", ++tnr, "mtox0"); | 70 if (strcmp(str42, s) == 0) 71 printf("ok %d - %s\n", ++tnr, "mtox0"); 72 else 73 printf("not ok %d - %s\n", ++tnr, "mtox0"); |
74 mfree(t2); | 74 mp_mfree(t2); |
75} 76 77static int 78testgcd(void) 79{ 80 | 75} 76 77static int 78testgcd(void) 79{ 80 |
81 gcd(c10, c15, t0); | 81 mp_gcd(c10, c15, t0); |
82 testmcmp(t0, c5, "gcd0"); 83} 84 85static int 86testmsqrt(void) 87{ 88 | 82 testmcmp(t0, c5, "gcd0"); 83} 84 85static int 86testmsqrt(void) 87{ 88 |
89 msqrt(c25, t0, t1); | 89 mp_msqrt(c25, t0, t1); |
90 testmcmp(t0, c5, "msqrt0"); 91 testmcmp(t1, c0, "msqrt1"); | 90 testmcmp(t0, c5, "msqrt0"); 91 testmcmp(t1, c0, "msqrt1"); |
92 msqrt(c42, t0, t1); | 92 mp_msqrt(c42, t0, t1); |
93 testmcmp(t0, c6, "msqrt2"); 94 testmcmp(t1, c6, "msqrt3"); 95} 96 97static int 98testdiv(void) 99{ 100 short ro; 101 MINT *t2; 102 | 93 testmcmp(t0, c6, "msqrt2"); 94 testmcmp(t1, c6, "msqrt3"); 95} 96 97static int 98testdiv(void) 99{ 100 short ro; 101 MINT *t2; 102 |
103 mdiv(c42, c5, t0, t1); | 103 mp_mdiv(c42, c5, t0, t1); |
104 testmcmp(t0, c8, "mdiv0"); 105 testmcmp(t1, c2, "mdiv1"); 106 | 104 testmcmp(t0, c8, "mdiv0"); 105 testmcmp(t1, c2, "mdiv1"); 106 |
107 mdiv(c10, c8, t0, t1); | 107 mp_mdiv(c10, c8, t0, t1); |
108 testmcmp(t0, c1, "mdiv2"); 109 testmcmp(t1, c2, "mdiv3"); 110 | 108 testmcmp(t0, c1, "mdiv2"); 109 testmcmp(t1, c2, "mdiv3"); 110 |
111 sdiv(c42, 5, t0, &ro); | 111 mp_sdiv(c42, 5, t0, &ro); |
112 testmcmp(t0, c8, "sdiv0"); | 112 testmcmp(t0, c8, "sdiv0"); |
113 t2 = itom(ro); // Simpler to use common testmcmp() | 113 t2 = mp_itom(ro); // Simpler to use common testmcmp() |
114 testmcmp(t2, c2, "sdiv1"); | 114 testmcmp(t2, c2, "sdiv1"); |
115 mfree(t2); | 115 mp_mfree(t2); |
116 | 116 |
117 sdiv(c10, 8, t0, &ro); | 117 mp_sdiv(c10, 8, t0, &ro); |
118 testmcmp(t0, c1, "sdiv2"); | 118 testmcmp(t0, c1, "sdiv2"); |
119 t2 = itom(ro); // Simpler to use common testmcmp() | 119 t2 = mp_itom(ro); // Simpler to use common testmcmp() |
120 testmcmp(t2, c2, "sdiv3"); | 120 testmcmp(t2, c2, "sdiv3"); |
121 mfree(t2); | 121 mp_mfree(t2); |
122} 123 124static int 125testmult(void) 126{ 127 | 122} 123 124static int 125testmult(void) 126{ 127 |
128 mult(c5, c2, t0); | 128 mp_mult(c5, c2, t0); |
129 testmcmp(t0, c10, "mmult0"); | 129 testmcmp(t0, c10, "mmult0"); |
130 mult(c3, c14, t0); | 130 mp_mult(c3, c14, t0); |
131 testmcmp(t0, c42, "mmult1"); 132} 133 134static int 135testpow(void) 136{ 137 | 131 testmcmp(t0, c42, "mmult1"); 132} 133 134static int 135testpow(void) 136{ 137 |
138 pow(c2, c3, c10, t0); | 138 mp_pow(c2, c3, c10, t0); |
139 testmcmp(t0, c8, "pow0"); | 139 testmcmp(t0, c8, "pow0"); |
140 pow(c2, c3, c3, t0); | 140 mp_pow(c2, c3, c3, t0); |
141 testmcmp(t0, c2, "pow1"); | 141 testmcmp(t0, c2, "pow1"); |
142 rpow(c2, 3, t0); | 142 mp_rpow(c2, 3, t0); |
143 testmcmp(t0, c8, "rpow0"); 144} 145 146/* 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. --- 4 unchanged lines hidden (view full) --- 155 156 printf("1..25\n"); 157 158 /* 159 * Init "constants" variables - done in this somewhat 160 * cumbersome way to in theory be able to check for memory 161 * leaks. 162 */ | 143 testmcmp(t0, c8, "rpow0"); 144} 145 146/* 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. --- 4 unchanged lines hidden (view full) --- 155 156 printf("1..25\n"); 157 158 /* 159 * Init "constants" variables - done in this somewhat 160 * cumbersome way to in theory be able to check for memory 161 * leaks. 162 */ |
163 c0 = itom(0); 164 c1 = itom(1); 165 c2 = itom(2); 166 c3 = itom(3); 167 c5 = itom(5); 168 c6 = itom(6); 169 c8 = itom(8); 170 c10 = itom(10); 171 c14 = itom(14); 172 c15 = itom(15); 173 c25 = itom(25); 174 c42 = itom(42); 175 c43 = itom(43); 176 c44 = itom(44); 177 c45 = itom(45); | 163 c0 = mp_itom(0); 164 c1 = mp_itom(1); 165 c2 = mp_itom(2); 166 c3 = mp_itom(3); 167 c5 = mp_itom(5); 168 c6 = mp_itom(6); 169 c8 = mp_itom(8); 170 c10 = mp_itom(10); 171 c14 = mp_itom(14); 172 c15 = mp_itom(15); 173 c25 = mp_itom(25); 174 c42 = mp_itom(42); 175 c43 = mp_itom(43); 176 c44 = mp_itom(44); 177 c45 = mp_itom(45); |
178 179 // Init temp variables | 178 179 // Init temp variables |
180 t0 = itom(0); 181 t1 = itom(0); | 180 t0 = mp_itom(0); 181 t1 = mp_itom(0); |
182 183 // Run tests 184 testsimpel(); 185 testgcd(); 186 testdiv(); 187 testmult(); 188 testpow(); 189 testmsqrt(); 190 191 // Cleanup | 182 183 // Run tests 184 testsimpel(); 185 testgcd(); 186 testdiv(); 187 testmult(); 188 testpow(); 189 testmsqrt(); 190 191 // Cleanup |
192 mfree(c0); 193 mfree(c1); 194 mfree(c2); 195 mfree(c3); 196 mfree(c5); 197 mfree(c6); 198 mfree(c8); 199 mfree(c10); 200 mfree(c14); 201 mfree(c15); 202 mfree(c25); 203 mfree(c42); 204 mfree(c43); 205 mfree(c44); 206 mfree(c45); 207 mfree(t0); 208 mfree(t1); | 192 mp_mfree(c0); 193 mp_mfree(c1); 194 mp_mfree(c2); 195 mp_mfree(c3); 196 mp_mfree(c5); 197 mp_mfree(c6); 198 mp_mfree(c8); 199 mp_mfree(c10); 200 mp_mfree(c14); 201 mp_mfree(c15); 202 mp_mfree(c25); 203 mp_mfree(c42); 204 mp_mfree(c43); 205 mp_mfree(c44); 206 mp_mfree(c45); 207 mp_mfree(t0); 208 mp_mfree(t1); |
209 210 return (EX_OK); 211} | 209 210 return (EX_OK); 211} |