security/nss/lib/freebl/mpi/tests/mptest-9.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-9.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/*
     1.5 + *    mptest-9.c
     1.6 + *
     1.7 + *   Test logical functions
     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 +#include "mpi.h"
    1.21 +#include "mplogic.h"
    1.22 +
    1.23 +int main(int argc, char *argv[])
    1.24 +{
    1.25 +  mp_int    a, b, c;
    1.26 +  int       pco;
    1.27 +  mp_err    res;
    1.28 +
    1.29 +  printf("Test 9: Logical functions\n\n");
    1.30 +
    1.31 +  if(argc < 3) {
    1.32 +    fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
    1.33 +    return 1;
    1.34 +  }
    1.35 +
    1.36 +  mp_init(&a); mp_init(&b); mp_init(&c);
    1.37 +  mp_read_radix(&a, argv[1], 16);
    1.38 +  mp_read_radix(&b, argv[2], 16);
    1.39 +
    1.40 +  printf("a       = "); mp_print(&a, stdout); fputc('\n', stdout);
    1.41 +  printf("b       = "); mp_print(&b, stdout); fputc('\n', stdout);
    1.42 +
    1.43 +  mpl_not(&a, &c);
    1.44 +  printf("~a      = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.45 +
    1.46 +  mpl_and(&a, &b, &c);
    1.47 +  printf("a & b   = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.48 +
    1.49 +  mpl_or(&a, &b, &c);
    1.50 +  printf("a | b   = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.51 +
    1.52 +  mpl_xor(&a, &b, &c);
    1.53 +  printf("a ^ b   = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.54 +
    1.55 +  mpl_rsh(&a, &c, 1);
    1.56 +  printf("a >>  1 = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.57 +  mpl_rsh(&a, &c, 5);
    1.58 +  printf("a >>  5 = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.59 +  mpl_rsh(&a, &c, 16);
    1.60 +  printf("a >> 16 = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.61 +
    1.62 +  mpl_lsh(&a, &c, 1);
    1.63 +  printf("a <<  1 = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.64 +  mpl_lsh(&a, &c, 5);
    1.65 +  printf("a <<  5 = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.66 +  mpl_lsh(&a, &c, 16);
    1.67 +  printf("a << 16 = "); mp_print(&c, stdout); fputc('\n', stdout);
    1.68 +
    1.69 +  mpl_num_set(&a, &pco);
    1.70 +  printf("population(a) = %d\n", pco);
    1.71 +  mpl_num_set(&b, &pco);
    1.72 +  printf("population(b) = %d\n", pco);
    1.73 +
    1.74 +  res = mpl_parity(&a);
    1.75 +  if(res == MP_EVEN)
    1.76 +    printf("a has even parity\n");
    1.77 +  else
    1.78 +    printf("a has odd parity\n");
    1.79 +  
    1.80 +  mp_clear(&c);
    1.81 +  mp_clear(&b);
    1.82 +  mp_clear(&a);
    1.83 +
    1.84 +  return 0;
    1.85 +}
    1.86 +

mercurial