bn_mp_copy.cGo to the documentation of this file.00001 #include <tommath.h> 00002 #ifdef BN_MP_COPY_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 /* copy, b = a */ 00019 int 00020 mp_copy (mp_int * a, mp_int * b) 00021 { 00022 int res, n; 00023 00024 /* if dst == src do nothing */ 00025 if (a == b) { 00026 return MP_OKAY; 00027 } 00028 00029 /* grow dest */ 00030 if (b->alloc < a->used) { 00031 if ((res = mp_grow (b, a->used)) != MP_OKAY) { 00032 return res; 00033 } 00034 } 00035 00036 /* zero b and copy the parameters over */ 00037 { 00038 register mp_digit *tmpa, *tmpb; 00039 00040 /* pointer aliases */ 00041 00042 /* source */ 00043 tmpa = a->dp; 00044 00045 /* destination */ 00046 tmpb = b->dp; 00047 00048 /* copy all the digits */ 00049 for (n = 0; n < a->used; n++) { 00050 *tmpb++ = *tmpa++; 00051 } 00052 00053 /* clear high digits */ 00054 for (; n < b->used; n++) { 00055 *tmpb++ = 0; 00056 } 00057 } 00058 00059 /* copy used count and sign */ 00060 b->used = a->used; 00061 b->sign = a->sign; 00062 return MP_OKAY; 00063 } 00064 #endif 00065 00066 /* $Source: /cvsroot/tcl/libtommath/bn_mp_copy.c,v $ */ 00067 /* $Revision: 1.1.1.3 $ */ 00068 /* $Date: 2006/12/01 00:08:11 $ */
Generated on Wed Mar 12 12:18:24 2008 by 1.5.1 |