- 925D35158574838825AEE8B2269787E17FA2F3C3FC6BC6929EF573BBA3B1477F157FB9F162E627B13C5E60F02D6BEFCCCE395123FC061F8F2317173BD5CE8DC4
+ 0EB9FD7240D16B287C06A319D1D170AEA9AA046B4F443FF1339F509D8E7B42317425FD369CEDB6E7E3D898700BA917B0B56A83305D730A5CD7D5BD09F4809986
eucrypt/smg_rsa/tests/tests.c
(1 . 6)(1 . 8)
262 #include "smg_rsa.h"
263 #include "mpi.h"
264
265 #include <stdlib.h>
266 #include <unistd.h>
267 #include <time.h>
268
269 void err(char *msg)
(28 . 19)(30 . 71)
271 printf("ENTROPY source timing: %d kB in %ld seconds, at an average speed of %f kB/s over %d runs of %d octets each\n", nruns*noctets, diff, kbps, nruns, noctets);
272 }
273
274 void test_is_composite(int nruns, char *hex_number, int expected) {
275 int i;
276 int output;
277 int count_ok = 0;
278 int source = open_entropy_source(ENTROPY_SOURCE);
279 MPI p = mpi_alloc(0);
280
281 mpi_fromstr(p, hex_number);
282 printf("TEST is_composite on MPI(hex) ");
283 mpi_print(stdout, p, 1);
284 for (i=0; i < nruns; i++) {
285 printf(".");
286 fflush(stdout);
287 output = is_composite(p, M_R_ITERATIONS, source);
288 if (output == expected)
289 count_ok = count_ok + 1;
290 }
291 printf("done, with %d out of %d correct runs for expected=%d: %s\n", count_ok, nruns, expected, count_ok==nruns? "PASS":"FAIL");
292 mpi_free(p);
293 close(source);
294 }
295
296 int main(int ac, char **av)
297 {
298 int nruns;
299 int id;
300
301 if (ac<2) {
302 printf("Usage: %s number_of_runs\n", av[0]);
303 printf("Usage: %s number_of_runs [testID]\n", av[0]);
304 return -1;
305 }
306 nruns = atoi(av[1]);
307
308 printf("Timing entropy source...\n");
309 time_entropy_source(nruns,4096);
310 if (ac < 3)
311 id = 0;
312 else
313 id = atoi(av[2]);
314
315 if (id == 0 || id == 1) {
316 printf("Timing entropy source...\n");
317 time_entropy_source(nruns,4096);
318 }
319
320 if (id == 0 || id == 2) {
321
322 /* a few primes (decimal): 65537, 116447, 411949103, 20943302231 */
323 test_is_composite(nruns, "0x10001", 0);
324 test_is_composite(nruns, "0x1C6DF", 0);
325 test_is_composite(nruns, "0x188DD82F", 0);
326 test_is_composite(nruns, "0x4E0516E57", 0);
327 /* a few mersenne primes (decimal): 2^13 - 1 = 8191, 2^17 - 1 = 131071, 2^31 - 1 = 2147483647 */
328 test_is_composite(nruns, "0x1FFF", 0);
329 test_is_composite(nruns, "0x1FFFF", 0);
330 test_is_composite(nruns, "0x7FFFFFFF", 0);
331 /* a few carmichael numbers, in decimal: 561, 60977817398996785 */
332 test_is_composite(nruns, "0x231", 1);
333 test_is_composite(nruns, "0xD8A300793EEF31", 1);
334 /* an even number */
335 test_is_composite(nruns, "0x15A9E672864B1E", 1);
336 /* a phuctor-found non-prime public exponent: 170141183460469231731687303715884105731 */
337 test_is_composite(nruns, "0x80000000000000000000000000000003", 1);
338 }
339
340 if (id > 2)
341 printf("Current test ids: 0 for all, 1 for entropy source test only, 2 for is_composite test only.");
342
343 return 0;
344 }