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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  *    mptest-9.c
     3  *
     4  *   Test logical functions
     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 <string.h>
    13 #include <ctype.h>
    14 #include <limits.h>
    15 #include <time.h>
    17 #include "mpi.h"
    18 #include "mplogic.h"
    20 int main(int argc, char *argv[])
    21 {
    22   mp_int    a, b, c;
    23   int       pco;
    24   mp_err    res;
    26   printf("Test 9: Logical functions\n\n");
    28   if(argc < 3) {
    29     fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
    30     return 1;
    31   }
    33   mp_init(&a); mp_init(&b); mp_init(&c);
    34   mp_read_radix(&a, argv[1], 16);
    35   mp_read_radix(&b, argv[2], 16);
    37   printf("a       = "); mp_print(&a, stdout); fputc('\n', stdout);
    38   printf("b       = "); mp_print(&b, stdout); fputc('\n', stdout);
    40   mpl_not(&a, &c);
    41   printf("~a      = "); mp_print(&c, stdout); fputc('\n', stdout);
    43   mpl_and(&a, &b, &c);
    44   printf("a & b   = "); mp_print(&c, stdout); fputc('\n', stdout);
    46   mpl_or(&a, &b, &c);
    47   printf("a | b   = "); mp_print(&c, stdout); fputc('\n', stdout);
    49   mpl_xor(&a, &b, &c);
    50   printf("a ^ b   = "); mp_print(&c, stdout); fputc('\n', stdout);
    52   mpl_rsh(&a, &c, 1);
    53   printf("a >>  1 = "); mp_print(&c, stdout); fputc('\n', stdout);
    54   mpl_rsh(&a, &c, 5);
    55   printf("a >>  5 = "); mp_print(&c, stdout); fputc('\n', stdout);
    56   mpl_rsh(&a, &c, 16);
    57   printf("a >> 16 = "); mp_print(&c, stdout); fputc('\n', stdout);
    59   mpl_lsh(&a, &c, 1);
    60   printf("a <<  1 = "); mp_print(&c, stdout); fputc('\n', stdout);
    61   mpl_lsh(&a, &c, 5);
    62   printf("a <<  5 = "); mp_print(&c, stdout); fputc('\n', stdout);
    63   mpl_lsh(&a, &c, 16);
    64   printf("a << 16 = "); mp_print(&c, stdout); fputc('\n', stdout);
    66   mpl_num_set(&a, &pco);
    67   printf("population(a) = %d\n", pco);
    68   mpl_num_set(&b, &pco);
    69   printf("population(b) = %d\n", pco);
    71   res = mpl_parity(&a);
    72   if(res == MP_EVEN)
    73     printf("a has even parity\n");
    74   else
    75     printf("a has odd parity\n");
    77   mp_clear(&c);
    78   mp_clear(&b);
    79   mp_clear(&a);
    81   return 0;
    82 }

mercurial