security/nss/lib/freebl/mpi/tests/mptest-2.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/freebl/mpi/tests/mptest-2.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +/*
     1.5 + * Simple test driver for MPI library
     1.6 + *
     1.7 + * Test 2: Basic addition and subtraction test
     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 +
    1.19 +#include "mpi.h"
    1.20 +
    1.21 +int main(int argc, char *argv[])
    1.22 +{
    1.23 +  mp_int a, b, c;
    1.24 +
    1.25 +  if(argc < 3) {
    1.26 +    fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
    1.27 +    return 1;
    1.28 +  }
    1.29 +
    1.30 +  printf("Test 2: Basic addition and subtraction\n\n");
    1.31 +
    1.32 +  mp_init(&a);
    1.33 +  mp_init(&b);
    1.34 +
    1.35 +  mp_read_radix(&a, argv[1], 10);
    1.36 +  mp_read_radix(&b, argv[2], 10);
    1.37 +  printf("a = "); mp_print(&a, stdout); fputc('\n', stdout);
    1.38 +  printf("b = "); mp_print(&b, stdout); fputc('\n', stdout);
    1.39 +  
    1.40 +  mp_init(&c);
    1.41 +  printf("c = a + b\n");
    1.42 +
    1.43 +  mp_add(&a, &b, &c);
    1.44 +  printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.45 +  
    1.46 +  printf("c = a - b\n");
    1.47 +  
    1.48 +  mp_sub(&a, &b, &c);
    1.49 +  printf("c = "); mp_print(&c, stdout); fputc('\n', stdout);  
    1.50 +
    1.51 +  mp_clear(&c);
    1.52 +  mp_clear(&b);
    1.53 +  mp_clear(&a);
    1.54 +
    1.55 +  return 0;
    1.56 +}

mercurial