bn_mp_mod_2d.cGo to the documentation of this file.00001 #include <tommath.h> 00002 #ifdef BN_MP_MOD_2D_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 /* calc a value mod 2**b */ 00019 int 00020 mp_mod_2d (mp_int * a, int b, mp_int * c) 00021 { 00022 int x, res; 00023 00024 /* if b is <= 0 then zero the int */ 00025 if (b <= 0) { 00026 mp_zero (c); 00027 return MP_OKAY; 00028 } 00029 00030 /* if the modulus is larger than the value than return */ 00031 if (b >= (int) (a->used * DIGIT_BIT)) { 00032 res = mp_copy (a, c); 00033 return res; 00034 } 00035 00036 /* copy */ 00037 if ((res = mp_copy (a, c)) != MP_OKAY) { 00038 return res; 00039 } 00040 00041 /* zero digits above the last digit of the modulus */ 00042 for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) { 00043 c->dp[x] = 0; 00044 } 00045 /* clear the digit that is not completely outside/inside the modulus */ 00046 c->dp[b / DIGIT_BIT] &= 00047 (mp_digit) ((((mp_digit) 1) << (((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1)); 00048 mp_clamp (c); 00049 return MP_OKAY; 00050 } 00051 #endif 00052 00053 /* $Source: /cvsroot/tcl/libtommath/bn_mp_mod_2d.c,v $ */ 00054 /* $Revision: 1.1.1.3 $ */ 00055 /* $Date: 2006/12/01 00:08:11 $ */
Generated on Wed Mar 12 12:18:24 2008 by 1.5.1 |