1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/freebl/mpi/tests/mptest-7.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* 1.5 + * Simple test driver for MPI library 1.6 + * 1.7 + * Test 7: Random and divisibility tests 1.8 + * 1.9 + * This Source Code Form is subject to the terms of the Mozilla Public 1.10 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.11 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.12 + 1.13 +#include <stdio.h> 1.14 +#include <stdlib.h> 1.15 +#include <string.h> 1.16 +#include <ctype.h> 1.17 +#include <limits.h> 1.18 +#include <time.h> 1.19 + 1.20 +#define MP_IOFUNC 1 1.21 +#include "mpi.h" 1.22 + 1.23 +#include "mpprime.h" 1.24 + 1.25 +int main(int argc, char *argv[]) 1.26 +{ 1.27 + mp_digit num; 1.28 + mp_int a, b; 1.29 + 1.30 + srand(time(NULL)); 1.31 + 1.32 + if(argc < 3) { 1.33 + fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]); 1.34 + return 1; 1.35 + } 1.36 + 1.37 + printf("Test 7: Random & divisibility tests\n\n"); 1.38 + 1.39 + mp_init(&a); 1.40 + mp_init(&b); 1.41 + 1.42 + mp_read_radix(&a, argv[1], 10); 1.43 + mp_read_radix(&b, argv[2], 10); 1.44 + 1.45 + printf("a = "); mp_print(&a, stdout); fputc('\n', stdout); 1.46 + printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); 1.47 + 1.48 + if(mpp_divis(&a, &b) == MP_YES) 1.49 + printf("a is divisible by b\n"); 1.50 + else 1.51 + printf("a is not divisible by b\n"); 1.52 + 1.53 + if(mpp_divis(&b, &a) == MP_YES) 1.54 + printf("b is divisible by a\n"); 1.55 + else 1.56 + printf("b is not divisible by a\n"); 1.57 + 1.58 + printf("\nb = mpp_random()\n"); 1.59 + mpp_random(&b); 1.60 + printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); 1.61 + mpp_random(&b); 1.62 + printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); 1.63 + mpp_random(&b); 1.64 + printf("b = "); mp_print(&b, stdout); fputc('\n', stdout); 1.65 + 1.66 + printf("\nTesting a for divisibility by first 170 primes\n"); 1.67 + num = 170; 1.68 + if(mpp_divis_primes(&a, &num) == MP_YES) 1.69 + printf("It is divisible by at least one of them\n"); 1.70 + else 1.71 + printf("It is not divisible by any of them\n"); 1.72 + 1.73 + mp_clear(&b); 1.74 + mp_clear(&a); 1.75 + 1.76 + return 0; 1.77 +}