bn_mp_and.c

Go to the documentation of this file.
00001 #include <tommath.h>
00002 #ifdef BN_MP_AND_C
00003 /* LibTomMath, multiple-precision integer library -- Tom St Denis
00004  *
00005  * LibTomMath is a library that provides multiple-precision
00006  * integer arithmetic as well as number theoretic functionality.
00007  *
00008  * The library was designed directly after the MPI library by
00009  * Michael Fromberger but has been written from scratch with
00010  * additional optimizations in place.
00011  *
00012  * The library is free for all purposes without any express
00013  * guarantee it works.
00014  *
00015  * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
00016  */
00017 
00018 /* AND two ints together */
00019 int
00020 mp_and (mp_int * a, mp_int * b, mp_int * c)
00021 {
00022   int     res, ix, px;
00023   mp_int  t, *x;
00024 
00025   if (a->used > b->used) {
00026     if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
00027       return res;
00028     }
00029     px = b->used;
00030     x = b;
00031   } else {
00032     if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
00033       return res;
00034     }
00035     px = a->used;
00036     x = a;
00037   }
00038 
00039   for (ix = 0; ix < px; ix++) {
00040     t.dp[ix] &= x->dp[ix];
00041   }
00042 
00043   /* zero digits above the last from the smallest mp_int */
00044   for (; ix < t.used; ix++) {
00045     t.dp[ix] = 0;
00046   }
00047 
00048   mp_clamp (&t);
00049   mp_exch (c, &t);
00050   mp_clear (&t);
00051   return MP_OKAY;
00052 }
00053 #endif
00054 
00055 /* $Source: /cvsroot/tcl/libtommath/bn_mp_and.c,v $ */
00056 /* $Revision: 1.1.1.3 $ */
00057 /* $Date: 2006/12/01 00:08:11 $ */



Generated on Wed Mar 12 12:18:24 2008 by  doxygen 1.5.1