bn_mp_lshd.cGo to the documentation of this file.00001 #include <tommath.h> 00002 #ifdef BN_MP_LSHD_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 /* shift left a certain amount of digits */ 00019 int mp_lshd (mp_int * a, int b) 00020 { 00021 int x, res; 00022 00023 /* if its less than zero return */ 00024 if (b <= 0) { 00025 return MP_OKAY; 00026 } 00027 00028 /* grow to fit the new digits */ 00029 if (a->alloc < a->used + b) { 00030 if ((res = mp_grow (a, a->used + b)) != MP_OKAY) { 00031 return res; 00032 } 00033 } 00034 00035 { 00036 register mp_digit *top, *bottom; 00037 00038 /* increment the used by the shift amount then copy upwards */ 00039 a->used += b; 00040 00041 /* top */ 00042 top = a->dp + a->used - 1; 00043 00044 /* base */ 00045 bottom = a->dp + a->used - 1 - b; 00046 00047 /* much like mp_rshd this is implemented using a sliding window 00048 * except the window goes the otherway around. Copying from 00049 * the bottom to the top. see bn_mp_rshd.c for more info. 00050 */ 00051 for (x = a->used - 1; x >= b; x--) { 00052 *top-- = *bottom--; 00053 } 00054 00055 /* zero the lower digits */ 00056 top = a->dp; 00057 for (x = 0; x < b; x++) { 00058 *top++ = 0; 00059 } 00060 } 00061 return MP_OKAY; 00062 } 00063 #endif 00064 00065 /* $Source: /cvsroot/tcl/libtommath/bn_mp_lshd.c,v $ */ 00066 /* $Revision: 1.1.1.3 $ */ 00067 /* $Date: 2006/12/01 00:08:11 $ */
Generated on Wed Mar 12 12:18:24 2008 by 1.5.1 |