security/nss/lib/freebl/mpi/utils/lap.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  *  lap.c
     3  *
     4  *  Find least annihilating power of a mod m
     5  *
     6  * This Source Code Form is subject to the terms of the Mozilla Public
     7  * License, v. 2.0. If a copy of the MPL was not distributed with this
     8  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    10 #include <stdio.h>
    11 #include <stdlib.h>
    12 #include <signal.h>
    14 #include "mpi.h"
    16 void sig_catch(int ign);
    18 int g_quit = 0;
    20 int main(int argc, char *argv[])
    21 {
    22   mp_int   a, m, p, k;
    24   if(argc < 3) {
    25     fprintf(stderr, "Usage: %s <a> <m>\n", argv[0]);
    26     return 1;
    27   }
    29   mp_init(&a);
    30   mp_init(&m);
    31   mp_init(&p);
    32   mp_add_d(&p, 1, &p);
    34   mp_read_radix(&a, argv[1], 10);
    35   mp_read_radix(&m, argv[2], 10);
    37   mp_init_copy(&k, &a);
    39   signal(SIGINT, sig_catch);
    40 #ifndef __OS2__
    41   signal(SIGHUP, sig_catch);
    42 #endif
    43   signal(SIGTERM, sig_catch);
    45   while(mp_cmp(&p, &m) < 0) {
    46     if(g_quit) {
    47 	int  len;
    48 	char *buf;
    50 	len = mp_radix_size(&p, 10);
    51 	buf = malloc(len);
    52 	mp_toradix(&p, buf, 10);
    54 	fprintf(stderr, "Terminated at: %s\n", buf);
    55 	free(buf);
    56 	return 1;
    57     }
    58     if(mp_cmp_d(&k, 1) == 0) {
    59       int    len;
    60       char  *buf;
    62       len = mp_radix_size(&p, 10);
    63       buf = malloc(len);
    64       mp_toradix(&p, buf, 10);
    66       printf("%s\n", buf);
    68       free(buf);
    69       break;
    70     }
    72     mp_mulmod(&k, &a, &m, &k);
    73     mp_add_d(&p, 1, &p);
    74   }
    76   if(mp_cmp(&p, &m) >= 0) 
    77     printf("No annihilating power.\n");
    79   mp_clear(&p);
    80   mp_clear(&m);
    81   mp_clear(&a);
    82   return 0;
    83 }
    85 void sig_catch(int ign)
    86 {
    87   g_quit = 1;
    88 }

mercurial